2016-11-28 14:33:50 +01:00
cmake_minimum_required ( VERSION 2.6 )
2016-11-28 23:27:21 +01:00
2017-07-26 10:50:00 +02:00
option ( SYSTEM_GTEST "Use the googletest library provided by the system." )
if ( SYSTEM_GTEST )
find_package ( GTest REQUIRED )
set ( GTEST_LIBRARIES ${ GTEST_BOTH_LIBRARIES } )
2017-07-26 11:38:26 +02:00
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." )
2017-07-26 10:50:00 +02:00
else ( SYSTEM_GTEST )
2017-06-05 23:08:14 +02:00
2017-07-26 10:53:14 +02:00
# Bootstrap GoogleTest
INCLUDE ( ExternalProject )
2016-11-28 23:27:21 +01:00
2017-10-10 09:31:16 +02:00
# Use googletest with https://github.com/google/googletest/pull/1045 applied
2017-07-26 10:53:14 +02:00
ExternalProject_Add (
g o o g l e t e s t - d i s t r i b u t i o n
2017-10-10 09:31:16 +02:00
U R L h t t p s : / / g i t h u b . c o m / g o o g l e / g o o g l e t e s t / a r c h i v e / a d 4 9 e a a 0 4 6 6 b 9 8 f 2 1 4 4 9 e f a a a a e 8 1 7 6 8 3 d a a 8 b 9 9 . t a r . g z
U R L _ H A S H S H A 1 = e 4 6 8 b f d f f e 7 c 4 6 c 1 4 c e 0 6 b f b 4 8 a 2 9 b 6 2 0 1 9 0 8 5 0 4
2017-07-26 10:53:14 +02:00
T I M E O U T 1 0
C O N F I G U R E _ C O M M A N D " "
B U I L D _ C O M M A N D " "
I N S T A L L _ C O M M A N D " "
)
2016-11-28 23:27:21 +01:00
2017-07-26 10:53:14 +02: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
2017-07-26 10:53:14 +02:00
ExternalProject_Add (
g o o g l e t e s t
D E P E N D S g o o g l e t e s t - d i s t r i b u t i o n
D O W N L O A D _ C O M M A N D " "
S O U R C E _ D I R " $ { G O O G L E T E S T _ D I S T R I B _ S O U R C E _ D I R } / g o o g l e t e s t "
C M A K E _ A R G S " - D C M A K E _ C X X _ F L A G S = $ { T A R G E T _ M } "
B U I L D _ B Y P R O D U C T S " g o o g l e t e s t - p r e f i x / s r c / g o o g l e t e s t - b u i l d / $ { C M A K E _ S T A T I C _ L I B R A R Y _ P R E F I X } g t e s t $ { C M A K E _ S T A T I C _ L I B R A R Y _ S U F F I X } "
B U I L D _ B Y P R O D U C T S " g o o g l e t e s t - p r e f i x / s r c / g o o g l e t e s t - b u i l d / $ { C M A K E _ S T A T I C _ L I B R A R Y _ P R E F I X } g t e s t _ m a i n $ { C M A K E _ S T A T I C _ L I B R A R Y _ S U F F I X } "
# Disable install step
I N S T A L L _ C O M M A N D " "
# Wrap download, configure and build steps in a script to log output
L O G _ D O W N L O A D O N
L O G _ C O N F I G U R E O N
L O G _ B U I L D O N )
2016-11-28 23:27:21 +01:00
2017-07-26 10:53:14 +02:00
# Specify include dir
set ( GTEST_INCLUDE_DIRS ${ GOOGLETEST_DISTRIB_SOURCE_DIR } /googletest/include )
2016-11-28 23:27:21 +01:00
2017-07-26 10:53:14 +02: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
2017-07-26 10:53:14 +02:00
set ( GTEST_LIBRARIES gtest gtest_main pthread )
2017-07-26 10:50:00 +02:00
endif ( SYSTEM_GTEST )
2017-07-26 10:39:17 +02:00
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
2017-02-24 23:04:20 +01:00
# Some most common files required in tests
set ( COMMON_TEST_SOURCES
2017-05-08 18:35:15 +02:00
" $ { R O O T _ D I R } / s r c / o p e n r c t 2 / c o r e / C o n s o l e . c p p "
" $ { R O O T _ D I R } / s r c / o p e n r c t 2 / c o r e / D i a g n o s t i c s . c p p "
" $ { R O O T _ D I R } / s r c / o p e n r c t 2 / c o r e / G u a r d . c p p "
" $ { R O O T _ D I R } / s r c / o p e n r c t 2 / c o r e / S t r i n g . c p p "
2017-12-12 14:52:57 +01:00
" $ { R O O T _ D I R } / s r c / o p e n r c t 2 / D i a g n o s t i c . c p p "
2018-04-15 19:19:55 +02:00
" $ { R O O T _ D I R } / s r c / o p e n r c t 2 / l o c a l i s a t i o n / C o n v e r s i o n T a b l e s . c p p "
" $ { R O O T _ D I R } / s r c / o p e n r c t 2 / l o c a l i s a t i o n / C o n v e r t . c p p "
2018-01-06 18:32:25 +01:00
" $ { R O O T _ D I R } / s r c / o p e n r c t 2 / l o c a l i s a t i o n / F o r m a t C o d e s . c p p "
" $ { R O O T _ D I R } / s r c / o p e n r c t 2 / l o c a l i s a t i o n / U T F 8 . c p p "
2017-12-13 13:02:24 +01:00
" $ { R O O T _ D I R } / s r c / o p e n r c t 2 / u t i l / U t i l . c p p "
2017-05-08 18:35:15 +02:00
" $ { R O O T _ D I R } / s r c / o p e n r c t 2 / V e r s i o n . c p p "
2017-05-08 18:28:33 +02:00
)
2017-02-24 23:04:20 +01:00
# Create a re-usable library to save some compilation time
add_library ( test-common STATIC ${ COMMON_TEST_SOURCES } )
2020-07-25 09:09:15 +02:00
set_target_properties ( test-common PROPERTIES COMPILE_DEFINITIONS DISABLE_HTTP )
2017-02-24 23:04:20 +01:00
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.
2018-04-10 13:36:51 +02:00
execute_process ( COMMAND ${ CMAKE_COMMAND } -E create_symlink "${CMAKE_CURRENT_LIST_DIR}/testdata" "${CMAKE_CURRENT_BINARY_DIR}/testdata" )
2018-04-10 20:14:27 +02:00
install ( CODE "execute_process(COMMAND \" ${ CMAKE_COMMAND } \" -E create_symlink \"\$ENV{DESTDIR}${CMAKE_INSTALL_FULL_DATADIR}/openrct2\" \"${CMAKE_CURRENT_BINARY_DIR}/data\")")
2017-06-05 23:08:14 +02:00
2018-05-15 16:37:41 +02:00
if ( NOT MINGW AND NOT MSVC )
# For unicode code page conversion (required for ini and string tests)
find_package ( ICU 59.0 REQUIRED COMPONENTS uc )
target_link_libraries ( test-common ${ ICU_LIBRARIES } )
2018-12-19 23:31:24 +01:00
target_include_directories ( test-common SYSTEM PUBLIC ${ ICU_INCLUDE_DIRS } )
2018-05-15 16:37:41 +02:00
endif ( )
2018-05-06 16:53:42 +02:00
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
" $ { C M A K E _ C U R R E N T _ L I S T _ D I R } / s a w y e r c o d i n g _ t e s t . c p p "
2017-10-21 16:05:10 +02:00
" $ { R O O T _ D I R } / s r c / o p e n r c t 2 / c o r e / I S t r e a m . c p p "
" $ { R O O T _ D I R } / s r c / o p e n r c t 2 / c o r e / M e m o r y S t r e a m . c p p "
" $ { R O O T _ D I R } / s r c / o p e n r c t 2 / r c t 1 2 / S a w y e r C h u n k . c p p "
" $ { R O O T _ D I R } / s r c / o p e n r c t 2 / r c t 1 2 / S a w y e r C h u n k R e a d e r . c p p "
2017-12-13 13:02:24 +01:00
" $ { R O O T _ D I R } / s r c / o p e n r c t 2 / u t i l / S a w y e r C o d i n g . c p p "
2017-05-08 18:28:33 +02:00
)
2016-11-28 14:33:50 +01:00
add_executable ( test_sawyercoding ${ SAWYERCODING_TEST_SOURCES } )
2017-10-21 16:05:10 +02:00
target_link_libraries ( test_sawyercoding ${ GTEST_LIBRARIES } test-common ${ LDL } z )
2019-02-05 20:17:14 +01:00
target_link_platform_libraries ( test_sawyercoding )
2016-11-30 11:51:55 +01:00
add_test ( NAME sawyercoding COMMAND test_sawyercoding )
# LanguagePack test
set ( LANGUAGEPACK_TEST_SOURCES
2017-05-08 18:35:15 +02:00
" $ { C M A K E _ C U R R E N T _ L I S T _ D I R } / L a n g u a g e P a c k T e s t . c p p "
" $ { R O O T _ D I R } / s r c / o p e n r c t 2 / l o c a l i s a t i o n / L a n g u a g e P a c k . c p p "
2017-05-08 18:28:33 +02:00
)
2016-11-30 11:51:55 +01:00
add_executable ( test_languagepack ${ LANGUAGEPACK_TEST_SOURCES } )
2017-06-25 23:01:59 +02:00
if ( UNIX AND NOT ${ CMAKE_SYSTEM_NAME } MATCHES "BSD" )
# Include libdl for dlopen
set ( LDL dl )
endif ( )
2017-10-21 16:05:10 +02:00
target_link_libraries ( test_languagepack ${ GTEST_LIBRARIES } test-common ${ LDL } z )
2019-02-05 20:17:14 +01:00
target_link_platform_libraries ( test_languagepack )
2016-12-15 17:55:17 +01:00
add_test ( NAME languagepack COMMAND test_languagepack )
2017-02-23 23:26:11 +01:00
2017-02-24 23:04:20 +01:00
# INI test
2017-02-23 23:26:11 +01:00
set ( INI_TEST_SOURCES
2017-05-08 18:35:15 +02:00
" $ { C M A K E _ C U R R E N T _ L I S T _ D I R } / I n i W r i t e r T e s t . c p p "
" $ { C M A K E _ C U R R E N T _ L I S T _ D I R } / I n i R e a d e r T e s t . c p p "
" $ { R O O T _ D I R } / s r c / o p e n r c t 2 / c o n f i g / I n i R e a d e r . c p p "
" $ { R O O T _ D I R } / s r c / o p e n r c t 2 / c o n f i g / I n i W r i t e r . c p p "
" $ { R O O T _ D I R } / s r c / o p e n r c t 2 / c o r e / I S t r e a m . c p p "
" $ { R O O T _ D I R } / s r c / o p e n r c t 2 / c o r e / M e m o r y S t r e a m . c p p "
2017-05-08 18:28:33 +02:00
)
2017-02-23 23:26:11 +01:00
add_executable ( test_ini ${ INI_TEST_SOURCES } )
2019-02-03 23:32:51 +01:00
SET_CHECK_CXX_FLAGS ( test_ini )
2017-06-25 23:01:59 +02:00
target_link_libraries ( test_ini ${ GTEST_LIBRARIES } test-common ${ LDL } z )
2019-02-05 20:17:14 +01:00
target_link_platform_libraries ( test_ini )
2017-02-23 23:26:11 +01:00
add_test ( NAME ini COMMAND test_ini )
2017-02-24 23:04:36 +01:00
2019-03-02 14:40:24 +01:00
# Platform
add_executable ( test_platform ${ CMAKE_CURRENT_LIST_DIR } /Platform.cpp )
SET_CHECK_CXX_FLAGS ( test_platform )
target_link_libraries ( test_platform ${ GTEST_LIBRARIES } test-common ${ LDL } z libopenrct2 )
target_link_platform_libraries ( test_platform )
add_test ( NAME platform COMMAND test_platform )
2017-02-24 23:04:36 +01:00
# String test
set ( STRING_TEST_SOURCES
2017-05-08 18:35:15 +02:00
" $ { C M A K E _ C U R R E N T _ L I S T _ D I R } / S t r i n g T e s t . c p p "
2017-05-08 18:28:33 +02:00
)
2017-02-24 23:04:36 +01:00
add_executable ( test_string ${ STRING_TEST_SOURCES } )
2019-02-03 23:32:51 +01:00
SET_CHECK_CXX_FLAGS ( test_string )
2017-06-25 23:01:59 +02:00
target_link_libraries ( test_string ${ GTEST_LIBRARIES } test-common ${ LDL } z )
2019-02-05 20:17:14 +01:00
target_link_platform_libraries ( test_string )
2017-02-24 23:04:36 +01:00
add_test ( NAME string COMMAND test_string )
2017-06-03 15:39:40 +02:00
2018-04-15 19:19:55 +02:00
# Localisation test
set ( STRING_TEST_SOURCES "${CMAKE_CURRENT_LIST_DIR}/Localisation.cpp" )
add_executable ( test_localisation ${ STRING_TEST_SOURCES } )
2019-02-03 23:32:51 +01:00
SET_CHECK_CXX_FLAGS ( test_localisation )
2018-04-15 19:19:55 +02:00
target_link_libraries ( test_localisation ${ GTEST_LIBRARIES } test-common ${ LDL } z )
2019-02-05 20:17:14 +01:00
target_link_platform_libraries ( test_localisation )
2018-04-15 19:19:55 +02:00
add_test ( NAME localisation COMMAND test_localisation )
2017-08-31 10:36:01 +02:00
2018-06-01 23:47:29 +02:00
if ( NOT DISABLE_NETWORK )
# Crypt tests
add_executable ( test_crypt "${CMAKE_CURRENT_LIST_DIR}/CryptTests.cpp"
" $ { C M A K E _ C U R R E N T _ L I S T _ D I R } / T e s t D a t a . c p p " )
2019-02-03 23:32:51 +01:00
SET_CHECK_CXX_FLAGS ( test_crypt )
2018-06-01 23:47:29 +02:00
target_link_libraries ( test_crypt ${ GTEST_LIBRARIES } libopenrct2 )
2019-02-05 20:17:14 +01:00
target_link_platform_libraries ( test_crypt )
2018-06-01 23:47:29 +02:00
add_test ( NAME Crypt COMMAND test_crypt )
endif ( )
2018-05-23 02:01:48 +02:00
2018-05-12 01:04:16 +02:00
# ImageImporter tests
add_executable ( test_imageimporter "${CMAKE_CURRENT_LIST_DIR}/ImageImporterTests.cpp"
" $ { C M A K E _ C U R R E N T _ L I S T _ D I R } / T e s t D a t a . c p p " )
2019-02-03 23:32:51 +01:00
SET_CHECK_CXX_FLAGS ( test_imageimporter )
2018-05-12 01:04:16 +02:00
target_link_libraries ( test_imageimporter ${ GTEST_LIBRARIES } libopenrct2 )
2019-02-05 20:17:14 +01:00
target_link_platform_libraries ( test_imageimporter )
2018-05-12 01:04:16 +02:00
add_test ( NAME ImageImporter COMMAND test_imageimporter )
2017-08-31 10:36:01 +02:00
# Ride ratings test
set ( RIDE_RATINGS_TEST_SOURCES "${CMAKE_CURRENT_LIST_DIR}/RideRatings.cpp"
" $ { C M A K E _ C U R R E N T _ L I S T _ D I R } / T e s t D a t a . c p p " )
add_executable ( test_ride_ratings ${ RIDE_RATINGS_TEST_SOURCES } )
2019-02-03 23:32:51 +01:00
SET_CHECK_CXX_FLAGS ( test_ride_ratings )
2017-08-31 10:36:01 +02:00
target_link_libraries ( test_ride_ratings ${ GTEST_LIBRARIES } libopenrct2 ${ LDL } z )
2019-02-05 20:17:14 +01:00
target_link_platform_libraries ( test_ride_ratings )
2018-04-10 13:36:51 +02:00
add_test ( NAME ride_ratings COMMAND test_ride_ratings )
2017-08-31 10:36:01 +02:00
# Multi-launch test
set ( MULTILAUNCH_TEST_SOURCES "${CMAKE_CURRENT_LIST_DIR}/MultiLaunch.cpp"
" $ { C M A K E _ C U R R E N T _ L I S T _ D I R } / T e s t D a t a . c p p " )
add_executable ( test_multilaunch ${ MULTILAUNCH_TEST_SOURCES } )
2019-02-03 23:32:51 +01:00
SET_CHECK_CXX_FLAGS ( test_multilaunch )
2017-08-31 10:36:01 +02:00
target_link_libraries ( test_multilaunch ${ GTEST_LIBRARIES } libopenrct2 ${ LDL } z )
2019-02-05 20:17:14 +01:00
target_link_platform_libraries ( test_multilaunch )
2018-04-10 13:36:51 +02:00
add_test ( NAME multilaunch COMMAND test_multilaunch )
2018-04-17 13:13:58 +02:00
# Tile element test
set ( TILE_ELEMENT_TEST_SOURCES "${CMAKE_CURRENT_LIST_DIR}/TileElements.cpp"
" $ { C M A K E _ C U R R E N T _ L I S T _ D I R } / T e s t D a t a . c p p " )
add_executable ( test_tile_elements ${ TILE_ELEMENT_TEST_SOURCES } )
2019-02-03 23:32:51 +01:00
SET_CHECK_CXX_FLAGS ( test_tile_elements )
2018-04-17 19:44:20 +02:00
target_link_libraries ( test_tile_elements ${ GTEST_LIBRARIES } libopenrct2 ${ LDL } z )
2019-02-05 20:17:14 +01:00
target_link_platform_libraries ( test_tile_elements )
2018-04-17 13:13:58 +02:00
add_test ( NAME tile_elements COMMAND test_tile_elements )
2018-12-11 09:57:04 +01:00
2019-08-12 18:04:08 +02:00
# Replay tests
set ( REPLAY_TEST_SOURCES "${CMAKE_CURRENT_LIST_DIR}/ReplayTests.cpp"
" $ { C M A K E _ C U R R E N T _ L I S T _ D I R } / T e s t D a t a . c p p " )
add_executable ( test_replays ${ REPLAY_TEST_SOURCES } )
SET_CHECK_CXX_FLAGS ( test_replays )
target_link_libraries ( test_replays ${ GTEST_LIBRARIES } libopenrct2 ${ LDL } z )
target_link_platform_libraries ( test_replays )
add_test ( NAME replay_tests COMMAND test_replays )
2018-12-30 11:15:03 +01:00
2020-04-12 16:00:02 +02:00
# Play tests
set ( PLAY_TEST_SOURCES "${CMAKE_CURRENT_LIST_DIR}/PlayTests.cpp"
" $ { C M A K E _ C U R R E N T _ L I S T _ D I R } / T e s t D a t a . c p p " )
add_executable ( test_plays ${ PLAY_TEST_SOURCES } )
SET_CHECK_CXX_FLAGS ( test_plays )
target_link_libraries ( test_plays ${ GTEST_LIBRARIES } libopenrct2 ${ LDL } z )
target_link_platform_libraries ( test_plays )
add_test ( NAME play_tests COMMAND test_plays )
2018-12-30 11:15:03 +01:00
# Pathfinding test
set ( PATHFINDING_TEST_SOURCES "${CMAKE_CURRENT_LIST_DIR}/Pathfinding.cpp"
" $ { C M A K E _ C U R R E N T _ L I S T _ D I R } / T e s t D a t a . c p p " )
add_executable ( test_pathfinding ${ PATHFINDING_TEST_SOURCES } )
2019-02-03 23:32:51 +01:00
SET_CHECK_CXX_FLAGS ( test_pathfinding )
2018-12-30 11:15:03 +01:00
target_link_libraries ( test_pathfinding ${ GTEST_LIBRARIES } libopenrct2 ${ LDL } z )
2019-02-05 20:17:14 +01:00
target_link_platform_libraries ( test_pathfinding )
2018-12-30 11:15:03 +01:00
add_test ( NAME pathfinding COMMAND test_pathfinding )
2019-03-01 00:23:15 +01:00
2019-10-19 23:30:47 +02:00
# S6 Import/Export test
set ( S6IMPORTEXPORT_TEST_SOURCES "${CMAKE_CURRENT_LIST_DIR}/S6ImportExportTests.cpp"
2019-03-01 00:23:15 +01:00
" $ { C M A K E _ C U R R E N T _ L I S T _ D I R } / T e s t D a t a . c p p " )
2019-10-19 23:30:47 +02:00
add_executable ( test_s6importexporttests ${ S6IMPORTEXPORT_TEST_SOURCES } )
SET_CHECK_CXX_FLAGS ( test_s6importexporttests )
target_link_libraries ( test_s6importexporttests ${ GTEST_LIBRARIES } libopenrct2 ${ LDL } z )
target_link_platform_libraries ( test_s6importexporttests )
add_test ( NAME s6importexporttests COMMAND test_s6importexporttests )