diff --git a/CMakeLists.txt b/CMakeLists.txt index c8a685b71..f94d33323 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/cmake/Find-tests.cmake b/cmake/Find-tests.cmake new file mode 100644 index 000000000..06a5ce7be --- /dev/null +++ b/cmake/Find-tests.cmake @@ -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 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() + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b3647eac6..763e36e94 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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 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)