From 79edd8348052c0d14c2f4a2554d429572353612e Mon Sep 17 00:00:00 2001 From: Alan Antonuk Date: Thu, 1 Apr 2021 06:17:21 +0000 Subject: cmake: modernize how tests are enabled Note this changes the build option from BUILD_TESTS to BUILD_TESTING. Signed-off-by: GitHub --- CMakeLists.txt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'CMakeLists.txt') diff --git a/CMakeLists.txt b/CMakeLists.txt index bae759d..a9a29fd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -239,6 +239,9 @@ if (POPT_FOUND AND XmlTo_FOUND) set(DO_DOCS ON) endif() +if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) + include(CTest) +endif() option(BUILD_SHARED_LIBS "Build rabbitmq-c as a shared library" ON) option(BUILD_STATIC_LIBS "Build rabbitmq-c as a static library" ON) @@ -246,7 +249,6 @@ option(BUILD_STATIC_LIBS "Build rabbitmq-c as a static library" ON) option(BUILD_EXAMPLES "Build Examples" ON) option(BUILD_TOOLS "Build Tools (requires POPT Library)" ${POPT_FOUND}) option(BUILD_TOOLS_DOCS "Build man pages for Tools (requires xmlto)" ${DO_DOCS}) -option(BUILD_TESTS "Build tests (run tests with make test)" ON) option(BUILD_API_DOCS "Build Doxygen API docs" ${DOXYGEN_FOUND}) option(RUN_SYSTEM_TESTS "Run system tests (i.e. tests requiring an accessible RabbitMQ server instance on localhost)" OFF) @@ -270,15 +272,14 @@ if (BUILD_TOOLS) endif () endif () -if (BUILD_TESTS) +if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING) if (NOT BUILD_STATIC_LIBS) message(FATAL_ERROR "Tests can only be built against static libraries " "(set BUILD_STATIC_LIBS=ON)") endif () - enable_testing() add_subdirectory(tests) -endif (BUILD_TESTS) +endif () if (BUILD_API_DOCS) if (NOT DOXYGEN_FOUND) -- cgit v1.2.1