diff --git a/CMakeLists.txt b/CMakeLists.txt index bdfd2200..f17f66a5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -444,25 +444,24 @@ endif() if(TESTS) # Google Test library - find_path(GTEST_SRC_DIR NAMES src/gtest.cc src/gtest-all.cc PATHS /usr/src PATH_SUFFIXES gtest) - find_path(GTEST_INCLUDE_DIR gtest/gtest.h PATHS /usr/include) - if(NOT(FORCE_BUNDLED_GTEST) AND GTEST_SRC_DIR AND GTEST_INCLUDE_DIR) - message(STATUS "Using system gtest library in ${GTEST_SRC_DIR}") - else() - message(STATUS "Using bundled gtest library") - set(GTEST_SRC_DIR ${colobot_SOURCE_DIR}/lib/gtest) - set(GTEST_INCLUDE_DIR ${colobot_SOURCE_DIR}/lib/gtest/include) + find_package(GTest 1.10.0 QUIET) + if(NOT(FORCE_BUNDLED_GTEST) AND GTEST_FOUND) + message(STATUS "Using system gtest library in ${GTEST_BOTH_LIBRARIES}") + elseif(EXISTS "${colobot_SOURCE_DIR}/lib/googletest/googletest/CMakeLists.txt") + message(STATUS "Using gtest git submodule") + add_subdirectory("${colobot_SOURCE_DIR}/lib/googletest/googletest" "lib/googletest/googletest") + # Add aliases so target names are compatible with the find_package above + add_library(GTest::GTest ALIAS gtest) + add_library(GTest::Main ALIAS gtest_main) endif() - add_subdirectory(${GTEST_SRC_DIR} lib/gtest) - # Hippomocks library add_subdirectory(${colobot_SOURCE_DIR}/lib/hippomocks) # Tests targets enable_testing() + include(GoogleTest) add_subdirectory(test) - endif() diff --git a/src/tools/CMakeLists.txt b/src/tools/CMakeLists.txt index 4955acae..4923e4c8 100644 --- a/src/tools/CMakeLists.txt +++ b/src/tools/CMakeLists.txt @@ -5,5 +5,6 @@ add_executable(convert_model ../graphics/model/model_input.cpp ../graphics/model/model_output.cpp convert_model.cpp) -target_include_directories(convert_model PRIVATE . ..) #todo SDL2 +target_link_libraries(convert_model PRIVATE Boost::headers) +target_include_directories(convert_model PRIVATE . ..) diff --git a/test/cbot/CMakeLists.txt b/test/cbot/CMakeLists.txt index ce1f8e25..5be58335 100644 --- a/test/cbot/CMakeLists.txt +++ b/test/cbot/CMakeLists.txt @@ -1,19 +1,13 @@ -# Includes -include_directories( - ${COLOBOT_LOCAL_INCLUDES} +add_executable(CBot_console console.cpp) +target_link_directories(CBot_console PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ) - -# Libraries -set(LIBS - CBot - colobotbase # Needed for error strings (TODO: why are they on Colobot side? :/) - ${COLOBOT_LIBS} # Needed for colobotbase -) - -add_executable(CBot_console console.cpp) -target_link_libraries(CBot_console ${LIBS}) +target_link_libraries(CBot_console PRIVATE CBot colobotbase) add_executable(CBot_compile_graph compile_graph.cpp) -target_link_libraries(CBot_compile_graph CBot) \ No newline at end of file +target_link_directories(CBot_compile_graph PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_BINARY_DIR} +) +target_link_libraries(CBot_compile_graph CBot) diff --git a/test/unit/CMakeLists.txt b/test/unit/CMakeLists.txt index cd606397..ee7e20fb 100644 --- a/test/unit/CMakeLists.txt +++ b/test/unit/CMakeLists.txt @@ -1,48 +1,3 @@ -# Platform-dependent tests -if(PLATFORM_WINDOWS) - set(PLATFORM_TESTS common/system/system_windows_test.cpp) -elseif(PLATFORM_LINUX) - set(PLATFORM_TESTS common/system/system_linux_test.cpp) -endif() - -# Sources -set(UT_SOURCES - main.cpp - app/app_test.cpp - CBot/CBotToken_test.cpp - CBot/CBot_test.cpp - common/config_file_test.cpp - graphics/engine/lightman_test.cpp - math/func_test.cpp - math/geometry_test.cpp - math/matrix_test.cpp - math/vector_test.cpp - ${PLATFORM_TESTS} -) - -# Includes -include_directories( - common - math - ${CMAKE_CURRENT_SOURCE_DIR} - ${CMAKE_CURRENT_BINARY_DIR} - ${COLOBOT_LOCAL_INCLUDES} -) - -include_directories( - SYSTEM - ${GTEST_INCLUDE_DIR} - ${HIPPOMOCKS_INCLUDE_DIR} - ${COLOBOT_SYSTEM_INCLUDES} -) - -# Libraries -set(LIBS - gtest - colobotbase - ${COLOBOT_LIBS} -) - # Test files set(TEST_FILES @@ -55,15 +10,39 @@ file(COPY ${TEST_FILES} DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}) add_definitions(-DGTEST_HAS_TR1_TUPLE=0) -add_executable(colobot_ut ${UT_SOURCES}) -target_link_libraries(colobot_ut ${LIBS}) - -add_test( - NAME colobot_ut - COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/colobot_ut - WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} +add_executable(colobot_ut + main.cpp + app/app_test.cpp + CBot/CBotToken_test.cpp + CBot/CBot_test.cpp + common/config_file_test.cpp + graphics/engine/lightman_test.cpp + math/func_test.cpp + math/geometry_test.cpp + math/matrix_test.cpp + math/vector_test.cpp ) +# Platform-dependent tests +if(PLATFORM_WINDOWS) + target_sources(colobot_ut PRIVATE common/system/system_windows_test.cpp) +elseif(PLATFORM_LINUX) + target_sources(colobot_ut PRIVATE common/system/system_linux_test.cpp) +endif() + +target_include_directories(colobot_ut PRIVATE + common + math + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_BINARY_DIR} + ${COLOBOT_LOCAL_INCLUDES} +) + +target_link_libraries(colobot_ut PRIVATE GTest::GTest hippomocks colobotbase) + +gtest_discover_tests(colobot_ut + WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}) + # GoogleTest isn't compatible with -Wsuggest-override -Werror: # see https://github.com/google/googletest/issues/1063 if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0)