Skip to content

Commit 2f0caf7

Browse files
authored
build: support static OCIO self-builds (AcademySoftwareFoundation#4517)
* 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]>
1 parent 5592195 commit 2f0caf7

File tree

7 files changed

+260
-6
lines changed

7 files changed

+260
-6
lines changed

src/cmake/build_OpenColorIO.cmake

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
# OpenColorIO by hand!
77
######################################################################
88

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

26+
checked_find_package(pystring VERSION_MIN 1.1.3)
27+
checked_find_package(expat REQUIRED VERSION_MIN 2.5)
28+
checked_find_package(yaml-cpp REQUIRED VERSION_MIN 0.6.0)
29+
checked_find_package(minizip-ng REQUIRED VERSION_MIN 3.0.0)
30+
2631
string (MAKE_C_IDENTIFIER ${OpenColorIO_BUILD_VERSION} OpenColorIO_VERSION_IDENT)
2732

2833
build_dependency_with_cmake(OpenColorIO
@@ -31,6 +36,7 @@ build_dependency_with_cmake(OpenColorIO
3136
GIT_TAG ${OpenColorIO_GIT_TAG}
3237
CMAKE_ARGS
3338
-D BUILD_SHARED_LIBS=${OpenColorIO_BUILD_SHARED_LIBS}
39+
-D CMAKE_POSITION_INDEPENDENT_CODE=ON
3440
-D CMAKE_INSTALL_LIBDIR=lib
3541
# Don't built unnecessary parts of OCIO
3642
-D OCIO_BUILD_APPS=OFF
@@ -48,15 +54,14 @@ build_dependency_with_cmake(OpenColorIO
4854
)
4955

5056
# Set some things up that we'll need for a subsequent find_package to work
51-
52-
#list (APPEND CMAKE_PREFIX_PATH ${OpenColorIO_LOCAL_INSTALL_DIR})
5357
set (OpenColorIO_ROOT ${OpenColorIO_LOCAL_INSTALL_DIR})
5458
set (OpenColorIO_DIR ${OpenColorIO_LOCAL_INSTALL_DIR})
5559

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

6166
if (OpenColorIO_BUILD_SHARED_LIBS)
6267
install_local_dependency_libs (OpenColorIO OpenColorIO)

src/cmake/build_expat.cmake

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Copyright Contributors to the OpenImageIO project.
2+
# SPDX-License-Identifier: Apache-2.0
3+
# https://github.com/AcademySoftwareFoundation/OpenImageIO
4+
5+
######################################################################
6+
# expat by hand!
7+
######################################################################
8+
9+
set_cache (expat_BUILD_VERSION 2.6.3 "expat version for local builds")
10+
set (expat_GIT_REPOSITORY "https://github.com/libexpat/libexpat")
11+
12+
string(REPLACE "." ";" VERSION_LIST ${expat_BUILD_VERSION})
13+
list(GET VERSION_LIST 0 expat_VERSION_MAJOR)
14+
list(GET VERSION_LIST 1 expat_VERSION_MINOR)
15+
list(GET VERSION_LIST 2 expat_VERSION_PATCH)
16+
17+
set (expat_GIT_TAG "R_${expat_VERSION_MAJOR}_${expat_VERSION_MINOR}_${expat_VERSION_PATCH}")
18+
set_cache (expat_BUILD_SHARED_LIBS OFF #${LOCAL_BUILD_SHARED_LIBS_DEFAULT}
19+
DOC "Should execute a local expat build, if necessary, build shared libraries" ADVANCED)
20+
21+
22+
set (expat_LOCAL_SOURCE_DIR "${${PROJECT_NAME}_LOCAL_DEPS_ROOT}/expat/expat")
23+
24+
build_dependency_with_cmake(expat
25+
VERSION ${expat_BUILD_VERSION}
26+
GIT_REPOSITORY ${expat_GIT_REPOSITORY}
27+
GIT_TAG ${expat_GIT_TAG}
28+
SOURCE_SUBDIR expat/
29+
CMAKE_ARGS
30+
-D BUILD_SHARED_LIBS=${expat_BUILD_SHARED_LIBS}
31+
-D CMAKE_POSITION_INDEPENDENT_CODE=ON
32+
-D CMAKE_INSTALL_LIBDIR=lib
33+
-D CMAKE_C_FLAGS=${EXPAT_C_FLAGS}
34+
-D CMAKE_CXX_FLAGS=${EXPAT_CXX_FLAGS}
35+
-D EXPAT_BUILD_EXAMPLES=OFF
36+
-D EXPAT_BUILD_TESTS=OFF
37+
-D EXPAT_BUILD_TOOLS=OFF
38+
-D EXPAT_BUILD_DOCS=OFF
39+
-D EXPAT_SHARED_LIBS=${expat_BUILD_SHARED_LIBS}
40+
)
41+
42+
# Set some things up that we'll need for a subsequent find_package to work
43+
set (expat_REFIND TRUE)
44+
set (expat_VERSION ${expat_BUILD_VERSION})
45+
set (expat_DIR ${expat_ROOT}/lib/cmake/expat-${expat_VERSION})
46+
47+
if (WIN32)
48+
# Set the expat_LIBRARY variable to the full path to ${EXPAT_LIBRARIES}.
49+
# For some reason, find_package(expat) behaves differently on Windows
50+
find_package (EXPAT ${expat_BUILD_VERSION} EXACT REQUIRED)
51+
set_cache(expat_LIBRARY ${EXPAT_LIBRARIES} "Full path to the expat library")
52+
message(STATUS "expat_LIBRARY = ${expat_LIBRARY}")
53+
endif ()
54+
55+
if (expat_BUILD_SHARED_LIBS)
56+
install_local_dependency_libs (expat expat)
57+
endif ()

src/cmake/build_minizip-ng.cmake

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Copyright Contributors to the OpenImageIO project.
2+
# SPDX-License-Identifier: Apache-2.0
3+
# https://github.com/AcademySoftwareFoundation/OpenImageIO
4+
5+
######################################################################
6+
# minizip-ng by hand!
7+
######################################################################
8+
9+
10+
set_cache (minizip-ng_BUILD_VERSION 4.0.7 "minizip-ng version for local builds")
11+
set (minizip-ng_GIT_REPOSITORY "https://github.com/zlib-ng/minizip-ng")
12+
set (minizip-ng_GIT_TAG "${minizip-ng_BUILD_VERSION}")
13+
14+
set_cache (minizip-ng_BUILD_SHARED_LIBS OFF
15+
DOC "Should a local minizip-ng build, if necessary, build shared libraries" ADVANCED)
16+
17+
checked_find_package (ZLIB REQUIRED)
18+
19+
20+
build_dependency_with_cmake(minizip-ng
21+
VERSION ${minizip-ng_BUILD_VERSION}
22+
GIT_REPOSITORY ${minizip-ng_GIT_REPOSITORY}
23+
GIT_TAG ${minizip-ng_GIT_TAG}
24+
CMAKE_ARGS
25+
-D BUILD_SHARED_LIBS=${minizip-ng_BUILD_SHARED_LIBS}
26+
-D CMAKE_POSITION_INDEPENDENT_CODE=ON
27+
-D CMAKE_INSTALL_LIBDIR=lib
28+
# Since the other modules create a subfolder for the includes by default and since
29+
# minizip-ng does not, a suffix is added to CMAKE_INSTALL_INCLUDEDIR in order to
30+
# install the headers under a subdirectory named "minizip-ng".
31+
# Note that this does not affect external builds for minizip-ng.
32+
-D CMAKE_INSTALL_INCLUDEDIR=${CMAKE_INSTALL_INCLUDEDIR}/minizip-ng
33+
-D MZ_OPENSSL=OFF
34+
-D MZ_LIBBSD=OFF
35+
-D MZ_BUILD_TESTS=OFF
36+
-D MZ_COMPAT=OFF
37+
-D MZ_BZIP2=OFF
38+
-D MZ_LZMA=OFF
39+
-D MZ_LIBCOMP=OFF
40+
-D MZ_ZSTD=OFF
41+
-D MZ_PKCRYPT=OFF
42+
-D MZ_WZAES=OFF
43+
-D MZ_SIGNING=OFF
44+
-D MZ_ZLIB=ON
45+
-D MZ_ICONV=OFF
46+
-D MZ_FETCH_LIBS=OFF
47+
-D MZ_FORCE_FETCH_LIBS=OFF
48+
-D ZLIB_LIBRARY=${ZLIB_LIBRARIES}
49+
-D ZLIB_INCLUDE_DIR=${ZLIB_INCLUDE_DIRS}
50+
)
51+
52+
53+
set (minizip-ng_DIR ${minizip-ng_LOCAL_INSTALL_DIR}/lib/cmake/minizip-ng)
54+
set (minizip-ng_VERSION ${minizip-ng_BUILD_VERSION})
55+
set (minizip-ng_REFIND TRUE)
56+
set (minizip-ng_REFIND_VERSION ${minizip-ng_BUILD_VERSION})
57+
set (minizip-ng_REFIND_ARGS REQUIRED)

src/cmake/build_pystring.cmake

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Copyright Contributors to the OpenImageIO project.
2+
# SPDX-License-Identifier: Apache-2.0
3+
# https://github.com/AcademySoftwareFoundation/OpenImageIO
4+
5+
######################################################################
6+
# pystring by hand!
7+
######################################################################
8+
9+
set_cache (pystring_BUILD_VERSION 1.1.4 "pystring version for local builds")
10+
set (pystring_GIT_REPOSITORY "https://github.com/imageworks/pystring")
11+
# See imageworks/pystring issue #43, git commit #c5ca4f5
12+
# We require pystring commits made after the v1.1.4 tag to properly install headers!
13+
# TODO: Set this to "v${pystring_BUILD_VERSION}" once 1.1.5 is released
14+
set (pystring_GIT_TAG master)
15+
16+
17+
set_cache (pystring_BUILD_SHARED_LIBS OFF
18+
DOC "Should a local pystring build, if necessary, build shared libraries" ADVANCED)
19+
20+
string (MAKE_C_IDENTIFIER ${pystring_BUILD_VERSION} pystring_VERSION_IDENT)
21+
22+
build_dependency_with_cmake(pystring
23+
VERSION ${pystring_BUILD_VERSION}
24+
GIT_REPOSITORY ${pystring_GIT_REPOSITORY}
25+
GIT_TAG ${pystring_GIT_TAG}
26+
CMAKE_ARGS
27+
-D BUILD_SHARED_LIBS=${pystring_BUILD_SHARED_LIBS}
28+
-D CMAKE_POSITION_INDEPENDENT_CODE=ON
29+
-D CMAKE_INSTALL_LIBDIR=lib
30+
)
31+
32+
set (pystring_VERSION ${pystring_BUILD_VERSION})
33+
34+
set (pystring_REFIND TRUE)
35+
set (pystring_REFIND_VERSION ${pystring_BUILD_VERSION})
36+
37+
38+
if (pystring_BUILD_SHARED_LIBS)
39+
install_local_dependency_libs (pystring pystring)
40+
endif ()

src/cmake/build_yaml-cpp.cmake

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Copyright Contributors to the OpenImageIO project.
2+
# SPDX-License-Identifier: Apache-2.0
3+
# https://github.com/AcademySoftwareFoundation/OpenImageIO
4+
5+
######################################################################
6+
# yaml-cpp by hand!
7+
######################################################################
8+
9+
set_cache (yaml-cpp_BUILD_VERSION 0.8.0 "yaml-cpp version for local builds")
10+
set (yaml-cpp_GIT_REPOSITORY "https://github.com/jbeder/yaml-cpp")
11+
set (yaml-cpp_GIT_TAG "${yaml-cpp_BUILD_VERSION}") # NB: versions earlier than 0.8.0 had a "yaml-cpp-" prefix
12+
13+
set_cache (yaml-cpp_BUILD_SHARED_LIBS OFF
14+
DOC "Should a local yaml-cpp build, if necessary, build shared libraries" ADVANCED)
15+
16+
string (MAKE_C_IDENTIFIER ${yaml-cpp_BUILD_VERSION} yaml-cpp_VERSION_IDENT)
17+
18+
build_dependency_with_cmake(yaml-cpp
19+
VERSION ${yaml-cpp_BUILD_VERSION}
20+
GIT_REPOSITORY ${yaml-cpp_GIT_REPOSITORY}
21+
GIT_TAG ${yaml-cpp_GIT_TAG}
22+
CMAKE_ARGS
23+
-D YAML_CPP_BUILD_TESTS=OFF
24+
-D YAML_CPP_BUILD_TOOLS=OFF
25+
-D YAML_CPP_BUILD_CONTRIB=OFF
26+
-D YAML_BUILD_SHARED_LIBS=${yaml-cpp_BUILD_SHARED_LIBS}
27+
-D CMAKE_INSTALL_LIBDIR=lib
28+
)
29+
30+
set (yaml-cpp_ROOT ${yaml-cpp_LOCAL_INSTALL_DIR})
31+
set (yaml-cpp_DIR ${yaml-cpp_LOCAL_INSTALL_DIR})
32+
set (yaml-cpp_VERSION ${yaml-cpp_BUILD_VERSION})
33+
34+
set (yaml-cpp_REFIND TRUE)
35+
set (yaml-cpp_REFIND_ARGS CONFIG)
36+
set (yaml-cpp_REFIND_VERSION ${yaml-cpp_BUILD_VERSION})
37+
38+
39+
if (yaml-cpp_BUILD_SHARED_LIBS)
40+
install_local_dependency_libs (yaml-cpp yaml-cpp)
41+
endif ()

src/cmake/dependency_utils.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ macro (build_dependency_with_cmake pkgname)
502502
# noValueKeywords:
503503
"NOINSTALL"
504504
# singleValueKeywords:
505-
"GIT_REPOSITORY;GIT_TAG;VERSION"
505+
"GIT_REPOSITORY;GIT_TAG;VERSION;SOURCE_SUBDIR"
506506
# multiValueKeywords:
507507
"CMAKE_ARGS"
508508
# argsToParse:
@@ -549,7 +549,7 @@ macro (build_dependency_with_cmake pkgname)
549549
execute_process (COMMAND
550550
${CMAKE_COMMAND}
551551
# Put things in our special local build areas
552-
-S ${${pkgname}_LOCAL_SOURCE_DIR}
552+
-S ${${pkgname}_LOCAL_SOURCE_DIR}/${_pkg_SOURCE_SUBDIR}
553553
-B ${${pkgname}_LOCAL_BUILD_DIR}
554554
-DCMAKE_INSTALL_PREFIX=${${pkgname}_LOCAL_INSTALL_DIR}
555555
# Same build type as us
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Copyright Contributors to the OpenImageIO project.
2+
# SPDX-License-Identifier: Apache-2.0
3+
# https://github.com/AcademySoftwareFoundation/OpenImageIO
4+
5+
include (FindPackageHandleStandardArgs)
6+
7+
# Find include directory
8+
find_path(pystring_INCLUDE_DIR
9+
NAMES
10+
pystring.h
11+
HINTS
12+
${pystring_ROOT}
13+
PATH_SUFFIXES
14+
include
15+
include/pystring
16+
pystring/include
17+
)
18+
19+
# Find library
20+
find_library(pystring_LIBRARY
21+
NAMES
22+
pystring libpystring
23+
HINTS
24+
${pystring_ROOT}
25+
PATH_SUFFIXES
26+
pystring/lib
27+
lib64
28+
lib
29+
)
30+
31+
find_package_handle_standard_args(pystring
32+
REQUIRED_VARS
33+
pystring_INCLUDE_DIR
34+
pystring_LIBRARY
35+
VERSION_VAR pystring_VERSION
36+
)
37+
set(pystring_FOUND ${pystring_FOUND})
38+
39+
40+
if(pystring_FOUND AND NOT TARGET pystring::pystring)
41+
add_library(pystring::pystring UNKNOWN IMPORTED GLOBAL)
42+
set(_pystring_TARGET_CREATE TRUE)
43+
endif()
44+
45+
46+
if(_pystring_TARGET_CREATE)
47+
set_target_properties(pystring::pystring PROPERTIES
48+
IMPORTED_LOCATION ${pystring_LIBRARY}
49+
INTERFACE_INCLUDE_DIRECTORIES ${pystring_INCLUDE_DIR}
50+
)
51+
52+
mark_as_advanced(pystring_INCLUDE_DIR pystring_LIBRARY pystring_VERSION)
53+
endif()
54+

0 commit comments

Comments
 (0)