From dbd9a2606cce84e0793f1f5f39c47975a67b6845 Mon Sep 17 00:00:00 2001 From: redfish Date: Mon, 29 Aug 2016 12:12:19 -0400 Subject: [PATCH 1/3] cmake: tests: gtest target is not always defined #983 --- tests/CMakeLists.txt | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 33f5226ef..a3743d84c 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -28,6 +28,9 @@ # # Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers +# The docs say this only affects grouping in IDEs +set(folder "tests") + if (WIN32 AND STATIC) add_definitions(-DSTATICLIB) # miniupnp changed their static define @@ -52,6 +55,10 @@ else () PROPERTY COMPILE_FLAGS " -Wno-undef -Wno-sign-compare") endif() + + set_property(TARGET gtest gtest_main + PROPERTY + FOLDER "${folder}") endif () if (NOT DEFINED ENV{TRAVIS}) @@ -84,7 +91,7 @@ target_link_libraries(hash-target-tests cryptonote_core) set_property(TARGET hash-target-tests PROPERTY - FOLDER "tests") + FOLDER "${folder}") add_test( NAME hash-target @@ -97,4 +104,4 @@ else () add_custom_target(tests DEPENDS coretests difficulty hash performance_tests core_proxy unit_tests) endif () -set_property(TARGET gtest gtest_main hash-target-tests tests PROPERTY FOLDER "tests") +set_property(TARGET tests PROPERTY FOLDER "${folder}") From 4a9e94944c47c38c53967452efd83a7e4c2d4804 Mon Sep 17 00:00:00 2001 From: redfish Date: Mon, 29 Aug 2016 12:17:02 -0400 Subject: [PATCH 2/3] tests: cmake: use a list for enabled tests Avoid replicating common logic. --- tests/CMakeLists.txt | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index a3743d84c..9f546590c 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -97,11 +97,17 @@ add_test( NAME hash-target COMMAND hash-target-tests) -# Skip the core_tests if we are running in Travis-CI because they will take too long -if (DEFINED ENV{TRAVIS}) - add_custom_target(tests DEPENDS difficulty hash performance_tests core_proxy unit_tests) -else () - add_custom_target(tests DEPENDS coretests difficulty hash performance_tests core_proxy unit_tests) -endif () +set(enabled_tests + difficulty + hash + performance_tests + core_proxy + unit_tests) +# Skip the core_tests in Travis-CI because they will take too long +if (NOT DEFINED ENV{TRAVIS}) + list(APPEND enabled_tests coretests) +endif() + +add_custom_target(tests DEPENDS enabled_tests) set_property(TARGET tests PROPERTY FOLDER "${folder}") From 640a934d5f6163f1069dda933c590bf463d0d5d1 Mon Sep 17 00:00:00 2001 From: redfish Date: Mon, 29 Aug 2016 13:56:34 -0400 Subject: [PATCH 3/3] tests: cmake: fix building with system gtest Issues #980 #983 --- README.md | 2 +- tests/CMakeLists.txt | 7 ++++--- tests/daemon_tests/CMakeLists.txt | 2 +- tests/libwallet_api_tests/CMakeLists.txt | 2 +- tests/net_load_tests/CMakeLists.txt | 4 ++-- tests/unit_tests/CMakeLists.txt | 2 +- 6 files changed, 10 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 1f3e7dced..fbe1f4ef7 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,6 @@ Packaging for your favorite distribution would be a welcome contribution! * pkg-config * libunbound `>=1.4.16` (note: Unbound is not a dependency, libunbound is) * libevent `>=2.0` -* libgtest `>=1.5` * Boost `>=1.58` * BerkeleyDB `>=4.8` (note: on Ubuntu this means installing libdb-dev and libdb++-dev) * libunwind (optional, for stack trace on exception) @@ -87,6 +86,7 @@ Packaging for your favorite distribution would be a welcome contribution! * ldns `>=1.6.17` (optional, for statically-linked binaries) * expat `>=1.1` (optional, for statically-linked binaries) * bison or yacc (optional, for statically-linked binaries) +* GTest `>=1.5` (optional, for running test suite) (NOTE: `libgtest-dev` package in Ubuntu ships without binaries and requires a manual build; `gtest` on Arch includes binaries) * Doxygen (optional, for generating documentation) * graphviz (optional, for generating documentation) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 9f546590c..33d6c233d 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -42,21 +42,22 @@ find_package(GTest) if (GTest_FOUND) include_directories(SYSTEM ${GTEST_INCLUDE_DIRS}) else () + message(STATUS "GTest not found on the system: will use GTest bundled with this source") add_subdirectory(gtest) include_directories(SYSTEM "${gtest_SOURCE_DIR}/include" "${gtest_SOURCE_DIR}") # Emulate the FindGTest module's variable. - set(GTEST_MAIN_LIBRARIES gtest_main) + set(GTEST_LIBRARIES gtest) # Ignore some warnings when building gtest binaries. if(NOT MSVC) - set_property(TARGET gtest gtest_main + set_property(TARGET gtest APPEND_STRING PROPERTY COMPILE_FLAGS " -Wno-undef -Wno-sign-compare") endif() - set_property(TARGET gtest gtest_main + set_property(TARGET gtest PROPERTY FOLDER "${folder}") endif () diff --git a/tests/daemon_tests/CMakeLists.txt b/tests/daemon_tests/CMakeLists.txt index 25ca09ce4..ae11ab5d5 100644 --- a/tests/daemon_tests/CMakeLists.txt +++ b/tests/daemon_tests/CMakeLists.txt @@ -42,7 +42,7 @@ target_link_libraries(transfers crypto common epee - ${GTEST_MAIN_LIBRARIES} + ${GTEST_LIBRARIES} ${Boost_LIBRARIES}) file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/test_transfers") diff --git a/tests/libwallet_api_tests/CMakeLists.txt b/tests/libwallet_api_tests/CMakeLists.txt index e60947084..416192cce 100644 --- a/tests/libwallet_api_tests/CMakeLists.txt +++ b/tests/libwallet_api_tests/CMakeLists.txt @@ -40,7 +40,7 @@ add_executable(libwallet_api_tests target_link_libraries(libwallet_api_tests LINK_PRIVATE wallet - ${GTEST_MAIN_LIBRARIES} + ${GTEST_LIBRARIES} ${EXTRA_LIBRARIES}) set_property(TARGET libwallet_api_tests diff --git a/tests/net_load_tests/CMakeLists.txt b/tests/net_load_tests/CMakeLists.txt index c3a68d18d..2c97acf51 100644 --- a/tests/net_load_tests/CMakeLists.txt +++ b/tests/net_load_tests/CMakeLists.txt @@ -40,7 +40,7 @@ target_link_libraries(net_load_tests_clt otshell_utils p2p cryptonote_core - ${GTEST_MAIN_LIBRARIES} + ${GTEST_LIBRARIES} ${Boost_CHRONO_LIBRARY} ${Boost_DATE_TIME_LIBRARY} ${Boost_FILESYSTEM_LIBRARY} @@ -62,7 +62,7 @@ target_link_libraries(net_load_tests_srv otshell_utils p2p cryptonote_core - ${GTEST_MAIN_LIBRARIES} + ${GTEST_LIBRARIES} ${Boost_CHRONO_LIBRARY} ${Boost_DATE_TIME_LIBRARY} ${Boost_FILESYSTEM_LIBRARY} diff --git a/tests/unit_tests/CMakeLists.txt b/tests/unit_tests/CMakeLists.txt index 3d42809e3..d36c2748c 100644 --- a/tests/unit_tests/CMakeLists.txt +++ b/tests/unit_tests/CMakeLists.txt @@ -69,7 +69,7 @@ target_link_libraries(unit_tests rpc wallet p2p - ${GTEST_MAIN_LIBRARIES} + ${GTEST_LIBRARIES} ${Boost_CHRONO_LIBRARY} ${Boost_REGEX_LIBRARY} ${Boost_SYSTEM_LIBRARY}