From 99ba45a308c09f01976da483160dba93007413d1 Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Wed, 20 Jan 2021 02:25:46 +0000 Subject: [PATCH 01/20] Optional static builds of OSG, MyGUI, Bullet --- .gitignore | 2 +- .gitlab-ci.yml | 49 +++++-- CI/before_script.android.sh | 6 +- CI/before_script.linux.sh | 77 +++++----- CI/install_debian_deps.sh | 64 +++++++++ CMakeLists.txt | 90 ++++++------ apps/opencs/CMakeLists.txt | 14 ++ apps/openmw/CMakeLists.txt | 35 ++--- components/CMakeLists.txt | 2 +- extern/CMakeLists.txt | 139 +++++++++++++++++++ extern/osg-ffmpeg-videoplayer/CMakeLists.txt | 1 + 11 files changed, 361 insertions(+), 118 deletions(-) create mode 100755 CI/install_debian_deps.sh create mode 100644 extern/CMakeLists.txt diff --git a/.gitignore b/.gitignore index 1a164592a..8112f683a 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,7 @@ CMakeCache.txt cmake_install.cmake Makefile makefile -build* +build*/ prebuilt ##windows build process diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 810e23d38..7ad26bc55 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,19 +1,20 @@ +# Note: We set `needs` on each job to control the job DAG. +# See https://docs.gitlab.com/ee/ci/yaml/#needs stages: - build -.Debian: +.Debian_Image: tags: - docker - linux image: debian:bullseye + +.Debian: + extends: .Debian_Image cache: paths: - apt-cache/ - ccache/ - before_script: - - export APT_CACHE_DIR=`pwd`/apt-cache && mkdir -pv $APT_CACHE_DIR - - apt-get update -yq - - apt-get -o dir::cache::archives="$APT_CACHE_DIR" install -y cmake build-essential libboost-filesystem-dev libboost-program-options-dev libboost-system-dev libboost-iostreams-dev libavcodec-dev libavformat-dev libavutil-dev libswscale-dev libswresample-dev libsdl2-dev libqt5opengl5-dev libopenal-dev libopenscenegraph-dev libunshield-dev libtinyxml-dev libmygui-dev libbullet-dev liblz4-dev ccache git clang stage: build script: - export CCACHE_BASEDIR="`pwd`" @@ -33,6 +34,8 @@ Debian_GCC: extends: .Debian cache: key: Debian_GCC.v2 + before_script: + - CI/install_debian_deps.sh gcc openmw-deps openmw-deps-dynamic variables: CC: gcc CXX: g++ @@ -41,31 +44,52 @@ Debian_GCC: timeout: 2h Debian_GCC_tests: - extends: .Debian + extends: Debian_GCC cache: key: Debian_GCC_tests.v2 variables: - CC: gcc - CXX: g++ + CCACHE_SIZE: 1G + BUILD_TESTS_ONLY: 1 + +Debian_GCC_Static_Deps: + extends: Debian_GCC + cache: + key: Debian_GCC_Static_Deps + paths: + - apt-cache/ + - ccache/ + - build/extern/fetched/ + before_script: + - CI/install_debian_deps.sh gcc openmw-deps openmw-deps-static + variables: + CI_OPENMW_USE_STATIC_DEPS: 1 + +Debian_GCC_Static_Deps_tests: + extends: Debian_GCC_Static_Deps + cache: + key: Debian_GCC_Static_Deps_tests + variables: CCACHE_SIZE: 1G BUILD_TESTS_ONLY: 1 Debian_Clang: extends: .Debian + before_script: + - CI/install_debian_deps.sh clang openmw-deps openmw-deps-dynamic cache: key: Debian_Clang.v2 variables: CC: clang CXX: clang++ CCACHE_SIZE: 2G + # When CCache doesn't exist (e.g. first build on a fork), build takes more than 1h, which is the default for forks. + timeout: 2h Debian_Clang_tests: - extends: .Debian + extends: Debian_Clang cache: key: Debian_Clang_tests.v2 variables: - CC: clang - CXX: clang++ CCACHE_SIZE: 1G BUILD_TESTS_ONLY: 1 @@ -286,12 +310,13 @@ Debian_AndroidNDK_arm64-v8a: paths: - apt-cache/ - ccache/ + - build/extern/fetched/ before_script: - export APT_CACHE_DIR=`pwd`/apt-cache && mkdir -pv $APT_CACHE_DIR - echo "deb http://deb.debian.org/debian unstable main contrib" > /etc/apt/sources.list - echo "google-android-ndk-installer google-android-installers/mirror select https://dl.google.com" | debconf-set-selections - apt-get update -yq - - apt-get -o dir::cache::archives="$APT_CACHE_DIR" install -y cmake ccache curl unzip git build-essential google-android-ndk-installer + - apt-get -q -o dir::cache::archives="$APT_CACHE_DIR" install -y cmake ccache curl unzip git build-essential google-android-ndk-installer stage: build script: - export CCACHE_BASEDIR="`pwd`" diff --git a/CI/before_script.android.sh b/CI/before_script.android.sh index 8f0ec77da..3ea429f1b 100755 --- a/CI/before_script.android.sh +++ b/CI/before_script.android.sh @@ -3,7 +3,7 @@ # hack to work around: FFmpeg version is too old, 3.2 is required sed -i s/"NOT FFVER_OK"/"FALSE"/ CMakeLists.txt -mkdir build +mkdir -p build cd build cmake \ @@ -21,5 +21,7 @@ cmake \ -DBUILD_ESSIMPORTER=0 \ -DBUILD_OPENCS=0 \ -DBUILD_WIZARD=0 \ --DMyGUI_LIBRARY="/usr/lib/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/libMyGUIEngineStatic.a" \ +-DOPENMW_USE_SYSTEM_MYGUI=OFF \ +-DOPENMW_USE_SYSTEM_OSG=OFF \ +-DOPENMW_USE_SYSTEM_BULLET=OFF \ .. diff --git a/CI/before_script.linux.sh b/CI/before_script.linux.sh index 6df3dc32e..ef617e0d5 100755 --- a/CI/before_script.linux.sh +++ b/CI/before_script.linux.sh @@ -1,44 +1,55 @@ -#!/bin/bash -ex +#!/bin/bash + +set -xeo pipefail free -m if [[ "${BUILD_TESTS_ONLY}" ]]; then - export GOOGLETEST_DIR="$(pwd)/googletest/build/install" - env GENERATOR='Unix Makefiles' CONFIGURATION=Release CI/build_googletest.sh + export GOOGLETEST_DIR="${PWD}/googletest/build/install" + env GENERATOR='Unix Makefiles' CONFIGURATION=Release CI/build_googletest.sh +fi + +declare -a CMAKE_CONF_OPTS=( + -DCMAKE_C_COMPILER="${CC:-/usr/bin/cc}" + -DCMAKE_CXX_COMPILER="${CXX:-/usr/bin/c++}" + -DCMAKE_C_COMPILER_LAUNCHER=ccache + -DCMAKE_CXX_COMPILER_LAUNCHER=ccache + -DCMAKE_INSTALL_PREFIX=install + -DCMAKE_BUILD_TYPE=RelWithDebInfo + -DBUILD_SHARED_LIBS=OFF + -DUSE_SYSTEM_TINYXML=ON + -DCMAKE_INSTALL_PREFIX=install +) +declare -a CMAKE_CONF_ENV=() + +if [[ $CI_OPENMW_USE_STATIC_DEPS ]]; then + CMAKE_CONF_OPTS+=( + -DOPENMW_USE_SYSTEM_MYGUI=OFF + -DOPENMW_USE_SYSTEM_OSG=OFF + -DOPENMW_USE_SYSTEM_BULLET=OFF + ) fi -mkdir build +mkdir -p build cd build if [[ "${BUILD_TESTS_ONLY}" ]]; then - ${ANALYZE} 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_INSTALL_PREFIX=install \ - -D CMAKE_BUILD_TYPE=RelWithDebInfo \ - -D USE_SYSTEM_TINYXML=TRUE \ - -D BUILD_OPENMW=OFF \ - -D BUILD_BSATOOL=OFF \ - -D BUILD_ESMTOOL=OFF \ - -D BUILD_LAUNCHER=OFF \ - -D BUILD_MWINIIMPORTER=OFF \ - -D BUILD_ESSIMPORTER=OFF \ - -D BUILD_OPENCS=OFF \ - -D BUILD_WIZARD=OFF \ - -D BUILD_UNITTESTS=ON \ - -D GTEST_ROOT="${GOOGLETEST_DIR}" \ - -D GMOCK_ROOT="${GOOGLETEST_DIR}" \ - .. + env "${CMAKE_CONF_ENV[@]}" ${ANALYZE} cmake \ + "${CMAKE_CONF_OPTS[@]}" \ + -DBUILD_OPENMW=OFF \ + -DBUILD_BSATOOL=OFF \ + -DBUILD_ESMTOOL=OFF \ + -DBUILD_LAUNCHER=OFF \ + -DBUILD_MWINIIMPORTER=OFF \ + -DBUILD_ESSIMPORTER=OFF \ + -DBUILD_OPENCS=OFF \ + -DBUILD_WIZARD=OFF \ + -DBUILD_UNITTESTS=ON \ + -DGTEST_ROOT="${GOOGLETEST_DIR}" \ + -DGMOCK_ROOT="${GOOGLETEST_DIR}" \ + .. else - ${ANALYZE} cmake \ - -D CMAKE_C_COMPILER="${CC}" \ - -D CMAKE_CXX_COMPILER="${CXX}" \ - -D CMAKE_C_COMPILER_LAUNCHER=ccache \ - -D CMAKE_CXX_COMPILER_LAUNCHER=ccache \ - -D USE_SYSTEM_TINYXML=TRUE \ - -D CMAKE_INSTALL_PREFIX=install \ - -D CMAKE_BUILD_TYPE=Debug \ - .. + env "${CMAKE_CONF_ENV[@]}" ${ANALYZE} cmake \ + "${CMAKE_CONF_OPTS[@]}" \ + .. fi diff --git a/CI/install_debian_deps.sh b/CI/install_debian_deps.sh new file mode 100755 index 000000000..82d2ff681 --- /dev/null +++ b/CI/install_debian_deps.sh @@ -0,0 +1,64 @@ +#!/bin/bash + +set -euo pipefail + +print_help() { + echo "usage: $0 [group]..." + echo + echo " available groups: "${!GROUPED_DEPS[@]}"" +} + +declare -rA GROUPED_DEPS=( + [gcc]="binutils gcc g++ libc-dev" + [clang]="binutils clang" + + # Common dependencies for building OpenMW. + [openmw-deps]=" + make cmake ccache git pkg-config + + libboost-filesystem-dev libboost-program-options-dev + libboost-system-dev libboost-iostreams-dev + + libavcodec-dev libavformat-dev libavutil-dev libswscale-dev libswresample-dev + libsdl2-dev libqt5opengl5-dev libopenal-dev libunshield-dev libtinyxml-dev + libbullet-dev liblz4-dev libpng-dev libjpeg-dev + " + + # These dependencies can alternatively be built and linked statically. + [openmw-deps-dynamic]="libmygui-dev libopenscenegraph-dev" + + # Pre-requisites for building MyGUI and OSG for static linking. + # + # * MyGUI and OSG: libsdl2-dev liblz4-dev libfreetype6-dev + # * OSG: libgl-dev + # + # Plugins: + # * DAE: libcollada-dom-dev libboost-system-dev libboost-filesystem-dev + # * JPEG: libjpeg-dev + # * PNG: libpng-dev + [openmw-deps-static]=" + make cmake + ccache curl unzip libcollada-dom-dev libfreetype6-dev libjpeg-dev libpng-dev + libsdl2-dev libboost-system-dev libboost-filesystem-dev libgl-dev + " +) + +if [[ $# -eq 0 ]]; then + >&2 print_help + exit 1 +fi + +deps=() +for group in "$@"; do + if [[ ! -v GROUPED_DEPS[$group] ]]; then + >&2 echo "error: unknown group ${group}" + exit 1 + fi + deps+=(${GROUPED_DEPS[$group]}) +done + +export APT_CACHE_DIR="${PWD}/apt-cache" +set -x +mkdir -pv "$APT_CACHE_DIR" +apt-get update -yq +apt-get -q -o dir::cache::archives="$APT_CACHE_DIR" install -y "${deps[@]}" diff --git a/CMakeLists.txt b/CMakeLists.txt index 226511b52..be1f4dae4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,16 +1,11 @@ project(OpenMW) -cmake_minimum_required(VERSION 3.1.0) +cmake_minimum_required(VERSION 3.11) # CMP0083 NEW set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) # Detect OS include(cmake/OSIdentity.cmake) -# for link time optimization, remove if cmake version is >= 3.9 -if(POLICY CMP0069) - cmake_policy(SET CMP0069 NEW) -endif() - # Apps and tools option(BUILD_OPENMW "Build OpenMW" ON) option(BUILD_LAUNCHER "Build Launcher" ON) @@ -52,7 +47,6 @@ set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/) if (ANDROID) set(CMAKE_FIND_ROOT_PATH ${OPENMW_DEPENDENCIES_DIR} "${CMAKE_FIND_ROOT_PATH}") - set (OSG_PLUGINS_DIR CACHE STRING "") endif() # Version @@ -100,12 +94,18 @@ include(OpenMWMacros) configure_file ("${OpenMW_SOURCE_DIR}/docs/mainpage.hpp.cmake" "${OpenMW_BINARY_DIR}/docs/mainpage.hpp") -option(MYGUI_STATIC "Link static build of Mygui into the binaries" FALSE) option(BOOST_STATIC "Link static build of Boost into the binaries" FALSE) option(SDL2_STATIC "Link static build of SDL into the binaries" FALSE) -option(OSG_STATIC "Link static build of OpenSceneGraph into the binaries" FALSE) option(QT_STATIC "Link static build of QT into the binaries" FALSE) +option(OPENMW_USE_SYSTEM_OSG "Use system provided OpenSceneGraph libraries" ON) +option(OSG_STATIC "Link static build of OpenSceneGraph into the binaries" OFF) + +option(OPENMW_USE_SYSTEM_BULLET "Use system provided bullet physics library" ON) + +option(OPENMW_USE_SYSTEM_MYGUI "Use system provided mygui library" ON) +option(MYGUI_STATIC "Link static build of Mygui into the binaries" OFF) + 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) @@ -168,6 +168,8 @@ if (USE_QT) #set(CMAKE_AUTOMOC ON) endif() +add_subdirectory(extern) + # Sound setup # Require at least ffmpeg 3.2 for now @@ -243,6 +245,15 @@ if (WIN32) add_definitions(-DNOMINMAX -DWIN32_LEAN_AND_MEAN) endif() +if(OPENMW_USE_SYSTEM_BULLET) + set(REQUIRED_BULLET_VERSION 286) # Bullet 286 required due to runtime bugfixes for btCapsuleShape + if (DEFINED ENV{TRAVIS_BRANCH} OR DEFINED ENV{APPVEYOR}) + set(REQUIRED_BULLET_VERSION 283) # but for build testing, 283 is fine + endif() + + find_package(Bullet ${REQUIRED_BULLET_VERSION} REQUIRED COMPONENTS BulletCollision LinearMath) +endif() + if (NOT WIN32 AND BUILD_WIZARD) # windows users can just run the morrowind installer find_package(LIBUNSHIELD REQUIRED) # required only for non win32 when building openmw-wizard set(OPENMW_USE_UNSHIELD TRUE) @@ -261,35 +272,25 @@ if(NOT HAVE_STDINT_H) message(FATAL_ERROR "stdint.h was not found" ) endif() +if(OPENMW_USE_SYSTEM_OSG) + find_package(OpenSceneGraph 3.3.4 REQUIRED ${USED_OSG_COMPONENTS}) + if(OSG_STATIC) + unset(OSGPlugins_LIB_DIR) + foreach(OSGDB_LIB ${OSGDB_LIBRARY}) + # Skip library type names + if(EXISTS ${OSGDB_LIB} AND NOT IS_DIRECTORY ${OSGDB_LIB}) + get_filename_component(OSG_LIB_DIR ${OSGDB_LIB} DIRECTORY) + list(APPEND OSGPlugins_LIB_DIR "${OSG_LIB_DIR}/osgPlugins-${OPENSCENEGRAPH_VERSION}") + endif() + endforeach(OSGDB_LIB) + find_package(OSGPlugins REQUIRED COMPONENTS ${USED_OSG_PLUGINS}) + endif() +endif() -find_package(OpenSceneGraph 3.3.4 REQUIRED osgDB osgViewer osgText osgGA osgParticle osgUtil osgFX osgShadow osgAnimation) -include_directories(SYSTEM ${OPENSCENEGRAPH_INCLUDE_DIRS}) - -set(USED_OSG_PLUGINS - osgdb_bmp - osgdb_dds - osgdb_freetype - osgdb_jpeg - osgdb_osg - osgdb_png - osgdb_serializers_osg - osgdb_tga - ) - -set(OSGPlugins_LIB_DIR "") -foreach(OSGDB_LIB ${OSGDB_LIBRARY}) - # Skip library type names - if(EXISTS ${OSGDB_LIB} AND NOT IS_DIRECTORY ${OSGDB_LIB}) - get_filename_component(OSG_LIB_DIR ${OSGDB_LIB} DIRECTORY) - list(APPEND OSGPlugins_LIB_DIR "${OSG_LIB_DIR}/osgPlugins-${OPENSCENEGRAPH_VERSION}") - endif() -endforeach(OSGDB_LIB) +include_directories(BEFORE SYSTEM ${OPENSCENEGRAPH_INCLUDE_DIRS}) if(OSG_STATIC) add_definitions(-DOSG_LIBRARY_STATIC) - - find_package(OSGPlugins REQUIRED COMPONENTS ${USED_OSG_PLUGINS}) - list(APPEND OPENSCENEGRAPH_LIBRARIES ${OSGPlugins_LIBRARIES}) endif() set(BOOST_COMPONENTS system filesystem program_options iostreams) @@ -304,21 +305,18 @@ IF(BOOST_STATIC) set(Boost_USE_STATIC_LIBS ON) endif() -set(REQUIRED_BULLET_VERSION 286) # Bullet 286 required due to runtime bugfixes for btCapsuleShape -if (DEFINED ENV{TRAVIS_BRANCH} OR DEFINED ENV{APPVEYOR}) - set(REQUIRED_BULLET_VERSION 283) # but for build testing, 283 is fine -endif() - set(Boost_NO_BOOST_CMAKE ON) find_package(Boost 1.6.2 REQUIRED COMPONENTS ${BOOST_COMPONENTS}) -find_package(MyGUI 3.2.2 REQUIRED) +if(OPENMW_USE_SYSTEM_MYGUI) + find_package(MyGUI 3.2.2 REQUIRED) +endif() find_package(SDL2 2.0.9 REQUIRED) find_package(OpenAL REQUIRED) -find_package(Bullet ${REQUIRED_BULLET_VERSION} REQUIRED COMPONENTS BulletCollision LinearMath) -include_directories("." - SYSTEM +include_directories( + BEFORE SYSTEM + "." ${SDL2_INCLUDE_DIR} ${Boost_INCLUDE_DIR} ${MyGUI_INCLUDE_DIRS} @@ -848,11 +846,7 @@ elseif(NOT APPLE) # Install binaries IF(BUILD_OPENMW) - IF(ANDROID) - INSTALL(PROGRAMS "${INSTALL_SOURCE}/libopenmw.so" DESTINATION "${BINDIR}" ) - ELSE(ANDROID) - INSTALL(PROGRAMS "${INSTALL_SOURCE}/openmw" DESTINATION "${BINDIR}" ) - ENDIF(ANDROID) + INSTALL(PROGRAMS "$" DESTINATION "${BINDIR}" ) ENDIF(BUILD_OPENMW) IF(BUILD_LAUNCHER) INSTALL(PROGRAMS "${INSTALL_SOURCE}/openmw-launcher" DESTINATION "${BINDIR}" ) diff --git a/apps/opencs/CMakeLists.txt b/apps/opencs/CMakeLists.txt index b20920904..e6df90919 100644 --- a/apps/opencs/CMakeLists.txt +++ b/apps/opencs/CMakeLists.txt @@ -228,6 +228,20 @@ target_link_libraries(openmw-cs components ) +if(OSG_STATIC) + unset(_osg_plugins_static_files) + add_library(openmw_cs_osg_plugins INTERFACE) + foreach(_plugin ${USED_OSG_PLUGINS}) + string(TOUPPER ${_plugin} _plugin_uc) + list(APPEND _osg_plugins_static_files $) + target_link_libraries(openmw_cs_osg_plugins INTERFACE ${${_plugin_uc}_LIBRARY}) + endforeach() + # We use --whole-archive because OSG plugins use registration. + target_link_options(openmw_cs_osg_plugins INTERFACE + -Wl,--whole-archive ${_osg_plugins_static_files} -Wl,--no-whole-archive) + target_link_libraries(openmw-cs openmw_cs_osg_plugins) +endif(OSG_STATIC) + target_link_libraries(openmw-cs Qt5::Widgets Qt5::Core Qt5::Network Qt5::OpenGL) if (WIN32) diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index c01cbe60c..c87a96b3a 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -143,29 +143,22 @@ target_link_libraries(openmw components ) -if (ANDROID) - set (OSG_PLUGINS - -Wl,--whole-archive - ) - foreach(PLUGIN_NAME ${USED_OSG_PLUGINS}) - set(OSG_PLUGINS ${OSG_PLUGINS} ${OSG_PLUGINS_DIR}/lib${PLUGIN_NAME}.a) +if(OSG_STATIC) + unset(_osg_plugins_static_files) + add_library(openmw_osg_plugins INTERFACE) + foreach(_plugin ${USED_OSG_PLUGINS}) + string(TOUPPER ${_plugin} _plugin_uc) + list(APPEND _osg_plugins_static_files $) + target_link_libraries(openmw_osg_plugins INTERFACE ${${_plugin_uc}_LIBRARY}) endforeach() + # We use --whole-archive because OSG plugins use registration. + target_link_options(openmw_osg_plugins INTERFACE + -Wl,--whole-archive ${_osg_plugins_static_files} -Wl,--no-whole-archive) + target_link_libraries(openmw openmw_osg_plugins) +endif(OSG_STATIC) - set (OSG_PLUGINS - ${OSG_PLUGINS} -Wl,--no-whole-archive - ) - - target_link_libraries(openmw - EGL - android - log - dl - z - ${OPENSCENEGRAPH_LIBRARIES} - freetype - jpeg - png - ) +if (ANDROID) + target_link_libraries(openmw EGL android log z) endif (ANDROID) if (USE_SYSTEM_TINYXML) diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt index 832fc611f..09a2edb05 100644 --- a/components/CMakeLists.txt +++ b/components/CMakeLists.txt @@ -245,7 +245,7 @@ target_link_libraries(components RecastNavigation::Recast ) -if (BULLET_USE_DOUBLES AND (UBUNTU_FOUND OR DEBIAN_FOUND)) +if (BULLET_USE_DOUBLES AND (UBUNTU_FOUND OR DEBIAN_FOUND) AND OPENMW_USE_SYSTEM_BULLET) target_link_libraries(components BulletCollision-float64 LinearMath-float64) else() target_link_libraries(components ${BULLET_LIBRARIES}) diff --git a/extern/CMakeLists.txt b/extern/CMakeLists.txt new file mode 100644 index 000000000..f5743307a --- /dev/null +++ b/extern/CMakeLists.txt @@ -0,0 +1,139 @@ +# SPDX-License-Identifier: GPL-3.0-or-later + +# Like `FetchContent_MakeAvailable` but passes EXCLUDE_FROM_ALL to `add_subdirectory`. +macro(FetchContent_MakeAvailableExcludeFromAll) + foreach(contentName IN ITEMS ${ARGV}) + string(TOLOWER ${contentName} contentNameLower) + FetchContent_GetProperties(${contentName}) + if(NOT ${contentNameLower}_POPULATED) + FetchContent_Populate(${contentName}) + if(EXISTS ${${contentNameLower}_SOURCE_DIR}/CMakeLists.txt) + add_subdirectory(${${contentNameLower}_SOURCE_DIR} + ${${contentNameLower}_BINARY_DIR} EXCLUDE_FROM_ALL) + endif() + endif() + endforeach() +endmacro() + +if(NOT OPENMW_USE_SYSTEM_BULLET) + set(BUILD_BULLET3 OFF CACHE BOOL "") + set(BUILD_EXTRAS OFF CACHE BOOL "") + set(BUILD_OPENGL3_DEMOS OFF CACHE BOOL "") + set(BUILD_UNIT_TESTS OFF CACHE BOOL "") + set(BUILD_BULLET2_DEMOS OFF CACHE BOOL "") + set(BUILD_CLSOCKET OFF CACHE BOOL "") + set(BUILD_ENET OFF CACHE BOOL "") + set(BUILD_CPU_DEMOS OFF CACHE BOOL "") + set(BUILD_EGL OFF CACHE BOOL "") + + set(USE_DOUBLE_PRECISION ${BULLET_USE_DOUBLES} CACHE BOOL "") + set(BULLET2_MULTITHREADING ON CACHE BOOL "") + + # Version 3.08 with the following changes: + # 1. Fixes the linking of Threads: + # https://github.com/bulletphysics/bullet3/pull/3237 + # 2. Removes ~300 MiB of files not used here: + # rm -rf build3 data docs examples test Doxyfile + include(FetchContent) + FetchContent_Declare(bullet + URL https://github.com/glebm/bullet3/archive/ed5256454f4f84bd2c1728c88ddb0405d614e7d2.zip + URL_HASH MD5=e3c94fac35a7be885ad8843f828a0f96 + SOURCE_DIR fetched/bullet + ) + FetchContent_MakeAvailableExcludeFromAll(bullet) + + set(BULLET_INCLUDE_DIRS ${bullet_SOURCE_DIR}/src PARENT_SCOPE) + + # The order here is important to work around a bug in Bullet: + # https://github.com/bulletphysics/bullet3/issues/3233 + set(BULLET_LIBRARIES BulletCollision LinearMath PARENT_SCOPE) +endif() + +if(NOT OPENMW_USE_SYSTEM_MYGUI) + set(MYGUI_STATIC ON CACHE BOOL "") + + set(MYGUI_RENDERSYSTEM 4 CACHE STRING "") + set(MYGUI_DISABLE_PLUGINS TRUE CACHE BOOL "") + set(MYGUI_BUILD_DEMOS OFF CACHE BOOL "") + set(MYGUI_BUILD_PLUGINS OFF CACHE BOOL "") + set(MYGUI_BUILD_TOOLS OFF CACHE BOOL "") + + include(FetchContent) + FetchContent_Declare(mygui + URL https://github.com/MyGUI/mygui/archive/MyGUI3.4.0.zip + URL_HASH MD5=9e990a4240430cbf567bfe73488a274e + SOURCE_DIR fetched/mygui + ) + FetchContent_MakeAvailableExcludeFromAll(mygui) + + set(MyGUI_INCLUDE_DIRS ${mygui_SOURCE_DIR}/MyGUIEngine/include PARENT_SCOPE) + set(MyGUI_LIBRARIES MyGUIEngine PARENT_SCOPE) +endif() + +set(USED_OSG_COMPONENTS + osgDB + osgViewer + osgText + osgGA + osgParticle + osgUtil + osgFX + osgShadow + osgAnimation) +set(USED_OSG_COMPONENTS ${USED_OSG_COMPONENTS} PARENT_SCOPE) +set(USED_OSG_PLUGINS + osgdb_bmp + osgdb_dds + osgdb_freetype + osgdb_jpeg + osgdb_osg + osgdb_png + osgdb_serializers_osg + osgdb_tga) +set(USED_OSG_PLUGINS ${USED_OSG_PLUGINS} PARENT_SCOPE) +if(NOT OPENMW_USE_SYSTEM_OSG) + set(OSG_STATIC ON CACHE BOOL "") + + set(DYNAMIC_OPENTHREADS OFF CACHE BOOL "") + set(DYNAMIC_OPENSCENEGRAPH OFF CACHE BOOL "") + set(BUILD_OSG_APPLICATIONS OFF CACHE BOOL "") + set(BUILD_OSG_DEPRECATED_SERIALIZERS OFF CACHE BOOL "") + + set(BUILD_OSG_PLUGINS_BY_DEFAULT OFF CACHE BOOL "") + set(BUILD_OSG_PLUGIN_BMP ON CACHE BOOL "") + set(BUILD_OSG_PLUGIN_DDS ON CACHE BOOL "") + set(BUILD_OSG_PLUGIN_FREETYPE ON CACHE BOOL "") + set(BUILD_OSG_PLUGIN_JPEG ON CACHE BOOL "") + set(BUILD_OSG_PLUGIN_OSG ON CACHE BOOL "") + set(BUILD_OSG_PLUGIN_PNG ON CACHE BOOL "") + set(BUILD_OSG_PLUGIN_TGA ON CACHE BOOL "") + set(BUILD_OSG_PLUGIN_KTX ON CACHE BOOL "") + + set(OSG_USE_FLOAT_MATRIX ON CACHE BOOL "") + set(OSG_USE_FLOAT_PLANE ON CACHE BOOL "") + set(OSG_USE_FLOAT_QUAT ON CACHE BOOL "") + + set(OPENGL_PROFILE "GL2" CACHE STRING "") + + # branch OpenSceneGraph-3.6 on 18 Jan 2021. + # + https://github.com/openscenegraph/OpenSceneGraph/pull/1032 + # + https://github.com/openscenegraph/OpenSceneGraph/pull/1033 + include(FetchContent) + FetchContent_Declare(osg + URL https://github.com/glebm/OpenSceneGraph/archive/041090d84d9d4b72f1202457fceae0ec6f79b663.zip + URL_HASH MD5=2cbf8126b27a45a2a44efe9fa39090f3 + SOURCE_DIR fetched/osg + ) + FetchContent_MakeAvailableExcludeFromAll(osg) + + set(OPENSCENEGRAPH_INCLUDE_DIRS ${osg_SOURCE_DIR}/include ${osg_BINARY_DIR}/include PARENT_SCOPE) + set(OSG_LIBRARIES OpenThreads osg PARENT_SCOPE) + foreach(_name ${USED_OSG_COMPONENTS}) + string(TOUPPER ${_name} _name_uc) + set(${_name_uc}_LIBRARIES ${_name} PARENT_SCOPE) + endforeach() + foreach(_name ${USED_OSG_PLUGINS}) + string(TOUPPER ${_name} _name_uc) + set(${_name_uc}_LIBRARY ${_name} PARENT_SCOPE) + endforeach() +endif() diff --git a/extern/osg-ffmpeg-videoplayer/CMakeLists.txt b/extern/osg-ffmpeg-videoplayer/CMakeLists.txt index 5289cd3af..8ab51196a 100644 --- a/extern/osg-ffmpeg-videoplayer/CMakeLists.txt +++ b/extern/osg-ffmpeg-videoplayer/CMakeLists.txt @@ -13,5 +13,6 @@ set(OSG_FFMPEG_VIDEOPLAYER_SOURCE_FILES include_directories(${FFmpeg_INCLUDE_DIRS}) add_library(${OSG_FFMPEG_VIDEOPLAYER_LIBRARY} STATIC ${OSG_FFMPEG_VIDEOPLAYER_SOURCE_FILES}) target_link_libraries(${OSG_FFMPEG_VIDEOPLAYER_LIBRARY} ${FFmpeg_LIBRARIES} ${Boost_THREAD_LIBRARY}) +target_link_libraries(${OSG_FFMPEG_VIDEOPLAYER_LIBRARY} ${OSG_LIBRARIES}) link_directories(${CMAKE_CURRENT_BINARY_DIR}) From 93fe84aea8921a87f7aaf7fc949b425324a3c276 Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Wed, 20 Jan 2021 19:03:54 +0000 Subject: [PATCH 02/20] cmake: Move USED_OSG_(COMPONENTS|PLUGINS) from extern to top-level --- CMakeLists.txt | 19 +++++++++++++++++++ extern/CMakeLists.txt | 21 --------------------- 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index be1f4dae4..f883aecfc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -272,6 +272,25 @@ if(NOT HAVE_STDINT_H) message(FATAL_ERROR "stdint.h was not found" ) endif() +set(USED_OSG_COMPONENTS + osgDB + osgViewer + osgText + osgGA + osgParticle + osgUtil + osgFX + osgShadow + osgAnimation) +set(USED_OSG_PLUGINS + osgdb_bmp + osgdb_dds + osgdb_freetype + osgdb_jpeg + osgdb_osg + osgdb_png + osgdb_serializers_osg + osgdb_tga) if(OPENMW_USE_SYSTEM_OSG) find_package(OpenSceneGraph 3.3.4 REQUIRED ${USED_OSG_COMPONENTS}) if(OSG_STATIC) diff --git a/extern/CMakeLists.txt b/extern/CMakeLists.txt index f5743307a..b426ac4bf 100644 --- a/extern/CMakeLists.txt +++ b/extern/CMakeLists.txt @@ -70,27 +70,6 @@ if(NOT OPENMW_USE_SYSTEM_MYGUI) set(MyGUI_LIBRARIES MyGUIEngine PARENT_SCOPE) endif() -set(USED_OSG_COMPONENTS - osgDB - osgViewer - osgText - osgGA - osgParticle - osgUtil - osgFX - osgShadow - osgAnimation) -set(USED_OSG_COMPONENTS ${USED_OSG_COMPONENTS} PARENT_SCOPE) -set(USED_OSG_PLUGINS - osgdb_bmp - osgdb_dds - osgdb_freetype - osgdb_jpeg - osgdb_osg - osgdb_png - osgdb_serializers_osg - osgdb_tga) -set(USED_OSG_PLUGINS ${USED_OSG_PLUGINS} PARENT_SCOPE) if(NOT OPENMW_USE_SYSTEM_OSG) set(OSG_STATIC ON CACHE BOOL "") From 8737453498d7dc4b62458e53f5318c76bc40865d Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Wed, 20 Jan 2021 19:19:36 +0000 Subject: [PATCH 03/20] cmake: Compiler-specific whole-archive macro --- CMakeLists.txt | 1 + apps/opencs/CMakeLists.txt | 4 ++-- apps/openmw/CMakeLists.txt | 4 ++-- cmake/WholeArchive.cmake | 10 ++++++++++ 4 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 cmake/WholeArchive.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index f883aecfc..658a961f3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -89,6 +89,7 @@ endif(EXISTS ${PROJECT_SOURCE_DIR}/.git) # Macros include(OpenMWMacros) +include(WholeArchive) # doxygen main page diff --git a/apps/opencs/CMakeLists.txt b/apps/opencs/CMakeLists.txt index e6df90919..17b3375f5 100644 --- a/apps/opencs/CMakeLists.txt +++ b/apps/opencs/CMakeLists.txt @@ -237,8 +237,8 @@ if(OSG_STATIC) target_link_libraries(openmw_cs_osg_plugins INTERFACE ${${_plugin_uc}_LIBRARY}) endforeach() # We use --whole-archive because OSG plugins use registration. - target_link_options(openmw_cs_osg_plugins INTERFACE - -Wl,--whole-archive ${_osg_plugins_static_files} -Wl,--no-whole-archive) + get_whole_archive_options(_opts ${_osg_plugins_static_files}) + target_link_options(openmw_cs_osg_plugins INTERFACE ${_opts}) target_link_libraries(openmw-cs openmw_cs_osg_plugins) endif(OSG_STATIC) diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index c87a96b3a..308b8bd5e 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -152,8 +152,8 @@ if(OSG_STATIC) target_link_libraries(openmw_osg_plugins INTERFACE ${${_plugin_uc}_LIBRARY}) endforeach() # We use --whole-archive because OSG plugins use registration. - target_link_options(openmw_osg_plugins INTERFACE - -Wl,--whole-archive ${_osg_plugins_static_files} -Wl,--no-whole-archive) + get_whole_archive_options(_opts ${_osg_plugins_static_files}) + target_link_options(openmw_osg_plugins INTERFACE ${_opts}) target_link_libraries(openmw openmw_osg_plugins) endif(OSG_STATIC) diff --git a/cmake/WholeArchive.cmake b/cmake/WholeArchive.cmake new file mode 100644 index 000000000..a834e830e --- /dev/null +++ b/cmake/WholeArchive.cmake @@ -0,0 +1,10 @@ +macro (get_whole_archive_options OUT_VAR) + # We use --whole-archive because OSG plugins use registration. + if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + set(${OUT_VAR} -Wl,--whole-archive ${ARGN} -Wl,--no-whole-archive) + elseif (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") + set(${OUT_VAR} -Wl,-all_load ${ARGN} -Wl,-noall_load) + else () + message(FATAL_ERROR "get_whole_archive_options not implemented for CMAKE_CXX_COMPILER_ID ${CMAKE_CXX_COMPILER_ID}") + endif() +endmacro (whole_archive_options) From a06f598442e99e9ae7869a9db106e51ab5b9cfe8 Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Wed, 20 Jan 2021 19:59:34 +0000 Subject: [PATCH 04/20] cmake: Move USED_OSG_(COMPONENTS|PLUGINS) before add_subdirectory(extern) --- CMakeLists.txt | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 658a961f3..5e7e59713 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -169,6 +169,26 @@ if (USE_QT) #set(CMAKE_AUTOMOC ON) endif() +set(USED_OSG_COMPONENTS + osgDB + osgViewer + osgText + osgGA + osgParticle + osgUtil + osgFX + osgShadow + osgAnimation) +set(USED_OSG_PLUGINS + osgdb_bmp + osgdb_dds + osgdb_freetype + osgdb_jpeg + osgdb_osg + osgdb_png + osgdb_serializers_osg + osgdb_tga) + add_subdirectory(extern) # Sound setup @@ -273,25 +293,6 @@ if(NOT HAVE_STDINT_H) message(FATAL_ERROR "stdint.h was not found" ) endif() -set(USED_OSG_COMPONENTS - osgDB - osgViewer - osgText - osgGA - osgParticle - osgUtil - osgFX - osgShadow - osgAnimation) -set(USED_OSG_PLUGINS - osgdb_bmp - osgdb_dds - osgdb_freetype - osgdb_jpeg - osgdb_osg - osgdb_png - osgdb_serializers_osg - osgdb_tga) if(OPENMW_USE_SYSTEM_OSG) find_package(OpenSceneGraph 3.3.4 REQUIRED ${USED_OSG_COMPONENTS}) if(OSG_STATIC) From 90766dcc82309f806b0243ab272585b8a47bab7d Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Wed, 20 Jan 2021 20:01:32 +0000 Subject: [PATCH 05/20] cmake: get_whole_archive_options macro -> function --- cmake/WholeArchive.cmake | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cmake/WholeArchive.cmake b/cmake/WholeArchive.cmake index a834e830e..2def95e8a 100644 --- a/cmake/WholeArchive.cmake +++ b/cmake/WholeArchive.cmake @@ -1,10 +1,10 @@ -macro (get_whole_archive_options OUT_VAR) +function (get_whole_archive_options OUT_VAR) # We use --whole-archive because OSG plugins use registration. if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - set(${OUT_VAR} -Wl,--whole-archive ${ARGN} -Wl,--no-whole-archive) + set(${OUT_VAR} -Wl,--whole-archive ${ARGN} -Wl,--no-whole-archive PARENT_SCOPE) elseif (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") - set(${OUT_VAR} -Wl,-all_load ${ARGN} -Wl,-noall_load) + set(${OUT_VAR} -Wl,-all_load ${ARGN} -Wl,-noall_load PARENT_SCOPE) else () message(FATAL_ERROR "get_whole_archive_options not implemented for CMAKE_CXX_COMPILER_ID ${CMAKE_CXX_COMPILER_ID}") endif() -endmacro (whole_archive_options) +endfunction (whole_archive_options) From 98564b0aae7df4b9bf9cf52b4a06c44c4b6d1fff Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Wed, 20 Jan 2021 20:14:12 +0000 Subject: [PATCH 06/20] cmake: move cmake_minimum_required bump to extern/CMakeLists.txt --- CMakeLists.txt | 2 +- extern/CMakeLists.txt | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5e7e59713..5a497733c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ project(OpenMW) -cmake_minimum_required(VERSION 3.11) # CMP0083 NEW +cmake_minimum_required(VERSION 3.1.0) # CMP0083 NEW set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) diff --git a/extern/CMakeLists.txt b/extern/CMakeLists.txt index b426ac4bf..646558897 100644 --- a/extern/CMakeLists.txt +++ b/extern/CMakeLists.txt @@ -16,6 +16,8 @@ macro(FetchContent_MakeAvailableExcludeFromAll) endmacro() if(NOT OPENMW_USE_SYSTEM_BULLET) + cmake_minimum_required(VERSION 3.11) # for FetchContent + set(BUILD_BULLET3 OFF CACHE BOOL "") set(BUILD_EXTRAS OFF CACHE BOOL "") set(BUILD_OPENGL3_DEMOS OFF CACHE BOOL "") @@ -50,6 +52,8 @@ if(NOT OPENMW_USE_SYSTEM_BULLET) endif() if(NOT OPENMW_USE_SYSTEM_MYGUI) + cmake_minimum_required(VERSION 3.11) # for FetchContent + set(MYGUI_STATIC ON CACHE BOOL "") set(MYGUI_RENDERSYSTEM 4 CACHE STRING "") @@ -71,6 +75,8 @@ if(NOT OPENMW_USE_SYSTEM_MYGUI) endif() if(NOT OPENMW_USE_SYSTEM_OSG) + cmake_minimum_required(VERSION 3.11) # for FetchContent + set(OSG_STATIC ON CACHE BOOL "") set(DYNAMIC_OPENTHREADS OFF CACHE BOOL "") From 4dc0fd299f45006e95b813dfdfd714ff0dd94def Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Wed, 20 Jan 2021 22:19:10 +0000 Subject: [PATCH 07/20] cmake/WholeArchive.cmake: fix typo --- cmake/WholeArchive.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/WholeArchive.cmake b/cmake/WholeArchive.cmake index 2def95e8a..be88da818 100644 --- a/cmake/WholeArchive.cmake +++ b/cmake/WholeArchive.cmake @@ -7,4 +7,4 @@ function (get_whole_archive_options OUT_VAR) else () message(FATAL_ERROR "get_whole_archive_options not implemented for CMAKE_CXX_COMPILER_ID ${CMAKE_CXX_COMPILER_ID}") endif() -endfunction (whole_archive_options) +endfunction (get_whole_archive_options) From 26814b238626f2c204a8756257bd52ff2445a6b7 Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Wed, 20 Jan 2021 22:32:40 +0000 Subject: [PATCH 08/20] CMakeLists.txt: Restore policies as we unbumped cmake version --- CMakeLists.txt | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5a497733c..336e8cb52 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,8 +1,18 @@ project(OpenMW) -cmake_minimum_required(VERSION 3.1.0) # CMP0083 NEW +cmake_minimum_required(VERSION 3.1.0) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) +# for link time optimization, remove if cmake version is >= 3.9 +if(POLICY CMP0069) # LTO + cmake_policy(SET CMP0069 NEW) +endif() + +# for position-independent executable, remove if cmake version is >= 3.14 +if(POLICY CMP0083) + cmake_policy(SET CMP0083 NEW) +endif() + # Detect OS include(cmake/OSIdentity.cmake) From 402e43678c7219aef4afbf0abec57b7b213c69d8 Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Wed, 20 Jan 2021 22:44:46 +0000 Subject: [PATCH 09/20] extern/CMakeLists.txt: Bump OSG --- extern/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/extern/CMakeLists.txt b/extern/CMakeLists.txt index 646558897..f3ebfa00f 100644 --- a/extern/CMakeLists.txt +++ b/extern/CMakeLists.txt @@ -105,8 +105,8 @@ if(NOT OPENMW_USE_SYSTEM_OSG) # + https://github.com/openscenegraph/OpenSceneGraph/pull/1033 include(FetchContent) FetchContent_Declare(osg - URL https://github.com/glebm/OpenSceneGraph/archive/041090d84d9d4b72f1202457fceae0ec6f79b663.zip - URL_HASH MD5=2cbf8126b27a45a2a44efe9fa39090f3 + URL https://github.com/glebm/OpenSceneGraph/archive/7fd71578dfe9283f15b999e82e802ccfda87d936.zip + URL_HASH MD5=c1bad7cc5e263ac650ae1269f212b752 SOURCE_DIR fetched/osg ) FetchContent_MakeAvailableExcludeFromAll(osg) From f0febe095ca16235dd1b505163df08cfc0776521 Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Thu, 21 Jan 2021 13:52:52 +0000 Subject: [PATCH 10/20] extern/CMakeLists.txt: Set OSG/MYGUI_STATIC on PARENT_SCOPE --- extern/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/extern/CMakeLists.txt b/extern/CMakeLists.txt index f3ebfa00f..4ba3d8af1 100644 --- a/extern/CMakeLists.txt +++ b/extern/CMakeLists.txt @@ -54,7 +54,7 @@ endif() if(NOT OPENMW_USE_SYSTEM_MYGUI) cmake_minimum_required(VERSION 3.11) # for FetchContent - set(MYGUI_STATIC ON CACHE BOOL "") + set(MYGUI_STATIC ON CACHE BOOL "" PARENT_SCOPE) set(MYGUI_RENDERSYSTEM 4 CACHE STRING "") set(MYGUI_DISABLE_PLUGINS TRUE CACHE BOOL "") @@ -77,7 +77,7 @@ endif() if(NOT OPENMW_USE_SYSTEM_OSG) cmake_minimum_required(VERSION 3.11) # for FetchContent - set(OSG_STATIC ON CACHE BOOL "") + set(OSG_STATIC ON CACHE BOOL "" PARENT_SCOPE) set(DYNAMIC_OPENTHREADS OFF CACHE BOOL "") set(DYNAMIC_OPENSCENEGRAPH OFF CACHE BOOL "") From eba151884e57eb92883c989ac5ce22563ff74261 Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Thu, 21 Jan 2021 16:26:41 +0000 Subject: [PATCH 11/20] Fix Android build https://github.com/openscenegraph/OpenSceneGraph/pull/1037 --- extern/CMakeLists.txt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/extern/CMakeLists.txt b/extern/CMakeLists.txt index 4ba3d8af1..6d3d46fb0 100644 --- a/extern/CMakeLists.txt +++ b/extern/CMakeLists.txt @@ -83,6 +83,7 @@ if(NOT OPENMW_USE_SYSTEM_OSG) set(DYNAMIC_OPENSCENEGRAPH OFF CACHE BOOL "") set(BUILD_OSG_APPLICATIONS OFF CACHE BOOL "") set(BUILD_OSG_DEPRECATED_SERIALIZERS OFF CACHE BOOL "") + set(OSG_FIND_3RD_PARTY_DEPS OFF CACHE BOOL "") set(BUILD_OSG_PLUGINS_BY_DEFAULT OFF CACHE BOOL "") set(BUILD_OSG_PLUGIN_BMP ON CACHE BOOL "") @@ -103,10 +104,11 @@ if(NOT OPENMW_USE_SYSTEM_OSG) # branch OpenSceneGraph-3.6 on 18 Jan 2021. # + https://github.com/openscenegraph/OpenSceneGraph/pull/1032 # + https://github.com/openscenegraph/OpenSceneGraph/pull/1033 + # + https://github.com/openscenegraph/OpenSceneGraph/pull/1037 include(FetchContent) FetchContent_Declare(osg - URL https://github.com/glebm/OpenSceneGraph/archive/7fd71578dfe9283f15b999e82e802ccfda87d936.zip - URL_HASH MD5=c1bad7cc5e263ac650ae1269f212b752 + URL https://github.com/glebm/OpenSceneGraph/archive/7684224d8a9a8f60447d6561faf32a7b58fb5204.zip + URL_HASH MD5=d67088aeb976486287343c1287b56ba3 SOURCE_DIR fetched/osg ) FetchContent_MakeAvailableExcludeFromAll(osg) From 377bd27aa75d5c807b4c87a4531a1d17fb9b948d Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Fri, 22 Jan 2021 16:01:11 +0000 Subject: [PATCH 12/20] set(BUILD_SHARED_LIBS ${OSG/MYGUI_STATIC}) --- extern/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/extern/CMakeLists.txt b/extern/CMakeLists.txt index 6d3d46fb0..4fd453601 100644 --- a/extern/CMakeLists.txt +++ b/extern/CMakeLists.txt @@ -68,6 +68,7 @@ if(NOT OPENMW_USE_SYSTEM_MYGUI) URL_HASH MD5=9e990a4240430cbf567bfe73488a274e SOURCE_DIR fetched/mygui ) + set(BUILD_SHARED_LIBS ${MYGUI_STATIC}) FetchContent_MakeAvailableExcludeFromAll(mygui) set(MyGUI_INCLUDE_DIRS ${mygui_SOURCE_DIR}/MyGUIEngine/include PARENT_SCOPE) @@ -111,6 +112,7 @@ if(NOT OPENMW_USE_SYSTEM_OSG) URL_HASH MD5=d67088aeb976486287343c1287b56ba3 SOURCE_DIR fetched/osg ) + set(BUILD_SHARED_LIBS ${OSG_STATIC}) FetchContent_MakeAvailableExcludeFromAll(osg) set(OPENSCENEGRAPH_INCLUDE_DIRS ${osg_SOURCE_DIR}/include ${osg_BINARY_DIR}/include PARENT_SCOPE) From daf080ff192ad664f2fb714ccfe64a056be52040 Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Fri, 22 Jan 2021 19:37:07 +0000 Subject: [PATCH 13/20] cmake: Move MYGUI/OSG_STATIC default to top-level Makes it clear that the USE_SYSTEM variables affect the defaults of STATIC variables. --- CMakeLists.txt | 6 ++++++ extern/CMakeLists.txt | 4 ---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 336e8cb52..fc0d1b32c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -111,11 +111,17 @@ option(QT_STATIC "Link static build of QT into the binaries" FALSE) option(OPENMW_USE_SYSTEM_OSG "Use system provided OpenSceneGraph libraries" ON) option(OSG_STATIC "Link static build of OpenSceneGraph into the binaries" OFF) +if(NOT OPENMW_USE_SYSTEM_OSG) + set(OSG_STATIC ON CACHE BOOL "") +endif() option(OPENMW_USE_SYSTEM_BULLET "Use system provided bullet physics library" ON) option(OPENMW_USE_SYSTEM_MYGUI "Use system provided mygui library" ON) option(MYGUI_STATIC "Link static build of Mygui into the binaries" OFF) +if(NOT OPENMW_USE_SYSTEM_MYGUI) + set(MYGUI_STATIC ON CACHE BOOL "") +endif() 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) diff --git a/extern/CMakeLists.txt b/extern/CMakeLists.txt index 4fd453601..de2f80ddf 100644 --- a/extern/CMakeLists.txt +++ b/extern/CMakeLists.txt @@ -54,8 +54,6 @@ endif() if(NOT OPENMW_USE_SYSTEM_MYGUI) cmake_minimum_required(VERSION 3.11) # for FetchContent - set(MYGUI_STATIC ON CACHE BOOL "" PARENT_SCOPE) - set(MYGUI_RENDERSYSTEM 4 CACHE STRING "") set(MYGUI_DISABLE_PLUGINS TRUE CACHE BOOL "") set(MYGUI_BUILD_DEMOS OFF CACHE BOOL "") @@ -78,8 +76,6 @@ endif() if(NOT OPENMW_USE_SYSTEM_OSG) cmake_minimum_required(VERSION 3.11) # for FetchContent - set(OSG_STATIC ON CACHE BOOL "" PARENT_SCOPE) - set(DYNAMIC_OPENTHREADS OFF CACHE BOOL "") set(DYNAMIC_OPENSCENEGRAPH OFF CACHE BOOL "") set(BUILD_OSG_APPLICATIONS OFF CACHE BOOL "") From 99061345cc652d827e4a1dea9af49958ef207f6e Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Fri, 22 Jan 2021 20:44:21 +0000 Subject: [PATCH 14/20] WholeArchive.cmake: Fix mismatched args warning --- cmake/WholeArchive.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/WholeArchive.cmake b/cmake/WholeArchive.cmake index be88da818..0e4a09c79 100644 --- a/cmake/WholeArchive.cmake +++ b/cmake/WholeArchive.cmake @@ -7,4 +7,4 @@ function (get_whole_archive_options OUT_VAR) else () message(FATAL_ERROR "get_whole_archive_options not implemented for CMAKE_CXX_COMPILER_ID ${CMAKE_CXX_COMPILER_ID}") endif() -endfunction (get_whole_archive_options) +endfunction () From 3d334dae754fdc67851812cc2ef5c2be8c8909fd Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Fri, 22 Jan 2021 21:33:07 +0000 Subject: [PATCH 15/20] Fix MYGUI/OSG_STATIC and BUILD_SHARED_LIBS --- CMakeLists.txt | 20 ++++++++++++-------- extern/CMakeLists.txt | 14 ++++++++++++-- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fc0d1b32c..5ba48c01d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -109,19 +109,23 @@ option(BOOST_STATIC "Link static build of Boost into the binaries" FALSE) option(SDL2_STATIC "Link static build of SDL into the binaries" FALSE) option(QT_STATIC "Link static build of QT into the binaries" FALSE) +option(OPENMW_USE_SYSTEM_BULLET "Use system provided bullet physics library" ON) + option(OPENMW_USE_SYSTEM_OSG "Use system provided OpenSceneGraph libraries" ON) -option(OSG_STATIC "Link static build of OpenSceneGraph into the binaries" OFF) -if(NOT OPENMW_USE_SYSTEM_OSG) - set(OSG_STATIC ON CACHE BOOL "") +if(OPENMW_USE_SYSTEM_OSG) + set(_osg_static_default OFF) +else() + set(_osg_static_default ON) endif() - -option(OPENMW_USE_SYSTEM_BULLET "Use system provided bullet physics library" ON) +option(OSG_STATIC "Link static build of OpenSceneGraph into the binaries" ${_osg_static_default}) option(OPENMW_USE_SYSTEM_MYGUI "Use system provided mygui library" ON) -option(MYGUI_STATIC "Link static build of Mygui into the binaries" OFF) -if(NOT OPENMW_USE_SYSTEM_MYGUI) - set(MYGUI_STATIC ON CACHE BOOL "") +if(OPENMW_USE_SYSTEM_MYGUI) + set(_mygui_static_default OFF) +else() + set(_mygui_static_default ON) endif() +option(MYGUI_STATIC "Link static build of Mygui into the binaries" ${_mygui_static_default}) 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) diff --git a/extern/CMakeLists.txt b/extern/CMakeLists.txt index de2f80ddf..a8e741bd9 100644 --- a/extern/CMakeLists.txt +++ b/extern/CMakeLists.txt @@ -60,13 +60,18 @@ if(NOT OPENMW_USE_SYSTEM_MYGUI) set(MYGUI_BUILD_PLUGINS OFF CACHE BOOL "") set(MYGUI_BUILD_TOOLS OFF CACHE BOOL "") + if(MYGUI_STATIC) + set(BUILD_SHARED_LIBS OFF) + else() + set(BUILD_SHARED_LIBS ON) + endif() + include(FetchContent) FetchContent_Declare(mygui URL https://github.com/MyGUI/mygui/archive/MyGUI3.4.0.zip URL_HASH MD5=9e990a4240430cbf567bfe73488a274e SOURCE_DIR fetched/mygui ) - set(BUILD_SHARED_LIBS ${MYGUI_STATIC}) FetchContent_MakeAvailableExcludeFromAll(mygui) set(MyGUI_INCLUDE_DIRS ${mygui_SOURCE_DIR}/MyGUIEngine/include PARENT_SCOPE) @@ -98,6 +103,12 @@ if(NOT OPENMW_USE_SYSTEM_OSG) set(OPENGL_PROFILE "GL2" CACHE STRING "") + if(OSG_STATIC) + set(BUILD_SHARED_LIBS OFF) + else() + set(BUILD_SHARED_LIBS ON) + endif() + # branch OpenSceneGraph-3.6 on 18 Jan 2021. # + https://github.com/openscenegraph/OpenSceneGraph/pull/1032 # + https://github.com/openscenegraph/OpenSceneGraph/pull/1033 @@ -108,7 +119,6 @@ if(NOT OPENMW_USE_SYSTEM_OSG) URL_HASH MD5=d67088aeb976486287343c1287b56ba3 SOURCE_DIR fetched/osg ) - set(BUILD_SHARED_LIBS ${OSG_STATIC}) FetchContent_MakeAvailableExcludeFromAll(osg) set(OPENSCENEGRAPH_INCLUDE_DIRS ${osg_SOURCE_DIR}/include ${osg_BINARY_DIR}/include PARENT_SCOPE) From 4098b455f59f6e3f5b8e8d11a5a212db7a65a06b Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Fri, 22 Jan 2021 22:37:10 +0000 Subject: [PATCH 16/20] extern/CMakeLists.txt: Bump OSG All the necessary fixes have been upstreamed --- extern/CMakeLists.txt | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/extern/CMakeLists.txt b/extern/CMakeLists.txt index a8e741bd9..d82f57b20 100644 --- a/extern/CMakeLists.txt +++ b/extern/CMakeLists.txt @@ -109,14 +109,11 @@ if(NOT OPENMW_USE_SYSTEM_OSG) set(BUILD_SHARED_LIBS ON) endif() - # branch OpenSceneGraph-3.6 on 18 Jan 2021. - # + https://github.com/openscenegraph/OpenSceneGraph/pull/1032 - # + https://github.com/openscenegraph/OpenSceneGraph/pull/1033 - # + https://github.com/openscenegraph/OpenSceneGraph/pull/1037 + # branch OpenSceneGraph-3.6 on 23 Jan 2021. include(FetchContent) FetchContent_Declare(osg - URL https://github.com/glebm/OpenSceneGraph/archive/7684224d8a9a8f60447d6561faf32a7b58fb5204.zip - URL_HASH MD5=d67088aeb976486287343c1287b56ba3 + URL https://github.com/openscenegraph/OpenSceneGraph/archive/b8862d04203c7d5576fc8189fe4df83c4e855b9b.zip + URL_HASH MD5=d80a42eb9c983c08b40ecd103bae03f4 SOURCE_DIR fetched/osg ) FetchContent_MakeAvailableExcludeFromAll(osg) From 3308c717f877423aa4c3640374ea462b21a3ce82 Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Sun, 24 Jan 2021 01:20:23 +0000 Subject: [PATCH 17/20] extern/CMakeLists.txt: Switch to openmw's OSG --- extern/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/extern/CMakeLists.txt b/extern/CMakeLists.txt index d82f57b20..fd21b7072 100644 --- a/extern/CMakeLists.txt +++ b/extern/CMakeLists.txt @@ -112,8 +112,8 @@ if(NOT OPENMW_USE_SYSTEM_OSG) # branch OpenSceneGraph-3.6 on 23 Jan 2021. include(FetchContent) FetchContent_Declare(osg - URL https://github.com/openscenegraph/OpenSceneGraph/archive/b8862d04203c7d5576fc8189fe4df83c4e855b9b.zip - URL_HASH MD5=d80a42eb9c983c08b40ecd103bae03f4 + URL https://github.com/OpenMW/osg/archive/e65f47c4ab3a0b53cc19f517961671e5f840a08d.zip + URL_HASH MD5=0c967fe48d80744f6956f6b0b67ef7c6 SOURCE_DIR fetched/osg ) FetchContent_MakeAvailableExcludeFromAll(osg) From 2798db541844fffe4b1f9b572087e0ee7f20deed Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Sun, 24 Jan 2021 18:44:18 +0000 Subject: [PATCH 18/20] CI/before_script.linux.sh: -> 4 spaces and remove unused ENV --- CI/before_script.linux.sh | 67 +++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 34 deletions(-) diff --git a/CI/before_script.linux.sh b/CI/before_script.linux.sh index ef617e0d5..5f74b4714 100755 --- a/CI/before_script.linux.sh +++ b/CI/before_script.linux.sh @@ -5,51 +5,50 @@ set -xeo pipefail free -m if [[ "${BUILD_TESTS_ONLY}" ]]; then - export GOOGLETEST_DIR="${PWD}/googletest/build/install" - env GENERATOR='Unix Makefiles' CONFIGURATION=Release CI/build_googletest.sh + export GOOGLETEST_DIR="${PWD}/googletest/build/install" + env GENERATOR='Unix Makefiles' CONFIGURATION=Release CI/build_googletest.sh fi declare -a CMAKE_CONF_OPTS=( - -DCMAKE_C_COMPILER="${CC:-/usr/bin/cc}" - -DCMAKE_CXX_COMPILER="${CXX:-/usr/bin/c++}" - -DCMAKE_C_COMPILER_LAUNCHER=ccache - -DCMAKE_CXX_COMPILER_LAUNCHER=ccache - -DCMAKE_INSTALL_PREFIX=install - -DCMAKE_BUILD_TYPE=RelWithDebInfo - -DBUILD_SHARED_LIBS=OFF - -DUSE_SYSTEM_TINYXML=ON - -DCMAKE_INSTALL_PREFIX=install + -DCMAKE_C_COMPILER="${CC:-/usr/bin/cc}" + -DCMAKE_CXX_COMPILER="${CXX:-/usr/bin/c++}" + -DCMAKE_C_COMPILER_LAUNCHER=ccache + -DCMAKE_CXX_COMPILER_LAUNCHER=ccache + -DCMAKE_INSTALL_PREFIX=install + -DCMAKE_BUILD_TYPE=RelWithDebInfo + -DBUILD_SHARED_LIBS=OFF + -DUSE_SYSTEM_TINYXML=ON + -DCMAKE_INSTALL_PREFIX=install ) -declare -a CMAKE_CONF_ENV=() if [[ $CI_OPENMW_USE_STATIC_DEPS ]]; then - CMAKE_CONF_OPTS+=( - -DOPENMW_USE_SYSTEM_MYGUI=OFF - -DOPENMW_USE_SYSTEM_OSG=OFF - -DOPENMW_USE_SYSTEM_BULLET=OFF - ) + CMAKE_CONF_OPTS+=( + -DOPENMW_USE_SYSTEM_MYGUI=OFF + -DOPENMW_USE_SYSTEM_OSG=OFF + -DOPENMW_USE_SYSTEM_BULLET=OFF + ) fi mkdir -p build cd build if [[ "${BUILD_TESTS_ONLY}" ]]; then - env "${CMAKE_CONF_ENV[@]}" ${ANALYZE} cmake \ - "${CMAKE_CONF_OPTS[@]}" \ - -DBUILD_OPENMW=OFF \ - -DBUILD_BSATOOL=OFF \ - -DBUILD_ESMTOOL=OFF \ - -DBUILD_LAUNCHER=OFF \ - -DBUILD_MWINIIMPORTER=OFF \ - -DBUILD_ESSIMPORTER=OFF \ - -DBUILD_OPENCS=OFF \ - -DBUILD_WIZARD=OFF \ - -DBUILD_UNITTESTS=ON \ - -DGTEST_ROOT="${GOOGLETEST_DIR}" \ - -DGMOCK_ROOT="${GOOGLETEST_DIR}" \ - .. + ${ANALYZE} cmake \ + "${CMAKE_CONF_OPTS[@]}" \ + -DBUILD_OPENMW=OFF \ + -DBUILD_BSATOOL=OFF \ + -DBUILD_ESMTOOL=OFF \ + -DBUILD_LAUNCHER=OFF \ + -DBUILD_MWINIIMPORTER=OFF \ + -DBUILD_ESSIMPORTER=OFF \ + -DBUILD_OPENCS=OFF \ + -DBUILD_WIZARD=OFF \ + -DBUILD_UNITTESTS=ON \ + -DGTEST_ROOT="${GOOGLETEST_DIR}" \ + -DGMOCK_ROOT="${GOOGLETEST_DIR}" \ + .. else - env "${CMAKE_CONF_ENV[@]}" ${ANALYZE} cmake \ - "${CMAKE_CONF_OPTS[@]}" \ - .. + ${ANALYZE} cmake \ + "${CMAKE_CONF_OPTS[@]}" \ + .. fi From 93bc5848af328457a29406a25460343b01c897f7 Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Mon, 25 Jan 2021 21:02:29 +0000 Subject: [PATCH 19/20] .gitlab-ci.yml: Bump Android cache key to v3 --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 7ad26bc55..42c70c980 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -306,7 +306,7 @@ Debian_AndroidNDK_arm64-v8a: variables: CCACHE_SIZE: 3G cache: - key: Debian_AndroidNDK_arm64-v8a.v2 + key: Debian_AndroidNDK_arm64-v8a.v3 paths: - apt-cache/ - ccache/ From c8db4b9b3407ddedea2b3e665abe8b9c8ed61716 Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Tue, 26 Jan 2021 19:01:52 +0000 Subject: [PATCH 20/20] .gitlab-ci.yml: Increase Android timeout (1h -> 1h30m) --- .gitlab-ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 42c70c980..e63a8b9d9 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -331,3 +331,5 @@ Debian_AndroidNDK_arm64-v8a: artifacts: paths: - build/install/ + # When CCache doesn't exist (e.g. first build on a fork), build takes more than 1h, which is the default for forks. + timeout: 1h30m