Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide options to use system libglbinding/libassimp instead of the built-in dependencies. #26

Merged
merged 1 commit into from
Jul 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions doomsday/apps/client/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
34 changes: 27 additions & 7 deletions doomsday/build/scripts/build_deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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 <generator> Use CMake <generator> when configuring build.
-t <type> Set CMake build type (e.g., Release).
-d <dir> Set build directory.
--help Show this help.
-G <generator> Use CMake <generator> when configuring build.
-t <type> Set CMake build type (e.g., Release).
-d <dir> 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)
Expand All @@ -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)
Expand Down
12 changes: 10 additions & 2 deletions doomsday/cmake/FindAssimp.cmake
Original file line number Diff line number Diff line change
@@ -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 ()
10 changes: 8 additions & 2 deletions doomsday/cmake/Findglbinding.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
2 changes: 2 additions & 0 deletions doomsday/cmake/Options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
87 changes: 87 additions & 0 deletions doomsday/cmake/assimp-system.cmake
Original file line number Diff line number Diff line change
@@ -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)

33 changes: 33 additions & 0 deletions doomsday/cmake/glbinding-system.cmake
Original file line number Diff line number Diff line change
@@ -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)

16 changes: 13 additions & 3 deletions doomsday/libs/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down