From b3ee613ad2e1f60c09127c0df5d7c5a7980e680e Mon Sep 17 00:00:00 2001 From: Claus Klein Date: Sun, 11 Mar 2018 15:07:08 +0100 Subject: [PATCH] CMakeLists.txt requires Gtest while testing use debug postfix like boost does --- CMakeLists.txt | 70 ++++++++++++++++++++++---------------------------- 1 file changed, 30 insertions(+), 40 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6091644..39d9b8c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,17 +50,6 @@ check_symbol_exists("sysconf" "unistd.h" HAVE_FUNC_SYSCONF) # set debug postfix a la boost set(CMAKE_DEBUG_POSTFIX "-d") -if(SNAPPY_BUILD_TESTS) - find_package(GTest) - if(GTEST_FOUND) - set(HAVE_GTEST 1) - endif(GTEST_FOUND) - - find_package(Gflags) - if(GFLAGS_FOUND) - set(HAVE_GFLAGS 1) - endif(GFLAGS_FOUND) -endif(SNAPPY_BUILD_TESTS) configure_file( "${PROJECT_SOURCE_DIR}/cmake/config.h.in" @@ -123,40 +112,41 @@ if(BUILD_SHARED_LIBS) set_target_properties(snappy PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON) endif(BUILD_SHARED_LIBS) -if(GTEST_FOUND OR GFLAGS_FOUND) - if(SNAPPY_BUILD_TESTS) - enable_testing() +if(SNAPPY_BUILD_TESTS) + find_package(GTest REQUIRED) + find_package(Gflags) + find_package(Threads) - add_executable(snappy_unittest "") - target_sources(snappy_unittest - PRIVATE - "${PROJECT_SOURCE_DIR}/snappy_unittest.cc" - "${PROJECT_SOURCE_DIR}/snappy-test.cc" - ) - target_compile_definitions(snappy_unittest PRIVATE -DHAVE_CONFIG_H) - target_link_libraries(snappy_unittest snappy ${GFLAGS_LIBRARIES} ${GTEST_LIBRARIES}) + enable_testing() - if(HAVE_LIBZ) - target_link_libraries(snappy_unittest z) - endif(HAVE_LIBZ) - if(HAVE_LIBLZO2) - target_link_libraries(snappy_unittest lzo2.a) - endif(HAVE_LIBLZO2) + add_executable(snappy_unittest "") + target_sources(snappy_unittest + PRIVATE + "${PROJECT_SOURCE_DIR}/snappy_unittest.cc" + "${PROJECT_SOURCE_DIR}/snappy-test.cc" + ) + target_compile_definitions(snappy_unittest PRIVATE -DHAVE_CONFIG_H) + target_link_libraries(snappy_unittest snappy ${GFLAGS_LIBRARIES} ${GTEST_LIBRARIES} ${THREADS_LIBRARIES}) - target_include_directories(snappy_unittest - BEFORE PRIVATE - "${PROJECT_SOURCE_DIR}" - "${GTEST_INCLUDE_DIRS}" - "${GFLAGS_INCLUDE_DIRS}" - ) + if(HAVE_LIBZ) + target_link_libraries(snappy_unittest z) + endif(HAVE_LIBZ) + if(HAVE_LIBLZO2) + target_link_libraries(snappy_unittest lzo2) + endif(HAVE_LIBLZO2) - add_test( - NAME snappy_unittest - WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}" - COMMAND "${PROJECT_BINARY_DIR}/snappy_unittest") - endif(SNAPPY_BUILD_TESTS) -endif(GTEST_FOUND OR GFLAGS_FOUND) + target_include_directories(snappy_unittest + BEFORE PRIVATE + "${PROJECT_SOURCE_DIR}" + "${GTEST_INCLUDE_DIRS}" + "${GFLAGS_INCLUDE_DIRS}" + ) + add_test( + NAME snappy_unittest + WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}" + COMMAND "${PROJECT_BINARY_DIR}/snappy_unittest") +endif(SNAPPY_BUILD_TESTS) include(GNUInstallDirs) install(TARGETS snappy