2016-06-22 21:20:59 +00:00
|
|
|
# Copyright (C) 2001-2016 David Capello
|
2016-03-29 22:02:18 +00:00
|
|
|
# Find tests and add rules to compile them and run them
|
2016-03-29 10:06:59 +00:00
|
|
|
|
|
|
|
function(find_tests dir dependencies)
|
|
|
|
file(GLOB tests ${CMAKE_CURRENT_SOURCE_DIR}/${dir}/*_tests.cpp)
|
|
|
|
list(REMOVE_AT ARGV 0)
|
2016-03-29 22:02:18 +00:00
|
|
|
|
2016-03-29 10:06:59 +00:00
|
|
|
# Add gtest include directory so we can #include <gtest/gtest.h> in tests source code
|
|
|
|
include_directories(${CMAKE_SOURCE_DIR}/third_party/gtest/include)
|
2016-03-29 22:02:18 +00:00
|
|
|
|
2016-03-29 10:06:59 +00:00
|
|
|
# See if the test is linked with "she" library.
|
|
|
|
list(FIND dependencies she link_with_she)
|
|
|
|
if(link_with_she)
|
|
|
|
set(extra_definitions -DLINKED_WITH_SHE)
|
|
|
|
endif()
|
2016-03-29 22:02:18 +00:00
|
|
|
|
2016-03-29 10:06:59 +00:00
|
|
|
foreach(testsourcefile ${tests})
|
|
|
|
get_filename_component(testname ${testsourcefile} NAME_WE)
|
2016-03-29 22:02:18 +00:00
|
|
|
|
2016-03-29 10:06:59 +00:00
|
|
|
add_executable(${testname} ${testsourcefile})
|
|
|
|
add_test(NAME ${testname} COMMAND ${testname})
|
2016-03-29 22:02:18 +00:00
|
|
|
|
2016-03-29 10:06:59 +00:00
|
|
|
if(MSVC)
|
|
|
|
# Fix problem compiling gen from a Visual Studio solution
|
|
|
|
set_target_properties(${testname}
|
2016-06-22 21:20:59 +00:00
|
|
|
PROPERTIES LINK_FLAGS -ENTRY:"mainCRTStartup")
|
2016-03-29 10:06:59 +00:00
|
|
|
endif()
|
2016-03-29 22:02:18 +00:00
|
|
|
|
2016-03-29 10:06:59 +00:00
|
|
|
target_link_libraries(${testname} gtest ${ARGV} ${PLATFORM_LIBS})
|
2016-03-29 22:02:18 +00:00
|
|
|
|
2016-03-29 10:06:59 +00:00
|
|
|
if(extra_definitions)
|
|
|
|
set_target_properties(${testname}
|
2016-06-22 21:20:59 +00:00
|
|
|
PROPERTIES COMPILE_FLAGS ${extra_definitions})
|
2016-03-29 10:06:59 +00:00
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
endfunction()
|