Make building tests optional

Added new option ENABLE_TESTS in CMake (ON by default)
This commit is contained in:
Azamat H. Hackimov 2016-03-29 15:06:59 +05:00
parent 27b55030e2
commit 7964f1feb1
3 changed files with 55 additions and 42 deletions

View File

@ -55,6 +55,7 @@ option(USE_SKIA_BACKEND "Use Skia backend" off)
option(ENABLE_MEMLEAK "Enable memory-leaks detector (only for developers)" off)
option(ENABLE_UPDATER "Enable automatic check for updates" on)
option(ENABLE_WEBSERVER "Enable support to run a webserver (for HTML5 gamedev)" off)
option(ENABLE_TESTS "Enable the unit tests" on)
option(ENABLE_TRIAL_MODE "Compile the trial version" off)
option(ENABLE_STEAM "Compile with Steam library" off)
option(FULLSCREEN_PLATFORM "Enable fullscreen by default" off)

41
cmake/Find-tests.cmake Normal file
View File

@ -0,0 +1,41 @@
# - Find tests
# Find tests and run them
#
# find_test(dir dependencies)
# DXGUID_FOUND - True if dxguid found.
function(find_tests dir dependencies)
file(GLOB tests ${CMAKE_CURRENT_SOURCE_DIR}/${dir}/*_tests.cpp)
list(REMOVE_AT ARGV 0)
# Add gtest include directory so we can #include <gtest/gtest.h> in tests source code
include_directories(${CMAKE_SOURCE_DIR}/third_party/gtest/include)
# 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()
foreach(testsourcefile ${tests})
get_filename_component(testname ${testsourcefile} NAME_WE)
add_executable(${testname} ${testsourcefile})
add_test(NAME ${testname} COMMAND ${testname})
if(MSVC)
# Fix problem compiling gen from a Visual Studio solution
set_target_properties(${testname}
PROPERTIES LINK_FLAGS -ENTRY:"mainCRTStartup")
endif()
target_link_libraries(${testname} gtest ${ARGV} ${PLATFORM_LIBS})
if(extra_definitions)
set_target_properties(${testname}
PROPERTIES COMPILE_FLAGS ${extra_definitions})
endif()
endforeach()
endfunction()

View File

@ -165,47 +165,18 @@ install(DIRECTORY ../data
######################################################################
# Tests
function(find_tests dir dependencies)
file(GLOB tests ${CMAKE_CURRENT_SOURCE_DIR}/${dir}/*_tests.cpp)
list(REMOVE_AT ARGV 0)
if(ENABLE_TESTS)
include(Find-tests)
# Add gtest include directory so we can #include <gtest/gtest.h> in tests source code
include_directories(${CMAKE_SOURCE_DIR}/third_party/gtest/include)
find_tests(base base-lib)
find_tests(undo undo-lib)
find_tests(gfx gfx-lib)
find_tests(doc doc-lib)
find_tests(render render-lib)
find_tests(css css-lib)
find_tests(ui ui-lib)
find_tests(app/file app-lib)
find_tests(app app-lib)
find_tests(. app-lib)
endif()
# 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()
foreach(testsourcefile ${tests})
get_filename_component(testname ${testsourcefile} NAME_WE)
add_executable(${testname} ${testsourcefile})
add_test(NAME ${testname} COMMAND ${testname})
if(MSVC)
# Fix problem compiling gen from a Visual Studio solution
set_target_properties(${testname}
PROPERTIES LINK_FLAGS -ENTRY:"mainCRTStartup")
endif()
target_link_libraries(${testname} gtest ${ARGV} ${PLATFORM_LIBS})
if(extra_definitions)
set_target_properties(${testname}
PROPERTIES COMPILE_FLAGS ${extra_definitions})
endif()
endforeach()
endfunction()
find_tests(base base-lib)
find_tests(undo undo-lib)
find_tests(gfx gfx-lib)
find_tests(doc doc-lib)
find_tests(render render-lib)
find_tests(css css-lib)
find_tests(ui ui-lib)
find_tests(app/file app-lib)
find_tests(app app-lib)
find_tests(. app-lib)