OpenRCT2/test/tests/CMakeLists.txt

161 lines
6.8 KiB
CMake
Raw Normal View History

2016-11-28 14:33:50 +01:00
cmake_minimum_required(VERSION 2.6)
2016-11-28 23:27:21 +01:00
2017-06-05 23:08:14 +02:00
option(DISABLE_RCT2_TESTS "Disable tests that require RollerCoaster Tycoon 2 assets.")
option(SYSTEM_GTEST "Use the googletest library provided by the system.")
if (SYSTEM_GTEST)
find_package(GTest REQUIRED)
set(GTEST_LIBRARIES ${GTEST_BOTH_LIBRARIES})
message(WARNING "Gtest strongly advices against using a system installation, see https://github.com/google/googletest/blob/master/googletest/docs/FAQ.md#why-is-it-not-recommended-to-install-a-pre-compiled-copy-of-google-test-for-example-into-usrlocal for detailed information. If errors occur please double-check without the SYSTEM_GTEST flag.")
else (SYSTEM_GTEST)
2017-06-05 23:08:14 +02:00
# Bootstrap GoogleTest
INCLUDE(ExternalProject)
2016-11-28 23:27:21 +01:00
ExternalProject_Add(
googletest-distribution
URL https://github.com/google/googletest/archive/release-1.8.0.tar.gz
URL_HASH SHA1=e7e646a6204638fe8e87e165292b8dd9cd4c36ed
TIMEOUT 10
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
)
2016-11-28 23:27:21 +01:00
# Specify include dir
ExternalProject_Get_Property(googletest-distribution SOURCE_DIR)
set(GOOGLETEST_DISTRIB_SOURCE_DIR "${SOURCE_DIR}")
2016-11-28 23:27:21 +01:00
ExternalProject_Add(
googletest
DEPENDS googletest-distribution
DOWNLOAD_COMMAND ""
SOURCE_DIR "${GOOGLETEST_DISTRIB_SOURCE_DIR}/googletest"
CMAKE_ARGS "-DCMAKE_CXX_FLAGS=${TARGET_M}"
BUILD_BYPRODUCTS "googletest-prefix/src/googletest-build/${CMAKE_STATIC_LIBRARY_PREFIX}gtest${CMAKE_STATIC_LIBRARY_SUFFIX}"
BUILD_BYPRODUCTS "googletest-prefix/src/googletest-build/${CMAKE_STATIC_LIBRARY_PREFIX}gtest_main${CMAKE_STATIC_LIBRARY_SUFFIX}"
# Disable install step
INSTALL_COMMAND ""
# Wrap download, configure and build steps in a script to log output
LOG_DOWNLOAD ON
LOG_CONFIGURE ON
LOG_BUILD ON)
2016-11-28 23:27:21 +01:00
# Specify include dir
set(GTEST_INCLUDE_DIRS ${GOOGLETEST_DISTRIB_SOURCE_DIR}/googletest/include)
2016-11-28 23:27:21 +01:00
# Library
ExternalProject_Get_Property(googletest BINARY_DIR)
set(GOOGLETEST_BINARY_DIR "${BINARY_DIR}")
set(GTEST_LIBRARY_PATH ${GOOGLETEST_BINARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}gtest${CMAKE_STATIC_LIBRARY_SUFFIX})
set(GTEST_MAIN_LIBRARY_PATH ${GOOGLETEST_BINARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}gtest_main${CMAKE_STATIC_LIBRARY_SUFFIX})
set(GTEST_LIBRARY gtest)
set(GTEST_MAIN_LIBRARY gtest_main)
add_library(${GTEST_LIBRARY} STATIC IMPORTED)
add_library(${GTEST_MAIN_LIBRARY} STATIC IMPORTED)
set_property(TARGET ${GTEST_LIBRARY} PROPERTY IMPORTED_LOCATION ${GTEST_LIBRARY_PATH})
set_property(TARGET ${GTEST_MAIN_LIBRARY} PROPERTY IMPORTED_LOCATION ${GTEST_MAIN_LIBRARY_PATH})
add_dependencies(${GTEST_LIBRARY} googletest)
add_dependencies(${GTEST_MAIN_LIBRARY} ${GTEST_LIBRARY})
2016-11-28 23:27:21 +01:00
set(GTEST_LIBRARIES gtest gtest_main pthread)
endif (SYSTEM_GTEST)
include_directories(SYSTEM ${GTEST_INCLUDE_DIRS})
2017-05-08 18:35:15 +02:00
include_directories("${ROOT_DIR}/src")
2017-05-08 22:03:10 +02:00
include_directories(${SDL2_INCLUDE_DIRS})
2016-11-30 11:51:55 +01:00
# Some most common files required in tests
set(COMMON_TEST_SOURCES
2017-05-08 18:35:15 +02:00
"${ROOT_DIR}/src/openrct2/core/Console.cpp"
"${ROOT_DIR}/src/openrct2/core/Diagnostics.cpp"
"${ROOT_DIR}/src/openrct2/core/Guard.cpp"
"${ROOT_DIR}/src/openrct2/core/String.cpp"
"${ROOT_DIR}/src/openrct2/diagnostic.c"
"${ROOT_DIR}/src/openrct2/localisation/format_codes.c"
"${ROOT_DIR}/src/openrct2/localisation/utf8.c"
"${ROOT_DIR}/src/openrct2/util/util.c"
"${ROOT_DIR}/src/openrct2/Version.cpp"
)
# Create a re-usable library to save some compilation time
add_library(test-common STATIC ${COMMON_TEST_SOURCES})
2017-06-05 23:08:14 +02:00
# Setup testdata. It should be fine here, as the only way to reach here is by explicitly requesting tests.
if (NOT "z$ENV{CI}" STREQUAL "z")
message("Detected CI environment. Disabling ride rating test.")
set(DISABLE_RCT2_TESTS ON)
endif ()
if (NOT DISABLE_RCT2_TESTS)
execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink "${CMAKE_CURRENT_LIST_DIR}/testdata" "${CMAKE_CURRENT_BINARY_DIR}/testdata")
2017-06-05 23:08:14 +02:00
endif ()
2016-11-28 14:37:27 +01:00
# Start of our tests
2016-11-28 23:27:21 +01:00
2016-11-30 11:51:55 +01:00
# sawyercoding test
2016-12-28 13:39:21 +01:00
set(SAWYERCODING_TEST_SOURCES
2017-05-08 18:35:15 +02:00
"${CMAKE_CURRENT_LIST_DIR}/sawyercoding_test.cpp"
"${ROOT_DIR}/src/openrct2/diagnostic.c"
"${ROOT_DIR}/src/openrct2/util/sawyercoding.c"
"${ROOT_DIR}/src/openrct2/localisation/utf8.c"
)
2016-11-28 14:33:50 +01:00
add_executable(test_sawyercoding ${SAWYERCODING_TEST_SOURCES})
2016-11-30 11:51:55 +01:00
target_link_libraries(test_sawyercoding ${GTEST_LIBRARIES})
add_test(NAME sawyercoding COMMAND test_sawyercoding)
# LanguagePack test
set(LANGUAGEPACK_TEST_SOURCES
2017-05-08 18:35:15 +02:00
"${CMAKE_CURRENT_LIST_DIR}/LanguagePackTest.cpp"
"${ROOT_DIR}/src/openrct2/localisation/LanguagePack.cpp"
)
2016-11-30 11:51:55 +01:00
add_executable(test_languagepack ${LANGUAGEPACK_TEST_SOURCES})
if (UNIX AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "BSD")
# Include libdl for dlopen
set(LDL dl)
endif ()
target_link_libraries(test_languagepack ${GTEST_LIBRARIES} test-common ${LDL} z SDL2)
add_test(NAME languagepack COMMAND test_languagepack)
2017-02-23 23:26:11 +01:00
# INI test
2017-02-23 23:26:11 +01:00
set(INI_TEST_SOURCES
2017-05-08 18:35:15 +02:00
"${CMAKE_CURRENT_LIST_DIR}/IniWriterTest.cpp"
"${CMAKE_CURRENT_LIST_DIR}/IniReaderTest.cpp"
"${ROOT_DIR}/src/openrct2/config/IniReader.cpp"
"${ROOT_DIR}/src/openrct2/config/IniWriter.cpp"
"${ROOT_DIR}/src/openrct2/core/IStream.cpp"
"${ROOT_DIR}/src/openrct2/core/MemoryStream.cpp"
)
2017-02-23 23:26:11 +01:00
add_executable(test_ini ${INI_TEST_SOURCES})
target_link_libraries(test_ini ${GTEST_LIBRARIES} test-common ${LDL} z)
2017-02-23 23:26:11 +01:00
add_test(NAME ini COMMAND test_ini)
2017-02-24 23:04:36 +01:00
# String test
set(STRING_TEST_SOURCES
2017-05-08 18:35:15 +02:00
"${CMAKE_CURRENT_LIST_DIR}/StringTest.cpp"
)
2017-02-24 23:04:36 +01:00
add_executable(test_string ${STRING_TEST_SOURCES})
target_link_libraries(test_string ${GTEST_LIBRARIES} test-common ${LDL} z)
2017-02-24 23:04:36 +01:00
add_test(NAME string COMMAND test_string)
2017-06-03 15:39:40 +02:00
2017-06-05 23:08:14 +02:00
if (NOT DISABLE_RCT2_TESTS)
2017-06-21 18:39:10 +02:00
# Ride ratings test
2017-06-05 22:51:57 +02:00
set(RIDE_RATINGS_TEST_SOURCES "${CMAKE_CURRENT_LIST_DIR}/RideRatings.cpp"
"${CMAKE_CURRENT_LIST_DIR}/TestData.cpp")
add_executable(test_ride_ratings ${RIDE_RATINGS_TEST_SOURCES})
target_link_libraries(test_ride_ratings ${GTEST_LIBRARIES} libopenrct2 ${LDL} z)
2017-06-05 22:51:57 +02:00
add_test(NAME ride_ratings COMMAND test_ride_ratings)
2017-06-21 18:39:10 +02:00
# Multi-launch test
set(MULTILAUNCH_TEST_SOURCES "${CMAKE_CURRENT_LIST_DIR}/MultiLaunch.cpp"
"${CMAKE_CURRENT_LIST_DIR}/TestData.cpp")
add_executable(test_multilaunch ${MULTILAUNCH_TEST_SOURCES})
target_link_libraries(test_multilaunch ${GTEST_LIBRARIES} libopenrct2 ${LDL} z)
2017-06-21 18:39:10 +02:00
add_test(NAME multilaunch COMMAND test_multilaunch)
2017-06-05 22:51:57 +02:00
endif ()