1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-02-04 03:40:14 +00:00

Merge branch 'google_test_fetch_content' into 'master'

Use FetchContent to get googletest

See merge request OpenMW/openmw!2240
This commit is contained in:
psi29a 2022-08-04 09:53:52 +00:00
commit 77b82add49
6 changed files with 152 additions and 215 deletions

View File

@ -11,8 +11,6 @@ BUILD_UNITTESTS=OFF
BUILD_BENCHMARKS=OFF BUILD_BENCHMARKS=OFF
if [[ "${BUILD_TESTS_ONLY}" ]]; then if [[ "${BUILD_TESTS_ONLY}" ]]; then
export GOOGLETEST_DIR="${PWD}/googletest/build/install"
env GENERATOR='Unix Makefiles' CONFIGURATION=Release CI/build_googletest.sh
BUILD_UNITTESTS=ON BUILD_UNITTESTS=ON
BUILD_BENCHMARKS=ON BUILD_BENCHMARKS=ON
fi fi
@ -99,8 +97,6 @@ if [[ "${BUILD_TESTS_ONLY}" ]]; then
-DBUILD_NIFTEST=OFF \ -DBUILD_NIFTEST=OFF \
-DBUILD_UNITTESTS=${BUILD_UNITTESTS} \ -DBUILD_UNITTESTS=${BUILD_UNITTESTS} \
-DBUILD_BENCHMARKS=${BUILD_BENCHMARKS} \ -DBUILD_BENCHMARKS=${BUILD_BENCHMARKS} \
-DGTEST_ROOT="${GOOGLETEST_DIR}" \
-DGMOCK_ROOT="${GOOGLETEST_DIR}" \
.. ..
else else
${ANALYZE} cmake \ ${ANALYZE} cmake \

View File

@ -642,16 +642,6 @@ if [ -z $SKIP_DOWNLOAD ]; then
"https://gitlab.com/OpenMW/openmw-deps/-/raw/main/windows/LuaJIT-2.1.0-beta3-msvc${LUA_MSVC_YEAR}-win${BITS}.7z" \ "https://gitlab.com/OpenMW/openmw-deps/-/raw/main/windows/LuaJIT-2.1.0-beta3-msvc${LUA_MSVC_YEAR}-win${BITS}.7z" \
"LuaJIT-2.1.0-beta3-msvc${LUA_MSVC_YEAR}-win${BITS}.7z" "LuaJIT-2.1.0-beta3-msvc${LUA_MSVC_YEAR}-win${BITS}.7z"
# Google test and mock
if [ -n "$TEST_FRAMEWORK" ]; then
echo "Google test 1.11.0..."
if [ -d googletest ]; then
printf " Google test exists, skipping."
else
git clone -b release-1.11.0 https://github.com/google/googletest.git
fi
fi
# ICU # ICU
download "ICU ${ICU_VER/_/.}"\ download "ICU ${ICU_VER/_/.}"\
"https://github.com/unicode-org/icu/releases/download/release-${ICU_VER/_/-}/icu4c-${ICU_VER}-Win${BITS}-MSVC2019.zip" \ "https://github.com/unicode-org/icu/releases/download/release-${ICU_VER/_/-}/icu4c-${ICU_VER}-Win${BITS}-MSVC2019.zip" \
@ -1003,61 +993,6 @@ printf "LuaJIT 2.1.0-beta3... "
done done
echo Done. echo Done.
} }
cd $DEPS
echo
# Google Test and Google Mock
if [ -n "$TEST_FRAMEWORK" ]; then
printf "Google test 1.11.0 ..."
cd googletest
mkdir -p build${MSVC_DISPLAY_YEAR}
cd build${MSVC_DISPLAY_YEAR}
GOOGLE_INSTALL_ROOT="${DEPS_INSTALL}/GoogleTest"
for CONFIGURATION in ${CONFIGURATIONS[@]}; do
# FindGMock.cmake mentions Release explicitly, but not RelWithDebInfo. Only one optimised library config can be used, so go for the safer one.
GTEST_CONFIG=$([ $CONFIGURATION == "RelWithDebInfo" ] && echo "Release" || echo "$CONFIGURATION" )
if [ $GTEST_CONFIG == "Debug" ]; then
DEBUG_SUFFIX="d"
else
DEBUG_SUFFIX=""
fi
if [ ! -f "$GOOGLE_INSTALL_ROOT/lib/gtest${DEBUG_SUFFIX}.lib" ]; then
# Always use MSBuild solution files as they don't need the environment activating
cmake .. -DCMAKE_USE_WIN32_THREADS_INIT=1 -G "Visual Studio $MSVC_REAL_VER $MSVC_DISPLAY_YEAR" "-A $([ $BITS -eq 64 ] && echo "x64" || echo "Win32")" -DBUILD_SHARED_LIBS=1
cmake --build . --config "${GTEST_CONFIG}"
cmake --install . --config "${GTEST_CONFIG}" --prefix "${GOOGLE_INSTALL_ROOT}"
fi
add_runtime_dlls $CONFIGURATION "${GOOGLE_INSTALL_ROOT}\bin\gtest_main${DEBUG_SUFFIX}.dll"
add_runtime_dlls $CONFIGURATION "${GOOGLE_INSTALL_ROOT}\bin\gtest${DEBUG_SUFFIX}.dll"
add_runtime_dlls $CONFIGURATION "${GOOGLE_INSTALL_ROOT}\bin\gmock_main${DEBUG_SUFFIX}.dll"
add_runtime_dlls $CONFIGURATION "${GOOGLE_INSTALL_ROOT}\bin\gmock${DEBUG_SUFFIX}.dll"
done
add_cmake_opts -DBUILD_UNITTESTS=yes
# FindGTest and FindGMock do not work perfectly on Windows
# but we can help them by telling them everything we know about installation
add_cmake_opts -DGMOCK_ROOT="$GOOGLE_INSTALL_ROOT"
add_cmake_opts -DGTEST_ROOT="$GOOGLE_INSTALL_ROOT"
add_cmake_opts -DGTEST_LIBRARY="$GOOGLE_INSTALL_ROOT/lib/gtest.lib"
add_cmake_opts -DGTEST_MAIN_LIBRARY="$GOOGLE_INSTALL_ROOT/lib/gtest_main.lib"
add_cmake_opts -DGMOCK_LIBRARY="$GOOGLE_INSTALL_ROOT/lib/gmock.lib"
add_cmake_opts -DGMOCK_MAIN_LIBRARY="$GOOGLE_INSTALL_ROOT/lib/gmock_main.lib"
add_cmake_opts -DGTEST_LIBRARY_DEBUG="$GOOGLE_INSTALL_ROOT/lib/gtestd.lib"
add_cmake_opts -DGTEST_MAIN_LIBRARY_DEBUG="$GOOGLE_INSTALL_ROOT/lib/gtest_maind.lib"
add_cmake_opts -DGMOCK_LIBRARY_DEBUG="$GOOGLE_INSTALL_ROOT/lib/gmockd.lib"
add_cmake_opts -DGMOCK_MAIN_LIBRARY_DEBUG="$GOOGLE_INSTALL_ROOT/lib/gmock_maind.lib"
add_cmake_opts -DGTEST_LINKED_AS_SHARED_LIBRARY=True
add_cmake_opts -DGTEST_LIBRARY_TYPE=SHARED
add_cmake_opts -DGTEST_MAIN_LIBRARY_TYPE=SHARED
echo Done.
fi
cd $DEPS cd $DEPS
echo echo
@ -1176,6 +1111,10 @@ if [ "${BUILD_BENCHMARKS}" ]; then
add_cmake_opts -DBUILD_BENCHMARKS=ON add_cmake_opts -DBUILD_BENCHMARKS=ON
fi fi
if [ -n "${TEST_FRAMEWORK}" ]; then
add_cmake_opts -DBUILD_UNITTESTS=ON
fi
if [ -n "$ACTIVATE_MSVC" ]; then if [ -n "$ACTIVATE_MSVC" ]; then
echo -n "- Activating MSVC in the current shell... " echo -n "- Activating MSVC in the current shell... "
command -v vswhere >/dev/null 2>&1 || { echo "Error: vswhere is not on the path."; wrappedExit 1; } command -v vswhere >/dev/null 2>&1 || { echo "Error: vswhere is not on the path."; wrappedExit 1; }

View File

@ -1,17 +0,0 @@
#!/bin/sh -ex
git clone -b release-1.11.0 https://github.com/google/googletest.git
cd googletest
mkdir build
cd build
cmake \
-D CMAKE_C_COMPILER="${CC}" \
-D CMAKE_CXX_COMPILER="${CXX}" \
-D CMAKE_C_COMPILER_LAUNCHER=ccache \
-D CMAKE_CXX_COMPILER_LAUNCHER=ccache \
-D CMAKE_BUILD_TYPE="${CONFIGURATION}" \
-D CMAKE_INSTALL_PREFIX="${GOOGLETEST_DIR}" \
-G "${GENERATOR}" \
..
cmake --build . --config "${CONFIGURATION}" -- -j $(nproc)
cmake --install . --config "${CONFIGURATION}"

View File

@ -163,6 +163,7 @@ option(RECASTNAVIGATION_STATIC "Build recastnavigation static libraries" ${_reca
option(OPENMW_USE_SYSTEM_SQLITE3 "Use system provided SQLite3 library" ON) option(OPENMW_USE_SYSTEM_SQLITE3 "Use system provided SQLite3 library" ON)
option(OPENMW_USE_SYSTEM_BENCHMARK "Use system Google Benchmark library." OFF) option(OPENMW_USE_SYSTEM_BENCHMARK "Use system Google Benchmark library." OFF)
option(OPENMW_USE_SYSTEM_GOOGLETEST "Use system Google Test library." OFF)
option(OPENMW_UNITY_BUILD "Use fewer compilation units to speed up compile time" FALSE) option(OPENMW_UNITY_BUILD "Use fewer compilation units to speed up compile time" FALSE)
option(OPENMW_LTO_BUILD "Build OpenMW with Link-Time Optimization (Needs ~2GB of RAM)" OFF) option(OPENMW_LTO_BUILD "Build OpenMW with Link-Time Optimization (Needs ~2GB of RAM)" OFF)

View File

@ -1,130 +1,130 @@
find_package(GTest 1.10 REQUIRED) if (OPENMW_USE_SYSTEM_GOOGLETEST)
find_package(GMock 1.10 REQUIRED) find_package(GTest 1.10 REQUIRED)
find_package(GMock 1.10 REQUIRED)
if (GTEST_FOUND AND GMOCK_FOUND) endif()
include_directories(SYSTEM ${GTEST_INCLUDE_DIRS})
include_directories(SYSTEM ${GMOCK_INCLUDE_DIRS}) include_directories(SYSTEM ${GTEST_INCLUDE_DIRS})
include_directories(SYSTEM ${GMOCK_INCLUDE_DIRS})
file(GLOB UNITTEST_SRC_FILES
testing_util.hpp file(GLOB UNITTEST_SRC_FILES
testing_util.hpp
../openmw/mwworld/store.cpp
../openmw/mwworld/esmstore.cpp ../openmw/mwworld/store.cpp
mwworld/test_store.cpp ../openmw/mwworld/esmstore.cpp
mwworld/test_store.cpp
mwdialogue/test_keywordsearch.cpp
mwdialogue/test_keywordsearch.cpp
mwscript/test_scripts.cpp
mwscript/test_scripts.cpp
esm/test_fixed_string.cpp
esm/variant.cpp esm/test_fixed_string.cpp
esm/variant.cpp
lua/test_lua.cpp
lua/test_scriptscontainer.cpp lua/test_lua.cpp
lua/test_utilpackage.cpp lua/test_scriptscontainer.cpp
lua/test_serialization.cpp lua/test_utilpackage.cpp
lua/test_configuration.cpp lua/test_serialization.cpp
lua/test_l10n.cpp lua/test_configuration.cpp
lua/test_storage.cpp lua/test_l10n.cpp
lua/test_storage.cpp
lua/test_ui_content.cpp
lua/test_ui_content.cpp
misc/test_stringops.cpp
misc/test_endianness.cpp misc/test_stringops.cpp
misc/test_resourcehelpers.cpp misc/test_endianness.cpp
misc/progressreporter.cpp misc/test_resourcehelpers.cpp
misc/compression.cpp misc/progressreporter.cpp
misc/compression.cpp
nifloader/testbulletnifloader.cpp
nifloader/testbulletnifloader.cpp
detournavigator/navigator.cpp
detournavigator/settingsutils.cpp detournavigator/navigator.cpp
detournavigator/recastmeshbuilder.cpp detournavigator/settingsutils.cpp
detournavigator/gettilespositions.cpp detournavigator/recastmeshbuilder.cpp
detournavigator/recastmeshobject.cpp detournavigator/gettilespositions.cpp
detournavigator/navmeshtilescache.cpp detournavigator/recastmeshobject.cpp
detournavigator/tilecachedrecastmeshmanager.cpp detournavigator/navmeshtilescache.cpp
detournavigator/navmeshdb.cpp detournavigator/tilecachedrecastmeshmanager.cpp
detournavigator/serialization.cpp detournavigator/navmeshdb.cpp
detournavigator/asyncnavmeshupdater.cpp detournavigator/serialization.cpp
detournavigator/asyncnavmeshupdater.cpp
serialization/binaryreader.cpp
serialization/binarywriter.cpp serialization/binaryreader.cpp
serialization/sizeaccumulator.cpp serialization/binarywriter.cpp
serialization/integration.cpp serialization/sizeaccumulator.cpp
serialization/integration.cpp
settings/parser.cpp
settings/shadermanager.cpp settings/parser.cpp
settings/shadermanager.cpp
shader/parsedefines.cpp
shader/parsefors.cpp shader/parsedefines.cpp
shader/parselinks.cpp shader/parsefors.cpp
shader/shadermanager.cpp shader/parselinks.cpp
shader/shadermanager.cpp
../openmw/options.cpp
openmw/options.cpp ../openmw/options.cpp
openmw/options.cpp
sqlite3/db.cpp
sqlite3/request.cpp sqlite3/db.cpp
sqlite3/statement.cpp sqlite3/request.cpp
sqlite3/transaction.cpp sqlite3/statement.cpp
sqlite3/transaction.cpp
esmloader/load.cpp
esmloader/esmdata.cpp esmloader/load.cpp
esmloader/record.cpp esmloader/esmdata.cpp
esmloader/record.cpp
files/hash.cpp
files/hash.cpp
toutf8/toutf8.cpp
toutf8/toutf8.cpp
esm4/includes.cpp
esm4/includes.cpp
fx/lexer.cpp
fx/technique.cpp fx/lexer.cpp
fx/technique.cpp
esm3/readerscache.cpp
) esm3/readerscache.cpp
)
source_group(apps\\openmw_test_suite FILES openmw_test_suite.cpp ${UNITTEST_SRC_FILES})
source_group(apps\\openmw_test_suite FILES openmw_test_suite.cpp ${UNITTEST_SRC_FILES})
openmw_add_executable(openmw_test_suite openmw_test_suite.cpp ${UNITTEST_SRC_FILES})
openmw_add_executable(openmw_test_suite openmw_test_suite.cpp ${UNITTEST_SRC_FILES})
target_link_libraries(openmw_test_suite ${GMOCK_LIBRARIES} components)
# Fix for not visible pthreads functions for linker with glibc 2.15 target_link_libraries(openmw_test_suite GTest::GTest GMock::GMock components)
if (UNIX AND NOT APPLE) # Fix for not visible pthreads functions for linker with glibc 2.15
target_link_libraries(openmw_test_suite ${CMAKE_THREAD_LIBS_INIT}) if (UNIX AND NOT APPLE)
endif() target_link_libraries(openmw_test_suite ${CMAKE_THREAD_LIBS_INIT})
endif()
if (BUILD_WITH_CODE_COVERAGE)
add_definitions(--coverage) if (BUILD_WITH_CODE_COVERAGE)
target_link_libraries(openmw_test_suite gcov) add_definitions(--coverage)
endif() target_link_libraries(openmw_test_suite gcov)
endif()
file(DOWNLOAD
https://gitlab.com/OpenMW/example-suite/-/raw/8966dab24692555eec720c854fb0f73d108070cd/data/template.omwgame file(DOWNLOAD
${CMAKE_CURRENT_BINARY_DIR}/data/template.omwgame https://gitlab.com/OpenMW/example-suite/-/raw/8966dab24692555eec720c854fb0f73d108070cd/data/template.omwgame
EXPECTED_HASH SHA512=6e38642bcf013c5f496a9cb0bf3ec7c9553b6e86b836e7844824c5a05f556c9391167214469b6318401684b702d7569896bf743c85aee4198612b3315ba778d6 ${CMAKE_CURRENT_BINARY_DIR}/data/template.omwgame
) EXPECTED_HASH SHA512=6e38642bcf013c5f496a9cb0bf3ec7c9553b6e86b836e7844824c5a05f556c9391167214469b6318401684b702d7569896bf743c85aee4198612b3315ba778d6
)
target_compile_definitions(openmw_test_suite
PRIVATE OPENMW_DATA_DIR="${CMAKE_CURRENT_BINARY_DIR}/data" target_compile_definitions(openmw_test_suite
OPENMW_TEST_SUITE_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}") PRIVATE OPENMW_DATA_DIR="${CMAKE_CURRENT_BINARY_DIR}/data"
OPENMW_TEST_SUITE_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}")
if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.16 AND MSVC)
target_precompile_headers(openmw_test_suite PRIVATE if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.16 AND MSVC)
<boost/program_options/options_description.hpp> target_precompile_headers(openmw_test_suite PRIVATE
<boost/program_options/options_description.hpp>
<gtest/gtest.h>
<gtest/gtest.h>
<sol/sol.hpp>
<sol/sol.hpp>
<algorithm>
<filesystem> <algorithm>
<fstream> <filesystem>
<functional> <fstream>
<memory> <functional>
<string> <memory>
<vector> <string>
) <vector>
endif() )
endif() endif()

18
extern/CMakeLists.txt vendored
View File

@ -301,3 +301,21 @@ if (NOT OPENMW_USE_SYSTEM_ICU)
endforeach() endforeach()
set(ICU_LIBRARIES ICU::i18n ICU::uc ICU::data PARENT_SCOPE) set(ICU_LIBRARIES ICU::i18n ICU::uc ICU::data PARENT_SCOPE)
endif() endif()
if (BUILD_UNITTESTS AND NOT OPENMW_USE_SYSTEM_GOOGLETEST)
cmake_minimum_required(VERSION 3.11)
include(FetchContent)
FetchContent_Declare(googletest
URL https://github.com/google/googletest/archive/refs/tags/release-1.12.1.zip
URL_HASH SHA512=1479ea2f3172c622c0ca305f5b2bc45a42941221ec0ac7865e6d6d020ec4d008d952fc64e01a4c5138d7bed4148cf75596f25bb9e9044a98bbbf5662053ea11c
SOURCE_DIR fetched/googletest
)
if (MSVC)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
endif()
FetchContent_MakeAvailableExcludeFromAll(googletest)
add_library(GTest::GTest ALIAS gtest)
add_library(GMock::GMock ALIAS gmock)
endif()