Skip to content

Commit

Permalink
build: support static OCIO self-builds (#4517)
Browse files Browse the repository at this point in the history
* Add build recipes for certain dependencies needed for linking static
OpenColorIO libs: expat, minizip-ng, pystring, and yaml-cpp

* Add SOURCE_SUBDIR option to `build_dependency_with_cmake` that mimics
the behavior of the FetchContent option of the same name
 
* Tweak OpenColorIO build recipe to always build static libraries by
default.

---------

Signed-off-by: Zach Lewis <[email protected]>
  • Loading branch information
zachlewis authored Nov 6, 2024
1 parent 5592195 commit 2f0caf7
Show file tree
Hide file tree
Showing 7 changed files with 260 additions and 6 deletions.
13 changes: 9 additions & 4 deletions src/cmake/build_OpenColorIO.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
# OpenColorIO by hand!
######################################################################

set_cache (OpenColorIO_BUILD_VERSION 2.3.2 "OpenColorIO version for local builds")
set_cache (OpenColorIO_BUILD_VERSION 2.4.0 "OpenColorIO version for local builds")
set (OpenColorIO_GIT_REPOSITORY "https://github.com/AcademySoftwareFoundation/OpenColorIO")
set (OpenColorIO_GIT_TAG "v${OpenColorIO_BUILD_VERSION}")
set_cache (OpenColorIO_BUILD_SHARED_LIBS ON
set_cache (OpenColorIO_BUILD_SHARED_LIBS OFF #ON
DOC "Should a local OpenColorIO build, if necessary, build shared libraries" ADVANCED)
# We would prefer to build a static OCIO, but haven't figured out how to make
# it all work with the static dependencies, it just makes things complicated
Expand All @@ -23,6 +23,11 @@ unset (OPENCOLORIO_VERSION_MAJOR)
unset (OPENCOLORIO_VERSION_MINOR)
unset (OpenColorIO_DIR)

checked_find_package(pystring VERSION_MIN 1.1.3)
checked_find_package(expat REQUIRED VERSION_MIN 2.5)
checked_find_package(yaml-cpp REQUIRED VERSION_MIN 0.6.0)
checked_find_package(minizip-ng REQUIRED VERSION_MIN 3.0.0)

string (MAKE_C_IDENTIFIER ${OpenColorIO_BUILD_VERSION} OpenColorIO_VERSION_IDENT)

build_dependency_with_cmake(OpenColorIO
Expand All @@ -31,6 +36,7 @@ build_dependency_with_cmake(OpenColorIO
GIT_TAG ${OpenColorIO_GIT_TAG}
CMAKE_ARGS
-D BUILD_SHARED_LIBS=${OpenColorIO_BUILD_SHARED_LIBS}
-D CMAKE_POSITION_INDEPENDENT_CODE=ON
-D CMAKE_INSTALL_LIBDIR=lib
# Don't built unnecessary parts of OCIO
-D OCIO_BUILD_APPS=OFF
Expand All @@ -48,15 +54,14 @@ build_dependency_with_cmake(OpenColorIO
)

# Set some things up that we'll need for a subsequent find_package to work

#list (APPEND CMAKE_PREFIX_PATH ${OpenColorIO_LOCAL_INSTALL_DIR})
set (OpenColorIO_ROOT ${OpenColorIO_LOCAL_INSTALL_DIR})
set (OpenColorIO_DIR ${OpenColorIO_LOCAL_INSTALL_DIR})

# Signal to caller that we need to find again at the installed location
# set (OpenColorIO_REFIND TRUE)
# set (OpenColorIO_REFIND_ARGS CONFIG)
find_package (OpenColorIO ${OpenColorIO_BUILD_VERSION} EXACT CONFIG REQUIRED)
find_package(pystring REQUIRED)

if (OpenColorIO_BUILD_SHARED_LIBS)
install_local_dependency_libs (OpenColorIO OpenColorIO)
Expand Down
57 changes: 57 additions & 0 deletions src/cmake/build_expat.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Copyright Contributors to the OpenImageIO project.
# SPDX-License-Identifier: Apache-2.0
# https://github.com/AcademySoftwareFoundation/OpenImageIO

######################################################################
# expat by hand!
######################################################################

set_cache (expat_BUILD_VERSION 2.6.3 "expat version for local builds")
set (expat_GIT_REPOSITORY "https://github.com/libexpat/libexpat")

string(REPLACE "." ";" VERSION_LIST ${expat_BUILD_VERSION})
list(GET VERSION_LIST 0 expat_VERSION_MAJOR)
list(GET VERSION_LIST 1 expat_VERSION_MINOR)
list(GET VERSION_LIST 2 expat_VERSION_PATCH)

set (expat_GIT_TAG "R_${expat_VERSION_MAJOR}_${expat_VERSION_MINOR}_${expat_VERSION_PATCH}")
set_cache (expat_BUILD_SHARED_LIBS OFF #${LOCAL_BUILD_SHARED_LIBS_DEFAULT}
DOC "Should execute a local expat build, if necessary, build shared libraries" ADVANCED)


set (expat_LOCAL_SOURCE_DIR "${${PROJECT_NAME}_LOCAL_DEPS_ROOT}/expat/expat")

build_dependency_with_cmake(expat
VERSION ${expat_BUILD_VERSION}
GIT_REPOSITORY ${expat_GIT_REPOSITORY}
GIT_TAG ${expat_GIT_TAG}
SOURCE_SUBDIR expat/
CMAKE_ARGS
-D BUILD_SHARED_LIBS=${expat_BUILD_SHARED_LIBS}
-D CMAKE_POSITION_INDEPENDENT_CODE=ON
-D CMAKE_INSTALL_LIBDIR=lib
-D CMAKE_C_FLAGS=${EXPAT_C_FLAGS}
-D CMAKE_CXX_FLAGS=${EXPAT_CXX_FLAGS}
-D EXPAT_BUILD_EXAMPLES=OFF
-D EXPAT_BUILD_TESTS=OFF
-D EXPAT_BUILD_TOOLS=OFF
-D EXPAT_BUILD_DOCS=OFF
-D EXPAT_SHARED_LIBS=${expat_BUILD_SHARED_LIBS}
)

# Set some things up that we'll need for a subsequent find_package to work
set (expat_REFIND TRUE)
set (expat_VERSION ${expat_BUILD_VERSION})
set (expat_DIR ${expat_ROOT}/lib/cmake/expat-${expat_VERSION})

if (WIN32)
# Set the expat_LIBRARY variable to the full path to ${EXPAT_LIBRARIES}.
# For some reason, find_package(expat) behaves differently on Windows
find_package (EXPAT ${expat_BUILD_VERSION} EXACT REQUIRED)
set_cache(expat_LIBRARY ${EXPAT_LIBRARIES} "Full path to the expat library")
message(STATUS "expat_LIBRARY = ${expat_LIBRARY}")
endif ()

if (expat_BUILD_SHARED_LIBS)
install_local_dependency_libs (expat expat)
endif ()
57 changes: 57 additions & 0 deletions src/cmake/build_minizip-ng.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Copyright Contributors to the OpenImageIO project.
# SPDX-License-Identifier: Apache-2.0
# https://github.com/AcademySoftwareFoundation/OpenImageIO

######################################################################
# minizip-ng by hand!
######################################################################


set_cache (minizip-ng_BUILD_VERSION 4.0.7 "minizip-ng version for local builds")
set (minizip-ng_GIT_REPOSITORY "https://github.com/zlib-ng/minizip-ng")
set (minizip-ng_GIT_TAG "${minizip-ng_BUILD_VERSION}")

set_cache (minizip-ng_BUILD_SHARED_LIBS OFF
DOC "Should a local minizip-ng build, if necessary, build shared libraries" ADVANCED)

checked_find_package (ZLIB REQUIRED)


build_dependency_with_cmake(minizip-ng
VERSION ${minizip-ng_BUILD_VERSION}
GIT_REPOSITORY ${minizip-ng_GIT_REPOSITORY}
GIT_TAG ${minizip-ng_GIT_TAG}
CMAKE_ARGS
-D BUILD_SHARED_LIBS=${minizip-ng_BUILD_SHARED_LIBS}
-D CMAKE_POSITION_INDEPENDENT_CODE=ON
-D CMAKE_INSTALL_LIBDIR=lib
# Since the other modules create a subfolder for the includes by default and since
# minizip-ng does not, a suffix is added to CMAKE_INSTALL_INCLUDEDIR in order to
# install the headers under a subdirectory named "minizip-ng".
# Note that this does not affect external builds for minizip-ng.
-D CMAKE_INSTALL_INCLUDEDIR=${CMAKE_INSTALL_INCLUDEDIR}/minizip-ng
-D MZ_OPENSSL=OFF
-D MZ_LIBBSD=OFF
-D MZ_BUILD_TESTS=OFF
-D MZ_COMPAT=OFF
-D MZ_BZIP2=OFF
-D MZ_LZMA=OFF
-D MZ_LIBCOMP=OFF
-D MZ_ZSTD=OFF
-D MZ_PKCRYPT=OFF
-D MZ_WZAES=OFF
-D MZ_SIGNING=OFF
-D MZ_ZLIB=ON
-D MZ_ICONV=OFF
-D MZ_FETCH_LIBS=OFF
-D MZ_FORCE_FETCH_LIBS=OFF
-D ZLIB_LIBRARY=${ZLIB_LIBRARIES}
-D ZLIB_INCLUDE_DIR=${ZLIB_INCLUDE_DIRS}
)


set (minizip-ng_DIR ${minizip-ng_LOCAL_INSTALL_DIR}/lib/cmake/minizip-ng)
set (minizip-ng_VERSION ${minizip-ng_BUILD_VERSION})
set (minizip-ng_REFIND TRUE)
set (minizip-ng_REFIND_VERSION ${minizip-ng_BUILD_VERSION})
set (minizip-ng_REFIND_ARGS REQUIRED)
40 changes: 40 additions & 0 deletions src/cmake/build_pystring.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright Contributors to the OpenImageIO project.
# SPDX-License-Identifier: Apache-2.0
# https://github.com/AcademySoftwareFoundation/OpenImageIO

######################################################################
# pystring by hand!
######################################################################

set_cache (pystring_BUILD_VERSION 1.1.4 "pystring version for local builds")
set (pystring_GIT_REPOSITORY "https://github.com/imageworks/pystring")
# See imageworks/pystring issue #43, git commit #c5ca4f5
# We require pystring commits made after the v1.1.4 tag to properly install headers!
# TODO: Set this to "v${pystring_BUILD_VERSION}" once 1.1.5 is released
set (pystring_GIT_TAG master)


set_cache (pystring_BUILD_SHARED_LIBS OFF
DOC "Should a local pystring build, if necessary, build shared libraries" ADVANCED)

string (MAKE_C_IDENTIFIER ${pystring_BUILD_VERSION} pystring_VERSION_IDENT)

build_dependency_with_cmake(pystring
VERSION ${pystring_BUILD_VERSION}
GIT_REPOSITORY ${pystring_GIT_REPOSITORY}
GIT_TAG ${pystring_GIT_TAG}
CMAKE_ARGS
-D BUILD_SHARED_LIBS=${pystring_BUILD_SHARED_LIBS}
-D CMAKE_POSITION_INDEPENDENT_CODE=ON
-D CMAKE_INSTALL_LIBDIR=lib
)

set (pystring_VERSION ${pystring_BUILD_VERSION})

set (pystring_REFIND TRUE)
set (pystring_REFIND_VERSION ${pystring_BUILD_VERSION})


if (pystring_BUILD_SHARED_LIBS)
install_local_dependency_libs (pystring pystring)
endif ()
41 changes: 41 additions & 0 deletions src/cmake/build_yaml-cpp.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright Contributors to the OpenImageIO project.
# SPDX-License-Identifier: Apache-2.0
# https://github.com/AcademySoftwareFoundation/OpenImageIO

######################################################################
# yaml-cpp by hand!
######################################################################

set_cache (yaml-cpp_BUILD_VERSION 0.8.0 "yaml-cpp version for local builds")
set (yaml-cpp_GIT_REPOSITORY "https://github.com/jbeder/yaml-cpp")
set (yaml-cpp_GIT_TAG "${yaml-cpp_BUILD_VERSION}") # NB: versions earlier than 0.8.0 had a "yaml-cpp-" prefix

set_cache (yaml-cpp_BUILD_SHARED_LIBS OFF
DOC "Should a local yaml-cpp build, if necessary, build shared libraries" ADVANCED)

string (MAKE_C_IDENTIFIER ${yaml-cpp_BUILD_VERSION} yaml-cpp_VERSION_IDENT)

build_dependency_with_cmake(yaml-cpp
VERSION ${yaml-cpp_BUILD_VERSION}
GIT_REPOSITORY ${yaml-cpp_GIT_REPOSITORY}
GIT_TAG ${yaml-cpp_GIT_TAG}
CMAKE_ARGS
-D YAML_CPP_BUILD_TESTS=OFF
-D YAML_CPP_BUILD_TOOLS=OFF
-D YAML_CPP_BUILD_CONTRIB=OFF
-D YAML_BUILD_SHARED_LIBS=${yaml-cpp_BUILD_SHARED_LIBS}
-D CMAKE_INSTALL_LIBDIR=lib
)

set (yaml-cpp_ROOT ${yaml-cpp_LOCAL_INSTALL_DIR})
set (yaml-cpp_DIR ${yaml-cpp_LOCAL_INSTALL_DIR})
set (yaml-cpp_VERSION ${yaml-cpp_BUILD_VERSION})

set (yaml-cpp_REFIND TRUE)
set (yaml-cpp_REFIND_ARGS CONFIG)
set (yaml-cpp_REFIND_VERSION ${yaml-cpp_BUILD_VERSION})


if (yaml-cpp_BUILD_SHARED_LIBS)
install_local_dependency_libs (yaml-cpp yaml-cpp)
endif ()
4 changes: 2 additions & 2 deletions src/cmake/dependency_utils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ macro (build_dependency_with_cmake pkgname)
# noValueKeywords:
"NOINSTALL"
# singleValueKeywords:
"GIT_REPOSITORY;GIT_TAG;VERSION"
"GIT_REPOSITORY;GIT_TAG;VERSION;SOURCE_SUBDIR"
# multiValueKeywords:
"CMAKE_ARGS"
# argsToParse:
Expand Down Expand Up @@ -549,7 +549,7 @@ macro (build_dependency_with_cmake pkgname)
execute_process (COMMAND
${CMAKE_COMMAND}
# Put things in our special local build areas
-S ${${pkgname}_LOCAL_SOURCE_DIR}
-S ${${pkgname}_LOCAL_SOURCE_DIR}/${_pkg_SOURCE_SUBDIR}
-B ${${pkgname}_LOCAL_BUILD_DIR}
-DCMAKE_INSTALL_PREFIX=${${pkgname}_LOCAL_INSTALL_DIR}
# Same build type as us
Expand Down
54 changes: 54 additions & 0 deletions src/cmake/modules/Findpystring.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Copyright Contributors to the OpenImageIO project.
# SPDX-License-Identifier: Apache-2.0
# https://github.com/AcademySoftwareFoundation/OpenImageIO

include (FindPackageHandleStandardArgs)

# Find include directory
find_path(pystring_INCLUDE_DIR
NAMES
pystring.h
HINTS
${pystring_ROOT}
PATH_SUFFIXES
include
include/pystring
pystring/include
)

# Find library
find_library(pystring_LIBRARY
NAMES
pystring libpystring
HINTS
${pystring_ROOT}
PATH_SUFFIXES
pystring/lib
lib64
lib
)

find_package_handle_standard_args(pystring
REQUIRED_VARS
pystring_INCLUDE_DIR
pystring_LIBRARY
VERSION_VAR pystring_VERSION
)
set(pystring_FOUND ${pystring_FOUND})


if(pystring_FOUND AND NOT TARGET pystring::pystring)
add_library(pystring::pystring UNKNOWN IMPORTED GLOBAL)
set(_pystring_TARGET_CREATE TRUE)
endif()


if(_pystring_TARGET_CREATE)
set_target_properties(pystring::pystring PROPERTIES
IMPORTED_LOCATION ${pystring_LIBRARY}
INTERFACE_INCLUDE_DIRECTORIES ${pystring_INCLUDE_DIR}
)

mark_as_advanced(pystring_INCLUDE_DIR pystring_LIBRARY pystring_VERSION)
endif()

0 comments on commit 2f0caf7

Please sign in to comment.