Skip to content

Commit

Permalink
Builder: Script for building dependencies
Browse files Browse the repository at this point in the history
build_deps.py builds dependencies from source. The CMake configuration is set up to use these for the build.
  • Loading branch information
skyjake committed Sep 1, 2019
1 parent 7871dcb commit 412688d
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 229 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@ precompiled.h.cpp
compile_commands.json
/products
/debian
/distrib/deps

8 changes: 4 additions & 4 deletions doomsday/apps/client/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ endif ()

# Dependencies --------------------------------------------------------------------------

find_package (Foundation)
find_package (the_Foundation REQUIRED)
find_package (glbinding REQUIRED)
find_package (Amethyst QUIET)
find_package (SDL2Libs)
find_package (GLBindings)
if (WIN32)
find_package (DirectX)
endif ()
Expand Down Expand Up @@ -327,8 +327,8 @@ if (APPLE AND NOT IOS)
doom64
heretic
hexen
${FOUNDATION_TARGET}
${GLBINDING_TARGET}
the_Foundation::the_Foundation
glbinding::glbinding
)
if (TARGET audio_fmod)
deng_install_bundle_deps (client fmodex)
Expand Down
79 changes: 79 additions & 0 deletions doomsday/build/scripts/build_deps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/usr/bin/env python3

FORMATS = [ '3DS', 'AC', 'ASE', 'ASSBIN', 'ASSXML', 'B3D', 'BVH', 'COLLADA',
'DXF', 'CSM', 'HMP', 'IRR', 'LWO', 'LWS', 'MD2', 'MD3', 'MD5', 'MDC', 'MDL', 'NFF',
'NDO', 'OFF', 'OBJ', 'OGRE', 'OPENGEX', 'PLY', 'MS3D', 'COB', 'BLEND', 'IFC', 'XGL',
'FBX', 'Q3D', 'Q3BSP', 'RAW', 'SMD', 'STL', 'TERRAGEN', '3D', 'X']

ENABLED_FORMATS = ['3DS', 'COLLADA', 'MD2', 'MD3', 'MD5', 'MDL', 'OBJ', 'BLEND', 'FBX',
'IRR']

fmt_flag = {}
for fmt in FORMATS:
fmt_flag[fmt] = 'YES' if fmt in ENABLED_FORMATS else 'NO'

# Builds dependencies using CMake.
# The libraries are installed under the specified directory.
dependencies = [
(
'the_Foundation',
'ssh://git@github.com/skyjake/the_Foundation.git', 'master',
['-DUNISTRING_DIR=/usr/local']
),
(
'Open Asset Import Library',
'https://github.com/assimp/assimp.git', 'v4.1.0',
['-Wno-dev',
'-DASSIMP_BUILD_ASSIMP_TOOLS=OFF',
'-DASSIMP_BUILD_TESTS=OFF'] +
['-DASSIMP_BUILD_%s_IMPORTER=%s' % (fmt, fmt_flag[fmt]) for fmt in FORMATS]
),
(
'cginternals/glbinding',
'https://github.com/cginternals/glbinding.git', 'v3.0.2',
['-Wno-dev',
'-DOPTION_BUILD_EXAMPLES=NO',
'-DOPTION_BUILD_TOOLS=NO',
'-DOPTION_BUILD_TESTS=NO']
)
]

import os
import shutil
import subprocess
import sys

BUILD_TYPE = 'Release'
BUILD_DIR = os.path.normpath(os.path.abspath(sys.argv[1]))
GENERATOR = sys.argv[2]
PRODUCTS_DIR = os.path.join(BUILD_DIR, 'products')
os.makedirs(PRODUCTS_DIR, exist_ok=True)

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)
if not os.path.exists(src_dir):
os.makedirs(src_dir, exist_ok=True)
os.chdir(src_dir)
subprocess.check_call(['git', 'clone', git_url, '.'])
else:
os.chdir(src_dir)
subprocess.check_call(['git', 'fetch', '--tags'])
subprocess.check_call(['git', 'checkout', git_tag])
build_dir = os.path.join(src_dir, 'build')
if GENERATOR == 'clean':
shutil.rmtree(build_dir)
continue
os.makedirs(build_dir, exist_ok=True)
os.chdir(build_dir)
print(build_dir)
subprocess.check_call(['cmake',
'-G', GENERATOR,
'-DCMAKE_BUILD_TYPE=' + BUILD_TYPE,
'-DCMAKE_INSTALL_PREFIX=' + PRODUCTS_DIR] +
cmake_opts +
['..'])
subprocess.check_call(['cmake',
'--build', '.',
'--target', 'install'
])
3 changes: 2 additions & 1 deletion doomsday/cmake/Config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ set (CMAKE_INSTALL_DEFAULT_COMPONENT_NAME "client")
if (NOT DE_SDK_DIR STREQUAL "")
list (APPEND CMAKE_PREFIX_PATH "${DE_SDK_DIR}/${DE_INSTALL_LIB_DIR}")
endif ()
list (APPEND CMAKE_PREFIX_PATH "${DE_DISTRIB_DIR}/../deps")
list (APPEND CMAKE_MODULE_PATH "${DE_DISTRIB_DIR}/../deps/products/lib/cmake/assimp-4.1")

if (WIN32)
set (MSYS2_LIBS_DIR "" CACHE PATH "msys2-libs directory")
endif ()
# find_package (the_Foundation REQUIRED)

# Platform-Specific Configuration --------------------------------------------

Expand Down
147 changes: 5 additions & 142 deletions doomsday/cmake/FindAssimp.cmake
Original file line number Diff line number Diff line change
@@ -1,143 +1,6 @@
find_package (PkgConfig QUIET)
include (assimp-config) # from deps

# Prefer to use Assimp installed on the system.
pkg_check_modules (ASSIMP assimp)
if (ASSIMP_FOUND)
#add_library (assimp ALIAS PkgConfig::ASSIMP)
status (FATAL_ERROR "TODO: Add INTERFACE library target with ASSIMP libs")
else ()
set (ASSIMP_RELEASE 4.1.0)
message (STATUS "Open Asset Import Library ${ASSIMP_RELEASE} will be downloaded and built")
include (ExternalProject)
set (assimpOpts
-Wno-dev
-DASSIMP_BUILD_ASSIMP_TOOLS=OFF
-DASSIMP_BUILD_TESTS=OFF)
if (MSVC)
# Don't bother with multiconfig, always use the release build.
list (APPEND assimpOpts -DCMAKE_BUILD_TYPE=Release)
endif ()
set (_allAssimpFormats
3DS AC ASE ASSBIN ASSXML B3D BVH COLLADA DXF CSM HMP IRR LWO LWS MD2 MD3 MD5
MDC MDL NFF NDO OFF OBJ OGRE OPENGEX PLY MS3D COB BLEND IFC XGL FBX Q3D Q3BSP RAW SMD
STL TERRAGEN 3D X)
set (_enabledAssimpFormats 3DS COLLADA MD2 MD3 MD5 MDL OBJ BLEND FBX IRR)
foreach (_fmt ${_allAssimpFormats})
list (FIND _enabledAssimpFormats ${_fmt} _pos)
if (_pos GREATER -1)
set (_enabled YES)
else ()
set (_enabled NO)
endif ()
list (APPEND assimpOpts -DASSIMP_BUILD_${_fmt}_IMPORTER=${_enabled})
endforeach (_fmt)
set (assimpLibName libassimp.4.dylib)
ExternalProject_Add (github-assimp
GIT_REPOSITORY https://github.com/assimp/assimp.git
GIT_TAG v${ASSIMP_RELEASE}
CMAKE_ARGS ${assimpOpts}
PREFIX assimp
BUILD_BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/assimp/src/github-assimp-build/code/${assimpLibName}
INSTALL_COMMAND ""
)
add_library (assimp INTERFACE)
target_include_directories (assimp INTERFACE
${CMAKE_CURRENT_BINARY_DIR}/assimp/src/github-assimp/include
${CMAKE_CURRENT_BINARY_DIR}/assimp/src/github-assimp-build/include)
target_link_libraries (assimp INTERFACE
${CMAKE_CURRENT_BINARY_DIR}/assimp/src/github-assimp-build/code/${assimpLibName})
add_dependencies (assimp github-assimp)
endif ()

if (TARGET assimp)
set (ASSIMP_TARGET assimp)
endif ()

#if (assimp_FOUND)
# message (STATUS "Using libassimp on the system")
#endif ()

#set (_oldPath ${LIBASSIMP})

#if (NOT TARGET libassimp)
# add_library (libassimp INTERFACE)

# # It is a bit unorthodox to access the build products of an external project via
# # the CMake target object. The current setup exists because the "libassimp"
# # interface target can either represent an Assimp installation somewhere in the
# # file system, or the build products of the Assimp that gets built as part of
# # Doomsday.

# if (TARGET assimp)
# # Assimp is built as a subdir.
# # Use the built target location from the "assimp" target.
# set (ASSIMP_INCLUDE_DIRS ${DE_EXTERNAL_SOURCE_DIR}/assimp/include)
# set (LIBASSIMP $<TARGET_LINKER_FILE:assimp>)
# if (APPLE)
# # The assimp library will be bundled into Doomsday.app. This will
# # inform the installer to include the real library in addition to
# # version symlinks (CMake bug?).
# # (see: deng_install_bundle_deps() in Macros.cmake)
# target_link_libraries (libassimp INTERFACE $<TARGET_FILE:assimp>;$<TARGET_LINKER_FILE:assimp>)
# elseif (UNIX)
# get_property (depLibs TARGET assimp PROPERTY LINK_LIBRARIES)
# target_link_libraries (libassimp INTERFACE ${depLibs})
# set (depLibs)
# endif ()
# else ()
# # Try to find assimp using pkg-config.
# if (PKG_CONFIG_FOUND AND NOT DEFINED ASSIMP_DIR)
# pkg_check_modules (ASSIMP QUIET assimp)
# if (NOT ASSIMP_LIBRARIES)
# set (ASSIMP_LIBRARIES assimp)
# endif ()
# find_library (LIBASSIMP ${ASSIMP_LIBRARIES}
# PATHS
# ${ASSIMP_LIBRARY_DIRS}
# /usr/local/lib
# )
# endif ()
# if (NOT LIBASSIMP)
# # Try to find assimp manually.
# find_library (LIBASSIMP NAMES assimp assimpd
# PATHS
# ${DE_EXTERNAL_SOURCE_DIR}/assimp
# ${ASSIMP_DIR}
# PATH_SUFFIXES lib/Release lib/Debug lib
# NO_DEFAULT_PATH
# )
# endif ()
# endif ()
# mark_as_advanced (LIBASSIMP)

# if (NOT LIBASSIMP)
# message (FATAL_ERROR "Open Asset Import Library not found. Go to ${DE_EXTERNAL_SOURCE_DIR}/assimp and compile. If you install it somewhere, set the ASSIMP_DIR variable to specify the location. If pkg-config is available, it is used to find libassimp.")
# endif ()

# if (ASSIMP_INCLUDE_DIRS)
# target_include_directories (libassimp INTERFACE ${ASSIMP_INCLUDE_DIRS})
# else ()
# # Try to deduce include dir from the library location.
# get_filename_component (_assimpBase ${LIBASSIMP} DIRECTORY)
# find_file (LIBASSIMP_IMPORTER_HPP
# assimp/Importer.hpp
# HINTS /usr/include /usr/local/include
# ${_assimpBase}/include
# ${_assimpBase}/../include
# ${_assimpBase}/../../include
# )
# mark_as_advanced (LIBASSIMP_IMPORTER_HPP)
# if (NOT LIBASSIMP_IMPORTER_HPP)
# message (FATAL_ERROR "Could not find Open Asset Import Library headers.\n")
# endif ()
# get_filename_component (_incDir ${LIBASSIMP_IMPORTER_HPP} DIRECTORY)
# get_filename_component (_incDir ${_incDir} DIRECTORY)
# target_include_directories (libassimp INTERFACE ${_incDir})
# endif ()

# target_link_libraries (libassimp INTERFACE ${LIBASSIMP})
#endif ()

#if (NOT _oldPath STREQUAL LIBASSIMP)
# message (STATUS "Found Open Asset Import Library: ${LIBASSIMP}")
#endif ()
add_library (assimp INTERFACE)
target_compile_options (assimp INTERFACE ${ASSIMP_CXX_FLAGS})
target_include_directories (assimp INTERFACE ${ASSIMP_INCLUDE_DIRS})
target_link_libraries (assimp INTERFACE -L${ASSIMP_LIBRARY_DIRS} -l${ASSIMP_LIBRARIES})
26 changes: 0 additions & 26 deletions doomsday/cmake/FindFoundation.cmake

This file was deleted.

51 changes: 0 additions & 51 deletions doomsday/cmake/FindGLBindings.cmake

This file was deleted.

4 changes: 2 additions & 2 deletions doomsday/libs/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ project (DE_LIBCORE)
include (../../cmake/Config.cmake)

# Dependencies.
find_package (Foundation)
find_package (the_Foundation REQUIRED)
include (ZLIB)
find_package (Git QUIET)

Expand Down Expand Up @@ -71,7 +71,7 @@ deng_add_package (net.dengine.stdlib)

deng_add_library (libcore ${SOURCES} ${HEADERS})
target_include_directories (libcore PRIVATE ${ZLIB_INCLUDE_DIR})
target_link_libraries (libcore PUBLIC ${ZLIB_LIBRARIES} ${FOUNDATION_TARGET})
target_link_libraries (libcore PUBLIC ${ZLIB_LIBRARIES} the_Foundation::the_Foundation)
if (WIN32)
# timeBeginPeriod, timeEndPeriod
target_link_libraries (libcore PRIVATE winmm)
Expand Down
6 changes: 3 additions & 3 deletions doomsday/libs/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ endif ()
# Dependencies.
find_package (SDL2Libs)
find_package (Stb)
find_package (GLBindings)
find_package (glbinding REQUIRED)
find_package (Assimp)
if (DE_X11)
find_package (X11 REQUIRED)
Expand Down Expand Up @@ -131,8 +131,8 @@ endif ()

deng_link_libraries (libgui PUBLIC DengComms)
target_link_libraries (libgui
PUBLIC ${GLBINDING_TARGET}
PRIVATE SDL2 SDL2_ttf stb ${ASSIMP_TARGET}
PUBLIC glbinding::glbinding
PRIVATE SDL2 SDL2_ttf stb assimp
)
if (WIN32)
# Direct2D is used for DPI information.
Expand Down

0 comments on commit 412688d

Please sign in to comment.