From 6f6e452dfafc7eb80f38f514a6d3ac95ecd19497 Mon Sep 17 00:00:00 2001 From: elsid Date: Fri, 10 Mar 2023 01:19:15 +0100 Subject: [PATCH] Add executable to run CS tests --- CI/before_script.msvc.sh | 1 + CMakeLists.txt | 20 +++++++++++---- apps/opencs/CMakeLists.txt | 37 ++++++++++++++++----------- apps/opencs_tests/CMakeLists.txt | 31 ++++++++++++++++++++++ apps/opencs_tests/main.cpp | 7 +++++ apps/openmw_test_suite/CMakeLists.txt | 5 ---- extern/CMakeLists.txt | 2 +- 7 files changed, 77 insertions(+), 26 deletions(-) create mode 100644 apps/opencs_tests/CMakeLists.txt create mode 100644 apps/opencs_tests/main.cpp diff --git a/CI/before_script.msvc.sh b/CI/before_script.msvc.sh index d4930dce9c..59fc8b8c0a 100644 --- a/CI/before_script.msvc.sh +++ b/CI/before_script.msvc.sh @@ -1117,6 +1117,7 @@ fi if [ -n "${TEST_FRAMEWORK}" ]; then add_cmake_opts -DBUILD_UNITTESTS=ON + add_cmake_opts -DBUILD_OPENCS_TESTS=ON fi if [ -n "$ACTIVATE_MSVC" ]; then diff --git a/CMakeLists.txt b/CMakeLists.txt index 4954722843..bc964f60d7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -54,13 +54,14 @@ option(BUILD_UNITTESTS "Enable Unittests with Google C++ Unittest" OFF) option(BUILD_BENCHMARKS "Build benchmarks with Google Benchmark" OFF) option(BUILD_NAVMESHTOOL "Build navmesh tool" ON) option(BUILD_BULLETOBJECTTOOL "Build Bullet object tool" ON) +option(BUILD_OPENCS_TESTS "Build OpenMW Construction Set tests" OFF) set(OpenGL_GL_PREFERENCE LEGACY) # Use LEGACY as we use GL2; GLNVD is for GL3 and up. -if (NOT BUILD_LAUNCHER AND NOT BUILD_OPENCS AND NOT BUILD_WIZARD) - set(USE_QT FALSE) -else() +if (BUILD_LAUNCHER OR BUILD_OPENCS OR BUILD_WIZARD OR BUILD_OPENCS_TESTS) set(USE_QT TRUE) +else() + set(USE_QT FALSE) endif() # If the user doesn't supply a CMAKE_BUILD_TYPE via command line, choose one for them. @@ -294,6 +295,11 @@ if (OPENMW_USE_SYSTEM_YAML_CPP) find_package(yaml-cpp REQUIRED) endif() +if ((BUILD_UNITTESTS OR BUILD_OPENCS_TESTS) AND OPENMW_USE_SYSTEM_GOOGLETEST) + find_package(GTest 1.10 REQUIRED) + find_package(GMock 1.10 REQUIRED) +endif() + add_subdirectory(extern) # Sound setup @@ -621,7 +627,7 @@ endif (CMAKE_CXX_COMPILER_ID STREQUAL GNU OR CMAKE_CXX_COMPILER_ID STREQUAL Clan add_subdirectory (extern/osg-ffmpeg-videoplayer) add_subdirectory (extern/oics) add_subdirectory (extern/Base64) -if (BUILD_OPENCS AND Qt5_FOUND) +if ((BUILD_OPENCS OR BUILD_OPENCS_TESTS) AND Qt5_FOUND) add_subdirectory (extern/osgQt) endif() @@ -657,7 +663,7 @@ if (BUILD_ESSIMPORTER) add_subdirectory (apps/essimporter ) endif() -if (BUILD_OPENCS) +if (BUILD_OPENCS OR BUILD_OPENCS_TESTS) add_subdirectory (apps/opencs) endif() @@ -686,6 +692,10 @@ if (BUILD_BULLETOBJECTTOOL) add_subdirectory( apps/bulletobjecttool ) endif() +if (BUILD_OPENCS_TESTS) + add_subdirectory(apps/opencs_tests) +endif() + if (WIN32) if (MSVC) foreach( OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES} ) diff --git a/apps/opencs/CMakeLists.txt b/apps/opencs/CMakeLists.txt index 2104d80750..2247d71717 100644 --- a/apps/opencs/CMakeLists.txt +++ b/apps/opencs/CMakeLists.txt @@ -176,18 +176,25 @@ add_library(openmw-cs-lib set_target_properties(openmw-cs-lib PROPERTIES OUTPUT_NAME openmw-cs) -openmw_add_executable(openmw-cs - MACOSX_BUNDLE - ${OPENCS_MAC_ICON} - ${OPENCS_CFG} - ${OPENCS_DEFAULT_FILTERS_FILE} - ${OPENCS_OPENMW_CFG} - main.cpp -) +if(BUILD_OPENCS) + openmw_add_executable(openmw-cs + MACOSX_BUNDLE + ${OPENCS_MAC_ICON} + ${OPENCS_CFG} + ${OPENCS_DEFAULT_FILTERS_FILE} + ${OPENCS_OPENMW_CFG} + main.cpp + ) -target_link_libraries(openmw-cs openmw-cs-lib) + target_link_libraries(openmw-cs openmw-cs-lib) -if(APPLE) + if (BUILD_WITH_CODE_COVERAGE) + target_compile_options(openmw-cs-lib PRIVATE --coverage) + target_link_libraries(openmw-cs-lib gcov) + endif() +endif() + +if(APPLE AND BUILD_OPENCS) set(OPENCS_BUNDLE_NAME "OpenMW-CS") set(OPENCS_BUNDLE_RESOURCES_DIR "${OpenMW_BINARY_DIR}/${OPENCS_BUNDLE_NAME}.app/Contents/Resources") @@ -218,7 +225,7 @@ if(APPLE) add_custom_command(TARGET openmw-cs POST_BUILD COMMAND cp "${OpenMW_BINARY_DIR}/resources/version" "${OPENCS_BUNDLE_RESOURCES_DIR}/resources") -endif(APPLE) +endif() target_link_libraries(openmw-cs-lib # CMake's built-in OSG finder does not use pkgconfig, so we have to @@ -240,6 +247,9 @@ target_link_libraries(openmw-cs-lib Qt::Widgets Qt::Core Qt::Network Qt::OpenGL) if (WIN32) target_link_libraries(openmw-cs-lib ${Boost_LOCALE_LIBRARY}) +endif() + +if (WIN32 AND BUILD_OPENCS) INSTALL(TARGETS openmw-cs RUNTIME DESTINATION ".") get_generator_is_multi_config(multi_config) @@ -259,8 +269,7 @@ if (MSVC) endif (CMAKE_CL_64) endif (MSVC) - -if(APPLE) +if(APPLE AND BUILD_OPENCS) INSTALL(TARGETS openmw-cs BUNDLE DESTINATION "." COMPONENT Bundle) endif() @@ -271,8 +280,6 @@ endif(USE_QT) if (BUILD_WITH_CODE_COVERAGE) target_compile_options(openmw-cs-lib PRIVATE --coverage) target_link_libraries(openmw-cs-lib gcov) - target_compile_options(openmw-cs PRIVATE --coverage) - target_link_libraries(openmw-cs gcov) endif() if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.16 AND MSVC) diff --git a/apps/opencs_tests/CMakeLists.txt b/apps/opencs_tests/CMakeLists.txt new file mode 100644 index 0000000000..00d8d0177c --- /dev/null +++ b/apps/opencs_tests/CMakeLists.txt @@ -0,0 +1,31 @@ +file(GLOB OPENCS_TESTS_SRC_FILES + main.cpp +) + +source_group(apps\\openmw-cs-tests FILES ${OPENCS_TESTS_SRC_FILES}) + +openmw_add_executable(openmw-cs-tests ${OPENCS_TESTS_SRC_FILES}) + +target_include_directories(openmw-cs-tests SYSTEM PRIVATE ${GTEST_INCLUDE_DIRS}) +target_include_directories(openmw-cs-tests SYSTEM PRIVATE ${GMOCK_INCLUDE_DIRS}) + +target_link_libraries(openmw-cs-tests PRIVATE + openmw-cs-lib + GTest::GTest + GMock::GMock +) + +if (UNIX AND NOT APPLE) + target_link_libraries(openmw-cs-tests PRIVATE ${CMAKE_THREAD_LIBS_INIT}) +endif() + +if (BUILD_WITH_CODE_COVERAGE) + target_compile_options(openmw-cs-tests PRIVATE --coverage) + target_link_libraries(openmw-cs-tests PRIVATE gcov) +endif() + +if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.16 AND MSVC) + target_precompile_headers(openmw-cs-tests PRIVATE + + ) +endif() diff --git a/apps/opencs_tests/main.cpp b/apps/opencs_tests/main.cpp new file mode 100644 index 0000000000..e1a8e67397 --- /dev/null +++ b/apps/opencs_tests/main.cpp @@ -0,0 +1,7 @@ +#include + +int main(int argc, char* argv[]) +{ + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/apps/openmw_test_suite/CMakeLists.txt b/apps/openmw_test_suite/CMakeLists.txt index 6e7f191eae..34892905c1 100644 --- a/apps/openmw_test_suite/CMakeLists.txt +++ b/apps/openmw_test_suite/CMakeLists.txt @@ -1,8 +1,3 @@ -if (OPENMW_USE_SYSTEM_GOOGLETEST) - find_package(GTest 1.10 REQUIRED) - find_package(GMock 1.10 REQUIRED) -endif() - include_directories(SYSTEM ${GTEST_INCLUDE_DIRS}) include_directories(SYSTEM ${GMOCK_INCLUDE_DIRS}) diff --git a/extern/CMakeLists.txt b/extern/CMakeLists.txt index 20b62dbd84..36b56b2611 100644 --- a/extern/CMakeLists.txt +++ b/extern/CMakeLists.txt @@ -303,7 +303,7 @@ if (NOT OPENMW_USE_SYSTEM_ICU) set(ICU_LIBRARIES ICU::i18n ICU::uc ICU::data PARENT_SCOPE) endif() -if (BUILD_UNITTESTS AND NOT OPENMW_USE_SYSTEM_GOOGLETEST) +if ((BUILD_UNITTESTS OR BUILD_OPENCS_TESTS) AND NOT OPENMW_USE_SYSTEM_GOOGLETEST) cmake_minimum_required(VERSION 3.11) include(FetchContent)