Make tests work with targets
parent
3da26a38ed
commit
81ddda4515
|
@ -444,25 +444,24 @@ endif()
|
||||||
|
|
||||||
if(TESTS)
|
if(TESTS)
|
||||||
# Google Test library
|
# Google Test library
|
||||||
find_path(GTEST_SRC_DIR NAMES src/gtest.cc src/gtest-all.cc PATHS /usr/src PATH_SUFFIXES gtest)
|
find_package(GTest 1.10.0 QUIET)
|
||||||
find_path(GTEST_INCLUDE_DIR gtest/gtest.h PATHS /usr/include)
|
if(NOT(FORCE_BUNDLED_GTEST) AND GTEST_FOUND)
|
||||||
if(NOT(FORCE_BUNDLED_GTEST) AND GTEST_SRC_DIR AND GTEST_INCLUDE_DIR)
|
message(STATUS "Using system gtest library in ${GTEST_BOTH_LIBRARIES}")
|
||||||
message(STATUS "Using system gtest library in ${GTEST_SRC_DIR}")
|
elseif(EXISTS "${colobot_SOURCE_DIR}/lib/googletest/googletest/CMakeLists.txt")
|
||||||
else()
|
message(STATUS "Using gtest git submodule")
|
||||||
message(STATUS "Using bundled gtest library")
|
add_subdirectory("${colobot_SOURCE_DIR}/lib/googletest/googletest" "lib/googletest/googletest")
|
||||||
set(GTEST_SRC_DIR ${colobot_SOURCE_DIR}/lib/gtest)
|
# Add aliases so target names are compatible with the find_package above
|
||||||
set(GTEST_INCLUDE_DIR ${colobot_SOURCE_DIR}/lib/gtest/include)
|
add_library(GTest::GTest ALIAS gtest)
|
||||||
|
add_library(GTest::Main ALIAS gtest_main)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_subdirectory(${GTEST_SRC_DIR} lib/gtest)
|
|
||||||
|
|
||||||
# Hippomocks library
|
# Hippomocks library
|
||||||
add_subdirectory(${colobot_SOURCE_DIR}/lib/hippomocks)
|
add_subdirectory(${colobot_SOURCE_DIR}/lib/hippomocks)
|
||||||
|
|
||||||
# Tests targets
|
# Tests targets
|
||||||
enable_testing()
|
enable_testing()
|
||||||
|
include(GoogleTest)
|
||||||
add_subdirectory(test)
|
add_subdirectory(test)
|
||||||
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -5,5 +5,6 @@ add_executable(convert_model
|
||||||
../graphics/model/model_input.cpp
|
../graphics/model/model_input.cpp
|
||||||
../graphics/model/model_output.cpp
|
../graphics/model/model_output.cpp
|
||||||
convert_model.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 . ..)
|
||||||
|
|
||||||
|
|
|
@ -1,19 +1,13 @@
|
||||||
# Includes
|
add_executable(CBot_console console.cpp)
|
||||||
include_directories(
|
target_link_directories(CBot_console PRIVATE
|
||||||
${COLOBOT_LOCAL_INCLUDES}
|
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}
|
${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
${CMAKE_CURRENT_BINARY_DIR}
|
${CMAKE_CURRENT_BINARY_DIR}
|
||||||
)
|
)
|
||||||
|
target_link_libraries(CBot_console PRIVATE CBot colobotbase)
|
||||||
# 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})
|
|
||||||
|
|
||||||
add_executable(CBot_compile_graph compile_graph.cpp)
|
add_executable(CBot_compile_graph compile_graph.cpp)
|
||||||
target_link_libraries(CBot_compile_graph CBot)
|
target_link_directories(CBot_compile_graph PRIVATE
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}
|
||||||
|
)
|
||||||
|
target_link_libraries(CBot_compile_graph CBot)
|
||||||
|
|
|
@ -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
|
# Test files
|
||||||
|
|
||||||
set(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_definitions(-DGTEST_HAS_TR1_TUPLE=0)
|
||||||
|
|
||||||
add_executable(colobot_ut ${UT_SOURCES})
|
add_executable(colobot_ut
|
||||||
target_link_libraries(colobot_ut ${LIBS})
|
main.cpp
|
||||||
|
app/app_test.cpp
|
||||||
add_test(
|
CBot/CBotToken_test.cpp
|
||||||
NAME colobot_ut
|
CBot/CBot_test.cpp
|
||||||
COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/colobot_ut
|
common/config_file_test.cpp
|
||||||
WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
|
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:
|
# GoogleTest isn't compatible with -Wsuggest-override -Werror:
|
||||||
# see https://github.com/google/googletest/issues/1063
|
# 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)
|
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0)
|
||||||
|
|
Loading…
Reference in New Issue