CMakeLists.txt 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. # Find packages required to compile tests. Imported targets are directory-scoped, so the Boost components that the
  2. # engine links (found in src/) have to be looked up here too.
  3. find_package(Boost REQUIRED COMPONENTS filesystem unit_test_framework program_options thread
  4. OPTIONAL_COMPONENTS system chrono)
  5. # Compiler options.
  6. if(UNIX OR APPLE)
  7. add_definitions(-DBOOST_TEST_DYN_LINK)
  8. endif()
  9. if (UNIX)
  10. add_definitions(-DPOSIX) # For SUDM. TODO: Add elses?
  11. endif()
  12. # Directories to include for test compilations.
  13. include_directories(
  14. ${CMAKE_SOURCE_DIR}/src
  15. ${CMAKE_SOURCE_DIR}/src/installer
  16. ${CMAKE_CURRENT_SOURCE_DIR}
  17. ${ZLIB_INCLUDE_DIRS}
  18. ${OGRE_INCLUDE_DIRS}
  19. ${QT_QTCORE_INCLUDE_DIR}
  20. ${QT_QTGUI_INCLUDE_DIR}
  21. ${QT_QTCORE_INCLUDE_DIR}
  22. ${QT_QTGUI_INCLUDE_DIR}
  23. )
  24. # Test source files. Each folder lists its own in its CMakeLists.txt, with one of these functions: vgears_tests for
  25. # the main test program, and vgears_installer_tests for the one of the installer logic.
  26. function(vgears_collect_tests property)
  27. foreach(_source IN LISTS ARGN)
  28. file(RELATIVE_PATH _path "${PROJECT_SOURCE_DIR}/test" "${CMAKE_CURRENT_SOURCE_DIR}/${_source}")
  29. set_property(GLOBAL APPEND PROPERTY ${property} "${_path}")
  30. endforeach()
  31. endfunction()
  32. function(vgears_tests)
  33. vgears_collect_tests(VGEARS_TESTS ${ARGN})
  34. endfunction()
  35. function(vgears_installer_tests)
  36. vgears_collect_tests(VGEARS_INSTALLER_TESTS ${ARGN})
  37. endfunction()
  38. add_subdirectory(common)
  39. add_subdirectory(engine)
  40. add_subdirectory(formats)
  41. add_subdirectory(installer)
  42. get_property(TEST_SOURCE_FILES GLOBAL PROPERTY VGEARS_TESTS)
  43. list(SORT TEST_SOURCE_FILES)
  44. get_property(INSTALLER_TEST_SOURCE_FILES GLOBAL PROPERTY VGEARS_INSTALLER_TESTS)
  45. list(SORT INSTALLER_TEST_SOURCE_FILES)
  46. # Generate tests
  47. add_executable(v-gears-tests main.cpp ${TEST_SOURCE_FILES})
  48. SET_PROPERTY(TARGET v-gears-tests PROPERTY FOLDER "build/v-gears-test")
  49. # Qt imported targets are directory-scoped: the ones created in src/ are not
  50. # visible here. Look them up again in this scope, and fall back to plain
  51. # linker flags when the config package is unavailable.
  52. if(NOT TARGET Qt5::Widgets)
  53. find_package(Qt5 COMPONENTS Core Widgets QUIET)
  54. endif()
  55. if(TARGET Qt5::Widgets)
  56. set(_test_qt_libs Qt5::Widgets Qt5::Core)
  57. else()
  58. set(_test_qt_libs -lQt5Widgets -lQt5Core)
  59. endif()
  60. # The tests use the same libraries as the engine (read from its target, as the variables set in src/ are not visible
  61. # here), plus libarchive, which the installer code needs.
  62. get_target_property(_engine_libs v-gears LINK_LIBRARIES)
  63. target_link_libraries(v-gears-tests
  64. libvgears
  65. ${_test_qt_libs}
  66. ${_engine_libs}
  67. archive
  68. ${ZLIB_LIBRARIES}
  69. Boost::unit_test_framework
  70. )
  71. add_test(NAME v-gears-tests COMMAND v-gears-tests)
  72. # Tests of the installer logic that doesn't need the rest of the engine (layout, option rules, verifier, log), and of
  73. # the data directory lookup shared by the game and the installer.
  74. add_executable(v-gears-installer-tests
  75. ${INSTALLER_TEST_SOURCE_FILES}
  76. # The code under test, which is built again here so these tests don't need the whole engine.
  77. ${CMAKE_SOURCE_DIR}/src/common/DataDirectory.cpp
  78. ${CMAKE_SOURCE_DIR}/src/common/InstallStamp.cpp
  79. ${CMAKE_SOURCE_DIR}/src/common/OgrePlugins.cpp
  80. ${CMAKE_SOURCE_DIR}/src/installer/extractors/MovieCamera.cpp
  81. ${CMAKE_SOURCE_DIR}/src/installer/steps/ExternalTools.cpp
  82. ${CMAKE_SOURCE_DIR}/src/installer/cli/InstallCommandLine.cpp
  83. ${CMAKE_SOURCE_DIR}/src/installer/steps/InstallLayout.cpp
  84. ${CMAKE_SOURCE_DIR}/src/installer/steps/InstallLog.cpp
  85. ${CMAKE_SOURCE_DIR}/src/installer/steps/InstallOptions.cpp
  86. ${CMAKE_SOURCE_DIR}/src/installer/steps/InstallVerifier.cpp
  87. ${CMAKE_SOURCE_DIR}/src/installer/steps/VideoFiles.cpp
  88. )
  89. SET_PROPERTY(TARGET v-gears-installer-tests PROPERTY FOLDER "build/v-gears-test")
  90. target_link_libraries(v-gears-installer-tests ${_test_qt_libs} ${Boost_LIBRARIES})
  91. target_compile_definitions(v-gears-installer-tests PRIVATE VGEARS_SOURCE_DIR="${CMAKE_SOURCE_DIR}")
  92. add_test(NAME v-gears-installer-tests COMMAND v-gears-installer-tests)