From 4929455ab4675aa38f277bfa610c9c758fd5366f Mon Sep 17 00:00:00 2001 From: Zach Lewis Date: Tue, 15 Oct 2024 10:30:56 -0400 Subject: [PATCH] build: Add IGNORE_HOMEBREWED_DEPS CMake option When `-DIGNORE_HOMEBREWED_DEPS=ON` is provided, ignore libraries that live under the following paths: - /opt/homebrew - /usr/local - /usr/X11 - /usr/X11R6 Also, builds invoked with `build_dependency_with_cmake` will now inherit CMAKE_IGNORE_PATH and CMAKE_IGNORE_PREFIX_PATH values set in a higher-level scope. This prevents dependencies from finding sub-dependencies where it shouldn't. For example, if we're ignoring homebrewed dependencies, even though brew-installed PNG and brew-installed freetype may be ignored when first trying to find the dependencies, we need to make sure that when we build freetype locally, we take care _not_ to link brew-installed PNG. Signed-off-by: Zach Lewis --- .github/workflows/wheel.yml | 12 +++++++----- CMakeLists.txt | 12 ++++++++++++ INSTALL.md | 27 ++++++++++++++------------- Makefile | 4 ++++ src/cmake/dependency_utils.cmake | 8 ++++++++ 5 files changed, 45 insertions(+), 18 deletions(-) diff --git a/.github/workflows/wheel.yml b/.github/workflows/wheel.yml index 732e3cf105..130852ed03 100644 --- a/.github/workflows/wheel.yml +++ b/.github/workflows/wheel.yml @@ -282,7 +282,8 @@ jobs: SKBUILD_CMAKE_ARGS: | -DOpenImageIO_BUILD_LOCAL_DEPS=TIFF; -DOpenImageIO_BUILD_MISSING_DEPS=all; - -DCMAKE_IGNORE_PREFIX_PATH=/opt/homebrew + -DIGNORE_HOMEBREWED_DEPS=ON; + -DLINKSTATIC=ON - uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0 with: @@ -341,10 +342,11 @@ jobs: CIBW_BUILD: ${{ matrix.python }} CIBW_ARCHS: ${{ matrix.arch }} # Ignore dependencies installed by homebrew (e.g. freetype) - SKBUILD_CMAKE_ARGS: | - -DOpenImageIO_BUILD_LOCAL_DEPS=TIFF; - -DOpenImageIO_BUILD_MISSING_DEPS=all; - -DCMAKE_IGNORE_PREFIX_PATH=/opt/homebrew + CMAKE_ARGS: | + -DOpenImageIO_BUILD_LOCAL_DEPS=TIFF + -DOpenImageIO_BUILD_MISSING_DEPS=all + -DIGNORE_HOMEBREWED_DEPS=ON + -DLINKSTATIC=ON #TODO: Re-enable the PNG plugin until we can figure out why the system PNG is causing problems ENABLE_PNG: 'OFF' diff --git a/CMakeLists.txt b/CMakeLists.txt index a720988a36..6aad5dbd8e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -122,6 +122,18 @@ option (EMBEDPLUGINS "Embed format plugins in libOpenImageIO" ON) set (PLUGIN_SEARCH_PATH "" CACHE STRING "Default plugin search path") file (TO_NATIVE_PATH "${PLUGIN_SEARCH_PATH}" PLUGIN_SEARCH_PATH_NATIVE) set (CMAKE_DEBUG_POSTFIX "_d" CACHE STRING "Library naming postfix for Debug builds") +option (IGNORE_HOMEBREWED_DEPS "If ON, will ignore homebrew-installed dependencies" OFF) + +# Ignore prefixes for dependencies managed by homebrew on macOS +# https://gitlab.kitware.com/cmake/cmake/-/issues/21918#note_920016 +if (IGNORE_HOMEBREWED_DEPS) + set (CMAKE_IGNORE_PATH) + foreach (_prefix /opt/homebrew /usr/local /usr/X11 /usr/X11R6) + list (APPEND CMAKE_IGNORE_PATH ${_prefix}/lib ${_prefix}/bin ${_prefix}/include) + endforeach () + message (STATUS "Ignoring homebrewed dependencies.") +endif () + if (CMAKE_UNITY_BUILD_BATCH_SIZE) set (UNITY_SMALL_BATCH_SIZE "${CMAKE_UNITY_BUILD_BATCH_SIZE}" CACHE STRING "Unity batch mode size for expensive files") diff --git a/INSTALL.md b/INSTALL.md index fa1168bd4d..07fddf1cfe 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -230,19 +230,20 @@ Make targets you should know about: Additionally, a few helpful modifiers alter some build-time options: -| Target | Command | -| ------------------------- | ---------------------------------------------- | -| make VERBOSE=1 ... | Show all compilation commands | -| make STOP_ON_WARNING=0 | Do not stop building if compiler warns | -| make EMBEDPLUGINS=0 ... | Don't compile the plugins into libOpenImageIO | -| make USE_OPENGL=0 ... | Skip anything that needs OpenGL | -| make USE_QT=0 ... | Skip anything that needs Qt | -| make MYCC=xx MYCXX=yy ... | Use custom compilers | -| make USE_PYTHON=0 ... | Don't build the Python binding | -| make BUILD_SHARED_LIBS=0 | Build static library instead of shared | -| make LINKSTATIC=1 ... | Link with static external libraries when possible | -| make SOVERSION=nn ... | Include the specified major version number in the shared object metadata | -| make NAMESPACE=name | Wrap everything in another namespace | +| Target | Command | +| ----------------------------- | ------------------------------------------------------------------------- | +| make VERBOSE=1 ... | Show all compilation commands | +| make STOP_ON_WARNING=0 | Do not stop building if compiler warns | +| make EMBEDPLUGINS=0 ... | Don't compile the plugins into libOpenImageIO | +| make USE_OPENGL=0 ... | Skip anything that needs OpenGL | +| make USE_QT=0 ... | Skip anything that needs Qt | +| make MYCC=xx MYCXX=yy ... | Use custom compilers | +| make USE_PYTHON=0 ... | Don't build the Python binding | +| make BUILD_SHARED_LIBS=0 | Build static library instead of shared | +| make IGNORE_HOMEBREWED_DEPS=1 | Ignore homebrew-managed dependencies | +| make LINKSTATIC=1 ... | Link with static external libraries when possible | +| make SOVERSION=nn ... | Include the specified major version number in the shared object metadata | +| make NAMESPACE=name | Wrap everything in another namespace | The command 'make help' will list all possible options. diff --git a/Makefile b/Makefile index dea67f0b8d..82ac9b35f0 100644 --- a/Makefile +++ b/Makefile @@ -206,6 +206,9 @@ ifneq (${BUILD_MISSING_DEPS},) MY_CMAKE_FLAGS += -DBUILD_MISSING_DEPS:BOOL=${BUILD_MISSING_DEPS} endif +ifneq ($(IGNORE_HOMEBREWED_DEPS),) + MY_CMAKE_FLAGS += -DIGNORE_HOMEBREWED_DEPS:BOOL=${IGNORE_HOMEBREWED_DEPS} +endif #$(info MY_CMAKE_FLAGS = ${MY_CMAKE_FLAGS}) #$(info MY_MAKE_FLAGS = ${MY_MAKE_FLAGS}) @@ -383,6 +386,7 @@ help: @echo " USE_NUKE=0 Don't build Nuke plugins" @echo " Nuke_ROOT=path Custom Nuke installation" @echo " NUKE_VERSION=ver Custom Nuke version" + @echo " IGNORE_HOMEBREWED_DEPS=1 Don't use dependencies installed by Homebrew" @echo " OIIO build-time options:" @echo " INSTALL_PREFIX=path Set installation prefix (default: ./${INSTALL_PREFIX})" @echo " NAMESPACE=name Override namespace base name (default: OpenImageIO)" diff --git a/src/cmake/dependency_utils.cmake b/src/cmake/dependency_utils.cmake index 99504819db..08d66ca3f4 100644 --- a/src/cmake/dependency_utils.cmake +++ b/src/cmake/dependency_utils.cmake @@ -546,6 +546,14 @@ macro (build_dependency_with_cmake pkgname) ) endif () + # Make sure to inherit the CMAKE_IGNORE_PATH and CMAKE_IGNORE_PREFIX_PATHs + if (CMAKE_IGNORE_PATH) + list (APPEND _pkg_CMAKE_ARGS -DCMAKE_IGNORE_PATH=${CMAKE_IGNORE_PATH}) + endif () + if (CMAKE_IGNORE_PREFIX_PATH) + list (APPEND _pkg_CMAKE_ARGS -DCMAKE_IGNORE_PREFIX_PATH=${CMAKE_IGNORE_PREFIX_PATH}) + endif () + execute_process (COMMAND ${CMAKE_COMMAND} # Put things in our special local build areas