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..a881ec576b 100644 --- a/doomsday/cmake/FindAssimp.cmake +++ b/doomsday/cmake/FindAssimp.cmake @@ -1,8 +1,16 @@ -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}) +if (DE_USE_SYSTEM_ASSIMP) + target_link_libraries (assimp INTERFACE ${ASSIMP_LIBRARIES}) +else () + target_link_libraries (assimp INTERFACE -L${ASSIMP_LIBRARY_DIRS} -l${ASSIMP_LIBRARIES}) +endif () 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/cmake/assimp-system.cmake b/doomsday/cmake/assimp-system.cmake new file mode 100644 index 0000000000..fae57835f4 --- /dev/null +++ b/doomsday/cmake/assimp-system.cmake @@ -0,0 +1,87 @@ +if(CMAKE_SIZEOF_VOID_P EQUAL 8) + set(ASSIMP_ARCHITECTURE "64") +elseif(CMAKE_SIZEOF_VOID_P EQUAL 4) + set(ASSIMP_ARCHITECTURE "32") +endif(CMAKE_SIZEOF_VOID_P EQUAL 8) + +if(WIN32) + set(ASSIMP_ROOT_DIR CACHE PATH "ASSIMP root directory") + + # Find path of each library + find_path(ASSIMP_INCLUDE_DIR + NAMES + assimp/anim.h + HINTS + ${ASSIMP_ROOT_DIR}/include + ) + + if(MSVC12) + set(ASSIMP_MSVC_VERSION "vc120") + elseif(MSVC14) + set(ASSIMP_MSVC_VERSION "vc140") + endif(MSVC12) + + if(MSVC12 OR MSVC14) + + find_path(ASSIMP_LIBRARY_DIR + NAMES + assimp-${ASSIMP_MSVC_VERSION}-mt.lib + HINTS + ${ASSIMP_ROOT_DIR}/lib${ASSIMP_ARCHITECTURE} + ) + + find_library(ASSIMP_LIBRARY_RELEASE assimp-${ASSIMP_MSVC_VERSION}-mt.lib PATHS ${ASSIMP_LIBRARY_DIR}) + find_library(ASSIMP_LIBRARY_DEBUG assimp-${ASSIMP_MSVC_VERSION}-mtd.lib PATHS ${ASSIMP_LIBRARY_DIR}) + + set(ASSIMP_LIBRARY + optimized ${ASSIMP_LIBRARY_RELEASE} + debug ${ASSIMP_LIBRARY_DEBUG} + ) + + set(ASSIMP_LIBRARIES "ASSIMP_LIBRARY_RELEASE" "ASSIMP_LIBRARY_DEBUG") + + FUNCTION(ASSIMP_COPY_BINARIES TargetDirectory) + ADD_CUSTOM_TARGET(AssimpCopyBinaries + COMMAND ${CMAKE_COMMAND} -E copy ${ASSIMP_ROOT_DIR}/bin${ASSIMP_ARCHITECTURE}/assimp-${ASSIMP_MSVC_VERSION}-mtd.dll ${TargetDirectory}/Debug/assimp-${ASSIMP_MSVC_VERSION}-mtd.dll + COMMAND ${CMAKE_COMMAND} -E copy ${ASSIMP_ROOT_DIR}/bin${ASSIMP_ARCHITECTURE}/assimp-${ASSIMP_MSVC_VERSION}-mt.dll ${TargetDirectory}/Release/assimp-${ASSIMP_MSVC_VERSION}-mt.dll + COMMENT "Copying Assimp binaries to '${TargetDirectory}'" + VERBATIM) + ENDFUNCTION(ASSIMP_COPY_BINARIES) + + endif() + +elseif (DE_USE_SYSTEM_ASSIMP) + + find_path( + ASSIMP_INCLUDE_DIR + NAMES assimp/postprocess.h assimp/scene.h assimp/version.h assimp/config.h assimp/cimport.h + PATHS /usr/local/include + PATHS /usr/include/ + + ) + + find_library( + ASSIMP_LIBRARIES + NAMES assimp + PATHS /usr/local/lib/ + PATHS /usr/lib64/ + PATHS /usr/lib/ + ) + +endif(WIN32 OR DE_USE_SYSTEM_ASSIMP) + + +if (ASSIMP_INCLUDE_DIR AND ASSIMP_LIBRARIES) + SET(assimp_FOUND TRUE) +ENDIF (ASSIMP_INCLUDE_DIR AND ASSIMP_LIBRARIES) + +if (assimp_FOUND) + if (NOT assimp_FIND_QUIETLY) + message(STATUS "Found asset importer library: ${ASSIMP_LIBRARIES}") + endif (NOT assimp_FIND_QUIETLY) +else (assimp_FOUND) + if (DE_USE_SYSTEM_ASSIMP OR assimp_FIND_REQUIRED) + message(FATAL_ERROR "Could not find asset importer library") + endif (assimp_FIND_REQUIRED) +endif (assimp_FOUND) + diff --git a/doomsday/cmake/glbinding-system.cmake b/doomsday/cmake/glbinding-system.cmake new file mode 100644 index 0000000000..1db7fa2c0d --- /dev/null +++ b/doomsday/cmake/glbinding-system.cmake @@ -0,0 +1,33 @@ +# Find the glbinding headers and library in standard system paths + +find_path( + glbinding_INCLUDE_DIR + NAMES glbinding/glbinding-version.h + PATHS /usr/local/include + PATHS /usr/include/ +) + +find_library( + glbinding_LIBRARIES + NAMES glbinding + PATHS /usr/local/lib64/ + PATHS /usr/local/lib/ + PATHS /usr/lib64/ + PATHS /usr/lib/ +) + +if (glbinding_INCLUDE_DIR AND glbinding_LIBRARIES) + SET(glbinding_FOUND TRUE) + SET(glbinding::glbinding_FOUND TRUE) + + FILE(READ ${glbinding_INCLUDE_DIR}/glbinding/glbinding-version.h GLBINDING_VERSION_H) + STRING(REGEX MATCH "define[ ]+GLBINDING_VERSION_MAJOR[ ]+\"[0-9]+" GLBINDING_MAJOR_VERSION_LINE "${GLBINDING_VERSION_H}") + STRING(REGEX REPLACE "define[ ]+GLBINDING_VERSION_MAJOR[ ]+\"([0-9]+)" "\\1" glbinding_VERSION_MAJOR "${GLBINDING_MAJOR_VERSION_LINE}") + + STRING(REGEX MATCH "define[ ]+GLBINDING_VERSION_MINOR[ ]+\"[0-9]+" GLBINDING_MINOR_VERSION_LINE "${GLBINDING_VERSION_H}") + STRING(REGEX REPLACE "define[ ]+GLBINDING_VERSION_MINOR[ ]+\"([0-9]+)" "\\1" glbinding_VERSION_MINOR "${GLBINDING_MINOR_VERSION_LINE}") + + message (STATUS "Using system glbinding library, version ${glbinding_VERSION_MAJOR}.${glbinding_VERSION_MINOR}") + +ENDIF (glbinding_INCLUDE_DIRS AND glbinding_LIBRARIES) + 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