diff --git a/CMakeLists.txt b/CMakeLists.txt index 15e9a7c2..939d12b2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,6 +19,7 @@ option(INTROSPECTION "Build with introspection" OFF) option(LIB "System install" ON) option(STATIC_LIB OFF) option(DEBUG "Build with -g3" OFF) +option(TESTS "Build tests and perform their before install step" OFF) set(PIP_UTILS 1) if(LIBPROJECT) set(PIP_UTILS ${UTILS}) @@ -221,6 +222,10 @@ else() message(STATUS "Building PIP release version") endif() +if (TESTS) + include(DownloadGTest.cmake) + option(CONCURRENT_TESTS "Enable tests for concurrent library" ON) +endif() # Check if std::iostream operators support if(STD_IOSTREAM) @@ -487,7 +492,7 @@ if (NOT PIP_FREERTOS) list(APPEND PIP_LIBS_TARGETS pip_concurrent) # Enable build tests for concurrent module - if(CONCURRENT_TESTING) + if(CONCURRENT_TESTS) add_subdirectory(src_concurrent/test) endif() diff --git a/DownloadGTest.cmake b/DownloadGTest.cmake new file mode 100644 index 00000000..b6b9e5a5 --- /dev/null +++ b/DownloadGTest.cmake @@ -0,0 +1,31 @@ +# Download and unpack googletest at configure time +configure_file(GTestCMakeLists.txt.in googletest-download/CMakeLists.txt) +execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . + RESULT_VARIABLE result + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download ) +if(result) + message(FATAL_ERROR "CMake step for googletest failed: ${result}") +endif() +execute_process(COMMAND ${CMAKE_COMMAND} --build . + RESULT_VARIABLE result + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download ) +if(result) + message(FATAL_ERROR "Build step for googletest failed: ${result}") +endif() + +# Prevent overriding the parent project's compiler/linker +# settings on Windows +set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) + +# Add googletest directly to our build. This defines +# the gtest and gtest_main targets. +add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/googletest-src + ${CMAKE_CURRENT_BINARY_DIR}/googletest-build + EXCLUDE_FROM_ALL) + +# The gtest/gtest_main targets carry header search path +# dependencies automatically when using CMake 2.8.11 or +# later. Otherwise we have to add them here ourselves. +if (CMAKE_VERSION VERSION_LESS 2.8.11) + include_directories("${gtest_SOURCE_DIR}/include") +endif() \ No newline at end of file diff --git a/src_concurrent/test/CMakeLists.txt.in b/GTestCMakeLists.txt.in similarity index 100% rename from src_concurrent/test/CMakeLists.txt.in rename to GTestCMakeLists.txt.in diff --git a/src_concurrent/test/CMakeLists.txt b/src_concurrent/test/CMakeLists.txt index 3a120782..04f4206d 100644 --- a/src_concurrent/test/CMakeLists.txt +++ b/src_concurrent/test/CMakeLists.txt @@ -1,35 +1,4 @@ project(concurrent_test) -# Download and unpack googletest at configure time -configure_file(CMakeLists.txt.in googletest-download/CMakeLists.txt) -execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . - RESULT_VARIABLE result - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download ) -if(result) - message(FATAL_ERROR "CMake step for googletest failed: ${result}") -endif() -execute_process(COMMAND ${CMAKE_COMMAND} --build . - RESULT_VARIABLE result - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download ) -if(result) - message(FATAL_ERROR "Build step for googletest failed: ${result}") -endif() - -# Prevent overriding the parent project's compiler/linker -# settings on Windows -set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) - -# Add googletest directly to our build. This defines -# the gtest and gtest_main targets. -add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/googletest-src - ${CMAKE_CURRENT_BINARY_DIR}/googletest-build - EXCLUDE_FROM_ALL) - -# The gtest/gtest_main targets carry header search path -# dependencies automatically when using CMake 2.8.11 or -# later. Otherwise we have to add them here ourselves. -if (CMAKE_VERSION VERSION_LESS 2.8.11) - include_directories("${gtest_SOURCE_DIR}/include") -endif() file(GLOB_RECURSE CPPS "*.cpp") #find_package(GTest REQUIRED)