diff --git a/.travis.yml b/.travis.yml index 759498ab2..43131c890 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,7 +19,7 @@ before_install: before_script: - mkdir build - cd build - - cmake .. -DUSE_SHARED_CURL=$SHARED -DUSE_SHARED_GIFLIB=$SHARED -DUSE_SHARED_JPEGLIB=$SHARED -DUSE_SHARED_ZLIB=$SHARED -DUSE_SHARED_LIBPNG=$SHARED -DUSE_SHARED_TINYXML=$SHARED -DUSE_SHARED_PIXMAN=$SHARED -DUSE_SHARED_ALLEGRO4=$SHARED + - cmake .. -DUSE_SHARED_CURL=$SHARED -DUSE_SHARED_GIFLIB=$SHARED -DUSE_SHARED_JPEGLIB=$SHARED -DUSE_SHARED_ZLIB=$SHARED -DUSE_SHARED_LIBPNG=$SHARED -DUSE_SHARED_TINYXML=$SHARED -DUSE_SHARED_PIXMAN=$SHARED -DUSE_SHARED_ALLEGRO4=$SHARED -DENABLE_TESTS=ON script: - "make" diff --git a/CMakeLists.txt b/CMakeLists.txt index c8a685b71..ef15818c4 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" off) 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/FindTests.cmake b/cmake/FindTests.cmake new file mode 100644 index 000000000..308be1ab1 --- /dev/null +++ b/cmake/FindTests.cmake @@ -0,0 +1,35 @@ +# Find tests and add rules to compile them and run them + +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..bac9f3b82 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -165,47 +165,17 @@ 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(FindTests) - # 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() - -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) + 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()