From 7233996a2ba3f469d617812527ff1b22451300ce Mon Sep 17 00:00:00 2001 From: Brent Spillner Date: Wed, 10 May 2023 03:53:02 +1000 Subject: [PATCH] Added option to link against system assimp/glbinding libraries instead of building as dependencies. --- doomsday/apps/client/CMakeLists.txt | 10 ++++++++ doomsday/build/scripts/build_deps.py | 34 ++++++++++++++++++++++------ doomsday/cmake/FindAssimp.cmake | 8 +++++-- doomsday/cmake/Findglbinding.cmake | 10 ++++++-- doomsday/cmake/Options.cmake | 2 ++ doomsday/libs/gui/CMakeLists.txt | 16 ++++++++++--- 6 files changed, 66 insertions(+), 14 deletions(-) diff --git a/doomsday/apps/client/CMakeLists.txt b/doomsday/apps/client/CMakeLists.txt index d720e72f3c..195643f5a4 100644 --- a/doomsday/apps/client/CMakeLists.txt +++ b/doomsday/apps/client/CMakeLists.txt @@ -221,6 +221,16 @@ endif() target_link_libraries (client PUBLIC doomsdaygui) deng_link_libraries (client PUBLIC DengGui DengDoomsday DengGameKit DengGloom) +if (DE_USE_SYSTEM_GLBINDING) + target_link_libraries (client PUBLIC glbinding) + deng_link_libraries (client PUBLIC glbinding) +endif() + +if (DE_USE_SYSTEM_ASSIMP) + target_link_libraries (client PUBLIC assimp) + deng_link_libraries (client PUBLIC assimp) +endif() + # Extensions ---------------------------------------------------------------------------- target_link_libraries (client PRIVATE importsave) diff --git a/doomsday/build/scripts/build_deps.py b/doomsday/build/scripts/build_deps.py index 874e8301f0..8dd4a3fb1d 100755 --- a/doomsday/build/scripts/build_deps.py +++ b/doomsday/build/scripts/build_deps.py @@ -12,6 +12,8 @@ def print_config(cfg): IS_MSYS = os.getenv('MSYSTEM') == 'MSYS' IS_MINGW = os.getenv('MSYSTEM') == 'MINGW64' +build_foundation = build_assimp = build_glbinding = True + PATCH_DIR = os.path.abspath(os.path.dirname(__file__)) if IS_MSYS: @@ -69,7 +71,7 @@ def print_config(cfg): ) ] -if IS_MACOS: del dependencies[2] # using glbinding from Homebrew +if IS_MACOS: build_glbinding = False # using glbinding from Homebrew import shutil import subprocess @@ -111,6 +113,12 @@ def print_config(cfg): elif opt == '-d': idx += 1 cfg['build_dir'] = os.path.abspath(sys.argv[idx]) + elif opt == '--skip-foundation': + build_foundation = False + elif opt == '--skip-assimp': + build_assimp = False + elif opt == '--skip-glbinding': + build_glbinding = False else: raise Exception('Unknown option: ' + opt) idx += 1 @@ -120,14 +128,17 @@ def print_config(cfg): Usage: build_deps.py [opts] [commands] build-dir Commands: - build Build using existing config. - clean Clean the build directory. + build Build using existing config. + clean Clean the build directory. Options: - -G Use CMake when configuring build. - -t Set CMake build type (e.g., Release). - -d Set build directory. - --help Show this help. + -G Use CMake when configuring build. + -t Set CMake build type (e.g., Release). + -d Set build directory. + --help Show this help. + --skip-foundation Do not build the_Foundation library + --skip-assimp Do not build Open Asset Importer library + --skip-glbinding Do not build glbinding library """) print_config(cfg) exit(0) @@ -147,6 +158,15 @@ def print_config(cfg): shutil.rmtree(PRODUCTS_DIR) os.makedirs(PRODUCTS_DIR, exist_ok=True) +if not build_glbinding: + del dependencies[2] + +if not build_assimp: + del dependencies[1] + +if not build_foundation: + del dependencies[0] + for long_name, git_url, git_tag, cmake_opts in dependencies: name = os.path.splitext(os.path.basename(git_url))[0] src_dir = os.path.join(BUILD_DIR, name) diff --git a/doomsday/cmake/FindAssimp.cmake b/doomsday/cmake/FindAssimp.cmake index cad0eb424c..92e4b00af1 100644 --- a/doomsday/cmake/FindAssimp.cmake +++ b/doomsday/cmake/FindAssimp.cmake @@ -1,8 +1,12 @@ -include (assimp-config) # from deps +if (DE_USE_SYSTEM_ASSIMP) + include (${DE_CMAKE_DIR}/assimp-system.cmake) +else () + include (assimp-config) # from deps +endif () add_library (assimp INTERFACE) set (_cxxFlags ${ASSIMP_CXX_FLAGS}) separate_arguments (_cxxFlags) target_compile_options (assimp INTERFACE ${_cxxFlags}) target_include_directories (assimp INTERFACE ${ASSIMP_INCLUDE_DIRS}) -target_link_libraries (assimp INTERFACE -L${ASSIMP_LIBRARY_DIRS} -l${ASSIMP_LIBRARIES}) +target_link_libraries (assimp INTERFACE ${ASSIMP_LIBRARIES}) diff --git a/doomsday/cmake/Findglbinding.cmake b/doomsday/cmake/Findglbinding.cmake index d944ec4a9f..c92e9f26df 100644 --- a/doomsday/cmake/Findglbinding.cmake +++ b/doomsday/cmake/Findglbinding.cmake @@ -3,14 +3,20 @@ message (STATUS "Looking for glbinding...") if (APPLE) # Homebrew's glbinding CMake config doesn't seem to work. include (${glbinding_DIR}/cmake/glbinding/glbinding-export.cmake) +elseif (DE_USE_SYSTEM_GLBINDING) + include (${DE_CMAKE_DIR}/glbinding-system.cmake) else () # Use the glbinding built by build_deps.py. include (${DE_DEPENDS_DIR}/products/glbinding-config.cmake) set (glbinding_DIR ${DE_DEPENDS_DIR}/products) endif () -if (MSYS OR WIN32) - set (DE_GLBINDING_VERSION 3) +if (DE_USE_SYSTEM_GLBINDING) + set (DE_GLBINDING_VERSION ${glbinding_VERSION_MAJOR}) +elseif (MSYS OR WIN32) + set (DE_GLBINDING_VERSION 3) else () set (DE_GLBINDING_VERSION 2) endif () + +message (STATUS "Found glbinding version ${DE_GLBINDING_VERSION}") diff --git a/doomsday/cmake/Options.cmake b/doomsday/cmake/Options.cmake index b2def0c7d3..4c49dd17d5 100644 --- a/doomsday/cmake/Options.cmake +++ b/doomsday/cmake/Options.cmake @@ -21,6 +21,8 @@ option (DE_ENABLE_SDK "Enable installation of the Doomsday SDK" OFF) option (DE_ENABLE_TESTS "Enable tests" OFF) option (DE_ENABLE_TOOLS "Enable tools" ON) option (DE_ENABLE_DEPLOYMENT "Enable deployment of all dependencies" ON) +option (DE_USE_SYSTEM_ASSIMP "Use system-provided assimp library" OFF) +option (DE_USE_SYSTEM_GLBINDING "Use system-provided glbinding library" OFF) option (DE_FIXED_ASM "Use inline assembler for fixed-point math" ${DE_FIXED_ASM_DEFAULT} diff --git a/doomsday/libs/gui/CMakeLists.txt b/doomsday/libs/gui/CMakeLists.txt index 5d2797c3b7..a7a7ae5f6e 100644 --- a/doomsday/libs/gui/CMakeLists.txt +++ b/doomsday/libs/gui/CMakeLists.txt @@ -91,7 +91,11 @@ deng_link_libraries (libgui PUBLIC DengCore) target_link_libraries (libgui PRIVATE SDL2 stb assimp) if (NOT DE_HAVE_OPENGL_ES) target_compile_definitions (libgui PRIVATE DE_GLBINDING_VERSION=${DE_GLBINDING_VERSION}) - target_link_libraries (libgui PUBLIC glbinding::glbinding) + if (DE_USE_SYSTEM_GLBINDING) + target_link_libraries (libgui PUBLIC glbinding) + else () + target_link_libraries (libgui PUBLIC glbinding::glbinding) + endif () endif () if (WIN32) target_link_libraries (libgui PUBLIC opengl32.lib) @@ -140,11 +144,17 @@ elseif (CYGWIN) COMPONENT client ) endif () -if (UNIX_LINUX) +if (UNIX_LINUX AND NOT DE_USE_SYSTEM_ASSIMP) install ( FILES ${ASSIMP_ROOT_DIR}/lib/libassimp.so.4 ${ASSIMP_ROOT_DIR}/lib/libassimp.so.4.1.0 - ${glbinding_DIR}/lib/libglbinding.so.2 + DESTINATION ${DE_INSTALL_LIB_DIR} + COMPONENT client + ) +endif () +if (UNIX_LINUX AND NOT DE_USE_SYSTEM_GLBINDING) + install ( + FILES ${glbinding_DIR}/lib/libglbinding.so.2 ${glbinding_DIR}/lib/libglbinding.so.2.1.4 DESTINATION ${DE_INSTALL_LIB_DIR} COMPONENT client