OpenColorIO icon indicating copy to clipboard operation
OpenColorIO copied to clipboard

Build external dependencies with FetchContent

Open remia opened this issue 3 years ago • 1 comments

When we are missing external dependencies and OCIO_INSTALL_EXT_PACKAGES has been set to MISSING or ALL , we use CMake ExternalProject to build these locally. This works but tends to be hard to manage correctly with modern CMake library that can export a number of targets as well as custom commands and probably other items. We also have a lot of manual CMake flags passing from the main project to the external ones, that are easy to miss.

An example of this would be OpenEXR which export more than 5 different targets we have to manually create, at the risk of getting out of sync when something changes upstream. Another case is pybind11 which export custom commands like pybind11_add_module which we cannot currently use in the build because it will not be there when pybind11 has been built locally I believe.

For well behaved modern CMake dependencies, it may be good to look into FetchContent instead, which behave similar to add_subdirectory and make the integration easier.

remia avatar May 04 '22 08:05 remia

Unless I'm doing something wrong, I'm running into an issue with OCIO which would probably be resolved by implementing this.

Issue is that I have a project with essentially does something like

FetchContent_Declare(Imath ... )
FetchContent_Declare(ZLib ... )
FetchContent_Declare(OpenColorIO ... )

FetchContent_MakeAvailable(Imath ZLib)
FetchContent_MakeAvailable(OpenColorIO)

OpenColorIO (or I think more specifically CMake/ExternalProject) is unable to detect that Imath and ZLib already exist as targets, and so either fails to configure or redownloads and builds them depending on OCIO_INSTALL_EXT_PACKAGES. There's probably a way to solve this without switching to FetchContent in OpenColorIO, but I think implementing FetchContent would probably be a better, cleaner solution.

SRHMorris avatar Jul 23 '25 10:07 SRHMorris