Skip to content

Commit 91761f2

Browse files
Adsk Contrib - OCIO cmake improvements (#1736)
* - Refactoring how OCIO search for minizip-ng. The first step is to search for an external minizip-ng. If not found, search for minizip-ng with MZ_COMPAT=ON (libminizip). If it is not found either, download and install minizip-ng with MZ_COMPAT=OFF. - Removing the minizip-ng part for the includes for minizip-ng headers. Signed-off-by: Cédrik Fuoco <cedrik.fuoco@autodesk.com> * Update comments Signed-off-by: Cédrik Fuoco <cedrik.fuoco@autodesk.com> * Improved find_package in Config mode (adding it back) Added missing scripts to install minizip-ng and zlib for the analysis workflow Signed-off-by: Cédrik Fuoco <cedrik.fuoco@autodesk.com> * Adding +x permissions for install_minizip_ng and zlib Fixing path to find zlib in install_minizip-ng.sh Signed-off-by: Cédrik Fuoco <cedrik.fuoco@autodesk.com> * Changing target name to match the one used by minizip-ng library (+ using the imported target instead of creating a new one when minizip-ng is found) Signed-off-by: Cédrik Fuoco <cedrik.fuoco@autodesk.com> * First pass for the OpenColorIOConfig.cmake file with the required dependencies only. A few extra fixes for OpenEXR, ZLIB and Minizip-ng. Signed-off-by: Cédrik Fuoco <cedrik.fuoco@autodesk.com> * Adding a informative message when building static ocio instead of per module. Signed-off-by: Cédrik Fuoco <cedrik.fuoco@autodesk.com> * Adding an extra step to test the consumer app with static OpenColorIO for Windows, Linux and MacOS. Signed-off-by: Cédrik Fuoco <cedrik.fuoco@autodesk.com> * Re-using the same test instead of creating a new one by removing the condition on build-shared. Signed-off-by: Cédrik Fuoco <cedrik.fuoco@autodesk.com> * Fixing spacing, typo and adding back the NOT in the condition. (it was removed for debugging purpose) Signed-off-by: Cédrik Fuoco <cedrik.fuoco@autodesk.com> * Changing directory where we share OCIO custom find modules (now in <install dir>/share/cmake/modules). Adding a cmake macro when installing OCIO since it is needed by some custom find modules. The find modules are only installed when building OCIO as a static library. The config.cmake.in files now only looks for the dependency when OCIO was built as a static library. Tentative (ci-workflow): Adding cmake-consumer test for static builds. Overhaul of the Findzlib module to be more inline with the FindZLIB from cmake and to be more robust. Signed-off-by: Cédrik Fuoco <cedrik.fuoco@autodesk.com> * Adding missing backward slashes and saving the build path in an existing step instead of creating a new step. Adding a check for CMake version for a section in Findzlib.cmake. Re-phrasing some comments. Signed-off-by: Cédrik Fuoco <cedrik.fuoco@autodesk.com> * Prevent the download of the dependencies in the scenario where static OCIO is linked to a consumer project. Since OCIO_INSTALL_EXT_PACKAGES is not defined, our find module tries to download the dependencies, but we don't want that mecanism for consumer project. Signed-off-by: Cédrik Fuoco <cedrik.fuoco@autodesk.com> * Changing path where OCIO install its own custom find module. Removing custom Findzlib and making modifications to use CMake FindZLIB. Created a InstallZLIB module which does the download and install part if OCIO_INSTALL_EXT_PACAKGES is ALL or MISSING. Tweaked config.cmake.in to use CMake FindZLIB. Signed-off-by: Cédrik Fuoco <cedrik.fuoco@autodesk.com> * Adding more details in comments Signed-off-by: Cédrik Fuoco <cedrik.fuoco@autodesk.com> * Removing an extra "shell" property in CI workflow. Signed-off-by: Cédrik Fuoco <cedrik.fuoco@autodesk.com> * Fix issues discovered with the failing CI workflow: Cmake-consumer test now prefer the static version of the dependencies. Fix an issue where yaml-cpp is not found by a consumer app (variable spelled incorectly in Findyaml-cpp). Fix an issue expat library is not found by a consumer app on Windows. Adding support for OCIO's <pkg_name>_STATIC_LIBRARY for ZLIB while supporting ZLIB_USE_STATIC_LIBS (CMake 3.24+) from CMake's FindZLIB. Signed-off-by: Cédrik Fuoco <cedrik.fuoco@autodesk.com> * Removing pystring_STATIC_LIBRARY does not exists in CI workflow. Detecting if the build is Debug in the find module that OCIO installs since they can't rely on variables set by OCIO CMakefiles. Fix issue with yaml-cpp library naming in debug. Signed-off-by: Cédrik Fuoco <cedrik.fuoco@autodesk.com> * Fix issues on Windows with expat and minizip-ng library naming when building static OCIO. Signed-off-by: Cédrik Fuoco <cedrik.fuoco@autodesk.com> * Added option for macOS CI job in order to get more info on a failed job. Will be reverted once the issue is found. Signed-off-by: Cédrik Fuoco <cedrik.fuoco@autodesk.com> * Fixing a issue on macOS. Improving ZLIB usage comments. Bumping minizip-ng to the latest version - 3.0.7. Bumping ZLIB to the latest version 2.1.13 to fix a vulnerability (CVE-2022-37434) Signed-off-by: Cédrik Fuoco <cedrik.fuoco@autodesk.com> * Proposing to remove Findminizip module since external minizip-ng build need to be done with the same option as the internal build. Otherwise, linking and symbols issues are going to happend if the other libraries are not linked in correctly. It is going to simplify the maintainability of OCIO. Signed-off-by: Cédrik Fuoco <cedrik.fuoco@autodesk.com> * Removing findminizip.cmake from the install since it does not exist anymore. Signed-off-by: Cédrik Fuoco <cedrik.fuoco@autodesk.com> Signed-off-by: Cédrik Fuoco <cedrik.fuoco@autodesk.com> Signed-off-by: Cédrik Fuoco <105517825+cedrik-fuoco-adsk@users.noreply.github.com>
1 parent 17f5c98 commit 91761f2

15 files changed

Lines changed: 611 additions & 404 deletions

.github/workflows/ci_workflow.yml

Lines changed: 92 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,11 +287,12 @@ jobs:
287287
--target install \
288288
--config ${{ matrix.build-type }} \
289289
-- -j$(nproc)
290+
echo "ocio_build_path=$(pwd)" >> $GITHUB_ENV
290291
working-directory: _build
291292
- name: Test
292293
run: ctest -V -C ${{ matrix.build-type }}
293294
working-directory: _build
294-
- name: Test CMake Consumer
295+
- name: Test CMake Consumer with shared OCIO
295296
if: matrix.build-shared == 'ON'
296297
run: |
297298
cmake . \
@@ -301,6 +302,34 @@ jobs:
301302
--config ${{ matrix.build-type }}
302303
./consumer
303304
working-directory: _build/tests/cmake-consumer-dist
305+
- name: Test CMake Consumer with static OCIO
306+
if: matrix.build-shared == 'OFF'
307+
# The yaml-cpp_VERSION is set below because Findyaml-cpp.cmake needs it but is unable to
308+
# extract it from the headers, like the other modules.
309+
#
310+
# Prefer the static version of each dependencies by using <pkg>_STATIC_LIBRARY.
311+
# Alternatively, this can be done by setting <pkg>_LIBRARY and <pkg>_INCLUDE_DIR to
312+
# the static version of the package.
313+
run: |
314+
cmake . \
315+
-DCMAKE_PREFIX_PATH=../../../_install \
316+
-DCMAKE_BUILD_TYPE=${{ matrix.build-type }} \
317+
-Dexpat_ROOT=${{ env.ocio_build_path }}/ext/dist \
318+
-Dexpat_STATIC_LIBRARY=ON \
319+
-DImath_ROOT=${{ env.ocio_build_path }}/ext/dist \
320+
-DImath_STATIC_LIBRARY=ON \
321+
-Dpystring_ROOT=${{ env.ocio_build_path }}/ext/dist \
322+
-Dyaml-cpp_ROOT=${{ env.ocio_build_path }}/ext/dist \
323+
-Dyaml-cpp_STATIC_LIBRARY=ON \
324+
-Dyaml-cpp_VERSION=0.7.0 \
325+
-DZLIB_ROOT=${{ env.ocio_build_path }}/ext/dist \
326+
-DZLIB_STATIC_LIBRARY=ON \
327+
-Dminizip-ng_ROOT=${{ env.ocio_build_path }}/ext/dist \
328+
-Dminizip-ng_STATIC_LIBRARY=ON
329+
cmake --build . \
330+
--config ${{ matrix.build-type }}
331+
./consumer
332+
working-directory: _build/tests/cmake-consumer-dist
304333

305334
# ---------------------------------------------------------------------------
306335
# macOS
@@ -424,11 +453,12 @@ jobs:
424453
--target install \
425454
--config ${{ matrix.build-type }} \
426455
-- -j$(sysctl -n hw.ncpu)
456+
echo "ocio_build_path=$(pwd)" >> $GITHUB_ENV
427457
working-directory: _build
428458
- name: Test
429459
run: ctest -V -C ${{ matrix.build-type }}
430460
working-directory: _build
431-
- name: Test CMake Consumer
461+
- name: Test CMake Consumer with shared OCIO
432462
if: matrix.build-shared == 'ON'
433463
run: |
434464
cmake . \
@@ -438,6 +468,34 @@ jobs:
438468
--config ${{ matrix.build-type }}
439469
./consumer
440470
working-directory: _build/tests/cmake-consumer-dist
471+
- name: Test CMake Consumer with static OCIO
472+
if: matrix.build-shared == 'OFF'
473+
# The yaml-cpp_VERSION is set below because Findyaml-cpp.cmake needs it but is unable to
474+
# extract it from the headers, like the other modules.
475+
#
476+
# Prefer the static version of each dependencies by using <pkg>_STATIC_LIBRARY.
477+
# Alternatively, this can be done by setting <pkg>_LIBRARY and <pkg>_INCLUDE_DIR to
478+
# the static version of the package.
479+
run: |
480+
cmake . \
481+
-DCMAKE_PREFIX_PATH=../../../_install \
482+
-DCMAKE_BUILD_TYPE=${{ matrix.build-type }} \
483+
-Dexpat_ROOT=${{ env.ocio_build_path }}/ext/dist \
484+
-Dexpat_STATIC_LIBRARY=ON \
485+
-DImath_ROOT=${{ env.ocio_build_path }}/ext/dist \
486+
-DImath_STATIC_LIBRARY=ON \
487+
-Dpystring_ROOT=${{ env.ocio_build_path }}/ext/dist \
488+
-Dyaml-cpp_ROOT=${{ env.ocio_build_path }}/ext/dist \
489+
-Dyaml-cpp_STATIC_LIBRARY=ON \
490+
-Dyaml-cpp_VERSION=0.7.0 \
491+
-DZLIB_ROOT=${{ env.ocio_build_path }}/ext/dist \
492+
-DZLIB_STATIC_LIBRARY=ON \
493+
-Dminizip-ng_ROOT=${{ env.ocio_build_path }}/ext/dist \
494+
-Dminizip-ng_STATIC_LIBRARY=ON
495+
cmake --build . \
496+
--config ${{ matrix.build-type }}
497+
./consumer
498+
working-directory: _build/tests/cmake-consumer-dist
441499

442500
# ---------------------------------------------------------------------------
443501
# Windows
@@ -567,13 +625,14 @@ jobs:
567625
cmake --build . \
568626
--target install \
569627
--config ${{ matrix.build-type }}
628+
echo "ocio_build_path=$(pwd)" >> $GITHUB_ENV
570629
shell: bash
571630
working-directory: _build
572631
- name: Test
573632
run: ctest -V -C ${{ matrix.build-type }}
574633
shell: bash
575634
working-directory: _build
576-
- name: Test CMake Consumer
635+
- name: Test CMake Consumer with shared OCIO
577636
if: matrix.build-shared == 'ON'
578637
run: |
579638
cmake . \
@@ -585,3 +644,33 @@ jobs:
585644
./${{ matrix.build-type }}/consumer
586645
shell: bash
587646
working-directory: _build/tests/cmake-consumer-dist
647+
- name: Test CMake Consumer with static OCIO
648+
if: matrix.build-shared == 'OFF'
649+
# The yaml-cpp_VERSION is set below because Findyaml-cpp.cmake needs it but is unable to
650+
# extract it from the headers, like the other modules.
651+
#
652+
# Prefer the static version of each dependencies by using <pkg>_STATIC_LIBRARY.
653+
# Alternatively, this can be done by setting <pkg>_LIBRARY and <pkg>_INCLUDE_DIR to
654+
# the static version of the package.
655+
run: |
656+
cmake . \
657+
-DCMAKE_PREFIX_PATH=../../../_install \
658+
-DCMAKE_BUILD_TYPE=${{ matrix.build-type }} \
659+
-Dexpat_ROOT=${{ env.ocio_build_path }}/ext/dist \
660+
-Dexpat_STATIC_LIBRARY=ON \
661+
-DImath_ROOT=${{ env.ocio_build_path }}/ext/dist \
662+
-DImath_STATIC_LIBRARY=ON \
663+
-Dpystring_ROOT=${{ env.ocio_build_path }}/ext/dist \
664+
-Dyaml-cpp_ROOT=${{ env.ocio_build_path }}/ext/dist \
665+
-Dyaml-cpp_STATIC_LIBRARY=ON \
666+
-Dyaml-cpp_VERSION=0.7.0 \
667+
-DZLIB_ROOT=${{ env.ocio_build_path }}/ext/dist \
668+
-DZLIB_STATIC_LIBRARY=ON \
669+
-Dminizip-ng_ROOT=${{ env.ocio_build_path }}/ext/dist \
670+
-Dminizip-ng_STATIC_LIBRARY=ON
671+
cmake --build . \
672+
--config ${{ matrix.build-type }}
673+
export PATH=../../../_install/bin:$PATH
674+
./${{ matrix.build-type }}/consumer
675+
shell: bash
676+
working-directory: _build/tests/cmake-consumer-dist

CMakeLists.txt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,15 @@ if(OCIO_BUILD_STATIC)
251251
endif()
252252
endif()
253253

254+
if (NOT BUILD_SHARED_LIBS AND NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL NONE)
255+
message(STATUS "Note that building the static version of OpenColorIO does not embed the dependencies\
256+
into the library file. The needed dependencies must be linked to the consumer
257+
application or shared library that uses static OpenColorIO.
258+
259+
The following mandatory dependencies MUST be linked to the consumer application or shared library:
260+
expat, yaml-cpp, Imath, pystring, minizip-ng and ZLIB")
261+
endif()
262+
254263

255264
###############################################################################
256265
# Find or install external dependencies
@@ -299,6 +308,8 @@ set(OCIO_TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets.cmake")
299308
set(OCIO_VERSION_CONFIG "${CMAKE_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake")
300309
set(OCIO_PROJECT_CONFIG "${CMAKE_BINARY_DIR}/${PROJECT_NAME}Config.cmake")
301310
set(OCIO_CONFIG_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
311+
set(OCIO_CUSTOM_FIND_MODULE_DIR "${CMAKE_INSTALL_PREFIX}/share/OpenColorIO/cmake/modules")
312+
set(OCIO_CUSTOM_MACROS_MODULE_DIR "${CMAKE_INSTALL_PREFIX}/share/OpenColorIO/cmake/macros")
302313

303314
# Version fetched from the top level project()
304315
write_basic_package_version_file(
@@ -321,6 +332,24 @@ install(
321332
FILE ${OCIO_TARGETS_EXPORT_NAME}
322333
)
323334

335+
if (NOT BUILD_SHARED_LIBS)
336+
# Install custom macros used in the find modules.
337+
install(FILES
338+
${CMAKE_CURRENT_LIST_DIR}/share/cmake/macros/VersionUtils.cmake
339+
DESTINATION ${OCIO_CUSTOM_MACROS_MODULE_DIR}
340+
)
341+
342+
# Install custom Find modules.
343+
install(FILES
344+
${CMAKE_CURRENT_LIST_DIR}/share/cmake/modules/Findexpat.cmake
345+
${CMAKE_CURRENT_LIST_DIR}/share/cmake/modules/FindImath.cmake
346+
${CMAKE_CURRENT_LIST_DIR}/share/cmake/modules/Findpystring.cmake
347+
${CMAKE_CURRENT_LIST_DIR}/share/cmake/modules/Findminizip-ng.cmake
348+
${CMAKE_CURRENT_LIST_DIR}/share/cmake/modules/Findyaml-cpp.cmake
349+
DESTINATION ${OCIO_CUSTOM_FIND_MODULE_DIR}
350+
)
351+
endif()
352+
324353
install(
325354
FILES "${OCIO_PROJECT_CONFIG}" "${OCIO_VERSION_CONFIG}"
326355
DESTINATION "${OCIO_CONFIG_INSTALL_DIR}"

share/cmake/modules/FindExtPackages.cmake

Lines changed: 101 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,17 @@ set(CMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY ON CACHE BOOL
2121
set(CMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY ON CACHE BOOL
2222
"Disable CMake System Package Registry when finding packages")
2323

24+
if (APPLE)
25+
# Store the previous value of CMAKE_FIND_FRAMEWORK and CMAKE_FIND_APPBUNDLE.
26+
set(_PREVIOUS_CMAKE_FIND_FRAMEWORK ${CMAKE_FIND_FRAMEWORK})
27+
set(_PREVIOUS_CMAKE_FIND_APPBUNDLE ${CMAKE_FIND_APPBUNDLE})
28+
29+
# Prioritize other paths before Frameworks and Appbundle for find_path, find_library and
30+
# find_package.
31+
set(CMAKE_FIND_FRAMEWORK LAST)
32+
set(CMAKE_FIND_APPBUNDLE LAST)
33+
endif()
34+
2435
###############################################################################
2536
### Packages and versions ###
2637

@@ -41,14 +52,93 @@ find_package(pystring 1.1.3 REQUIRED)
4152
set(_Imath_ExternalProject_VERSION "3.1.5")
4253
find_package(Imath 3.0 REQUIRED)
4354

44-
# ZLIB
45-
# https://github.com/madler/zlib
46-
set(_zlib_ExternalProject_VERSION "1.2.12")
47-
find_package(zlib REQUIRED)
55+
###############################################################################
56+
### ZLIB (https://github.com/madler/zlib)
57+
###
58+
### The following variables can be set:
59+
### ZLIB_ROOT Location of ZLIB library file and includes folder.
60+
### Alternatively, ZLIB_LIBRARY and ZLIB_INCLUDE_DIR can be used.
61+
###
62+
### ZLIB_LIBRARY Location of ZLIB library file.
63+
### ZLIB_INCLUDE_DIR Location of ZLIB includes folder.
64+
###
65+
### ZLIB_VERSION ZLIB Version (CMake 3.26+)
66+
### ZLIB_VERSION_STRING ZLIB Version (CMake < 3.26)
67+
###
68+
###############################################################################
69+
# ZLIB 1.2.13 is used since it fixes a critical vulnerability.
70+
# See https://nvd.nist.gov/vuln/detail/CVE-2022-37434
71+
# See https://github.com/madler/zlib/releases/tag/v1.2.13
72+
set(_ZLIB_FIND_VERSION "1.2.13")
73+
set(_ZLIB_ExternalProject_VERSION ${_ZLIB_FIND_VERSION})
74+
75+
if(NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL ALL)
76+
# ZLIB_USE_STATIC_LIBS is supported only from CMake 3.24+.
77+
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.24.0")
78+
if (ZLIB_STATIC_LIBRARY)
79+
set(ZLIB_USE_STATIC_LIBS "${ZLIB_STATIC_LIBRARY}")
80+
endif()
81+
else() # For CMake < 3.24 since ZLIB_USE_STATIC_LIBS is not available.
82+
if(NOT ZLIB_LIBRARY)
83+
if(DEFINED CMAKE_FIND_LIBRARY_PREFIXES)
84+
set(_ZLIB_ORIG_CMAKE_FIND_LIBRARY_PREFIXES "${CMAKE_FIND_LIBRARY_PREFIXES}")
85+
else()
86+
set(_ZLIB_ORIG_CMAKE_FIND_LIBRARY_PREFIXES)
87+
endif()
88+
89+
if(DEFINED CMAKE_FIND_LIBRARY_SUFFIXES)
90+
set(_ZLIB_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES "${CMAKE_FIND_LIBRARY_SUFFIXES}")
91+
else()
92+
set(_ZLIB_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES)
93+
endif()
94+
95+
# Prefix/suffix for windows.
96+
if(WIN32)
97+
list(APPEND CMAKE_FIND_LIBRARY_PREFIXES "" "lib")
98+
list(APPEND CMAKE_FIND_LIBRARY_SUFFIXES ".dll.a")
99+
endif()
100+
101+
# Check if static lib is preferred.
102+
if(ZLIB_STATIC_LIBRARY OR ZLIB_USE_STATIC_LIBS)
103+
if(WIN32)
104+
set(CMAKE_FIND_LIBRARY_SUFFIXES .lib .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
105+
else()
106+
set(CMAKE_FIND_LIBRARY_SUFFIXES .a)
107+
endif()
108+
endif()
109+
endif()
110+
endif()
111+
112+
set(_ZLIB_REQUIRED REQUIRED)
113+
# Override REQUIRED if package can be installed
114+
if(OCIO_INSTALL_EXT_PACKAGES STREQUAL MISSING)
115+
set(_ZLIB_REQUIRED "")
116+
endif()
117+
118+
find_package(ZLIB ${_ZLIB_FIND_VERSION} ${_ZLIB_REQUIRED})
119+
120+
# Restore the original find library ordering
121+
if(DEFINED _ZLIB_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES)
122+
set(CMAKE_FIND_LIBRARY_SUFFIXES "${_ZLIB_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES}")
123+
else()
124+
set(CMAKE_FIND_LIBRARY_SUFFIXES)
125+
endif()
126+
127+
if(DEFINED _ZLIB_ORIG_CMAKE_FIND_LIBRARY_PREFIXES)
128+
set(CMAKE_FIND_LIBRARY_PREFIXES "${_ZLIB_ORIG_CMAKE_FIND_LIBRARY_PREFIXES}")
129+
else()
130+
set(CMAKE_FIND_LIBRARY_PREFIXES)
131+
endif()
132+
endif()
133+
134+
if(NOT ZLIB_FOUND AND OCIO_INSTALL_EXT_PACKAGES AND NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL NONE)
135+
include(InstallZLIB)
136+
endif()
137+
###############################################################################
48138

49139
# minizip-ng
50140
# https://github.com/zlib-ng/minizip-ng
51-
find_package(minizip-ng 3.0.6 REQUIRED)
141+
find_package(minizip-ng 3.0.7 REQUIRED)
52142

53143
if(OCIO_BUILD_APPS)
54144

@@ -157,3 +247,9 @@ if(OCIO_BUILD_TESTS)
157247
message(WARNING "Could NOT find OpenImageIO. Skipping build of the OSL unit tests.")
158248
endif()
159249
endif()
250+
251+
if (APPLE)
252+
# Restore CMAKE_FIND_FRAMEWORK and CMAKE_FIND_APPBUNDLE values.
253+
set(CMAKE_FIND_FRAMEWORK ${_PREVIOUS_CMAKE_FIND_FRAMEWORK})
254+
set(CMAKE_FIND_APPBUNDLE ${_PREVIOUS_CMAKE_FIND_APPBUNDLE})
255+
endif()

share/cmake/modules/FindImath.cmake

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@
2525
###############################################################################
2626
### Try to find package ###
2727

28+
# BUILD_TYPE_DEBUG variable is currently set in one of the OCIO's CMake files.
29+
# Now that some OCIO's find module are installed with the library itself (with static build),
30+
# a consumer app don't have access to the variables set by an OCIO's CMake files. Therefore, some
31+
# OCIO's find modules must detect the build type by itselves.
32+
set(BUILD_TYPE_DEBUG OFF)
33+
if(CMAKE_BUILD_TYPE MATCHES "[Dd][Ee][Bb][Uu][Gg]")
34+
set(BUILD_TYPE_DEBUG ON)
35+
endif()
36+
2837
if(NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL ALL)
2938
set(_Imath_REQUIRED_VARS Imath_LIBRARY)
3039
set(_Imath_LIB_VER "${Imath_FIND_VERSION_MAJOR}_${Imath_FIND_VERSION_MINOR}")
@@ -131,7 +140,7 @@ endif()
131140
###############################################################################
132141
### Install package from source ###
133142

134-
if(NOT Imath_FOUND AND NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL NONE)
143+
if(NOT Imath_FOUND AND OCIO_INSTALL_EXT_PACKAGES AND NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL NONE)
135144
include(ExternalProject)
136145
include(GNUInstallDirs)
137146

share/cmake/modules/FindOpenEXR.cmake

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ if(NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL ALL)
4545
if(OpenEXR_FOUND)
4646
get_target_property(OpenEXR_LIBRARY OpenEXR::OpenEXR LOCATION)
4747
get_target_property(OpenEXR_INCLUDE_DIR OpenEXR::OpenEXR INTERFACE_INCLUDE_DIRECTORIES)
48+
49+
# IMPORTED_GLOBAL property must be set to TRUE since alisasing a non-global imported target
50+
# is not possible until CMake 3.18+.
51+
set_target_properties(OpenEXR::OpenEXR PROPERTIES IMPORTED_GLOBAL TRUE)
4852
endif()
4953

5054
# Override REQUIRED if package can be installed
@@ -77,21 +81,22 @@ macro(set_target_location target_name)
7781
endif()
7882
endmacro()
7983

80-
if(NOT OpenEXR_FOUND AND NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL NONE)
84+
if(NOT OpenEXR_FOUND AND OCIO_INSTALL_EXT_PACKAGES AND NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL NONE)
8185
include(ExternalProject)
8286
include(GNUInstallDirs)
8387

8488
set(_EXT_DIST_ROOT "${CMAKE_BINARY_DIR}/ext/dist")
8589
set(_EXT_BUILD_ROOT "${CMAKE_BINARY_DIR}/ext/build")
8690

8791
# Required dependency
88-
# OCIO custom module to find ZLIB. (Findzlib)
89-
find_package(zlib)
9092
if(NOT ZLIB_FOUND)
91-
message(STATUS "ZLib is required to build OpenEXR.")
92-
return()
93+
find_package(ZLIB)
94+
if(NOT ZLIB_FOUND)
95+
message(STATUS "ZLib is required to build OpenEXR.")
96+
return()
97+
endif()
9398
endif()
94-
99+
95100
find_package(Threads)
96101
if(NOT Threads_FOUND)
97102
message(STATUS "Threads is required to build OpenEXR.")

0 commit comments

Comments
 (0)