diff --git a/CMakeLists.txt b/CMakeLists.txt index fd75803adc..c3d5c02679 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -115,6 +115,7 @@ option(FORCE32 "Force 32-bit build. It will add `-m32` to compiler flags") option(DISABLE_OPENGL "Disable OpenGL support.") option(DISABLE_RCT2 "Build a standalone version, without using code and data segments from vanilla. On by default." ON) option(USE_MMAP "Use mmap to try loading rct2's data segment into memory.") +option(WITH_TESTS "Build tests") set(COMMON_COMPILE_OPTIONS "${COMMON_COMPILE_OPTIONS} -fstrict-aliasing -Werror -Wundef -Wmissing-declarations -Winit-self -Wall -Wno-unknown-pragmas -Wno-unused-function -Wno-missing-braces -Wno-comment") @@ -407,6 +408,11 @@ install(FILES resources/logo/icon_x256.png DESTINATION share/icons/hicolor/256x2 install(FILES resources/logo/icon_flag.svg DESTINATION share/icons/hicolor/scalable/apps RENAME openrct2.svg) install(FILES distribution/linux/openrct2.desktop DESTINATION share/applications) +if (WITH_TESTS) + enable_testing() + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/test/tests/) +endif () + if (UNIX AND (NOT USE_MMAP) AND (NOT DISABLE_RCT2) AND (FORCE32)) file(GLOB_RECURSE ORCT2_RIDE_SOURCES "src/ride/*/*.c") file(GLOB_RECURSE ORCT2_RIDE_DEP_SOURCES "src/ride/ride_data.c" "src/ride/track_data.c" "src/ride/track_data_old.c" "src/ride/track_paint.c" "src/addresses.c" "src/diagnostic.c" "src/hook.c" "src/paint/map_element/map_element.c" "src/paint/paint_helpers.c") diff --git a/scripts/linux/build.sh b/scripts/linux/build.sh index 1370a63132..af7e33201e 100755 --- a/scripts/linux/build.sh +++ b/scripts/linux/build.sh @@ -75,7 +75,7 @@ pushd build chmod a+rwx $(pwd) chmod g+s $(pwd) # CMAKE and MAKE opts from environment - docker run -v $PARENT:/work/openrct2 -w /work/openrct2/build -i -t openrct2/openrct2:64bit-only bash -c "cmake ../ $OPENRCT2_CMAKE_OPTS && make $OPENRCT_MAKE_OPTS" + docker run -v $PARENT:/work/openrct2 -w /work/openrct2/build -i -t openrct2/openrct2:64bit-only bash -c "cmake ../ -DWITH_TESTS=on $OPENRCT2_CMAKE_OPTS && make $OPENRCT_MAKE_OPTS && make test ARGS=\"-V\"" elif [[ $TARGET == "linux" ]] then cmake $OPENRCT2_CMAKE_OPTS .. -DCMAKE_BUILD_TYPE=debug diff --git a/test/tests/CMakeLists.txt b/test/tests/CMakeLists.txt index a9b327886d..977522fef2 100644 --- a/test/tests/CMakeLists.txt +++ b/test/tests/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 2.6) - +# Bootstrap GoogleTest INCLUDE(ExternalProject) ExternalProject_Add( @@ -47,11 +47,14 @@ set_property(TARGET ${GTEST_MAIN_LIBRARY} PROPERTY IMPORTED_LOCATION ${GTEST_MAI add_dependencies(${GTEST_LIBRARY} googletest) add_dependencies(${GTEST_MAIN_LIBRARY} ${GTEST_LIBRARY}) -include_directories(${GTEST_INCLUDE_DIR}) +include_directories(SYSTEM ${GTEST_INCLUDE_DIR}) + +# Start of our tests set(SAWYERCODING_TEST_SOURCES "sawyercoding_test.cpp" "../../src/diagnostic.c" "../../src/util/sawyercoding.c" "../../src/localisation/utf8.c") set (CMAKE_CXX_STANDARD 11) add_executable(test_sawyercoding ${SAWYERCODING_TEST_SOURCES}) target_link_libraries(test_sawyercoding gtest gtest_main pthread) target_include_directories(test_sawyercoding PUBLIC "../../src") -target_include_directories(test_sawyercoding PUBLIC "/usr/include/SDL2") +add_test(NAME sawyercoding + COMMAND test_sawyercoding)