diff --git a/CMakeLists.txt b/CMakeLists.txt index 9f3fa518f0..932874f81c 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,6 +12,7 @@ set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/share/cmake/utils ${CMAKE_SOURCE_DIR}/share/cmake/macros ${CMAKE_SOURCE_DIR}/share/cmake/modules + ${CMAKE_SOURCE_DIR}/share/cmake/modules/install ) set(CMAKE_WARN_DEPRECATED ON) @@ -156,6 +157,9 @@ if (WIN32) option(OCIO_USE_WINDOWS_UNICODE "Compile with Windows Unicode support" ON) endif() +############################################################################### +# Other preferences +option(OCIO_VERBOSE "Display more information when searching or installing dependencies" OFF) ############################################################################### # Warnings / debugging settings @@ -171,13 +175,13 @@ endif() # Optimization / internal linking preferences option(OCIO_USE_SSE "Specify whether to enable SSE CPU performance optimizations" ON) -option(OCIO_USE_OIIO_CMAKE_CONFIG "Specify whether to look for OIIO using the generated CMake Config script instead of the custom FindOpenImageIO.cmake script" OFF) option(OCIO_USE_OIIO_FOR_APPS "Request OIIO to build apps (ociolutimage, ocioconvert and ociodisplay), the default uses OpenEXR." OFF) ############################################################################### # GPU configuration - +message(STATUS "") +message(STATUS "Checking for GPU configuration...") include(CheckSupportGL) diff --git a/docs/quick_start/installation.rst b/docs/quick_start/installation.rst index 600fa89e12..788ae7e16b 100644 --- a/docs/quick_start/installation.rst +++ b/docs/quick_start/installation.rst @@ -187,10 +187,26 @@ Three ``OCIO_INSTALL_EXT_PACKAGES`` options are available:: Existing Install Hints ++++++++++++++++++++++ -When using libraries already on your system, the CMake variable -``-D _ROOT=`` may be used to specify the path to the include and -library root directory rather than have CMake try to find it. The package names used -by OCIO are as follows (note that these are case-sensitive): +If the library is not installed in a typical location where CMake will find it, +you may specify the location using one of the following methods: + +- Set ``-D_DIR`` to point to the directory containing the CMake configuration file for the package. + +- Set ``-D_ROOT`` to point to the directory containing the lib and include directories. + +- Set ``-D_LIBRARY`` and ``-D_INCLUDE_DIR`` to point to the lib and include directories. + +Not all packages support all of the above options. Please refer the +OCIO CMake `find modules `_ for the package that you are having trouble with to see the options it supports. + +Usually CMake will use the dynamic library rather than static, if both are present. In this case, +you may set _STATIC_LIBRARY to ON to request use of the static one. If only the +static library is present (such as when OCIO builds the dependency), then the option is not needed. +The following packages support this option: +``expat``, ``yaml-cpp``, ``Imath``, ``lcms2``, and ``minizip-ng``. Using CMake 3.24+, it is +possible to prefer the static version of ``ZLIB`` with ``-DZLIB_USE_STATIC_LIBS=ON``. + +The package names used by OCIO are as follows (note that these are case-sensitive): Required: @@ -214,21 +230,6 @@ Optional: - ``GLUT`` - ``Python`` -There are scenarios in which some of the dependencies may not be compiled into an -OCIO dynamic library. This is more likely when OCIO does not download the packages -itself. In these cases, it may be helpful to additionally specify the CMake variable -``-D _STATIC_LIBRARY=ON``. The following package names support this hint: -``expat``, ``yaml-cpp``, ``Imath``, ``lcms2``, ``ZLIB``, and ``minizip-ng``. - -Rather than using ``_ROOT``, and possibly ``_STATIC_LIBRARY``, you may instead use -``-D _LIBRARY=`` and ``-D _INCLUDE_DIR=``. -In this case, the library path will control whether a static or dynamic library is used. -It may also be used to handle situations where the library and/or include files are not -in the typical location relative to the root directory. - -The OCIO `CMake find modules `_ -may be consulted for more detail on the handling of a given package and the CMake -variables it uses. Please note that if you provide your own ``minizip-ng``, rather than having OCIO's CMake download and build it, you will likely need to set its CMake variables the same way @@ -384,7 +385,7 @@ Windows While build environments may vary between users, the recommended way to build OCIO from source on Windows 7 or newer is to use the scripts provided in the Windows `share `_ -section of the OCIO repository. There are two scripts currently available. +section of the OCIO repository. There are two scripts currently available. The first script is called `ocio_deps.bat `_ @@ -396,14 +397,18 @@ and it provides some automation to install the most difficult dependencies. Thos - Glew - Python dependencies for documentation -Run this command to execute the ocio_deps.bat script:: +Run this command to execute the ocio_deps.bat script: +.. code-block:: bash + ocio_deps.bat --vcpkg The second script is called `ocio.bat `_ and it provide a way to configure and build OCIO from source. Moreover, this script executes the -install step of ``cmake`` as well as the unit tests. The main use case is the following:: +install step of ``cmake`` as well as the unit tests. The main use case is the following: + +.. code-block:: bash ocio.bat --b --i --vcpkg --ocio --type Release @@ -422,14 +427,26 @@ Quick environment configuration The quickest way to set the required :ref:`environment-setup` is to source the ``share/ocio/setup_ocio.sh`` script installed with OCIO. -On Windows, use the corresponding setup_ocio.bat file. +On Windows, use the corresponding setup_ocio.bat file. See OCIO's install directory under +share/ocio. + +For a temporary configuration of your terminal, you can run the following script: + +.. code-block:: bash + + # Windows - Execute setup_ocio.bat + [... path to OCIO install directory]/share/ocio/setup_ocio.bat + # Unix - Execute setup_ocio.sh + [... path to OCIO install directory]\share\ocio\setup_ocio.sh -For a simple single-user setup, add the following to ``~/.bashrc`` +For a more permanent option, add the following to ``~/.bashrc`` (assuming you are using bash, and the example install directory of -``/software/ocio``):: +``/software/ocio``): - source /software/ocio/share/ocio/setup_ocio.sh +.. code-block:: bash + source /software/ocio/share/ocio/setup_ocio.sh + The only environment variable you must configure manually is :envvar:`OCIO`, which points to the configuration file you wish to use. For prebuilt config files, see the diff --git a/share/cmake/macros/VersionUtils.cmake b/share/cmake/macros/VersionUtils.cmake index 9349c5da56..0283774e4c 100644 --- a/share/cmake/macros/VersionUtils.cmake +++ b/share/cmake/macros/VersionUtils.cmake @@ -6,8 +6,19 @@ macro(split_version_string version_var output_prefix) string(REPLACE "." ";" _version_var_list ${version_var}) - list(GET _version_var_list 0 ${output_prefix}_VERSION_MAJOR) - list(GET _version_var_list 1 ${output_prefix}_VERSION_MINOR) - list(GET _version_var_list 2 ${output_prefix}_VERSION_PATCH) + list(LENGTH _version_var_list _version_var_list_length) + + if (_version_var_list_length GREATER_EQUAL 1) + list(GET _version_var_list 0 ${output_prefix}_VERSION_MAJOR) + endif() + + if (_version_var_list_length GREATER_EQUAL 2) + list(GET _version_var_list 1 ${output_prefix}_VERSION_MINOR) + endif() + + if (_version_var_list_length GREATER_EQUAL 3) + list(GET _version_var_list 2 ${output_prefix}_VERSION_PATCH) + endif() + unset(_version_var_list) endmacro() diff --git a/share/cmake/macros/ocio_check_dependency_version.cmake b/share/cmake/macros/ocio_check_dependency_version.cmake new file mode 100644 index 0000000000..2c2b741192 --- /dev/null +++ b/share/cmake/macros/ocio_check_dependency_version.cmake @@ -0,0 +1,38 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright Contributors to the OpenColorIO Project. + +################################################################################################### +# ocio_check_dependency_version try to find the specified dependency and validate the version. +# +# Note that a function is used here to scoped-in any variables set by find_package. We do not want +# those variables to be propagated to the caller of the function. +# +# Argument: +# dep_name is the name of the dependency (package). Please note that dep_name is case sensitive. +# +################################################################################################### + +function (ocio_check_dependency_version dep_name output) + cmake_parse_arguments( + # prefix - Must be different than the one used in ocio_handle_dependency.cmake. + ocio_cdv + # options + "" + # one value keywords + "MIN_VERSION" + # multi value keywords + "" + # args + ${ARGN}) + + if (dep_name) + find_package(${dep_name} ${ocio_cdv_UNPARSED_ARGUMENTS}) + if (ocio_cdv_MIN_VERSION AND ${dep_name}_VERSION) + if (${${dep_name}_VERSION} VERSION_GREATER_EQUAL ocio_cdv_MIN_VERSION) + set(${output} TRUE) + else() + set(${output} FALSE) + endif() + endif() + endif() +endfunction() \ No newline at end of file diff --git a/share/cmake/macros/ocio_handle_dependency.cmake b/share/cmake/macros/ocio_handle_dependency.cmake new file mode 100644 index 0000000000..f7bb593561 --- /dev/null +++ b/share/cmake/macros/ocio_handle_dependency.cmake @@ -0,0 +1,234 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright Contributors to the OpenColorIO Project. + +include(ocio_install_dependency) + +################################################################################################### +# ocio_print_versions_error is a wrapper for messages when the dependency is not found. +# +# Arguments: +# dep_name is the name of the dependency (package). Please note that dep_name is case sensitive. +# message_color is the color of the message. +# +# Note that this macro is used in ocio_handle_dependency and should be there only. +################################################################################################### +macro (ocio_print_versions_error dep_name message_color) + if(NOT ocio_dep_MIN_VERSION AND NOT ocio_dep_MAX_VERSION AND NOT ocio_dep_RECOMMENDED_VERSION) + message(STATUS "${message_color}Could NOT find ${dep_name} (no version specified)${ColorReset}") + elseif(NOT ocio_dep_MIN_VERSION AND NOT ocio_dep_RECOMMENDED_VERSION) + message(STATUS "${message_color}Could NOT find ${dep_name} (maximum version: \"${ocio_dep_MAX_VERSION)\"${ColorReset}") + elseif(NOT ocio_dep_MIN_VERSION AND NOT ocio_dep_MAX_VERSION) + message(STATUS "${message_color}Could NOT find ${dep_name} (recommended version: \"${ocio_dep_RECOMMENDED_VERSION}\")\"${ColorReset}") + elseif(NOT ocio_dep_RECOMMENDED_VERSION AND NOT ocio_dep_MAX_VERSION) + message(STATUS "${message_color}Could NOT find ${dep_name} (minimum version: \"${ocio_dep_MIN_VERSION})\"${ColorReset}") + elseif(NOT ocio_dep_MIN_VERSION) + message(STATUS "${message_color}Could NOT find ${dep_name} (recommended version: \"${ocio_dep_RECOMMENDED_VERSION}\", maximum version: \"${ocio_dep_MAX_VERSION}\")${ColorReset}") + elseif(NOT ocio_dep_RECOMMENDED_VERSION) + message(STATUS "${message_color}Could NOT find ${dep_name} (minimum version: \"${ocio_dep_MIN_VERSION}\", maximum version: \"${ocio_dep_MAX_VERSION}\")${ColorReset}") + elseif(NOT ocio_dep_MAX_VERSION) + message(STATUS "${message_color}Could NOT find ${dep_name} (minimum version: \"${ocio_dep_MIN_VERSION}\", recommended version: \"${ocio_dep_RECOMMENDED_VERSION}\")${ColorReset}") + else() + message(STATUS "${message_color}Could NOT find ${dep_name} (minimum version: \"${ocio_dep_MIN_VERSION}\", recommended version: \"${ocio_dep_RECOMMENDED_VERSION}\", max: \"${ocio_dep_MAX_VERSION}\")${ColorReset}") + endif() +endmacro() + +# Using a macro because OCIO wants the scope to be the same as the caller scope. +# Find modules will set variables via the PARENT_SCOPE option and OCIO needs those +# variables in the caller scope. + +################################################################################################### +# ocio_handle_dependency is a wrapper for find_package with extra options (features). +# +# Argument: +# dep_name is the name of the dependency (package). Please note that dep_name is case sensitive. +# +# Options (no value): +# REQUIRED - Whether the dependency is required or not. Fails if missing. +# PREFER_CONFIG - Call find_package in CONFIG mode internally. +# Note that it tries to find Config.cmake or +# -Config.cmake directly. +# ALLOW_INSTALL - Try to install the dependency if not found. Note that a +# corresponding Install.cmake file must exist. +# VERBOSE - Enable extra logging. +# +# Options (one value): +# MIN_VERSION - Minimum version for the dependency. +# MAX_VERSION - Maximum version for the dependency. +# RECOMMENDED_VERSION - Recommended version for the dependency. +# RECOMMENDED_VERSION_REASON - Reason for the recommended version. +# +# Options (multiple values): +# VERSION_VARS - List of version variables. Default to _VERSION. +# COMPONENTS - List of components to find. Just like find_package option. +# PROMOTE_TARGET - List of targets that needs to be globally visible by setting +# the targets property IMPORTED_GLOBAL to true. Note that the +# targets must be created by the dependency. +# +# This is a macro because OCIO wants the scope to be the same as the caller scope. +# Find modules will set variables via the PARENT_SCOPE option and OCIO needs those +# variables in the caller scope. +# +################################################################################################### + +macro (ocio_handle_dependency dep_name) + cmake_parse_arguments( + # prefix + ocio_dep + # options + "REQUIRED;PREFER_CONFIG;ALLOW_INSTALL;VERBOSE" + # one value keywords + "MIN_VERSION;MAX_VERSION;RECOMMENDED_VERSION;RECOMMENDED_VERSION_REASON;PROMOTE_TARGET" + # multi value keywords + "VERSION_VARS;COMPONENTS" + # args + ${ARGN}) + + set(ocio_dep_FORCE_INSTALLATION OFF) + if(ocio_dep_ALLOW_INSTALL AND OCIO_INSTALL_EXT_PACKAGES STREQUAL ALL) + set(ocio_dep_FORCE_INSTALLATION ON) + endif() + + if(NOT ocio_dep_FORCE_INSTALLATION) + set(ocio_dep_QUIET_string "") + # Do not set to QUIET when OCIO_VERBOSE is ON. + if(NOT ocio_dep_VERBOSE AND NOT OCIO_VERBOSE) + set(${dep_name}_FIND_QUIETLY true) + set(ocio_dep_QUIET_string "QUIET") + endif() + + set(ocio_dep_CONFIG_string "") + if(ocio_dep_PREFER_CONFIG) + set(ocio_dep_CONFIG_string "CONFIG") + endif() + + set(ocio_dep_COMPONENTS_string "") + if(ocio_dep_COMPONENTS) + set(ocio_dep_COMPONENTS_string "COMPONENTS") + endif() + + if (${dep_name}_FOUND) + # Nothing to do. Already found. + else() + # Try to find the recommended, or higher, version. + # Note that the recommended version should always be specified. + find_package(${dep_name} + ${ocio_dep_RECOMMENDED_VERSION} + ${ocio_dep_CONFIG_string} + ${ocio_dep_COMPONENTS_string} + ${ocio_dep_COMPONENTS} + ${ocio_dep_QUIET_string} + ${ocio_dep_UNPARSED_ARGUMENTS}) + + if (NOT ${dep_name}_FOUND AND ocio_dep_PREFER_CONFIG) + # Try find_package in module mode instead of config mode. + find_package(${dep_name} + ${ocio_dep_RECOMMENDED_VERSION} + ${ocio_dep_COMPONENTS_string} + ${ocio_dep_COMPONENTS} + ${ocio_dep_QUIET_string} + ${ocio_dep_UNPARSED_ARGUMENTS}) + endif() + + if(NOT ${dep_name}_FOUND AND ocio_dep_MIN_VERSION + AND NOT ocio_dep_MIN_VERSION VERSION_EQUAL ocio_dep_MAX_VERSION + AND NOT ocio_dep_MIN_VERSION VERSION_EQUAL ocio_dep_RECOMMENDED_VERSION) + + # if the recommended, or higher, version is not found, try to find dependency with + # the minimum version. + find_package(${dep_name} + ${ocio_dep_MIN_VERSION} + ${ocio_dep_CONFIG_string} + ${ocio_dep_COMPONENTS_string} + ${ocio_dep_COMPONENTS} + ${ocio_dep_QUIET_string} + ${ocio_dep_UNPARSED_ARGUMENTS}) + if (NOT ${dep_name}_FOUND AND ocio_dep_PREFER_CONFIG) + # Try find_package in module mode instead of config mode. + find_package(${dep_name} + ${ocio_dep_MIN_VERSION} + ${ocio_dep_COMPONENTS_string} + ${ocio_dep_COMPONENTS} + ${ocio_dep_QUIET_string} + ${ocio_dep_UNPARSED_ARGUMENTS}) + endif() + endif() + endif() + + # Check which VERSION_VARS was set by find_package. + set(_VERSION_VAR "${dep_name}_VERSION") + foreach (_vervar ${ocio_dep_VERSION_VARS}) + if(${_vervar}) + set(_VERSION_VAR ${_vervar}) + break() + endif() + endforeach() + + if(_VERSION_VAR) + set(ocio_dep_VERSION ${${_VERSION_VAR}}) + endif() + + # Expecting that the minimum and recommended version are always provided. + # Make sure that the version is within the valid range. + if(${dep_name}_FOUND) + if (ocio_dep_VERSION) + # Make sure that the version found is not greater than the maximum version. + if(DEFINED ocio_dep_MAX_VERSION) + if(ocio_dep_VERSION VERSION_GREATER ocio_dep_MAX_VERSION) + # Display it as an error, but do not abort right now. + message(SEND_ERROR "${ColorError}Found ${dep_name} ${ocio_dep_VERSION}, but it is over the maximum version \"${ocio_dep_MAX_VERSION}\" ${ColorReset}") + set(_${dep_name}_found_displayed true) + endif() + endif() + + if(DEFINED ocio_dep_RECOMMENDED_VERSION) + if (ocio_dep_VERSION VERSION_LESS ocio_dep_RECOMMENDED_VERSION) + message(STATUS "${ColorSuccess}Found ${dep_name} (version \"${ocio_dep_VERSION}\") (recommended version: \"${ocio_dep_RECOMMENDED_VERSION}\")${ColorReset}") + if (ocio_dep_RECOMMENDED_VERSION_REASON) + message(STATUS " Reason: ${ocio_dep_RECOMMENDED_VERSION_REASON}") + endif() + set(_${dep_name}_found_displayed true) + endif() + endif() + + if(NOT _${dep_name}_found_displayed) + message(STATUS "${ColorSuccess}Found ${dep_name} (version \"${ocio_dep_VERSION}\")${ColorReset}") + endif() + else() + message(STATUS "${ColorSuccess}Found ${dep_name} (no version information)${ColorReset}") + endif() + else() + if(ocio_dep_REQUIRED AND NOT ocio_dep_ALLOW_INSTALL) + set(message_color "${ColorError}") + else() + set(message_color "${ColorReset}") + endif() + + ocio_print_versions_error(${dep_name} ${message_color}) + + if(${dep_name}_ROOT) + message(STATUS "${message_color} ${dep_name}_ROOT was: ${${dep_name}_ROOT} ${ColorReset}") + elseif($ENV{${dep_name}_ROOT}) + message(STATUS "${message_color} ENV ${dep_name}_ROOT was: ${${dep_name}_ROOT} ${ColorReset}") + endif() + + if(ocio_dep_ALLOW_INSTALL) + ocio_install_dependency(${dep_name} VERSION ${ocio_dep_RECOMMENDED_VERSION}) + endif() + + if(ocio_dep_REQUIRED) + if(NOT ${dep_name}_FOUND AND NOT ocio_dep_VERSION) + message(SEND_ERROR "${ColorError}${dep_name} is required, will abort at the end.${ColorReset}") + endif() + endif() + endif() + elseif(ocio_dep_FORCE_INSTALLATION) + # Skip the search and install dependency right away. + ocio_install_dependency(${dep_name} VERSION ${ocio_dep_RECOMMENDED_VERSION}) + endif() + + if(${dep_name}_FOUND AND ocio_dep_PROMOTE_TARGET) + foreach (_target_to_be_promoted_ ${ocio_dep_PROMOTE_TARGET}) + set_target_properties(${_target_to_be_promoted_} PROPERTIES IMPORTED_GLOBAL TRUE) + endforeach() + endif() +endmacro() \ No newline at end of file diff --git a/share/cmake/macros/ocio_install_dependency.cmake b/share/cmake/macros/ocio_install_dependency.cmake new file mode 100644 index 0000000000..f5b6a4e893 --- /dev/null +++ b/share/cmake/macros/ocio_install_dependency.cmake @@ -0,0 +1,46 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright Contributors to the OpenColorIO Project. + +################################################################################################### +# ocio_install_dependency installs a dependency by calling the corresponding Install module. +# e.g. Install.cmake +# +# Argument: +# dep_name is the name of the dependency (package). Please note that dep_name is case sensitive. +# +# Options (one value): +# VERSION - Version to install. +################################################################################################### +macro (ocio_install_dependency dep_name) + cmake_parse_arguments( + # prefix - Must be different than the one used in ocio_handle_dependency.cmake. + ocio_id + # options + "" + # one value keywords + "VERSION;PROMOTE_TARGET" + # multi value keywords + "" + # args + ${ARGN}) + + + if(NOT ${dep_name}_FOUND AND OCIO_INSTALL_EXT_PACKAGES AND NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL NONE) + set(OCIO_${dep_name}_RECOMMENDED_VERSION ${ocio_id_VERSION}) + include(Install${dep_name}) + set(_${dep_name}_built_by_ocio TRUE) + endif() + + if(${dep_name}_FOUND) + if(${dep_name}_FOUND AND ocio_id_PROMOTE_TARGET) + foreach (_target_to_be_promoted_ ${ocio_id_PROMOTE_TARGET}) + set_target_properties(${_target_to_be_promoted_} PROPERTIES IMPORTED_GLOBAL TRUE) + endforeach() + endif() + + if (${_${dep_name}_built_by_ocio}) + message(STATUS "${ColorSuccess}Installed ${dep_name} (version \"${ocio_id_VERSION}\")${ColorReset}") + endif() + endif() + unset(_${dep_name}_built_by_ocio) +endmacro() \ No newline at end of file diff --git a/share/cmake/modules/FindExtPackages.cmake b/share/cmake/modules/FindExtPackages.cmake index 25cfacb497..870b039bfc 100644 --- a/share/cmake/modules/FindExtPackages.cmake +++ b/share/cmake/modules/FindExtPackages.cmake @@ -6,6 +6,9 @@ # by the OCIO_INSTALL_EXT_PACKAGES option. # +include(Colors) +include(ocio_handle_dependency) + ############################################################################### ### Global package options ### @@ -32,116 +35,95 @@ if (APPLE) set(CMAKE_FIND_APPBUNDLE LAST) endif() + +message(STATUS "") +message(STATUS "Missing a dependency? Try the following possibilities:") +message(STATUS "If the package provides CMake's configuration file, use -D_DIR=.") +message(STATUS "If it doesn't provide it, try -D_ROOT=.") +message(STATUS "Alternatively, try -D_LIBRARY= and/or -D_INCLUDE_DIR=.") +message(STATUS "") +message(STATUS "Please refer to the find module under share/cmake/modules for extra information.") + ############################################################################### -### Packages and versions ### +## +## Required dependencies +## +############################################################################### +message(STATUS "") +message(STATUS "Checking for mandatory dependencies...") # expat # https://github.com/libexpat/libexpat -find_package(expat 2.4.1 REQUIRED) +ocio_handle_dependency( expat REQUIRED ALLOW_INSTALL + MIN_VERSION 2.4.1 + RECOMMENDED_VERSION 2.5.0 + RECOMMENDED_VERSION_REASON "CVE fixes and fix issue with symbol leakage when built as a static library") # yaml-cpp # https://github.com/jbeder/yaml-cpp -find_package(yaml-cpp 0.7.0 REQUIRED) +ocio_handle_dependency( yaml-cpp REQUIRED ALLOW_INSTALL + MIN_VERSION 0.6.3 + RECOMMENDED_VERSION 0.7.0 + RECOMMENDED_VERSION_REASON "Latest version tested with OCIO") # pystring # https://github.com/imageworks/pystring -find_package(pystring 1.1.3 REQUIRED) +ocio_handle_dependency( pystring REQUIRED ALLOW_INSTALL + MIN_VERSION 1.1.3 + RECOMMENDED_VERSION 1.1.3 + RECOMMENDED_VERSION_REASON "Latest version tested with OCIO") # Imath (>=3.1) # https://github.com/AcademySoftwareFoundation/Imath -set(_Imath_ExternalProject_VERSION "3.1.6") -find_package(Imath 3.0 REQUIRED) +ocio_handle_dependency( Imath REQUIRED ALLOW_INSTALL + MIN_VERSION 3.1.1 + RECOMMENDED_VERSION 3.1.6 + RECOMMENDED_VERSION_REASON "Latest version tested with OCIO") ############################################################################### -### ZLIB (https://github.com/madler/zlib) -### -### The following variables can be set: -### ZLIB_ROOT Location of ZLIB library file and includes folder. -### Alternatively, ZLIB_LIBRARY and ZLIB_INCLUDE_DIR can be used. -### -### ZLIB_LIBRARY Location of ZLIB library file. -### ZLIB_INCLUDE_DIR Location of ZLIB includes folder. -### -### ZLIB_VERSION ZLIB Version (CMake 3.26+) -### ZLIB_VERSION_STRING ZLIB Version (CMake < 3.26) -### +# ZLIB (https://github.com/madler/zlib) +# +# The following variables can be set: +# ZLIB_ROOT Location of ZLIB library file and includes folder. +# Alternatively, ZLIB_LIBRARY and ZLIB_INCLUDE_DIR can be used. +# +# ZLIB_LIBRARY Location of ZLIB library file. +# ZLIB_INCLUDE_DIR Location of ZLIB includes folder. +# +# ZLIB_VERSION ZLIB Version (CMake 3.26+) +# ZLIB_VERSION_STRING ZLIB Version (CMake < 3.26) +# +# +# ZLIB_USE_STATIC_LIBS Set to ON if static library is prefered (CMake 3.24+) +# ############################################################################### # ZLIB 1.2.13 is used since it fixes a critical vulnerability. # See https://nvd.nist.gov/vuln/detail/CVE-2022-37434 # See https://github.com/madler/zlib/releases/tag/v1.2.13 -set(_ZLIB_FIND_VERSION "1.2.13") -set(_ZLIB_ExternalProject_VERSION ${_ZLIB_FIND_VERSION}) - -if(NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL ALL) - # ZLIB_USE_STATIC_LIBS is supported only from CMake 3.24+. - if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.24.0") - if (ZLIB_STATIC_LIBRARY) - set(ZLIB_USE_STATIC_LIBS "${ZLIB_STATIC_LIBRARY}") - endif() - else() # For CMake < 3.24 since ZLIB_USE_STATIC_LIBS is not available. - if(NOT ZLIB_LIBRARY) - if(DEFINED CMAKE_FIND_LIBRARY_PREFIXES) - set(_ZLIB_ORIG_CMAKE_FIND_LIBRARY_PREFIXES "${CMAKE_FIND_LIBRARY_PREFIXES}") - else() - set(_ZLIB_ORIG_CMAKE_FIND_LIBRARY_PREFIXES) - endif() - - if(DEFINED CMAKE_FIND_LIBRARY_SUFFIXES) - set(_ZLIB_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES "${CMAKE_FIND_LIBRARY_SUFFIXES}") - else() - set(_ZLIB_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES) - endif() - - # Prefix/suffix for windows. - if(WIN32) - list(APPEND CMAKE_FIND_LIBRARY_PREFIXES "" "lib") - list(APPEND CMAKE_FIND_LIBRARY_SUFFIXES ".dll.a") - endif() - - # Check if static lib is preferred. - if(ZLIB_STATIC_LIBRARY OR ZLIB_USE_STATIC_LIBS) - if(WIN32) - set(CMAKE_FIND_LIBRARY_SUFFIXES .lib .a ${CMAKE_FIND_LIBRARY_SUFFIXES}) - else() - set(CMAKE_FIND_LIBRARY_SUFFIXES .a) - endif() - endif() - endif() - endif() - - set(_ZLIB_REQUIRED REQUIRED) - # Override REQUIRED if package can be installed - if(OCIO_INSTALL_EXT_PACKAGES STREQUAL MISSING) - set(_ZLIB_REQUIRED "") - endif() - - find_package(ZLIB ${_ZLIB_FIND_VERSION} ${_ZLIB_REQUIRED}) - - # Restore the original find library ordering - if(DEFINED _ZLIB_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES) - set(CMAKE_FIND_LIBRARY_SUFFIXES "${_ZLIB_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES}") - else() - set(CMAKE_FIND_LIBRARY_SUFFIXES) - endif() +ocio_handle_dependency( ZLIB REQUIRED ALLOW_INSTALL + MIN_VERSION 1.2.10 + RECOMMENDED_VERSION 1.2.13 + RECOMMENDED_VERSION_REASON "CVE fixes" + VERSION_VARS ZLIB_VERSION_STRING ZLIB_VERSION ) - if(DEFINED _ZLIB_ORIG_CMAKE_FIND_LIBRARY_PREFIXES) - set(CMAKE_FIND_LIBRARY_PREFIXES "${_ZLIB_ORIG_CMAKE_FIND_LIBRARY_PREFIXES}") - else() - set(CMAKE_FIND_LIBRARY_PREFIXES) - endif() -endif() - -if(NOT ZLIB_FOUND AND OCIO_INSTALL_EXT_PACKAGES AND NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL NONE) - include(InstallZLIB) -endif() ############################################################################### # minizip-ng # https://github.com/zlib-ng/minizip-ng -find_package(minizip-ng 3.0.7 REQUIRED) +ocio_handle_dependency( minizip-ng REQUIRED ALLOW_INSTALL + MIN_VERSION 3.0.6 + RECOMMENDED_VERSION 3.0.7 + RECOMMENDED_VERSION_REASON "Latest version tested with OCIO") -if(OCIO_BUILD_APPS) +############################################################################### +## +## Optional dependencies +## +############################################################################### +message(STATUS "") +message(STATUS "Checking for optional dependencies...") +if(OCIO_BUILD_APPS) # NOTE: Depending of the compiler version lcms2 2.2 does not compile with # C++17 so, if you change the lcms2 version update the code to compile # lcms2 and dependencies with C++17 or higher i.e. remove the cap of C++ @@ -149,13 +131,19 @@ if(OCIO_BUILD_APPS) # lcms2 # https://github.com/mm2/Little-CMS - find_package(lcms2 2.2 REQUIRED) + ocio_handle_dependency( lcms2 REQUIRED ALLOW_INSTALL + MIN_VERSION 2.2 + RECOMMENDED_VERSION 2.2 + RECOMMENDED_VERSION_REASON "Latest version tested with OCIO") endif() if(OCIO_BUILD_OPENFX) # openfx # https://github.com/ofxa/openfx - find_package(openfx 1.4 REQUIRED) + ocio_handle_dependency( openfx REQUIRED ALLOW_INSTALL + MIN_VERSION 1.4 + RECOMMENDED_VERSION 1.4 + RECOMMENDED_VERSION_REASON "Latest version tested with OCIO") endif() if (OCIO_PYTHON_VERSION AND NOT OCIO_BUILD_PYTHON) @@ -177,44 +165,110 @@ if(OCIO_BUILD_PYTHON OR OCIO_BUILD_DOCS) list(APPEND _Python_COMPONENTS Development) endif() + # Python - find_package(Python ${OCIO_PYTHON_VERSION} REQUIRED - COMPONENTS ${_Python_COMPONENTS}) + ocio_handle_dependency( Python REQUIRED + COMPONENTS ${_Python_COMPONENTS} + MIN_VERSION ${OCIO_PYTHON_VERSION} + RECOMMENDED_VERSION ${OCIO_PYTHON_VERSION} + RECOMMENDED_VERSION_REASON "Latest version tested with OCIO") if(OCIO_BUILD_PYTHON) # pybind11 # https://github.com/pybind/pybind11 # pybind11 2.9 fixes issues with MS Visual Studio 2022 (Debug). - find_package(pybind11 2.9.2 REQUIRED) + ocio_handle_dependency( pybind11 REQUIRED ALLOW_INSTALL + MIN_VERSION 2.9.2 + RECOMMENDED_VERSION 2.9.2 + RECOMMENDED_VERSION_REASON "Pybind 2.10.0+ does not work with Python 2.7 anymore") endif() endif() +# Set OpenEXR Minimum version as a variable since it it used at multiple places. +set(OpenEXR_MININUM_VERSION "3.0.5") if((OCIO_BUILD_APPS AND OCIO_USE_OIIO_FOR_APPS) OR OCIO_BUILD_TESTS) # OpenImageIO is required for OSL unit test and optional for apps. # OpenImageIO # https://github.com/OpenImageIO/oiio set(OIIO_VERSION "2.2.14") - - if(OCIO_USE_OIIO_CMAKE_CONFIG) - # TODO: Try when OIIO 2.4 is released (https://github.com/OpenImageIO/oiio/pull/3322). - # set(OPENIMAGEIO_CONFIG_DO_NOT_FIND_IMATH 1) - find_package(OpenImageIO ${OIIO_VERSION} CONFIG) + set(OIIO_RECOMMENDED_VERSION "2.4") + + # Supported from OIIO 2.4+. Setting this for lower versions doesn't affect anything. + set(OPENIMAGEIO_CONFIG_DO_NOT_FIND_IMATH 1) + + include(ocio_check_dependency_version) + # Since OpenImageIO will try to find OpenEXR through its OpenImageIOConfig.cmake file, + # let's try to find OpenEXR first and if the version is too old, OCIO will not try to find + # OpenImageIO. + ocio_check_dependency_version( OpenEXR "is_OpenEXR_VERSION_valid" + MIN_VERSION ${OpenEXR_MININUM_VERSION} + CONFIG) + + # Do not try to find OpenImageIO if the version of OpenEXR is too old. + if (is_OpenEXR_VERSION_valid) + ############################################################################### + # OpenImageIO (https://github.com/OpenImageIO/oiio) + # + # Variables defined by OpenImageIO CMake's configuration files: + # OpenImageIO_FOUND - Indicate whether the library was found or not + # OpenImageIO_LIB_DIR - Library's directory + # OpenImageIO_INCLUDE_DIR - Location of the header files + # OpenImageIO_VERSION - Library's version + # + # Imported targets defined by this module, if found: + # OpenImageIO::OpenImageIO + # OpenImageIO::OpenImageIO_Util + # + ############################################################################### + # Calling find_package in CONFIG mode using PREFER_CONFIG option as OIIO support + # config file since 2.1+ and OCIO minimum version is over that. + ocio_handle_dependency( OpenImageIO PREFER_CONFIG + MIN_VERSION ${OIIO_VERSION} + RECOMMENDED_VERSION ${OIIO_RECOMMENDED_VERSION} + PROMOTE_TARGET OpenImageIO::OpenImageIO) else() - find_package(OpenImageIO ${OIIO_VERSION}) + message(WARNING "Skipping OpenImageIO because the OpenEXR found by OpenImageIO is too old (under ${OpenEXR_MININUM_VERSION})") endif() endif() if(OCIO_BUILD_APPS) if(OCIO_USE_OIIO_FOR_APPS AND OpenImageIO_FOUND AND TARGET OpenImageIO::OpenImageIO) + if (USE_MSVC AND OCIO_IMAGE_BACKEND STREQUAL "OpenImageIO") + # Temporary until fixed in OpenImageIO: Mute some warnings from OpenImageIO farmhash.h + # C4267 (level 3) 'var' : conversion from 'size_t' to 'type', possible loss of data + # C4244 (level 3 & 4) 'conversion' conversion from 'type1' to 'type2', possible loss of data + target_compile_options(OpenImageIO::OpenImageIO PRIVATE /wd4267 /wd4244) + endif() + add_library(OpenColorIO::ImageIOBackend ALIAS OpenImageIO::OpenImageIO) set(OCIO_IMAGE_BACKEND OpenImageIO) else() - # OpenEXR - # https://github.com/AcademySoftwareFoundation/openexr - set(_OpenEXR_ExternalProject_VERSION "3.1.5") - find_package(OpenEXR 3.0) + ############################################################################### + # OpenEXR (https://github.com/AcademySoftwareFoundation/openexr) + # + # Variables defined by OpenEXR CMake's configuration files: + # OpenEXR_FOUND - Indicate whether the library was found or not + # OpenEXR_VERSION - Library's version + # + # Imported targets defined by this module, if found: + # OpenEXR::Iex + # OpenEXR::IexConfig + # OpenEXR::IlmThread + # OpenEXR::IlmThreadConfig + # OpenEXR::OpenEXR + # OpenEXR::OpenEXRConfig + # OpenEXR::OpenEXRCore + # OpenEXR::OpenEXRUtil + # + ############################################################################### + # Calling find_package in CONFIG mode using PREFER_CONFIG option. + ocio_handle_dependency( OpenEXR PREFER_CONFIG ALLOW_INSTALL + MIN_VERSION ${OpenEXR_MININUM_VERSION} + RECOMMENDED_VERSION 3.1.5 + RECOMMENDED_VERSION_REASON "Latest version tested with OCIO" + PROMOTE_TARGET OpenEXR::OpenEXR) if(OpenEXR_FOUND AND TARGET OpenEXR::OpenEXR) add_library(OpenColorIO::ImageIOBackend ALIAS OpenEXR::OpenEXR) @@ -236,15 +290,18 @@ if(OCIO_BUILD_TESTS) if(TARGET Imath::Imath) # OpenShadingLanguage # https://github.com/AcademySoftwareFoundation/OpenShadingLanguage - find_package(OpenShadingLanguage 1.11) + ocio_handle_dependency( OSL + MIN_VERSION 1.11 + RECOMMENDED_VERSION 1.11 + RECOMMENDED_VERSION_REASON "Latest version tested with OCIO") if(NOT OSL_FOUND) - message(WARNING "Could NOT find OpenShadingLanguage. Skipping build of the OSL unit tests.") + message(WARNING "Skipping build of the OpenShadingLanguage unit tests (OSL missing)") endif() else() - message(WARNING "Could NOT find Imath. Skipping build of the OSL unit tests.") + message(WARNING "Skipping build of the OpenShadingLanguage unit tests (Imath missing)") endif() else() - message(WARNING "Could NOT find OpenImageIO. Skipping build of the OSL unit tests.") + message(WARNING "Skipping build of the OpenShadingLanguage unit tests (OpenImageIO missing)") endif() endif() diff --git a/share/cmake/modules/FindImath.cmake b/share/cmake/modules/FindImath.cmake index 30f5b4e465..6126b934f7 100644 --- a/share/cmake/modules/FindImath.cmake +++ b/share/cmake/modules/FindImath.cmake @@ -1,25 +1,27 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright Contributors to the OpenColorIO Project. # -# Locate or install Imath +# Locate Imath # # Variables defined by this module: -# Imath_FOUND - If FALSE, do not try to link to ilmbase -# Imath_LIBRARY - Imath library to link to -# Imath_INCLUDE_DIR - Where to find ImathConfig.h -# Imath_VERSION - The version of the library +# Imath_FOUND - Indicate whether the library was found or not +# Imath_LIBRARY - Path to the library file +# Imath_INCLUDE_DIR - Location of the header files +# Imath_VERSION - Library's version # -# Targets defined by this module: -# Imath::Imath - IMPORTED target, if found +# Global targets defined by this module: +# Imath::Imath # -# By default, the dynamic libraries of Imath will be found. To find the -# static ones instead, you must set the Imath_STATIC_LIBRARY variable to -# TRUE before calling find_package(Imath ...). +# Usually CMake will use the dynamic library rather than static, if both are present. +# In this case, you may set Imath_STATIC_LIBRARY to ON to request use of the static one. +# If only the static library is present (such as when OCIO builds the dependency), then the option +# is not needed. # -# If Imath is not installed in a standard path, you can use the -# Imath_ROOT variable to tell CMake where to find it. If it is not found -# and OCIO_INSTALL_EXT_PACKAGES is set to MISSING or ALL, Imath will be -# downloaded, built, and statically-linked into libOpenColorIO at build time. +# If the library is not installed in a typical location where CMake will find it, you may specify +# the location using one of the following methods: +# -- Set -DImath_DIR to point to the directory containing the CMake configuration file for the package. +# -- Set -DImath_ROOT to point to the directory containing the lib and include directories. +# -- Set -DImath_LIBRARY and -DImath_INCLUDE_DIR to point to the lib and include directories. # ############################################################################### @@ -131,122 +133,12 @@ endif() ############################################################################### ### Create target -if (NOT TARGET Imath::Imath) +if (Imath_FOUND AND NOT TARGET Imath::Imath) add_library(Imath::Imath UNKNOWN IMPORTED GLOBAL) add_library(Imath::ImathConfig INTERFACE IMPORTED GLOBAL) set(_Imath_TARGET_CREATE TRUE) endif() -############################################################################### -### Install package from source ### - -if(NOT Imath_FOUND AND OCIO_INSTALL_EXT_PACKAGES AND NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL NONE) - include(ExternalProject) - include(GNUInstallDirs) - - set(_EXT_DIST_ROOT "${CMAKE_BINARY_DIR}/ext/dist") - set(_EXT_BUILD_ROOT "${CMAKE_BINARY_DIR}/ext/build") - - # Set find_package standard args - set(Imath_FOUND TRUE) - if(_Imath_ExternalProject_VERSION) - set(Imath_VERSION ${_Imath_ExternalProject_VERSION}) - else() - set(Imath_VERSION ${Imath_FIND_VERSION}) - endif() - set(Imath_INCLUDE_DIR "${_EXT_DIST_ROOT}/${CMAKE_INSTALL_INCLUDEDIR}") - - # Set the expected library name - if(BUILD_TYPE_DEBUG) - set(_Imath_LIB_SUFFIX "_d") - endif() - - include(VersionUtils) - split_version_string(${Imath_VERSION} _Imath_ExternalProject) - - set(_Imath_LIB_VER "${_Imath_ExternalProject_VERSION_MAJOR}_${_Imath_ExternalProject_VERSION_MINOR}") - - set(Imath_LIBRARY - "${_EXT_DIST_ROOT}/${CMAKE_INSTALL_LIBDIR}/${CMAKE_STATIC_LIBRARY_PREFIX}Imath-${_Imath_LIB_VER}${_Imath_LIB_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX}") - - if(_Imath_TARGET_CREATE) - if(MSVC) - set(Imath_CXX_FLAGS "${Imath_CXX_FLAGS} /EHsc") - endif() - - string(STRIP "${Imath_CXX_FLAGS}" Imath_CXX_FLAGS) - - set(Imath_CMAKE_ARGS - ${Imath_CMAKE_ARGS} - -DCMAKE_CXX_VISIBILITY_PRESET=${CMAKE_CXX_VISIBILITY_PRESET} - -DCMAKE_VISIBILITY_INLINES_HIDDEN=${CMAKE_VISIBILITY_INLINES_HIDDEN} - -DCMAKE_POSITION_INDEPENDENT_CODE=ON - -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} - -DCMAKE_CXX_FLAGS=${Imath_CXX_FLAGS} - -DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD} - -DCMAKE_INSTALL_MESSAGE=${CMAKE_INSTALL_MESSAGE} - -DCMAKE_INSTALL_PREFIX=${_EXT_DIST_ROOT} - -DCMAKE_INSTALL_BINDIR=${CMAKE_INSTALL_BINDIR} - -DCMAKE_INSTALL_DATADIR=${CMAKE_INSTALL_DATADIR} - -DCMAKE_INSTALL_LIBDIR=${CMAKE_INSTALL_LIBDIR} - -DCMAKE_INSTALL_INCLUDEDIR=${CMAKE_INSTALL_INCLUDEDIR} - -DCMAKE_OBJECT_PATH_MAX=${CMAKE_OBJECT_PATH_MAX} - -DBUILD_SHARED_LIBS=OFF - -DBUILD_TESTING=OFF - -DPYTHON=OFF - -DDOCS=OFF - -DIMATH_HALF_USE_LOOKUP_TABLE=OFF - ) - - if(CMAKE_TOOLCHAIN_FILE) - set(Imath_CMAKE_ARGS - ${Imath_CMAKE_ARGS} -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}) - endif() - - if(APPLE) - string(REPLACE ";" "$" ESCAPED_CMAKE_OSX_ARCHITECTURES "${CMAKE_OSX_ARCHITECTURES}") - - set(Imath_CMAKE_ARGS - ${Imath_CMAKE_ARGS} - -DCMAKE_OSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET} - -DCMAKE_OSX_ARCHITECTURES=${ESCAPED_CMAKE_OSX_ARCHITECTURES} - ) - endif() - - if (ANDROID) - set(Imath_CMAKE_ARGS - ${Imath_CMAKE_ARGS} - -DANDROID_PLATFORM=${ANDROID_PLATFORM} - -DANDROID_ABI=${ANDROID_ABI} - -DANDROID_STL=${ANDROID_STL}) - endif() - - # Hack to let imported target be built from ExternalProject_Add - file(MAKE_DIRECTORY ${Imath_INCLUDE_DIR}) - - ExternalProject_Add(imath_install - GIT_REPOSITORY "https://github.com/AcademySoftwareFoundation/Imath.git" - GIT_TAG "v${Imath_VERSION}" - GIT_CONFIG advice.detachedHead=false - GIT_SHALLOW TRUE - PREFIX "${_EXT_BUILD_ROOT}/Imath" - BUILD_BYPRODUCTS ${Imath_LIBRARY} - CMAKE_ARGS ${Imath_CMAKE_ARGS} - EXCLUDE_FROM_ALL TRUE - BUILD_COMMAND "" - INSTALL_COMMAND - ${CMAKE_COMMAND} --build . - --config ${CMAKE_BUILD_TYPE} - --target install - --parallel - ) - - add_dependencies(Imath::Imath imath_install) - - message(STATUS "Installing Imath: ${Imath_LIBRARY} (version \"${Imath_VERSION}\")") - endif() -endif() - ############################################################################### ### Configure target ### @@ -262,4 +154,4 @@ if(_Imath_TARGET_CREATE) ) mark_as_advanced(Imath_INCLUDE_DIR Imath_LIBRARY Imath_VERSION) -endif() +endif() \ No newline at end of file diff --git a/share/cmake/modules/FindOpenShadingLanguage.cmake b/share/cmake/modules/FindOSL.cmake similarity index 62% rename from share/cmake/modules/FindOpenShadingLanguage.cmake rename to share/cmake/modules/FindOSL.cmake index f73ffdf9b9..5cefe410bc 100644 --- a/share/cmake/modules/FindOpenShadingLanguage.cmake +++ b/share/cmake/modules/FindOSL.cmake @@ -1,51 +1,54 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright Contributors to the OpenColorIO Project. # -# Locate or install OpenShadingLanguage (OSL) +# Locate OpenShadingLanguage (OSL) # -# If the library is not installed in a standard path, you can use the OSL_ROOT -# variable to tell CMake where to find it. +# Variables defined by this module: +# OSL_FOUND - Indicate whether the library was found or not +# OSL_LIB_DIR - Location of the libary files +# OSL_INCLUDE_DIR - Location of the header files +# OSL_VERSION - Library's version +# OSL_SHADERS_INCLUDE_DIR - Location of the shader's header files +# OSL_SHADERS_DIR - Used for OSL unit tests +# +# These variables are set only when OSL_ROOT is provided: +# oslcomp_LIBRARY - Path to the library file +# oslexec_LIBRARY - Path to the library file +# +# Global targets defined by this module: +# osl::osl +# +# Usually CMake will use the dynamic library rather than static, if both are present. +# +# If the library is not installed in a typical location where CMake will find it, you may specify +# the location using one of the following methods: +# -- Set -DOpenShadingLanguage_DIR to point to the directory containing the CMake configuration file for the package. +# -- Set -DOpenShadingLanguage_ROOT to point to the directory containing the lib and include directories. # - - -if(NOT TARGET osl::osl) - add_library(osl::osl INTERFACE IMPORTED GLOBAL) - set(OSL_FOUND OFF) -endif() ############################################################################### ### Try to find package ### if(NOT DEFINED OSL_ROOT) - - find_package(OSL ${OpenShadingLanguage_FIND_VERSION} CONFIG) - - set(OpenShadingLanguage_VERSION ${OSL_VERSION}) - - # TODO: No variable to have the share directory? + find_package(OSL ${OSL_FIND_VERSION} CONFIG QUIET) set(OSL_SHADERS_INCLUDE_DIR ${OSL_INCLUDE_DIR}/../share) - # Variable used by the OSL unit tests. set(OSL_SHADERS_DIR ${OSL_SHADERS_INCLUDE_DIR}/OSL/shaders) include (FindPackageHandleStandardArgs) - find_package_handle_standard_args (OpenShadingLanguage - FOUND_VAR OpenShadingLanguage_FOUND - REQUIRED_VARS OSL_INCLUDE_DIR OSL_LIB_DIR OpenShadingLanguage_VERSION - VERSION_VAR OpenShadingLanguage_VERSION + find_package_handle_standard_args (OSL + REQUIRED_VARS + OSL_INCLUDE_DIR + OSL_LIB_DIR + VERSION_VAR + OSL_VERSION ) - - set(OSL_FOUND ${OpenShadingLanguage_FOUND}) - else() - set(OSL_INCLUDE_DIR ${OSL_ROOT}/include) - set(OSL_VERSION_HEADER "${OSL_INCLUDE_DIR}/OSL/oslversion.h") if(EXISTS "${OSL_VERSION_HEADER}") - # Try to figure out version number file (STRINGS "${OSL_VERSION_HEADER}" TMP REGEX "^#define OSL_LIBRARY_VERSION_MAJOR .*$") string (REGEX MATCHALL "[0-9]+" OSL_VERSION_MAJOR ${TMP}) @@ -54,12 +57,14 @@ else() file (STRINGS "${OSL_VERSION_HEADER}" TMP REGEX "^#define OSL_LIBRARY_VERSION_PATCH .*$") string (REGEX MATCHALL "[0-9]+" OSL_VERSION_PATCH ${TMP}) file (STRINGS "${OSL_VERSION_HEADER}" TMP REGEX "^#define OSL_LIBRARY_VERSION_TWEAK .*$") + if (TMP) string (REGEX MATCHALL "[0-9]+" OSL_VERSION_TWEAK ${TMP}) else () set (OSL_VERSION_TWEAK 0) endif () - set (OpenShadingLanguage_VERSION "${OSL_VERSION_MAJOR}.${OSL_VERSION_MINOR}.${OSL_VERSION_PATCH}.${OSL_VERSION_TWEAK}") + + set (OSL_VERSION "${OSL_VERSION_MAJOR}.${OSL_VERSION_MINOR}.${OSL_VERSION_PATCH}.${OSL_VERSION_TWEAK}") # Find the oslcomp library. find_library(oslcomp_LIBRARY @@ -92,58 +97,41 @@ else() ) set(OSL_SHADERS_INCLUDE_DIR ${OSL_ROOT}/share) - # Variable used by the OSL unit tests. set(OSL_SHADERS_DIR ${OSL_SHADERS_INCLUDE_DIR}/OSL/shaders) - - if(EXISTS "${OSL_SHADERS_DIR}") - - # Variable used by the OSL unit tests. - set(OSL_FOUND ON) - - endif() - endif() include (FindPackageHandleStandardArgs) - find_package_handle_standard_args (OpenShadingLanguage - FOUND_VAR OpenShadingLanguage_FOUND - REQUIRED_VARS OSL_INCLUDE_DIR oslcomp_LIBRARY oslexec_LIBRARY OpenShadingLanguage_VERSION - VERSION_VAR OpenShadingLanguage_VERSION + find_package_handle_standard_args (OSL + REQUIRED_VARS + OSL_INCLUDE_DIR + OSL_SHADERS_DIR + oslcomp_LIBRARY + oslexec_LIBRARY + VERSION_VAR + OSL_VERSION ) - - set(OSL_FOUND ${OpenShadingLanguage_FOUND}) - endif() ############################################################################### -### Check the C++ version ### - -# TODO: Which version starts to impose C++14? +### Create target -if(${CMAKE_CXX_STANDARD} LESS_EQUAL 11) - set(OSL_FOUND OFF) - message(WARNING "Need C++14 or higher to compile OpenShadingLanguage. Skipping build of the OSL unit tests") +if(NOT TARGET osl::osl) + add_library(osl::osl INTERFACE IMPORTED GLOBAL) endif() ############################################################################### ### Configure target ### if(OSL_FOUND) - - if (NOT OSL_FIND_QUIETLY) - message(STATUS "OpenShadingLanguage includes = ${OSL_INCLUDE_DIR}") - message(STATUS "OpenShadingLanguage shaders = ${OSL_SHADERS_DIR}") - message(STATUS "OpenShadingLanguage library dir = ${OSL_LIB_DIR}") - endif () - list(APPEND LIB_INCLUDE_DIRS ${OSL_INCLUDE_DIR}) list(APPEND LIB_INCLUDE_DIRS ${OSL_SHADERS_INCLUDE_DIR}) target_include_directories(osl::osl INTERFACE "${LIB_INCLUDE_DIRS}") target_link_libraries(osl::osl INTERFACE OSL::oslcomp OSL::oslexec) - if (${OpenShadingLanguage_VERSION} VERSION_GREATER_EQUAL "1.12" AND ${CMAKE_CXX_STANDARD} LESS_EQUAL 11) + # C++14 is required for OSL 1.12+ + if (${OSL_VERSION} VERSION_GREATER_EQUAL "1.12" AND ${CMAKE_CXX_STANDARD} LESS_EQUAL 11) set(OSL_FOUND OFF) message(WARNING "Need C++14 or higher to compile OpenShadingLanguage. Skipping build the OSL unit tests") endif() @@ -152,5 +140,4 @@ if(OSL_FOUND) oslcomp_LIBRARY oslcomp_FOUND oslexec_LIBRARY oslexec_FOUND ) - endif() diff --git a/share/cmake/modules/FindOpenImageIO.cmake b/share/cmake/modules/FindOpenImageIO.cmake deleted file mode 100644 index c8f68abd63..0000000000 --- a/share/cmake/modules/FindOpenImageIO.cmake +++ /dev/null @@ -1,174 +0,0 @@ -########################################################################### -# OpenImageIO https://www.openimageio.org -# Copyright 2008-present Contributors to the OpenImageIO project. -# SPDX-License-Identifier: BSD-3-Clause -# https://github.com/OpenImageIO/oiio/blob/master/LICENSE.md -# -# For an up-to-date version of this file, see: -# https://github.com/OpenImageIO/oiio/blob/master/src/cmake/Modules/FindOpenImageIO.cmake -# -########################################################################### -# -# CMake module to find OpenImageIO -# -# This module will set -# OpenImageIO_FOUND True, if found -# OPENIMAGEIO_INCLUDES directory where headers are found -# OPENIMAGEIO_LIBRARIES libraries for OIIO -# OPENIMAGEIO_LIBRARY_DIRS library dirs for OIIO -# OPENIMAGEIO_VERSION Version ("major.minor.patch.tweak") -# OPENIMAGEIO_VERSION_MAJOR Version major number -# OPENIMAGEIO_VERSION_MINOR Version minor number -# OPENIMAGEIO_VERSION_PATCH Version minor patch -# OPENIMAGEIO_VERSION_TWEAK Version minor tweak -# -# Imported targets: -# OpenImageIO::OpenImageIO The libOpenImageIO library. -# OpenImageIO::oiiotool The oiiotool executable. -# -# Special inputs: -# OpenImageIO_ROOT - if using CMake >= 3.12, will automatically search -# this area for OIIO components. -# OPENIMAGEIO_ROOT_DIR - custom "prefix" location of OIIO installation -# (expecting bin, lib, include subdirectories) -# This is deprecated, but will work for a while. -# OpenImageIO_FIND_QUIETLY - if set, print minimal console output -# OIIO_LIBNAME_SUFFIX - if set, optional nonstandard library suffix -# -########################################################################### -# -# NOTE: This file is deprecated. -# -# In OIIO 2.1+, we generate OpenImageIOConfig.cmake files that are now the -# preferred way for downstream projecs to find an installed OIIO. There -# should be no need to copy this FindOpenImageIO.cmake file into downstream -# projects, *unless* they need to work with a range of OIIO vesions that -# may include <2.1, which would lack the generated config files. -# -########################################################################### - - -# If 'OPENIMAGE_HOME' not set, use the env variable of that name if available -if (NOT OPENIMAGEIO_ROOT_DIR AND NOT $ENV{OPENIMAGEIO_ROOT_DIR} STREQUAL "") - set (OPENIMAGEIO_ROOT_DIR $ENV{OPENIMAGEIO_ROOT_DIR}) -endif () - -find_library (OPENIMAGEIO_LIBRARY - NAMES - OpenImageIO${OIIO_LIBNAME_SUFFIX} - HINTS - ${OPENIMAGEIO_ROOT_DIR} - PATH_SUFFIXES - lib64 - lib - OpenImageIO/lib -) -find_library (OPENIMAGEIO_UTIL_LIBRARY - NAMES - OpenImageIO_Util${OIIO_LIBNAME_SUFFIX} - HINTS - ${OPENIMAGEIO_ROOT_DIR} - PATH_SUFFIXES - lib64 - lib - OpenImageIO/lib -) -find_path (OPENIMAGEIO_INCLUDE_DIR - NAMES - OpenImageIO/imageio.h - HINTS - ${OPENIMAGEIO_ROOT_DIR} - PATH_SUFFIXES - OpenImageIO/include -) -find_program (OIIOTOOL_BIN - NAMES - oiiotool - HINTS - ${OPENIMAGEIO_ROOT_DIR} - PATH_SUFFIXES - OpenImageIO/bin -) - -# Try to figure out version number -set (OIIO_VERSION_HEADER "${OPENIMAGEIO_INCLUDE_DIR}/OpenImageIO/oiioversion.h") -if (EXISTS "${OIIO_VERSION_HEADER}") - file (STRINGS "${OIIO_VERSION_HEADER}" TMP REGEX "^#define OIIO_VERSION_MAJOR .*$") - string (REGEX MATCHALL "[0-9]+" OPENIMAGEIO_VERSION_MAJOR ${TMP}) - file (STRINGS "${OIIO_VERSION_HEADER}" TMP REGEX "^#define OIIO_VERSION_MINOR .*$") - string (REGEX MATCHALL "[0-9]+" OPENIMAGEIO_VERSION_MINOR ${TMP}) - file (STRINGS "${OIIO_VERSION_HEADER}" TMP REGEX "^#define OIIO_VERSION_PATCH .*$") - string (REGEX MATCHALL "[0-9]+" OPENIMAGEIO_VERSION_PATCH ${TMP}) - file (STRINGS "${OIIO_VERSION_HEADER}" TMP REGEX "^#define OIIO_VERSION_TWEAK .*$") - if (TMP) - string (REGEX MATCHALL "[0-9]+" OPENIMAGEIO_VERSION_TWEAK ${TMP}) - else () - set (OPENIMAGEIO_VERSION_TWEAK 0) - endif () - set (OPENIMAGEIO_VERSION "${OPENIMAGEIO_VERSION_MAJOR}.${OPENIMAGEIO_VERSION_MINOR}.${OPENIMAGEIO_VERSION_PATCH}.${OPENIMAGEIO_VERSION_TWEAK}") -endif () - -set (OIIO_IMATH_HEADER "${OPENIMAGEIO_INCLUDE_DIR}/OpenImageIO/Imath.h") -if (EXISTS "${OIIO_IMATH_HEADER}") - file (STRINGS "${OIIO_IMATH_HEADER}" TMP REGEX "^#define OIIO_USING_IMATH .*$") - string (REGEX MATCHALL "[0-9]" OIIO_IMATH_VERSION ${TMP}) - if (OIIO_IMATH_VERSION LESS 3) - message(STATUS "Skipping OpenImageIO built against OpenEXR 2, please use version 3 or greater.") - return () - endif () -endif () - -include (FindPackageHandleStandardArgs) -find_package_handle_standard_args ( - OpenImageIO - FOUND_VAR - OpenImageIO_FOUND - REQUIRED_VARS - OPENIMAGEIO_INCLUDE_DIR - OPENIMAGEIO_LIBRARY - OPENIMAGEIO_VERSION - VERSION_VAR - OPENIMAGEIO_VERSION -) - -set (OPENIMAGEIO_FOUND ${OpenImageIO_FOUND}) # Old name - -if (OpenImageIO_FOUND) - set (OPENIMAGEIO_INCLUDES ${OPENIMAGEIO_INCLUDE_DIR}) - set (OPENIMAGEIO_LIBRARIES ${OPENIMAGEIO_LIBRARY}) - get_filename_component (OPENIMAGEIO_LIBRARY_DIRS "${OPENIMAGEIO_LIBRARY}" DIRECTORY) - if (NOT OpenImageIO_FIND_QUIETLY) - message ( STATUS "OpenImageIO includes = ${OPENIMAGEIO_INCLUDE_DIR}" ) - message ( STATUS "OpenImageIO libraries = ${OPENIMAGEIO_LIBRARIES}" ) - message ( STATUS "OpenImageIO library_dirs = ${OPENIMAGEIO_LIBRARY_DIRS}" ) - endif () - - if (NOT TARGET OpenImageIO::OpenImageIO) - add_library(OpenImageIO::OpenImageIO UNKNOWN IMPORTED) - set_target_properties(OpenImageIO::OpenImageIO PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES "${OPENIMAGEIO_INCLUDES}") - - set_property(TARGET OpenImageIO::OpenImageIO APPEND PROPERTY - IMPORTED_LOCATION "${OPENIMAGEIO_LIBRARIES}") - endif () - - # Starting with OIIO v2.3, some utility classes are now only declared in OpenImageIO_Util - # (and not in both libraries like in older versions). - if (${OPENIMAGEIO_VERSION} VERSION_GREATER_EQUAL "2.3" AND NOT TARGET OpenImageIO::OpenImageIO_Util) - add_library(OpenImageIO::OpenImageIO_Util UNKNOWN IMPORTED) - set_target_properties(OpenImageIO::OpenImageIO_Util PROPERTIES - IMPORTED_LOCATION "${OPENIMAGEIO_UTIL_LIBRARY}") - target_link_libraries(OpenImageIO::OpenImageIO INTERFACE OpenImageIO::OpenImageIO_Util) - endif () - - # Starting with OIIO v2.3, OIIO needs to compile at least in C++14. - if (${OPENIMAGEIO_VERSION} VERSION_GREATER_EQUAL "2.3" AND ${CMAKE_CXX_STANDARD} LESS_EQUAL 11) - set(OpenImageIO_FOUND OFF) - message(WARNING "Need C++14 or higher to compile with OpenImageIO ${OPENIMAGEIO_VERSION}.") - endif () -endif () - -mark_as_advanced ( - OPENIMAGEIO_INCLUDE_DIR - OPENIMAGEIO_LIBRARY -) diff --git a/share/cmake/modules/FindSphinx.cmake b/share/cmake/modules/FindSphinx.cmake index adf1080988..9278c57d9a 100644 --- a/share/cmake/modules/FindSphinx.cmake +++ b/share/cmake/modules/FindSphinx.cmake @@ -4,14 +4,14 @@ # Locate Sphinx (Python documentation generator) # # Variables defined by this module: -# Sphinx_FOUND -# Sphinx_EXECUTABLE (CACHE) +# Sphinx_FOUND - Indicate whether the executable was found or not +# Sphinx_EXECUTABLE - Path to the executable file # -# Usage: -# find_package(Sphinx) # -# If Sphinx is not installed in a standard path, add it to the Sphinx_ROOT -# variable to tell CMake where to find it. +# If the executable is not installed in a typical location where CMake will find it, you may specify +# the location using one of the following methods: +# -- Set -DSphinx_ROOT to point to the directory containing the executable. +# -- Set -DSphinx_EXECUTABLE to point to executable file. # find_package(Python QUIET COMPONENTS Interpreter) diff --git a/share/cmake/modules/Findexpat.cmake b/share/cmake/modules/Findexpat.cmake index 8e23cbba0b..1e715bb0cf 100644 --- a/share/cmake/modules/Findexpat.cmake +++ b/share/cmake/modules/Findexpat.cmake @@ -1,25 +1,27 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright Contributors to the OpenColorIO Project. # -# Locate or install expat +# Locate expat # # Variables defined by this module: -# expat_FOUND - If FALSE, do not try to link to expat -# expat_LIBRARY - expat library to link to -# expat_INCLUDE_DIR - Where to find expat.h -# expat_VERSION - The version of the library +# expat_FOUND - Indicate whether the library was found or not +# expat_LIBRARY - Path to the library file +# expat_INCLUDE_DIR - Location of the header files +# expat_VERSION - Library's version # -# Targets defined by this module: -# expat::expat - IMPORTED target, if found +# Global targets defined by this module: +# expat::expat # -# By default, the dynamic libraries of expat will be found. To find the static -# ones instead, you must set the expat_STATIC_LIBRARY variable to TRUE -# before calling find_package(expat ...). +# Usually CMake will use the dynamic library rather than static, if both are present. +# In this case, you may set expat_STATIC_LIBRARY to ON to request use of the static one. +# If only the static library is present (such as when OCIO builds the dependency), then the option +# is not needed. # -# If expat is not installed in a standard path, you can use the expat_ROOT -# variable to tell CMake where to find it. If it is not found and -# OCIO_INSTALL_EXT_PACKAGES is set to MISSING or ALL, expat will be downloaded, -# built, and statically-linked into libOpenColorIO at build time. +# If the library is not installed in a typical location where CMake will find it, you may specify +# the location using one of the following methods: +# -- Set -Dexpat_DIR to point to the directory containing the CMake configuration file for the package. +# -- Set -Dexpat_ROOT to point to the directory containing the lib and include directories. +# -- Set -Dexpat_LIBRARY and -Dexpat_INCLUDE_DIR to point to the lib and include directories. # ############################################################################### @@ -96,7 +98,6 @@ if(NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL ALL) expat/include ) - # Expat uses prefix "lib" on all platform by default. # Library name doesn't change in debug. @@ -200,126 +201,11 @@ endif() ############################################################################### ### Create target -if(NOT TARGET expat::expat) +if(expat_FOUND AND NOT TARGET expat::expat) add_library(expat::expat UNKNOWN IMPORTED GLOBAL) set(_expat_TARGET_CREATE TRUE) endif() -############################################################################### -### Install package from source ### - -if(NOT expat_FOUND AND OCIO_INSTALL_EXT_PACKAGES AND NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL NONE) - include(ExternalProject) - include(GNUInstallDirs) - - set(_EXT_DIST_ROOT "${CMAKE_BINARY_DIR}/ext/dist") - set(_EXT_BUILD_ROOT "${CMAKE_BINARY_DIR}/ext/build") - - # Set find_package standard args - set(expat_FOUND TRUE) - set(expat_VERSION ${expat_FIND_VERSION}) - set(expat_INCLUDE_DIR "${_EXT_DIST_ROOT}/${CMAKE_INSTALL_INCLUDEDIR}") - - # Set the expected library name - if(WIN32) - if(BUILD_TYPE_DEBUG) - set(_expat_LIB_SUFFIX "d") - endif() - # Static Linking, Multi-threaded Dll naming (>=2.2.8): - # https://github.com/libexpat/libexpat/blob/R_2_2_8/expat/win32/README.txt - set(_expat_LIB_SUFFIX "${_expat_LIB_SUFFIX}MD") - endif() - - # Expat use a hardcoded lib prefix instead of CMAKE_STATIC_LIBRARY_PREFIX - # https://github.com/libexpat/libexpat/blob/R_2_4_1/expat/CMakeLists.txt#L374 - set(_expat_LIB_PREFIX "lib") - - set(expat_LIBRARY - "${_EXT_DIST_ROOT}/${CMAKE_INSTALL_LIBDIR}/${_expat_LIB_PREFIX}expat${_expat_LIB_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX}") - - if(_expat_TARGET_CREATE) - if(MSVC) - set(EXPAT_C_FLAGS "${EXPAT_C_FLAGS} /EHsc") - set(EXPAT_CXX_FLAGS "${EXPAT_CXX_FLAGS} /EHsc") - endif() - - string(STRIP "${EXPAT_C_FLAGS}" EXPAT_C_FLAGS) - string(STRIP "${EXPAT_CXX_FLAGS}" EXPAT_CXX_FLAGS) - - set(EXPAT_CMAKE_ARGS - ${EXPAT_CMAKE_ARGS} - -DCMAKE_POLICY_DEFAULT_CMP0063=NEW - -DCMAKE_C_VISIBILITY_PRESET=${CMAKE_C_VISIBILITY_PRESET} - -DCMAKE_CXX_VISIBILITY_PRESET=${CMAKE_CXX_VISIBILITY_PRESET} - -DCMAKE_VISIBILITY_INLINES_HIDDEN=${CMAKE_VISIBILITY_INLINES_HIDDEN} - -DCMAKE_POSITION_INDEPENDENT_CODE=ON - -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} - -DCMAKE_C_FLAGS=${EXPAT_C_FLAGS} - -DCMAKE_CXX_FLAGS=${EXPAT_CXX_FLAGS} - -DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD} - -DCMAKE_INSTALL_MESSAGE=${CMAKE_INSTALL_MESSAGE} - -DCMAKE_INSTALL_PREFIX=${_EXT_DIST_ROOT} - -DCMAKE_INSTALL_BINDIR=${CMAKE_INSTALL_BINDIR} - -DCMAKE_INSTALL_DATADIR=${CMAKE_INSTALL_DATADIR} - -DCMAKE_INSTALL_LIBDIR=${CMAKE_INSTALL_LIBDIR} - -DCMAKE_INSTALL_INCLUDEDIR=${CMAKE_INSTALL_INCLUDEDIR} - -DCMAKE_OBJECT_PATH_MAX=${CMAKE_OBJECT_PATH_MAX} - -DEXPAT_BUILD_DOCS=OFF - -DEXPAT_BUILD_EXAMPLES=OFF - -DEXPAT_BUILD_TESTS=OFF - -DEXPAT_BUILD_TOOLS=OFF - -DEXPAT_SHARED_LIBS=OFF - ) - - if(CMAKE_TOOLCHAIN_FILE) - set(EXPAT_CMAKE_ARGS - ${EXPAT_CMAKE_ARGS} -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}) - endif() - - if(APPLE) - string(REPLACE ";" "$" ESCAPED_CMAKE_OSX_ARCHITECTURES "${CMAKE_OSX_ARCHITECTURES}") - - set(EXPAT_CMAKE_ARGS - ${EXPAT_CMAKE_ARGS} - -DCMAKE_OSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET} - -DCMAKE_OSX_ARCHITECTURES=${ESCAPED_CMAKE_OSX_ARCHITECTURES} - ) - endif() - - if (ANDROID) - set(EXPAT_CMAKE_ARGS - ${EXPAT_CMAKE_ARGS} - -DANDROID_PLATFORM=${ANDROID_PLATFORM} - -DANDROID_ABI=${ANDROID_ABI} - -DANDROID_STL=${ANDROID_STL}) - endif() - - # Hack to let imported target be built from ExternalProject_Add - file(MAKE_DIRECTORY ${expat_INCLUDE_DIR}) - - ExternalProject_Add(expat_install - GIT_REPOSITORY "https://github.com/libexpat/libexpat.git" - GIT_TAG "R_${expat_FIND_VERSION_MAJOR}_${expat_FIND_VERSION_MINOR}_${expat_FIND_VERSION_PATCH}" - GIT_CONFIG advice.detachedHead=false - GIT_SHALLOW TRUE - PREFIX "${_EXT_BUILD_ROOT}/libexpat" - BUILD_BYPRODUCTS ${expat_LIBRARY} - SOURCE_SUBDIR expat - CMAKE_ARGS ${EXPAT_CMAKE_ARGS} - EXCLUDE_FROM_ALL TRUE - BUILD_COMMAND "" - INSTALL_COMMAND - ${CMAKE_COMMAND} --build . - --config ${CMAKE_BUILD_TYPE} - --target install - --parallel - ) - - add_dependencies(expat::expat expat_install) - message(STATUS "Installing expat: ${expat_LIBRARY} (version \"${expat_VERSION}\")") - endif() -endif() - ############################################################################### ### Configure target ### @@ -330,4 +216,4 @@ if(_expat_TARGET_CREATE) ) mark_as_advanced(expat_INCLUDE_DIR expat_LIBRARY expat_VERSION) -endif() +endif() \ No newline at end of file diff --git a/share/cmake/modules/Findlcms2.cmake b/share/cmake/modules/Findlcms2.cmake index f35fcf14f4..8183376330 100644 --- a/share/cmake/modules/Findlcms2.cmake +++ b/share/cmake/modules/Findlcms2.cmake @@ -1,7 +1,7 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright Contributors to the OpenColorIO Project. # -# Locate or install lcms2 +# Locate lcms2 # # Variables defined by this module: # lcms2_FOUND - If FALSE, do not try to link to lcms @@ -9,24 +9,20 @@ # lcms2_INCLUDE_DIR - Where to find lcms2.h # lcms2_VERSION - The version of the library # -# Targets defined by this module: +# Global targets defined by this module: # lcms2::lcms2 - IMPORTED target, if found # -# By default, the dynamic libraries of lcms2 will be found. To find the static -# ones instead, you must set the lcms2_STATIC_LIBRARY variable to TRUE -# before calling find_package(lcms2 ...). +# Usually CMake will use the dynamic library rather than static, if both are present. +# In this case, you may set lcms2_STATIC_LIBRARY to ON to request use of the static one. +# If only the static library is present (such as when OCIO builds the dependency), then the option +# is not needed. # -# If lcms2 is not installed in a standard path, you can use the lcms2_ROOT -# variable to tell CMake where to find it. If it is not found and -# OCIO_INSTALL_EXT_PACKAGES is set to MISSING or ALL, lcms2 will be -# downloaded, built, and statically-linked into libOpenColorIO at build time. +# If the library is not installed in a typical location where CMake will find it, you may specify +# the location using one of the following methods: +# -- Set -Dlcms2_ROOT to point to the directory containing the lib and include directories. +# -- Set -Dlcms2_LIBRARY and -Dlcms2_INCLUDE_DIR to point to the lib and include directories. # -if(NOT TARGET lcms2::lcms2) - add_library(lcms2::lcms2 UNKNOWN IMPORTED GLOBAL) - set(_lcms2_TARGET_CREATE TRUE) -endif() - ############################################################################### ### Try to find package ### @@ -95,104 +91,11 @@ if(NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL ALL) endif() ############################################################################### -### Install package from source ### - -if(NOT lcms2_FOUND AND OCIO_INSTALL_EXT_PACKAGES AND NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL NONE) - include(ExternalProject) - - set(_EXT_DIST_ROOT "${CMAKE_BINARY_DIR}/ext/dist") - set(_EXT_BUILD_ROOT "${CMAKE_BINARY_DIR}/ext/build") - - # Set find_package standard args - set(lcms2_FOUND TRUE) - set(lcms2_VERSION ${lcms2_FIND_VERSION}) - set(lcms2_INCLUDE_DIR "${_EXT_DIST_ROOT}/${CMAKE_INSTALL_INCLUDEDIR}/lcms2") - set(lcms2_LIBRARY - "${_EXT_DIST_ROOT}/${CMAKE_INSTALL_LIBDIR}/${CMAKE_STATIC_LIBRARY_PREFIX}lcms2${CMAKE_STATIC_LIBRARY_SUFFIX}") - - if(_lcms2_TARGET_CREATE) - if(UNIX) - set(lcms2_C_FLAGS "${lcms2_C_FLAGS} -fvisibility=hidden -fPIC") - endif() - - if("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") - set(lcms2_C_FLAGS "${lcms2_C_FLAGS} -Wno-aggressive-loop-optimizations") - endif() - - string(STRIP "${lcms2_C_FLAGS}" lcms2_C_FLAGS) - - # NOTE: Depending of the compiler version lcm2 2.2 does not compile with C++17 so revert - # to C++11 because the library is only used by a cmd line tool. - - set(lcms2_CXX_STANDARD ${CMAKE_CXX_STANDARD}) - if(${CMAKE_CXX_STANDARD} GREATER_EQUAL 17) - set(lcms2_CXX_STANDARD 11) - endif() - - set(lcms2_CMAKE_ARGS - ${lcms2_CMAKE_ARGS} - -DCMAKE_C_FLAGS=${lcms2_C_FLAGS} - -DCMAKE_CXX_STANDARD=${lcms2_CXX_STANDARD} - -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} - -DCMAKE_INSTALL_MESSAGE=${CMAKE_INSTALL_MESSAGE} - -DCMAKE_INSTALL_PREFIX=${_EXT_DIST_ROOT} - -DCMAKE_INSTALL_BINDIR=${CMAKE_INSTALL_BINDIR} - -DCMAKE_INSTALL_LIBDIR=${CMAKE_INSTALL_LIBDIR} - -DCMAKE_INSTALL_INCLUDEDIR=${CMAKE_INSTALL_INCLUDEDIR} - -DCMAKE_OBJECT_PATH_MAX=${CMAKE_OBJECT_PATH_MAX} - -DBUILD_SHARED_LIBS=OFF - ) - - if(CMAKE_TOOLCHAIN_FILE) - set(lcms2_CMAKE_ARGS - ${lcms2_CMAKE_ARGS} -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}) - endif() - - if(APPLE) - string(REPLACE ";" "$" ESCAPED_CMAKE_OSX_ARCHITECTURES "${CMAKE_OSX_ARCHITECTURES}") - - set(lcms2_CMAKE_ARGS - ${lcms2_CMAKE_ARGS} - -DCMAKE_OSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET} - -DCMAKE_OSX_ARCHITECTURES=${ESCAPED_CMAKE_OSX_ARCHITECTURES} - ) - endif() - - if (ANDROID) - set(lcms2_CMAKE_ARGS - ${lcms2_CMAKE_ARGS} - -DANDROID_PLATFORM=${ANDROID_PLATFORM} - -DANDROID_ABI=${ANDROID_ABI} - -DANDROID_STL=${ANDROID_STL}) - endif() - - # Hack to let imported target be built from ExternalProject_Add - file(MAKE_DIRECTORY ${lcms2_INCLUDE_DIR}) - - ExternalProject_Add(lcms2_install - GIT_REPOSITORY "https://github.com/mm2/Little-CMS.git" - GIT_TAG "lcms${lcms2_VERSION}" - GIT_CONFIG advice.detachedHead=false - GIT_SHALLOW TRUE - PREFIX "${_EXT_BUILD_ROOT}/Little-CMS" - BUILD_BYPRODUCTS ${lcms2_LIBRARY} - CMAKE_ARGS ${lcms2_CMAKE_ARGS} - EXCLUDE_FROM_ALL TRUE - PATCH_COMMAND - ${CMAKE_COMMAND} -E copy - "${CMAKE_SOURCE_DIR}/share/cmake/projects/Buildlcms2.cmake" - "CMakeLists.txt" - BUILD_COMMAND "" - INSTALL_COMMAND - ${CMAKE_COMMAND} --build . - --config ${CMAKE_BUILD_TYPE} - --target install - --parallel - ) +### Configure target ### - add_dependencies(lcms2::lcms2 lcms2_install) - message(STATUS "Installing lcms2: ${lcms2_LIBRARY} (version \"${lcms2_VERSION}\")") - endif() +if(lcms2_FOUND AND NOT TARGET lcms2::lcms2) + add_library(lcms2::lcms2 UNKNOWN IMPORTED GLOBAL) + set(_lcms2_TARGET_CREATE TRUE) endif() ############################################################################### diff --git a/share/cmake/modules/Findminizip-ng.cmake b/share/cmake/modules/Findminizip-ng.cmake index b961d1c9ac..4d66093839 100644 --- a/share/cmake/modules/Findminizip-ng.cmake +++ b/share/cmake/modules/Findminizip-ng.cmake @@ -1,7 +1,7 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright Contributors to the OpenColorIO Project. # -# Locate or install minizip-ng +# Locate minizip-ng # # Variables defined by this module: # minizip-ng_FOUND - If FALSE, do not try to link to minizip-ng @@ -9,13 +9,20 @@ # minizip-ng_INCLUDE_DIR - Where to find mz.h and other headers # minizip-ng_VERSION - The version of the library # -# Targets defined by this module: +# Global targets defined by this module: # MINIZIP::minizip-ng - IMPORTED target, if found # -# If minizip-ng is not installed in a standard path, you can use the minizip-ng_ROOT -# variable to tell CMake where to find it. If it is not found and -# OCIO_INSTALL_EXT_PACKAGES is set to MISSING or ALL, minizip-ng will be downloaded, -# built, and statically-linked into libOpenColorIO at build time. +# Usually CMake will use the dynamic library rather than static, if both are present. +# In this case, you may set minizip-ng_STATIC_LIBRARY to ON to request use of the static one. +# If only the static library is present (such as when OCIO builds the dependency), then the option +# is not needed. +# +# If the library is not installed in a typical location where CMake will find it, you may specify +# the location using one of the following methods: +# -- Set -Dminizip-ng_DIR to point to the directory containing the CMake configuration file for the package. +# -- Set -Dminizip-ng_ROOT to point to the directory containing the lib and include directories. +# -- Set -Dminizip-ng_LIBRARY and -Dminizip-ng_INCLUDE_DIR to point to the lib and include directories. +# # # For external builds of minizip-ng, please note that the same build options should be used. # Using more options, such as enabling other compression methods, will provoke linking issue @@ -23,6 +30,7 @@ # # e.g. Setting MZ_BZIP2=ON will cause linking issue since OCIO will not be linked against BZIP2. # + ############################################################################### ### Try to find package ### @@ -40,7 +48,7 @@ if(NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL ALL) # Search for minizip-ng-config.cmake find_package(minizip-ng ${minizip-ng_FIND_VERSION} CONFIG QUIET) endif() - + if (minizip-ng_FOUND) get_target_property(minizip-ng_INCLUDE_DIR MINIZIP::minizip-ng INTERFACE_INCLUDE_DIRECTORIES) get_target_property(minizip-ng_LIBRARY MINIZIP::minizip-ng LOCATION) @@ -176,120 +184,12 @@ endif() ############################################################################### ### Create target -if(NOT TARGET MINIZIP::minizip-ng) + +if(minizip-ng_FOUND AND NOT TARGET MINIZIP::minizip-ng) add_library(MINIZIP::minizip-ng UNKNOWN IMPORTED GLOBAL) set(_minizip-ng_TARGET_CREATE TRUE) endif() -############################################################################### -### Install package from source ### - -if(NOT minizip-ng_FOUND AND OCIO_INSTALL_EXT_PACKAGES AND NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL NONE) - include(ExternalProject) - include(GNUInstallDirs) - - set(_EXT_DIST_ROOT "${CMAKE_BINARY_DIR}/ext/dist") - set(_EXT_BUILD_ROOT "${CMAKE_BINARY_DIR}/ext/build") - - # Set find_package standard args - set(minizip-ng_FOUND TRUE) - set(minizip-ng_VERSION ${minizip-ng_FIND_VERSION}) - - set(minizip-ng_INCLUDE_DIR "${_EXT_DIST_ROOT}/${CMAKE_INSTALL_INCLUDEDIR}/minizip-ng") - - # Minizip-ng use a hardcoded lib prefix instead of CMAKE_STATIC_LIBRARY_PREFIX - set(_minizip-ng_LIB_PREFIX "lib") - - set(minizip-ng_LIBRARY - "${_EXT_DIST_ROOT}/${CMAKE_INSTALL_LIBDIR}/${_minizip-ng_LIB_PREFIX}minizip-ng${_minizip-ng_LIB_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX}") - - if(_minizip-ng_TARGET_CREATE) - set(minizip-ng_CMAKE_ARGS - ${minizip-ng_CMAKE_ARGS} - -DCMAKE_CXX_VISIBILITY_PRESET=${CMAKE_CXX_VISIBILITY_PRESET} - -DCMAKE_VISIBILITY_INLINES_HIDDEN=${CMAKE_VISIBILITY_INLINES_HIDDEN} - -DCMAKE_POSITION_INDEPENDENT_CODE=ON - -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} - -DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD} - -DCMAKE_INSTALL_MESSAGE=${CMAKE_INSTALL_MESSAGE} - -DCMAKE_INSTALL_PREFIX=${_EXT_DIST_ROOT} - -DCMAKE_INSTALL_BINDIR=${CMAKE_INSTALL_BINDIR} - -DCMAKE_INSTALL_DATADIR=${CMAKE_INSTALL_DATADIR} - -DCMAKE_INSTALL_LIBDIR=${CMAKE_INSTALL_LIBDIR} - # 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. - -DCMAKE_INSTALL_INCLUDEDIR=${CMAKE_INSTALL_INCLUDEDIR}/minizip-ng - -DCMAKE_OBJECT_PATH_MAX=${CMAKE_OBJECT_PATH_MAX} - -DBUILD_SHARED_LIBS=OFF - -DMZ_OPENSSL=OFF - -DMZ_LIBBSD=OFF - -DMZ_BUILD_TESTS=OFF - -DMZ_COMPAT=OFF - -DMZ_BZIP2=OFF - -DMZ_LZMA=OFF - -DMZ_LIBCOMP=OFF - -DMZ_ZSTD=OFF - -DMZ_PKCRYPT=OFF - -DMZ_WZAES=OFF - -DMZ_SIGNING=OFF - -DMZ_ZLIB=ON - -DMZ_ICONV=OFF - -DMZ_FETCH_LIBS=OFF - -DMZ_FORCE_FETCH_LIBS=OFF - -DZLIB_LIBRARY=${ZLIB_LIBRARIES} - -DZLIB_INCLUDE_DIR=${ZLIB_INCLUDE_DIRS} - ) - - if(CMAKE_TOOLCHAIN_FILE) - set(minizip-ng_CMAKE_ARGS - ${minizip-ng_CMAKE_ARGS} -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}) - endif() - - if(APPLE) - string(REPLACE ";" "$" ESCAPED_CMAKE_OSX_ARCHITECTURES "${CMAKE_OSX_ARCHITECTURES}") - - set(minizip-ng_CMAKE_ARGS - ${minizip-ng_CMAKE_ARGS} - -DCMAKE_OSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET} - -DCMAKE_OSX_ARCHITECTURES=${ESCAPED_CMAKE_OSX_ARCHITECTURES} - ) - endif() - - if (ANDROID) - set(minizip-ng_CMAKE_ARGS - ${minizip-ng_CMAKE_ARGS} - -DANDROID_PLATFORM=${ANDROID_PLATFORM} - -DANDROID_ABI=${ANDROID_ABI} - -DANDROID_STL=${ANDROID_STL}) - endif() - endif() - - # Hack to let imported target be built from ExternalProject_Add - file(MAKE_DIRECTORY ${minizip-ng_INCLUDE_DIR}) - - ExternalProject_Add(minizip-ng_install - GIT_REPOSITORY "https://github.com/zlib-ng/minizip-ng.git" - GIT_TAG "${minizip-ng_VERSION}" - GIT_CONFIG advice.detachedHead=false - GIT_SHALLOW TRUE - PREFIX "${_EXT_BUILD_ROOT}/libminizip-ng" - BUILD_BYPRODUCTS ${minizip-ng_LIBRARY} - CMAKE_ARGS ${minizip-ng_CMAKE_ARGS} - EXCLUDE_FROM_ALL TRUE - BUILD_COMMAND "" - INSTALL_COMMAND - ${CMAKE_COMMAND} --build . - --config ${CMAKE_BUILD_TYPE} - --target install - --parallel - ) - - add_dependencies(MINIZIP::minizip-ng minizip-ng_install) - message(STATUS "Installing minizip-ng: ${minizip-ng_LIBRARY} (version \"${minizip-ng_VERSION}\")") -endif() - ############################################################################### ### Configure target ### diff --git a/share/cmake/modules/Findopenfx.cmake b/share/cmake/modules/Findopenfx.cmake index 8b0eefb344..40dfac7072 100644 --- a/share/cmake/modules/Findopenfx.cmake +++ b/share/cmake/modules/Findopenfx.cmake @@ -1,26 +1,22 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright Contributors to the OpenColorIO Project. # -# Locate or install openfx +# Locate openfx # # Variables defined by this module: -# openfx_FOUND - If FALSE, do not try to include openfx -# openfx_INCLUDE_DIR - Where to find ofxCore.h -# openfx_VERSION - The version of the library +# openfx_FOUND - Indicate whether the library was found or not +# openfx_INCLUDE_DIR - Location of the header files +# openfx_VERSION - Library's version # -# Targets defined by this module: -# openfx::module - IMPORTED target, if found +# Global targets defined by this module: +# openfx::module # -# If openfx is not installed in a standard path, you can use the -# openfx_ROOT variable to tell CMake where to find it. If it is not found -# and OCIO_INSTALL_EXT_PACKAGES is set to MISSING or ALL, openfx will be -# downloaded at build time. +# Usually CMake will use the dynamic library rather than static, if both are present. +# +# If the library is not installed in a typical location where CMake will find it, you may specify +# the location using the following method: +# -- Set -Dopenfx_ROOT to point to the directory containing the lib and include directories. # - -if(NOT TARGET openfx::module) - add_library(openfx::module INTERFACE IMPORTED GLOBAL) - set(_openfx_TARGET_CREATE TRUE) -endif() ############################################################################### ### Try to find package ### @@ -56,45 +52,11 @@ if(NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL ALL) endif() ############################################################################### -### Install package from source ### - -if(NOT openfx_FOUND AND OCIO_INSTALL_EXT_PACKAGES AND NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL NONE) - include(ExternalProject) - include(GNUInstallDirs) - - set(_EXT_DIST_ROOT "${CMAKE_BINARY_DIR}/ext/dist") - set(_EXT_BUILD_ROOT "${CMAKE_BINARY_DIR}/ext/build") - set(_openfx_INSTALL_DIR "${_EXT_BUILD_ROOT}/openfx/src/openfx_install") +### Create target - # Set find_package standard args - set(openfx_FOUND TRUE) - set(openfx_VERSION ${openfx_FIND_VERSION}) - set(openfx_INCLUDE_DIR "${_EXT_DIST_ROOT}/${CMAKE_INSTALL_INCLUDEDIR}/openfx") - - if(_openfx_TARGET_CREATE) - # Hack to let imported target be built from ExternalProject_Add - file(MAKE_DIRECTORY ${openfx_INCLUDE_DIR}) - - ExternalProject_Add(openfx_install - GIT_REPOSITORY "https://github.com/ofxa/openfx.git" - GIT_TAG "OFX_Release_${openfx_FIND_VERSION_MAJOR}_${openfx_FIND_VERSION_MINOR}_TAG" - GIT_CONFIG advice.detachedHead=false - GIT_SHALLOW TRUE - PREFIX "${_EXT_BUILD_ROOT}/openfx" - BUILD_BYPRODUCTS ${openfx_INCLUDE_DIR} - CONFIGURE_COMMAND "" - BUILD_COMMAND - ${CMAKE_COMMAND} -E copy_directory - "${_EXT_BUILD_ROOT}/openfx/src/openfx_install/include" - "${openfx_INCLUDE_DIR}" - INSTALL_COMMAND "" - CMAKE_ARGS ${openfx_CMAKE_ARGS} - EXCLUDE_FROM_ALL TRUE - ) - - add_dependencies(openfx::module openfx_install) - message(STATUS "Installing openfx: ${openfx_INCLUDE_DIR} (version \"${openfx_VERSION}\")") - endif() +if(openfx_FOUND AND NOT TARGET openfx::module) + add_library(openfx::module INTERFACE IMPORTED GLOBAL) + set(_openfx_TARGET_CREATE TRUE) endif() ############################################################################### diff --git a/share/cmake/modules/Findpybind11.cmake b/share/cmake/modules/Findpybind11.cmake index e6c2f35a86..ccbb53e656 100644 --- a/share/cmake/modules/Findpybind11.cmake +++ b/share/cmake/modules/Findpybind11.cmake @@ -1,20 +1,23 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright Contributors to the OpenColorIO Project. # -# Locate or install pybind11 +# Locate pybind11 # # Variables defined by this module: # pybind11_FOUND - If FALSE, do not try to link to pybind11 # pybind11_INCLUDE_DIR - Where to find pybind11.h # pybind11_VERSION - The version of the library # -# Targets defined by this module: -# pybind11::module - IMPORTED target, if found +# Global targets defined by this module: +# pybind11::module # -# If pybind11 is not installed in a standard path, you can use the -# pybind11_ROOT variable to tell CMake where to find it. If it is not found -# and OCIO_INSTALL_EXT_PACKAGES is set to MISSING or ALL, pybind11 will be -# downloaded at build time. +# Usually CMake will use the dynamic library rather than static, if both are present. +# +# If the library is not installed in a typical location where CMake will find it, you may specify +# the location using one of the following methods: +# -- Set -Dpybind11_DIR to point to the directory containing the CMake configuration file for the package. +# -- Set -Dpybind11_ROOT to point to the directory containing the lib and include directories. +# -- Set -Dpybind11_LIBRARY and -Dpybind11_INCLUDE_DIR to point to the lib and include directories. # ############################################################################### @@ -126,94 +129,11 @@ endif() ############################################################################### ### Create target ### -if(NOT TARGET pybind11::module) +if(pybind11_FOUND AND NOT TARGET pybind11::module) add_library(pybind11::module INTERFACE IMPORTED GLOBAL) set(_pybind11_TARGET_CREATE TRUE) endif() -############################################################################### -### Install package from source ### - -if(NOT pybind11_FOUND AND OCIO_INSTALL_EXT_PACKAGES AND NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL NONE) - include(ExternalProject) - include(GNUInstallDirs) - - set(_EXT_DIST_ROOT "${CMAKE_BINARY_DIR}/ext/dist") - set(_EXT_BUILD_ROOT "${CMAKE_BINARY_DIR}/ext/build") - - # Set find_package standard args - set(pybind11_FOUND TRUE) - set(pybind11_VERSION ${pybind11_FIND_VERSION}) - set(pybind11_INCLUDE_DIR "${_EXT_DIST_ROOT}/${CMAKE_INSTALL_INCLUDEDIR}") - - if(_pybind11_TARGET_CREATE) - # Hack to let imported target be built from ExternalProject_Add - file(MAKE_DIRECTORY ${pybind11_INCLUDE_DIR}) - - set(pybind11_CMAKE_ARGS - ${pybind11_CMAKE_ARGS} - -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} - -DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD} - -DCMAKE_INSTALL_MESSAGE=${CMAKE_INSTALL_MESSAGE} - -DCMAKE_INSTALL_PREFIX=${_EXT_DIST_ROOT} - -DCMAKE_INSTALL_BINDIR=${CMAKE_INSTALL_BINDIR} - -DCMAKE_INSTALL_DATADIR=${CMAKE_INSTALL_DATADIR} - -DCMAKE_INSTALL_LIBDIR=${CMAKE_INSTALL_LIBDIR} - -DCMAKE_INSTALL_INCLUDEDIR=${CMAKE_INSTALL_INCLUDEDIR} - -DCMAKE_OBJECT_PATH_MAX=${CMAKE_OBJECT_PATH_MAX} - # Using FindPython mode (PYBIND11_FINDPYTHON=ON) doesn't seem to - # work when building on docker manylinux images where Development - # component is not available but is hardcoded in pybind11 script. - -DPYTHON_EXECUTABLE=${Python_EXECUTABLE} - -DPYBIND11_INSTALL=ON - -DPYBIND11_TEST=OFF - ) - - if(CMAKE_TOOLCHAIN_FILE) - set(pybind11_CMAKE_ARGS - ${pybind11_CMAKE_ARGS} -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}) - endif() - - if(APPLE) - string(REPLACE ";" "$" ESCAPED_CMAKE_OSX_ARCHITECTURES "${CMAKE_OSX_ARCHITECTURES}") - - set(pybind11_CMAKE_ARGS - ${pybind11_CMAKE_ARGS} - -DCMAKE_OSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET} - -DCMAKE_OSX_ARCHITECTURES=${ESCAPED_CMAKE_OSX_ARCHITECTURES} - ) - endif() - - if (ANDROID) - set(pybind11_CMAKE_ARGS - ${pybind11_CMAKE_ARGS} - -DANDROID_PLATFORM=${ANDROID_PLATFORM} - -DANDROID_ABI=${ANDROID_ABI} - -DANDROID_STL=${ANDROID_STL}) - endif() - - ExternalProject_Add(pybind11_install - GIT_REPOSITORY "https://github.com/pybind/pybind11.git" - GIT_TAG "v${pybind11_FIND_VERSION}" - GIT_CONFIG advice.detachedHead=false - GIT_SHALLOW TRUE - PREFIX "${_EXT_BUILD_ROOT}/pybind11" - BUILD_BYPRODUCTS ${pybind11_INCLUDE_DIR} - CMAKE_ARGS ${pybind11_CMAKE_ARGS} - EXCLUDE_FROM_ALL TRUE - BUILD_COMMAND "" - INSTALL_COMMAND - ${CMAKE_COMMAND} --build . - --config ${CMAKE_BUILD_TYPE} - --target install - --parallel - ) - - add_dependencies(pybind11::module pybind11_install) - message(STATUS "Installing pybind11: ${pybind11_INCLUDE_DIR} (version \"${pybind11_VERSION}\")") - endif() -endif() - ############################################################################### ### Configure target ### diff --git a/share/cmake/modules/Findpystring.cmake b/share/cmake/modules/Findpystring.cmake index bbd5e1fd27..c466115476 100644 --- a/share/cmake/modules/Findpystring.cmake +++ b/share/cmake/modules/Findpystring.cmake @@ -1,26 +1,25 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright Contributors to the OpenColorIO Project. # -# Locate or install pystring +# Locate pystring # # Variables defined by this module: -# pystring_FOUND - If FALSE, do not try to link to pystring -# pystring_LIBRARY - Where to find pystring -# pystring_INCLUDE_DIR - Where to find pystring.h +# pystring_FOUND - Indicate whether the library was found or not +# pystring_LIBRARY - Path to the library file +# pystring_INCLUDE_DIR - Location of the header files +# pystring_VERSION - Library's version # -# Targets defined by this module: +# Global targets defined by this module: # pystring::pystring - IMPORTED target, if found # -# If pystring is not installed in a standard path, you can use the -# pystring_ROOT variable to tell CMake where to find it. If it is not found -# and OCIO_INSTALL_EXT_PACKAGES is set to MISSING or ALL, pystring will be -# downloaded, built, and statically-linked into libOpenColorIO at build time. +# Usually CMake will use the dynamic library rather than static, if both are present. +# +# If the library is not installed in a typical location where CMake will find it, you may specify +# the location using one of the following methods: +# -- Set -Dpystring_ROOT to point to the directory containing the lib and include directories. +# -- Set -Dpystring_LIBRARY and -Dpystring_INCLUDE_DIR to point to the lib and include directories. # -if(NOT TARGET pystring::pystring) - add_library(pystring::pystring UNKNOWN IMPORTED GLOBAL) - set(_pystring_TARGET_CREATE TRUE) -endif() ############################################################################### ### Try to find package ### @@ -64,96 +63,11 @@ if(NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL ALL) endif() ############################################################################### -### Install package from source ### - -if(NOT pystring_FOUND AND OCIO_INSTALL_EXT_PACKAGES AND NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL NONE) - include(ExternalProject) - - set(_EXT_DIST_ROOT "${CMAKE_BINARY_DIR}/ext/dist") - set(_EXT_BUILD_ROOT "${CMAKE_BINARY_DIR}/ext/build") - - # Set find_package standard args - set(pystring_FOUND TRUE) - set(pystring_VERSION ${pystring_FIND_VERSION}) - set(pystring_INCLUDE_DIR "${_EXT_DIST_ROOT}/${CMAKE_INSTALL_INCLUDEDIR}") - - set(pystring_LIBRARY - "${_EXT_DIST_ROOT}/${CMAKE_INSTALL_LIBDIR}/${CMAKE_STATIC_LIBRARY_PREFIX}pystring${CMAKE_STATIC_LIBRARY_SUFFIX}") - - if(_pystring_TARGET_CREATE) - if(MSVC) - set(pystring_CXX_FLAGS "${pystring_CXX_FLAGS} /EHsc") - endif() - - string(STRIP "${pystring_CXX_FLAGS}" pystring_CXX_FLAGS) - - set(pystring_CMAKE_ARGS - ${pystring_CMAKE_ARGS} - -DCMAKE_CXX_VISIBILITY_PRESET=${CMAKE_CXX_VISIBILITY_PRESET} - -DCMAKE_VISIBILITY_INLINES_HIDDEN=${CMAKE_VISIBILITY_INLINES_HIDDEN} - -DCMAKE_POSITION_INDEPENDENT_CODE=ON - -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} - -DCMAKE_CXX_FLAGS=${pystring_CXX_FLAGS} - -DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD} - -DCMAKE_INSTALL_MESSAGE=${CMAKE_INSTALL_MESSAGE} - -DCMAKE_INSTALL_PREFIX=${_EXT_DIST_ROOT} - -DCMAKE_INSTALL_BINDIR=${CMAKE_INSTALL_BINDIR} - -DCMAKE_INSTALL_LIBDIR=${CMAKE_INSTALL_LIBDIR} - -DCMAKE_INSTALL_INCLUDEDIR=${CMAKE_INSTALL_INCLUDEDIR} - -DCMAKE_OBJECT_PATH_MAX=${CMAKE_OBJECT_PATH_MAX} - ) - - if(CMAKE_TOOLCHAIN_FILE) - set(pystring_CMAKE_ARGS - ${pystring_CMAKE_ARGS} -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}) - endif() - - if(APPLE) - string(REPLACE ";" "$" ESCAPED_CMAKE_OSX_ARCHITECTURES "${CMAKE_OSX_ARCHITECTURES}") - - set(pystring_CMAKE_ARGS - ${pystring_CMAKE_ARGS} - -DCMAKE_OSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET} - -DCMAKE_OSX_ARCHITECTURES=${ESCAPED_CMAKE_OSX_ARCHITECTURES} - ) - endif() - - - if (ANDROID) - set(pystring_CMAKE_ARGS - ${pystring_CMAKE_ARGS} - -DANDROID_PLATFORM=${ANDROID_PLATFORM} - -DANDROID_ABI=${ANDROID_ABI} - -DANDROID_STL=${ANDROID_STL}) - endif() - - # Hack to let imported target be built from ExternalProject_Add - file(MAKE_DIRECTORY ${pystring_INCLUDE_DIR}) - - ExternalProject_Add(pystring_install - GIT_REPOSITORY "https://github.com/imageworks/pystring.git" - GIT_TAG "v${pystring_FIND_VERSION}" - GIT_CONFIG advice.detachedHead=false - GIT_SHALLOW TRUE - PREFIX "${_EXT_BUILD_ROOT}/pystring" - BUILD_BYPRODUCTS ${pystring_LIBRARY} - CMAKE_ARGS ${pystring_CMAKE_ARGS} - EXCLUDE_FROM_ALL TRUE - PATCH_COMMAND - ${CMAKE_COMMAND} -E copy - "${CMAKE_SOURCE_DIR}/share/cmake/projects/Buildpystring.cmake" - "CMakeLists.txt" - BUILD_COMMAND "" - INSTALL_COMMAND - ${CMAKE_COMMAND} --build . - --config ${CMAKE_BUILD_TYPE} - --target install - --parallel - ) +### Configure target ### - add_dependencies(pystring::pystring pystring_install) - message(STATUS "Installing pystring: ${pystring_LIBRARY} (version \"${pystring_VERSION}\")") - endif() +if(pystring_FOUND AND NOT TARGET pystring::pystring) + add_library(pystring::pystring UNKNOWN IMPORTED GLOBAL) + set(_pystring_TARGET_CREATE TRUE) endif() ############################################################################### @@ -166,4 +80,4 @@ if(_pystring_TARGET_CREATE) ) mark_as_advanced(pystring_INCLUDE_DIR pystring_LIBRARY pystring_VERSION) -endif() +endif() \ No newline at end of file diff --git a/share/cmake/modules/Findyaml-cpp.cmake b/share/cmake/modules/Findyaml-cpp.cmake index 59558ce6a9..55e25e2c84 100644 --- a/share/cmake/modules/Findyaml-cpp.cmake +++ b/share/cmake/modules/Findyaml-cpp.cmake @@ -1,25 +1,27 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright Contributors to the OpenColorIO Project. # -# Locate or install yaml-cpp +# Locate yaml-cpp # # Variables defined by this module: -# yaml-cpp_FOUND - If FALSE, do not try to link to yamlcpp -# yaml-cpp_LIBRARY - yaml-cpp library to link to -# yaml-cpp_INCLUDE_DIR - Where to find yaml.h -# yaml-cpp_VERSION - The version of the library +# yaml-cpp_FOUND - Indicate whether the library was found or not +# yaml-cpp_LIBRARY - Path to the library file +# yaml-cpp_INCLUDE_DIR - Location of the header files +# yaml-cpp_VERSION - Library's version # -# Targets defined by this module: -# yaml-cpp - IMPORTED target, if found +# Global targets defined by this module: +# yaml-cpp # -# By default, the dynamic libraries of yaml-cpp will be found. To find the -# static ones instead, you must set the yaml-cpp_STATIC_LIBRARY variable to -# TRUE before calling find_package(yaml-cpp ...). +# Usually CMake will use the dynamic library rather than static, if both are present. +# In this case, you may set yaml-cpp_STATIC_LIBRARY to ON to request use of the static one. +# If only the static library is present (such as when OCIO builds the dependency), then the option +# is not needed. # -# If yaml-cpp is not installed in a standard path, you can use the -# yaml-cpp_ROOT variable to tell CMake where to find it. If it is not found -# and OCIO_INSTALL_EXT_PACKAGES is set to MISSING or ALL, yaml-cpp will be -# downloaded, built, and statically-linked into libOpenColorIO at build time. +# If the library is not installed in a typical location where CMake will find it, you may specify +# the location using one of the following methods: +# -- Set -Dyaml-cpp_DIR to point to the directory containing the CMake configuration file for the package. +# -- Set -Dyaml-cpp_ROOT to point to the directory containing the lib and include directories. +# -- Set -Dyaml-cpp_LIBRARY and -Dyaml-cpp_INCLUDE_DIR to point to the lib and include directories. # ############################################################################### @@ -128,128 +130,13 @@ if(NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL ALL) endif() ############################################################################### -### Create target (if previous 'find_package' call hasn't) ### +### Create target -if(NOT TARGET yaml-cpp) +if(yaml-cpp_FOUND AND NOT TARGET yaml-cpp) add_library(yaml-cpp UNKNOWN IMPORTED GLOBAL) set(_yaml-cpp_TARGET_CREATE TRUE) endif() -############################################################################### -### Install package from source ### - -if(NOT yaml-cpp_FOUND AND OCIO_INSTALL_EXT_PACKAGES AND NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL NONE) - include(ExternalProject) - include(GNUInstallDirs) - - set(_EXT_DIST_ROOT "${CMAKE_BINARY_DIR}/ext/dist") - set(_EXT_BUILD_ROOT "${CMAKE_BINARY_DIR}/ext/build") - - # Set find_package standard args - set(yaml-cpp_FOUND TRUE) - set(yaml-cpp_VERSION ${yaml-cpp_FIND_VERSION}) - set(yaml-cpp_INCLUDE_DIR "${_EXT_DIST_ROOT}/${CMAKE_INSTALL_INCLUDEDIR}") - - # Starting from 0.7.0, this is included on all platforms, we could also - # override CMAKE_DEBUG_POSTFIX to bypass it. - if(BUILD_TYPE_DEBUG) - string(APPEND _yaml-cpp_LIB_SUFFIX "d") - endif() - - # Set the expected library name - set(yaml-cpp_LIBRARY - "${_EXT_DIST_ROOT}/${CMAKE_INSTALL_LIBDIR}/${CMAKE_STATIC_LIBRARY_PREFIX}yaml-cpp${_yaml-cpp_LIB_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX}") - - if(_yaml-cpp_TARGET_CREATE) - if(MSVC) - set(yaml-cpp_CXX_FLAGS "${yaml-cpp_CXX_FLAGS} /EHsc") - endif() - - if(UNIX) - if(USE_CLANG) - # Remove some global 'shadow' warnings. - set(yaml-cpp_CXX_FLAGS "${yaml-cpp_CXX_FLAGS} -Wno-shadow") - endif() - endif() - - string(STRIP "${yaml-cpp_CXX_FLAGS}" yaml-cpp_CXX_FLAGS) - - set(yaml-cpp_CMAKE_ARGS - ${yaml-cpp_CMAKE_ARGS} - -DCMAKE_POLICY_DEFAULT_CMP0063=NEW - -DCMAKE_CXX_VISIBILITY_PRESET=${CMAKE_CXX_VISIBILITY_PRESET} - -DCMAKE_VISIBILITY_INLINES_HIDDEN=${CMAKE_VISIBILITY_INLINES_HIDDEN} - -DCMAKE_POSITION_INDEPENDENT_CODE=ON - -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} - -DCMAKE_CXX_FLAGS=${yaml-cpp_CXX_FLAGS} - -DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD} - -DCMAKE_INSTALL_MESSAGE=${CMAKE_INSTALL_MESSAGE} - -DCMAKE_INSTALL_PREFIX=${_EXT_DIST_ROOT} - -DCMAKE_INSTALL_BINDIR=${CMAKE_INSTALL_BINDIR} - -DCMAKE_INSTALL_DATADIR=${CMAKE_INSTALL_DATADIR} - -DCMAKE_INSTALL_LIBDIR=${CMAKE_INSTALL_LIBDIR} - -DCMAKE_INSTALL_INCLUDEDIR=${CMAKE_INSTALL_INCLUDEDIR} - -DCMAKE_OBJECT_PATH_MAX=${CMAKE_OBJECT_PATH_MAX} - -DBUILD_SHARED_LIBS=OFF - -DYAML_BUILD_SHARED_LIBS=OFF - -DYAML_CPP_BUILD_TESTS=OFF - -DYAML_CPP_BUILD_TOOLS=OFF - -DYAML_CPP_BUILD_CONTRIB=OFF - ) - - if(CMAKE_TOOLCHAIN_FILE) - set(yaml-cpp_CMAKE_ARGS - ${yaml-cpp_CMAKE_ARGS} -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}) - endif() - - if(APPLE) - string(REPLACE ";" "$" ESCAPED_CMAKE_OSX_ARCHITECTURES "${CMAKE_OSX_ARCHITECTURES}") - - set(yaml-cpp_CMAKE_ARGS - ${yaml-cpp_CMAKE_ARGS} - -DCMAKE_OSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET} - -DCMAKE_OSX_ARCHITECTURES=${ESCAPED_CMAKE_OSX_ARCHITECTURES} - ) - endif() - - - if (ANDROID) - set(yaml-cpp_CMAKE_ARGS - ${yaml-cpp_CMAKE_ARGS} - -DANDROID_PLATFORM=${ANDROID_PLATFORM} - -DANDROID_ABI=${ANDROID_ABI} - -DANDROID_STL=${ANDROID_STL}) - endif() - - set(yaml-cpp_GIT_TAG "yaml-cpp-${yaml-cpp_VERSION}") - - # Hack to let imported target be built from ExternalProject_Add - file(MAKE_DIRECTORY ${yaml-cpp_INCLUDE_DIR}) - - ExternalProject_Add(yaml-cpp_install - GIT_REPOSITORY "https://github.com/jbeder/yaml-cpp.git" - GIT_TAG ${yaml-cpp_GIT_TAG} - GIT_CONFIG advice.detachedHead=false - GIT_SHALLOW TRUE - PREFIX "${_EXT_BUILD_ROOT}/yaml-cpp" - BUILD_BYPRODUCTS ${yaml-cpp_LIBRARY} - CMAKE_ARGS ${yaml-cpp_CMAKE_ARGS} - EXCLUDE_FROM_ALL TRUE - BUILD_COMMAND "" - INSTALL_COMMAND - ${CMAKE_COMMAND} --build . - --config ${CMAKE_BUILD_TYPE} - --target install - --parallel - ) - - add_dependencies(yaml-cpp yaml-cpp_install) - message(STATUS - "Installing yaml-cpp: ${yaml-cpp_LIBRARY} (version \"${yaml-cpp_VERSION}\")" - ) - endif() -endif() - ############################################################################### ### Configure target ### @@ -260,4 +147,4 @@ if(_yaml-cpp_TARGET_CREATE) ) mark_as_advanced(yaml-cpp_INCLUDE_DIR yaml-cpp_LIBRARY yaml-cpp_VERSION) -endif() +endif() \ No newline at end of file diff --git a/share/cmake/modules/install/InstallImath.cmake b/share/cmake/modules/install/InstallImath.cmake new file mode 100644 index 0000000000..4f11d7d0a9 --- /dev/null +++ b/share/cmake/modules/install/InstallImath.cmake @@ -0,0 +1,154 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright Contributors to the OpenColorIO Project. +# +# Install Imath +# +# Variables defined by this module: +# Imath_FOUND - Indicate whether the library was found or not +# Imath_LIBRARY - Path to the library file +# Imath_INCLUDE_DIR - Location of the header files +# Imath_VERSION - Library's version +# +# Global targets defined by this module: +# Imath::Imath +# Imath::ImathConfig +# + + +############################################################################### +### Create target + +if (NOT TARGET Imath::Imath) + add_library(Imath::Imath UNKNOWN IMPORTED GLOBAL) + add_library(Imath::ImathConfig INTERFACE IMPORTED GLOBAL) + set(_Imath_TARGET_CREATE TRUE) +endif() + +############################################################################### +### Install package from source ### + +if(NOT Imath_FOUND AND OCIO_INSTALL_EXT_PACKAGES AND NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL NONE) + include(ExternalProject) + include(GNUInstallDirs) + + set(_EXT_DIST_ROOT "${CMAKE_BINARY_DIR}/ext/dist") + set(_EXT_BUILD_ROOT "${CMAKE_BINARY_DIR}/ext/build") + + # Set find_package standard args + set(Imath_FOUND TRUE) + if(OCIO_Imath_RECOMMENDED_VERSION) + set(Imath_VERSION ${OCIO_Imath_RECOMMENDED_VERSION}) + else() + set(Imath_VERSION ${Imath_FIND_VERSION}) + endif() + set(Imath_INCLUDE_DIR "${_EXT_DIST_ROOT}/${CMAKE_INSTALL_INCLUDEDIR}") + + # Set the expected library name + if(BUILD_TYPE_DEBUG) + set(_Imath_LIB_SUFFIX "_d") + endif() + + include(VersionUtils) + split_version_string(${Imath_VERSION} _Imath_ExternalProject) + + set(_Imath_LIB_VER "${_Imath_ExternalProject_VERSION_MAJOR}_${_Imath_ExternalProject_VERSION_MINOR}") + + set(Imath_LIBRARY + "${_EXT_DIST_ROOT}/${CMAKE_INSTALL_LIBDIR}/${CMAKE_STATIC_LIBRARY_PREFIX}Imath-${_Imath_LIB_VER}${_Imath_LIB_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX}") + + if(_Imath_TARGET_CREATE) + if(MSVC) + set(Imath_CXX_FLAGS "${Imath_CXX_FLAGS} /EHsc") + endif() + + string(STRIP "${Imath_CXX_FLAGS}" Imath_CXX_FLAGS) + + set(Imath_CMAKE_ARGS + ${Imath_CMAKE_ARGS} + -DCMAKE_CXX_VISIBILITY_PRESET=${CMAKE_CXX_VISIBILITY_PRESET} + -DCMAKE_VISIBILITY_INLINES_HIDDEN=${CMAKE_VISIBILITY_INLINES_HIDDEN} + -DCMAKE_POSITION_INDEPENDENT_CODE=ON + -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} + -DCMAKE_CXX_FLAGS=${Imath_CXX_FLAGS} + -DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD} + -DCMAKE_INSTALL_MESSAGE=${CMAKE_INSTALL_MESSAGE} + -DCMAKE_INSTALL_PREFIX=${_EXT_DIST_ROOT} + -DCMAKE_INSTALL_BINDIR=${CMAKE_INSTALL_BINDIR} + -DCMAKE_INSTALL_DATADIR=${CMAKE_INSTALL_DATADIR} + -DCMAKE_INSTALL_LIBDIR=${CMAKE_INSTALL_LIBDIR} + -DCMAKE_INSTALL_INCLUDEDIR=${CMAKE_INSTALL_INCLUDEDIR} + -DCMAKE_OBJECT_PATH_MAX=${CMAKE_OBJECT_PATH_MAX} + -DBUILD_SHARED_LIBS=OFF + -DBUILD_TESTING=OFF + -DPYTHON=OFF + -DDOCS=OFF + -DIMATH_HALF_USE_LOOKUP_TABLE=OFF + ) + + if(CMAKE_TOOLCHAIN_FILE) + set(Imath_CMAKE_ARGS + ${Imath_CMAKE_ARGS} -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}) + endif() + + if(APPLE) + string(REPLACE ";" "$" ESCAPED_CMAKE_OSX_ARCHITECTURES "${CMAKE_OSX_ARCHITECTURES}") + + set(Imath_CMAKE_ARGS + ${Imath_CMAKE_ARGS} + -DCMAKE_OSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET} + -DCMAKE_OSX_ARCHITECTURES=${ESCAPED_CMAKE_OSX_ARCHITECTURES} + ) + endif() + + if (ANDROID) + set(Imath_CMAKE_ARGS + ${Imath_CMAKE_ARGS} + -DANDROID_PLATFORM=${ANDROID_PLATFORM} + -DANDROID_ABI=${ANDROID_ABI} + -DANDROID_STL=${ANDROID_STL}) + endif() + + # Hack to let imported target be built from ExternalProject_Add + file(MAKE_DIRECTORY ${Imath_INCLUDE_DIR}) + + ExternalProject_Add(imath_install + GIT_REPOSITORY "https://github.com/AcademySoftwareFoundation/Imath.git" + GIT_TAG "v${Imath_VERSION}" + GIT_CONFIG advice.detachedHead=false + GIT_SHALLOW TRUE + PREFIX "${_EXT_BUILD_ROOT}/Imath" + BUILD_BYPRODUCTS ${Imath_LIBRARY} + CMAKE_ARGS ${Imath_CMAKE_ARGS} + EXCLUDE_FROM_ALL TRUE + BUILD_COMMAND "" + INSTALL_COMMAND + ${CMAKE_COMMAND} --build . + --config ${CMAKE_BUILD_TYPE} + --target install + --parallel + ) + + add_dependencies(Imath::Imath imath_install) + + if(OCIO_VERBOSE) + message(STATUS "Installing Imath: ${Imath_LIBRARY} (version \"${Imath_VERSION}\")") + endif() + endif() +endif() + +############################################################################### +### Configure target ### + +if(_Imath_TARGET_CREATE) + file(MAKE_DIRECTORY ${Imath_INCLUDE_DIR}/Imath) + + set_target_properties(Imath::Imath PROPERTIES + IMPORTED_LOCATION ${Imath_LIBRARY} + INTERFACE_INCLUDE_DIRECTORIES "${Imath_INCLUDE_DIR};${Imath_INCLUDE_DIR}/Imath" + ) + set_target_properties(Imath::ImathConfig PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${Imath_INCLUDE_DIR};${Imath_INCLUDE_DIR}/Imath" + ) + + mark_as_advanced(Imath_INCLUDE_DIR Imath_LIBRARY Imath_VERSION) +endif() diff --git a/share/cmake/modules/FindOpenEXR.cmake b/share/cmake/modules/install/InstallOpenEXR.cmake similarity index 75% rename from share/cmake/modules/FindOpenEXR.cmake rename to share/cmake/modules/install/InstallOpenEXR.cmake index 426305dab4..419fb4aa59 100644 --- a/share/cmake/modules/FindOpenEXR.cmake +++ b/share/cmake/modules/install/InstallOpenEXR.cmake @@ -1,13 +1,13 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright Contributors to the OpenColorIO Project. # -# Locate or install OpenEXR. +# Install OpenEXR # # Variables defined by this module: -# OpenEXR_FOUND - If FALSE, do not try to link to OpenEXR -# OpenEXR_LIBRARY - OpenEXR library to link to -# OpenEXR_INCLUDE_DIR - Where to find OpenEXR headers -# OpenEXR_VERSION - The version of the library +# OpenEXR_FOUND - Indicate whether the library was found or not +# OpenEXR_LIBRARY - Path to the library file +# OpenEXR_INCLUDE_DIR - Location of the header files +# OpenEXR_VERSION - Library's version # # Imported targets defined by this module, if found: # OpenEXR::Iex @@ -19,51 +19,10 @@ # OpenEXR::OpenEXRCore # OpenEXR::OpenEXRUtil # -# By default, the dynamic libraries of OpenEXR will be found. To find the -# static ones instead, you must set the OpenEXR_STATIC_LIBRARY variable to -# TRUE before calling find_package(OpenEXR ...). +# Depending on user options when configuring OCIO, OpenEXR can be used to +# build libOpenColorIOimageioapphelpers. # -# If OpenEXR is not installed in a standard path, you can use the -# OpenEXR_ROOT variable to tell CMake where to find it. If it is not found -# and OCIO_INSTALL_EXT_PACKAGES is set to MISSING or ALL, OpenEXR will be -# downloaded, statically-built, and used to generate -# libOpenColorIOimageioapphelpers. -# - -############################################################################### -### Try to find package ### - -if(NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL ALL) - set(_OpenEXR_REQUIRED_VARS OpenEXR_LIBRARY) - set(_OpenEXR_LIB_VER "${OpenEXR_FIND_VERSION_MAJOR}_${OpenEXR_FIND_VERSION_MINOR}") - if(NOT DEFINED OpenEXR_ROOT) - # Search for OpenEXRConfig.cmake - find_package(OpenEXR ${OpenEXR_FIND_VERSION} CONFIG QUIET) - endif() - - if(OpenEXR_FOUND) - get_target_property(OpenEXR_LIBRARY OpenEXR::OpenEXR LOCATION) - get_target_property(OpenEXR_INCLUDE_DIR OpenEXR::OpenEXR INTERFACE_INCLUDE_DIRECTORIES) - - # IMPORTED_GLOBAL property must be set to TRUE since alisasing a non-global imported target - # is not possible until CMake 3.18+. - set_target_properties(OpenEXR::OpenEXR PROPERTIES IMPORTED_GLOBAL TRUE) - endif() - - # Override REQUIRED if package can be installed - if(OCIO_INSTALL_EXT_PACKAGES STREQUAL MISSING) - set(OpenEXR_FIND_REQUIRED FALSE) - endif() - - include(FindPackageHandleStandardArgs) - find_package_handle_standard_args(OpenEXR - REQUIRED_VARS - ${_OpenEXR_REQUIRED_VARS} - VERSION_VAR - OpenEXR_VERSION - ) -endif() ############################################################################### ### Create target @@ -89,15 +48,13 @@ if(NOT OpenEXR_FOUND AND OCIO_INSTALL_EXT_PACKAGES AND NOT OCIO_INSTALL_EXT_PACK set(_EXT_BUILD_ROOT "${CMAKE_BINARY_DIR}/ext/build") # Required dependency + # Not trying to find ZLIB here since it is a required dependency of OCIO. if(NOT ZLIB_FOUND) - find_package(ZLIB) - if(NOT ZLIB_FOUND) - message(STATUS "ZLib is required to build OpenEXR.") - return() - endif() + message(STATUS "ZLIB is required to build OpenEXR.") + return() endif() - find_package(Threads) + ocio_handle_dependency(Threads) if(NOT Threads_FOUND) message(STATUS "Threads is required to build OpenEXR.") return() @@ -105,8 +62,8 @@ if(NOT OpenEXR_FOUND AND OCIO_INSTALL_EXT_PACKAGES AND NOT OCIO_INSTALL_EXT_PACK # Set find_package standard args set(OpenEXR_FOUND TRUE) - if(_OpenEXR_ExternalProject_VERSION) - set(OpenEXR_VERSION ${_OpenEXR_ExternalProject_VERSION}) + if(OCIO_OpenEXR_RECOMMENDED_VERSION) + set(OpenEXR_VERSION ${OCIO_OpenEXR_RECOMMENDED_VERSION}) else() set(OpenEXR_VERSION ${OpenEXR_FIND_VERSION}) endif() @@ -118,9 +75,9 @@ if(NOT OpenEXR_FOUND AND OCIO_INSTALL_EXT_PACKAGES AND NOT OCIO_INSTALL_EXT_PACK endif() include(VersionUtils) - split_version_string(${OpenEXR_VERSION} _OpenEXR_ExternalProject) + split_version_string(${OpenEXR_VERSION} _OpenEXR) - set(_OpenEXR_LIB_VER "${_OpenEXR_ExternalProject_VERSION_MAJOR}_${_OpenEXR_ExternalProject_VERSION_MINOR}") + set(_OpenEXR_LIB_VER "${_OpenEXR_VERSION_MAJOR}_${_OpenEXR_VERSION_MINOR}") set_target_location(Iex) set_target_location(IlmThread) @@ -220,7 +177,9 @@ if(NOT OpenEXR_FOUND AND OCIO_INSTALL_EXT_PACKAGES AND NOT OCIO_INSTALL_EXT_PACK add_dependencies(OpenEXR::OpenEXR openexr_install) - message(STATUS "Installing OpenEXR: ${OpenEXR_LIBRARY} (version \"${OpenEXR_VERSION}\")") + if(OCIO_VERBOSE) + message(STATUS "Installing OpenEXR: ${OpenEXR_LIBRARY} (version \"${OpenEXR_VERSION}\")") + endif() endif() endif() diff --git a/share/cmake/modules/InstallZLIB.cmake b/share/cmake/modules/install/InstallZLIB.cmake similarity index 78% rename from share/cmake/modules/InstallZLIB.cmake rename to share/cmake/modules/install/InstallZLIB.cmake index 954563ec4e..6aa3261fb9 100644 --- a/share/cmake/modules/InstallZLIB.cmake +++ b/share/cmake/modules/install/InstallZLIB.cmake @@ -7,17 +7,15 @@ # CMake's FindZLIB when installing ZLIB manually. # # Variables defined by this module: -# ZLIB_FOUND - If FALSE, do not try to link to zlib -# ZLIB_LIBRARIES - ZLIB library to link to -# ZLIB_INCLUDE_DIRS - Where to find zlib.h and other headers -# ZLIB_VERSION - The version of the library +# ZLIB_FOUND - Indicate whether the library was found or not +# ZLIB_LIBRARY - Path to the library file +# ZLIB_INCLUDE_DIR - Location of the header files +# ZLIB_VERSION - Library's version # -# Targets defined by this module: -# ZLIB::ZLIB - Properties: -# IMPORTED_LOCATION ${ZLIB_LIBRARIES} -# INTERFACE_INCLUDE_DIRECTORIES ${ZLIB_INCLUDE_DIRS} +# Global targets defined by this module: +# ZLIB::ZLIB # -############################################################################### + ############################################################################### ### Create target @@ -47,8 +45,8 @@ if(NOT ZLIB_FOUND AND OCIO_INSTALL_EXT_PACKAGES AND NOT OCIO_INSTALL_EXT_PACKAGE # Set find_package standard args set(ZLIB_FOUND TRUE) - if(_ZLIB_ExternalProject_VERSION) - set(ZLIB_VERSION ${_ZLIB_ExternalProject_VERSION}) + if(OCIO_ZLIB_RECOMMENDED_VERSION) + set(ZLIB_VERSION ${OCIO_ZLIB_RECOMMENDED_VERSION}) else() set(ZLIB_VERSION ${ZLIB_FIND_VERSION}) endif() @@ -70,6 +68,10 @@ if(NOT ZLIB_FOUND AND OCIO_INSTALL_EXT_PACKAGES AND NOT OCIO_INSTALL_EXT_PACKAGE if(_ZLIB_TARGET_CREATE) set(ZLIB_CMAKE_ARGS ${ZLIB_CMAKE_ARGS} + # Setting policy CMP0042 when building ZLIB since that project is using an old CMake + # version as the cmake_minimum_required and that version has no knowledge of the policy. + # Since that policy gets unset, it causes a warning with CMake 3.25+. + -DCMAKE_POLICY_DEFAULT_CMP0042=NEW -DCMAKE_CXX_VISIBILITY_PRESET=${CMAKE_CXX_VISIBILITY_PRESET} -DCMAKE_VISIBILITY_INLINES_HIDDEN=${CMAKE_VISIBILITY_INLINES_HIDDEN} -DCMAKE_POSITION_INDEPENDENT_CODE=ON @@ -134,11 +136,17 @@ if(NOT ZLIB_FOUND AND OCIO_INSTALL_EXT_PACKAGES AND NOT OCIO_INSTALL_EXT_PACKAGE add_dependencies(ZLIB::ZLIB ZLIB_install) - # Setting those variables to follow the same naming as the other OCIO custom find modules. - set(ZLIB_LIBRARY ${ZLIB_LIBRARIES}) - set(ZLIB_INCLUDE_DIR ${ZLIB_INCLUDE_DIRS}) - - message(STATUS "Installing ZLIB: ${ZLIB_LIBRARIES} (version \"${ZLIB_VERSION}\")") + # FindZLIB from CMake needs ZLIB_LIBRARY and ZLIB_INCLUDE_DIR. + # Starting CMake 3.17+, The mark_as_advanced() command no longer creates a cache entry if one + # does not already exist. (See policy CMP0102) + # For that reasons, ZLIB_LIBRARY and ZLIB_INCLUDE_DIR are set in the CMake's Cache since ZLIB + # is needed by other OCIO dependencies. + set(ZLIB_LIBRARY ${ZLIB_LIBRARIES} CACHE STRING "ZLIB library file") + set(ZLIB_INCLUDE_DIR ${ZLIB_INCLUDE_DIRS} CACHE STRING "ZLIB includes directory") + + if(OCIO_VERBOSE) + message(STATUS "Installing ZLIB: ${ZLIB_LIBRARIES} (version \"${ZLIB_VERSION}\") ") + endif() endif() diff --git a/share/cmake/modules/install/Installexpat.cmake b/share/cmake/modules/install/Installexpat.cmake new file mode 100644 index 0000000000..3908d60cc9 --- /dev/null +++ b/share/cmake/modules/install/Installexpat.cmake @@ -0,0 +1,161 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright Contributors to the OpenColorIO Project. +# +# Install expat +# +# Variables defined by this module: +# expat_FOUND - Indicate whether the library was found or not +# expat_LIBRARY - Path to the library file +# expat_INCLUDE_DIR - Location of the header files +# expat_VERSION - Library's version +# +# Global targets defined by this module: +# expat::expat +# + + +############################################################################### +### Create target + +if(NOT TARGET expat::expat) + add_library(expat::expat UNKNOWN IMPORTED GLOBAL) + set(_expat_TARGET_CREATE TRUE) +endif() + +############################################################################### +### Install package from source ### + +if(NOT expat_FOUND AND OCIO_INSTALL_EXT_PACKAGES AND NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL NONE) + include(ExternalProject) + include(GNUInstallDirs) + + set(_EXT_DIST_ROOT "${CMAKE_BINARY_DIR}/ext/dist") + set(_EXT_BUILD_ROOT "${CMAKE_BINARY_DIR}/ext/build") + + # Set find_package standard args + set(expat_FOUND TRUE) + if(OCIO_expat_RECOMMENDED_VERSION) + set(expat_VERSION ${OCIO_expat_RECOMMENDED_VERSION}) + else() + set(expat_VERSION ${expat_FIND_VERSION}) + endif() + set(expat_INCLUDE_DIR "${_EXT_DIST_ROOT}/${CMAKE_INSTALL_INCLUDEDIR}") + + # Set the expected library name + if(WIN32) + if(BUILD_TYPE_DEBUG) + set(_expat_LIB_SUFFIX "d") + endif() + # Static Linking, Multi-threaded Dll naming (>=2.2.8): + # https://github.com/libexpat/libexpat/blob/R_2_2_8/expat/win32/README.txt + set(_expat_LIB_SUFFIX "${_expat_LIB_SUFFIX}MD") + endif() + + # Expat use a hardcoded lib prefix instead of CMAKE_STATIC_LIBRARY_PREFIX + # https://github.com/libexpat/libexpat/blob/R_2_4_1/expat/CMakeLists.txt#L374 + set(_expat_LIB_PREFIX "lib") + + set(expat_LIBRARY + "${_EXT_DIST_ROOT}/${CMAKE_INSTALL_LIBDIR}/${_expat_LIB_PREFIX}expat${_expat_LIB_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX}") + + if(_expat_TARGET_CREATE) + if(MSVC) + set(EXPAT_C_FLAGS "${EXPAT_C_FLAGS} /EHsc") + set(EXPAT_CXX_FLAGS "${EXPAT_CXX_FLAGS} /EHsc") + endif() + + string(STRIP "${EXPAT_C_FLAGS}" EXPAT_C_FLAGS) + string(STRIP "${EXPAT_CXX_FLAGS}" EXPAT_CXX_FLAGS) + + set(EXPAT_CMAKE_ARGS + ${EXPAT_CMAKE_ARGS} + -DCMAKE_POLICY_DEFAULT_CMP0063=NEW + -DCMAKE_C_VISIBILITY_PRESET=${CMAKE_C_VISIBILITY_PRESET} + -DCMAKE_CXX_VISIBILITY_PRESET=${CMAKE_CXX_VISIBILITY_PRESET} + -DCMAKE_VISIBILITY_INLINES_HIDDEN=${CMAKE_VISIBILITY_INLINES_HIDDEN} + -DCMAKE_POSITION_INDEPENDENT_CODE=ON + -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} + -DCMAKE_C_FLAGS=${EXPAT_C_FLAGS} + -DCMAKE_CXX_FLAGS=${EXPAT_CXX_FLAGS} + -DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD} + -DCMAKE_INSTALL_MESSAGE=${CMAKE_INSTALL_MESSAGE} + -DCMAKE_INSTALL_PREFIX=${_EXT_DIST_ROOT} + -DCMAKE_INSTALL_BINDIR=${CMAKE_INSTALL_BINDIR} + -DCMAKE_INSTALL_DATADIR=${CMAKE_INSTALL_DATADIR} + -DCMAKE_INSTALL_LIBDIR=${CMAKE_INSTALL_LIBDIR} + -DCMAKE_INSTALL_INCLUDEDIR=${CMAKE_INSTALL_INCLUDEDIR} + -DCMAKE_OBJECT_PATH_MAX=${CMAKE_OBJECT_PATH_MAX} + -DEXPAT_BUILD_DOCS=OFF + -DEXPAT_BUILD_EXAMPLES=OFF + -DEXPAT_BUILD_TESTS=OFF + -DEXPAT_BUILD_TOOLS=OFF + -DEXPAT_SHARED_LIBS=OFF + ) + + if(CMAKE_TOOLCHAIN_FILE) + set(EXPAT_CMAKE_ARGS + ${EXPAT_CMAKE_ARGS} -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}) + endif() + + if(APPLE) + string(REPLACE ";" "$" ESCAPED_CMAKE_OSX_ARCHITECTURES "${CMAKE_OSX_ARCHITECTURES}") + + set(EXPAT_CMAKE_ARGS + ${EXPAT_CMAKE_ARGS} + -DCMAKE_OSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET} + -DCMAKE_OSX_ARCHITECTURES=${ESCAPED_CMAKE_OSX_ARCHITECTURES} + ) + endif() + + if (ANDROID) + set(EXPAT_CMAKE_ARGS + ${EXPAT_CMAKE_ARGS} + -DANDROID_PLATFORM=${ANDROID_PLATFORM} + -DANDROID_ABI=${ANDROID_ABI} + -DANDROID_STL=${ANDROID_STL}) + endif() + + # Hack to let imported target be built from ExternalProject_Add + file(MAKE_DIRECTORY ${expat_INCLUDE_DIR}) + + string(REPLACE "." ";" VERSION_LIST ${expat_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) + + ExternalProject_Add(expat_install + GIT_REPOSITORY "https://github.com/libexpat/libexpat.git" + GIT_TAG "R_${expat_VERSION_MAJOR}_${expat_VERSION_MINOR}_${expat_VERSION_PATCH}" + GIT_CONFIG advice.detachedHead=false + GIT_SHALLOW TRUE + PREFIX "${_EXT_BUILD_ROOT}/libexpat" + BUILD_BYPRODUCTS ${expat_LIBRARY} + SOURCE_SUBDIR expat + CMAKE_ARGS ${EXPAT_CMAKE_ARGS} + EXCLUDE_FROM_ALL TRUE + BUILD_COMMAND "" + INSTALL_COMMAND + ${CMAKE_COMMAND} --build . + --config ${CMAKE_BUILD_TYPE} + --target install + --parallel + ) + + add_dependencies(expat::expat expat_install) + if(OCIO_VERBOSE) + message(STATUS "Installing expat: ${expat_LIBRARY} (version \"${expat_VERSION}\")") + endif() + endif() +endif() + +############################################################################### +### Configure target ### + +if(_expat_TARGET_CREATE) + set_target_properties(expat::expat PROPERTIES + IMPORTED_LOCATION ${expat_LIBRARY} + INTERFACE_INCLUDE_DIRECTORIES ${expat_INCLUDE_DIR} + ) + + mark_as_advanced(expat_INCLUDE_DIR expat_LIBRARY expat_VERSION) +endif() diff --git a/share/cmake/modules/install/Installlcms2.cmake b/share/cmake/modules/install/Installlcms2.cmake new file mode 100644 index 0000000000..94303df7a5 --- /dev/null +++ b/share/cmake/modules/install/Installlcms2.cmake @@ -0,0 +1,142 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright Contributors to the OpenColorIO Project. +# +# Install lcms2 +# +# Variables defined by this module: +# lcms2_FOUND - Indicate whether the library was found or not +# lcms2_LIBRARY - Path to the library file +# lcms2_INCLUDE_DIR - Location of the header files +# lcms2_VERSION - Library's version +# +# Global targets defined by this module: +# lcms2::lcms2 +# + + +############################################################################### +### Configure target ### + +if(NOT TARGET lcms2::lcms2) + add_library(lcms2::lcms2 UNKNOWN IMPORTED GLOBAL) + set(_lcms2_TARGET_CREATE TRUE) +endif() + +############################################################################### +### Install package from source ### + +if(NOT lcms2_FOUND AND OCIO_INSTALL_EXT_PACKAGES AND NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL NONE) + include(ExternalProject) + + set(_EXT_DIST_ROOT "${CMAKE_BINARY_DIR}/ext/dist") + set(_EXT_BUILD_ROOT "${CMAKE_BINARY_DIR}/ext/build") + + # Set find_package standard args + set(lcms2_FOUND TRUE) + if(OCIO_lcms2_RECOMMENDED_VERSION) + set(lcms2_VERSION ${OCIO_lcms2_RECOMMENDED_VERSION}) + else() + set(lcms2_VERSION ${lcms2_FIND_VERSION}) + endif() + set(lcms2_INCLUDE_DIR "${_EXT_DIST_ROOT}/${CMAKE_INSTALL_INCLUDEDIR}/lcms2") + set(lcms2_LIBRARY + "${_EXT_DIST_ROOT}/${CMAKE_INSTALL_LIBDIR}/${CMAKE_STATIC_LIBRARY_PREFIX}lcms2${CMAKE_STATIC_LIBRARY_SUFFIX}") + + if(_lcms2_TARGET_CREATE) + if(UNIX) + set(lcms2_C_FLAGS "${lcms2_C_FLAGS} -fvisibility=hidden -fPIC") + endif() + + if("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") + set(lcms2_C_FLAGS "${lcms2_C_FLAGS} -Wno-aggressive-loop-optimizations") + endif() + + string(STRIP "${lcms2_C_FLAGS}" lcms2_C_FLAGS) + + # NOTE: Depending of the compiler version lcm2 2.2 does not compile with C++17 so revert + # to C++11 because the library is only used by a cmd line tool. + + set(lcms2_CXX_STANDARD ${CMAKE_CXX_STANDARD}) + if(${CMAKE_CXX_STANDARD} GREATER_EQUAL 17) + set(lcms2_CXX_STANDARD 11) + endif() + + set(lcms2_CMAKE_ARGS + ${lcms2_CMAKE_ARGS} + -DCMAKE_C_FLAGS=${lcms2_C_FLAGS} + -DCMAKE_CXX_STANDARD=${lcms2_CXX_STANDARD} + -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} + -DCMAKE_INSTALL_MESSAGE=${CMAKE_INSTALL_MESSAGE} + -DCMAKE_INSTALL_PREFIX=${_EXT_DIST_ROOT} + -DCMAKE_INSTALL_BINDIR=${CMAKE_INSTALL_BINDIR} + -DCMAKE_INSTALL_LIBDIR=${CMAKE_INSTALL_LIBDIR} + -DCMAKE_INSTALL_INCLUDEDIR=${CMAKE_INSTALL_INCLUDEDIR} + -DCMAKE_OBJECT_PATH_MAX=${CMAKE_OBJECT_PATH_MAX} + -DBUILD_SHARED_LIBS=OFF + ) + + if(CMAKE_TOOLCHAIN_FILE) + set(lcms2_CMAKE_ARGS + ${lcms2_CMAKE_ARGS} -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}) + endif() + + if(APPLE) + string(REPLACE ";" "$" ESCAPED_CMAKE_OSX_ARCHITECTURES "${CMAKE_OSX_ARCHITECTURES}") + + set(lcms2_CMAKE_ARGS + ${lcms2_CMAKE_ARGS} + -DCMAKE_OSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET} + -DCMAKE_OSX_ARCHITECTURES=${ESCAPED_CMAKE_OSX_ARCHITECTURES} + ) + endif() + + if (ANDROID) + set(lcms2_CMAKE_ARGS + ${lcms2_CMAKE_ARGS} + -DANDROID_PLATFORM=${ANDROID_PLATFORM} + -DANDROID_ABI=${ANDROID_ABI} + -DANDROID_STL=${ANDROID_STL}) + endif() + + # Hack to let imported target be built from ExternalProject_Add + file(MAKE_DIRECTORY ${lcms2_INCLUDE_DIR}) + + ExternalProject_Add(lcms2_install + GIT_REPOSITORY "https://github.com/mm2/Little-CMS.git" + GIT_TAG "lcms${lcms2_VERSION}" + GIT_CONFIG advice.detachedHead=false + GIT_SHALLOW TRUE + PREFIX "${_EXT_BUILD_ROOT}/Little-CMS" + BUILD_BYPRODUCTS ${lcms2_LIBRARY} + CMAKE_ARGS ${lcms2_CMAKE_ARGS} + EXCLUDE_FROM_ALL TRUE + PATCH_COMMAND + ${CMAKE_COMMAND} -E copy + "${CMAKE_SOURCE_DIR}/share/cmake/projects/Buildlcms2.cmake" + "CMakeLists.txt" + BUILD_COMMAND "" + INSTALL_COMMAND + ${CMAKE_COMMAND} --build . + --config ${CMAKE_BUILD_TYPE} + --target install + --parallel + ) + + add_dependencies(lcms2::lcms2 lcms2_install) + if(OCIO_VERBOSE) + message(STATUS "Installing lcms2: ${lcms2_LIBRARY} (version \"${lcms2_VERSION}\")") + endif() + endif() +endif() + +############################################################################### +### Configure target ### + +if(_lcms2_TARGET_CREATE) + set_target_properties(lcms2::lcms2 PROPERTIES + IMPORTED_LOCATION ${lcms2_LIBRARY} + INTERFACE_INCLUDE_DIRECTORIES ${lcms2_INCLUDE_DIR} + ) + + mark_as_advanced(lcms2_INCLUDE_DIR lcms2_LIBRARY lcms2_VERSION) +endif() \ No newline at end of file diff --git a/share/cmake/modules/install/Installminizip-ng.cmake b/share/cmake/modules/install/Installminizip-ng.cmake new file mode 100644 index 0000000000..6cbc1e39bd --- /dev/null +++ b/share/cmake/modules/install/Installminizip-ng.cmake @@ -0,0 +1,154 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright Contributors to the OpenColorIO Project. +# +# Install minizip-ng +# +# Variables defined by this module: +# minizip-ng_FOUND - Indicate whether the library was found or not +# minizip-ng_LIBRARY - Path to the library file +# minizip-ng_INCLUDE_DIR - Location of the header files +# minizip-ng_VERSION - Library's version +# +# Global targets defined by this module: +# minizip-ng::minizip-ng +# +# Link against the following target: +# ZLIB::ZLIB +# + + +############################################################################### +### Create target +if(NOT TARGET MINIZIP::minizip-ng) + add_library(MINIZIP::minizip-ng UNKNOWN IMPORTED GLOBAL) + set(_minizip-ng_TARGET_CREATE TRUE) +endif() + +############################################################################### +### Install package from source ### + +if(NOT minizip-ng_FOUND AND OCIO_INSTALL_EXT_PACKAGES AND NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL NONE) + include(ExternalProject) + include(GNUInstallDirs) + + set(_EXT_DIST_ROOT "${CMAKE_BINARY_DIR}/ext/dist") + set(_EXT_BUILD_ROOT "${CMAKE_BINARY_DIR}/ext/build") + + # Set find_package standard args + set(minizip-ng_FOUND TRUE) + if(OCIO_minizip-ng_RECOMMENDED_VERSION) + set(minizip-ng_VERSION ${OCIO_minizip-ng_RECOMMENDED_VERSION}) + else() + set(minizip-ng_VERSION ${minizip-ng_FIND_VERSION}) + endif() + + set(minizip-ng_INCLUDE_DIR "${_EXT_DIST_ROOT}/${CMAKE_INSTALL_INCLUDEDIR}/minizip-ng") + + # Minizip-ng use a hardcoded lib prefix instead of CMAKE_STATIC_LIBRARY_PREFIX + set(_minizip-ng_LIB_PREFIX "lib") + + set(minizip-ng_LIBRARY + "${_EXT_DIST_ROOT}/${CMAKE_INSTALL_LIBDIR}/${_minizip-ng_LIB_PREFIX}minizip-ng${_minizip-ng_LIB_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX}") + + if(_minizip-ng_TARGET_CREATE) + set(minizip-ng_CMAKE_ARGS + ${minizip-ng_CMAKE_ARGS} + -DCMAKE_CXX_VISIBILITY_PRESET=${CMAKE_CXX_VISIBILITY_PRESET} + -DCMAKE_VISIBILITY_INLINES_HIDDEN=${CMAKE_VISIBILITY_INLINES_HIDDEN} + -DCMAKE_POSITION_INDEPENDENT_CODE=ON + -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} + -DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD} + -DCMAKE_INSTALL_MESSAGE=${CMAKE_INSTALL_MESSAGE} + -DCMAKE_INSTALL_PREFIX=${_EXT_DIST_ROOT} + -DCMAKE_INSTALL_BINDIR=${CMAKE_INSTALL_BINDIR} + -DCMAKE_INSTALL_DATADIR=${CMAKE_INSTALL_DATADIR} + -DCMAKE_INSTALL_LIBDIR=${CMAKE_INSTALL_LIBDIR} + # 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. + -DCMAKE_INSTALL_INCLUDEDIR=${CMAKE_INSTALL_INCLUDEDIR}/minizip-ng + -DCMAKE_OBJECT_PATH_MAX=${CMAKE_OBJECT_PATH_MAX} + -DBUILD_SHARED_LIBS=OFF + -DMZ_OPENSSL=OFF + -DMZ_LIBBSD=OFF + -DMZ_BUILD_TESTS=OFF + -DMZ_COMPAT=OFF + -DMZ_BZIP2=OFF + -DMZ_LZMA=OFF + -DMZ_LIBCOMP=OFF + -DMZ_ZSTD=OFF + -DMZ_PKCRYPT=OFF + -DMZ_WZAES=OFF + -DMZ_SIGNING=OFF + -DMZ_ZLIB=ON + -DMZ_ICONV=OFF + -DMZ_FETCH_LIBS=OFF + -DMZ_FORCE_FETCH_LIBS=OFF + -DZLIB_LIBRARY=${ZLIB_LIBRARIES} + -DZLIB_INCLUDE_DIR=${ZLIB_INCLUDE_DIRS} + ) + + if(CMAKE_TOOLCHAIN_FILE) + set(minizip-ng_CMAKE_ARGS + ${minizip-ng_CMAKE_ARGS} -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}) + endif() + + if(APPLE) + string(REPLACE ";" "$" ESCAPED_CMAKE_OSX_ARCHITECTURES "${CMAKE_OSX_ARCHITECTURES}") + + set(minizip-ng_CMAKE_ARGS + ${minizip-ng_CMAKE_ARGS} + -DCMAKE_OSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET} + -DCMAKE_OSX_ARCHITECTURES=${ESCAPED_CMAKE_OSX_ARCHITECTURES} + ) + endif() + + if (ANDROID) + set(minizip-ng_CMAKE_ARGS + ${minizip-ng_CMAKE_ARGS} + -DANDROID_PLATFORM=${ANDROID_PLATFORM} + -DANDROID_ABI=${ANDROID_ABI} + -DANDROID_STL=${ANDROID_STL}) + endif() + endif() + + # Hack to let imported target be built from ExternalProject_Add + file(MAKE_DIRECTORY ${minizip-ng_INCLUDE_DIR}) + + ExternalProject_Add(minizip-ng_install + GIT_REPOSITORY "https://github.com/zlib-ng/minizip-ng.git" + GIT_TAG "${minizip-ng_VERSION}" + GIT_CONFIG advice.detachedHead=false + GIT_SHALLOW TRUE + PREFIX "${_EXT_BUILD_ROOT}/libminizip-ng" + BUILD_BYPRODUCTS ${minizip-ng_LIBRARY} + CMAKE_ARGS ${minizip-ng_CMAKE_ARGS} + EXCLUDE_FROM_ALL TRUE + BUILD_COMMAND "" + INSTALL_COMMAND + ${CMAKE_COMMAND} --build . + --config ${CMAKE_BUILD_TYPE} + --target install + --parallel + ) + + add_dependencies(MINIZIP::minizip-ng minizip-ng_install) + if(OCIO_VERBOSE) + message(STATUS "Installing minizip-ng: ${minizip-ng_LIBRARY} (version \"${minizip-ng_VERSION}\")") + endif() +endif() + +############################################################################### +### Configure target ### + +if(_minizip-ng_TARGET_CREATE) + set_target_properties(MINIZIP::minizip-ng PROPERTIES + IMPORTED_LOCATION "${minizip-ng_LIBRARY}" + INTERFACE_INCLUDE_DIRECTORIES "${minizip-ng_INCLUDE_DIR}" + ) + + mark_as_advanced(minizip-ng_INCLUDE_DIR minizip-ng_LIBRARY minizip-ng_VERSION) + + target_link_libraries(MINIZIP::minizip-ng INTERFACE ZLIB::ZLIB) +endif() \ No newline at end of file diff --git a/share/cmake/modules/install/Installopenfx.cmake b/share/cmake/modules/install/Installopenfx.cmake new file mode 100644 index 0000000000..36457f346f --- /dev/null +++ b/share/cmake/modules/install/Installopenfx.cmake @@ -0,0 +1,86 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright Contributors to the OpenColorIO Project. +# +# Install openfx +# +# Variables defined by this module: +# openfx_FOUND - Indicate whether the library was found or not +# openfx_INCLUDE_DIR - Location of the header files +# openfx_VERSION - Library's version +# +# Global targets defined by this module: +# openfx::module +# + + +############################################################################### +### Create target + +if(NOT TARGET openfx::module) + add_library(openfx::module INTERFACE IMPORTED GLOBAL) + set(_openfx_TARGET_CREATE TRUE) +endif() + +############################################################################### +### Install package from source ### + +if(NOT openfx_FOUND AND OCIO_INSTALL_EXT_PACKAGES AND NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL NONE) + include(ExternalProject) + include(GNUInstallDirs) + + set(_EXT_DIST_ROOT "${CMAKE_BINARY_DIR}/ext/dist") + set(_EXT_BUILD_ROOT "${CMAKE_BINARY_DIR}/ext/build") + set(_openfx_INSTALL_DIR "${_EXT_BUILD_ROOT}/openfx/src/openfx_install") + + # Set find_package standard args + set(openfx_FOUND TRUE) + if(OCIO_openfx_RECOMMENDED_VERSION) + set(openfx_VERSION ${OCIO_openfx_RECOMMENDED_VERSION}) + else() + set(openfx_VERSION ${openfx_FIND_VERSION}) + endif() + set(openfx_INCLUDE_DIR "${_EXT_DIST_ROOT}/${CMAKE_INSTALL_INCLUDEDIR}/openfx") + + if(_openfx_TARGET_CREATE) + # Hack to let imported target be built from ExternalProject_Add + file(MAKE_DIRECTORY ${openfx_INCLUDE_DIR}) + + include(VersionUtils) + split_version_string(${openfx_VERSION} openfx) + + ExternalProject_Add(openfx_install + GIT_REPOSITORY "https://github.com/ofxa/openfx.git" + # The latest version from 2015 is OFX_Release_1_4_TAG. + # Need to be careful since older version might have the patch number in the tag. + GIT_TAG "OFX_Release_${openfx_VERSION_MAJOR}_${openfx_VERSION_MINOR}_TAG" + GIT_CONFIG advice.detachedHead=false + GIT_SHALLOW TRUE + PREFIX "${_EXT_BUILD_ROOT}/openfx" + BUILD_BYPRODUCTS ${openfx_INCLUDE_DIR} + CONFIGURE_COMMAND "" + BUILD_COMMAND + ${CMAKE_COMMAND} -E copy_directory + "${_EXT_BUILD_ROOT}/openfx/src/openfx_install/include" + "${openfx_INCLUDE_DIR}" + INSTALL_COMMAND "" + CMAKE_ARGS ${openfx_CMAKE_ARGS} + EXCLUDE_FROM_ALL TRUE + ) + + add_dependencies(openfx::module openfx_install) + if(OCIO_VERBOSE) + message(STATUS "Installing openfx: ${openfx_INCLUDE_DIR} (version \"${openfx_VERSION}\")") + endif() + endif() +endif() + +############################################################################### +### Configure target ### + +if(_openfx_TARGET_CREATE) + set_target_properties(openfx::module PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${openfx_INCLUDE_DIR} + ) + + mark_as_advanced(openfx_INCLUDE_DIR) +endif() diff --git a/share/cmake/modules/install/Installpybind11.cmake b/share/cmake/modules/install/Installpybind11.cmake new file mode 100644 index 0000000000..9103c215cc --- /dev/null +++ b/share/cmake/modules/install/Installpybind11.cmake @@ -0,0 +1,122 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright Contributors to the OpenColorIO Project. +# +# Install pybind11 +# +# Variables defined by this module: +# pybind11_FOUND - Indicate whether the library was found or not +# pybind11_INCLUDE_DIR - Location of the header files +# pybind11_VERSION - Library's version +# +# Global targets defined by this module: +# pybind11::module +# + + +############################################################################### +### Create target ### + +if(NOT TARGET pybind11::module) + add_library(pybind11::module INTERFACE IMPORTED GLOBAL) + set(_pybind11_TARGET_CREATE TRUE) +endif() + +############################################################################### +### Install package from source ### + +if(NOT pybind11_FOUND AND OCIO_INSTALL_EXT_PACKAGES AND NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL NONE) + include(ExternalProject) + include(GNUInstallDirs) + + set(_EXT_DIST_ROOT "${CMAKE_BINARY_DIR}/ext/dist") + set(_EXT_BUILD_ROOT "${CMAKE_BINARY_DIR}/ext/build") + + # Set find_package standard args + set(pybind11_FOUND TRUE) + if(OCIO_pybind11_RECOMMENDED_VERSION) + set(pybind11_VERSION ${OCIO_pybind11_RECOMMENDED_VERSION}) + else() + set(pybind11_VERSION ${pybind11_FIND_VERSION}) + endif() + set(pybind11_INCLUDE_DIR "${_EXT_DIST_ROOT}/${CMAKE_INSTALL_INCLUDEDIR}") + + if(_pybind11_TARGET_CREATE) + # Hack to let imported target be built from ExternalProject_Add + file(MAKE_DIRECTORY ${pybind11_INCLUDE_DIR}) + + set(pybind11_CMAKE_ARGS + ${pybind11_CMAKE_ARGS} + -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} + -DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD} + -DCMAKE_INSTALL_MESSAGE=${CMAKE_INSTALL_MESSAGE} + -DCMAKE_INSTALL_PREFIX=${_EXT_DIST_ROOT} + -DCMAKE_INSTALL_BINDIR=${CMAKE_INSTALL_BINDIR} + -DCMAKE_INSTALL_DATADIR=${CMAKE_INSTALL_DATADIR} + -DCMAKE_INSTALL_LIBDIR=${CMAKE_INSTALL_LIBDIR} + -DCMAKE_INSTALL_INCLUDEDIR=${CMAKE_INSTALL_INCLUDEDIR} + -DCMAKE_OBJECT_PATH_MAX=${CMAKE_OBJECT_PATH_MAX} + # Using FindPython mode (PYBIND11_FINDPYTHON=ON) doesn't seem to + # work when building on docker manylinux images where Development + # component is not available but is hardcoded in pybind11 script. + -DPYTHON_EXECUTABLE=${Python_EXECUTABLE} + -DPYBIND11_INSTALL=ON + -DPYBIND11_TEST=OFF + ) + + if(CMAKE_TOOLCHAIN_FILE) + set(pybind11_CMAKE_ARGS + ${pybind11_CMAKE_ARGS} -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}) + endif() + + if(APPLE) + string(REPLACE ";" "$" ESCAPED_CMAKE_OSX_ARCHITECTURES "${CMAKE_OSX_ARCHITECTURES}") + + set(pybind11_CMAKE_ARGS + ${pybind11_CMAKE_ARGS} + -DCMAKE_OSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET} + -DCMAKE_OSX_ARCHITECTURES=${ESCAPED_CMAKE_OSX_ARCHITECTURES} + ) + endif() + + if (ANDROID) + set(pybind11_CMAKE_ARGS + ${pybind11_CMAKE_ARGS} + -DANDROID_PLATFORM=${ANDROID_PLATFORM} + -DANDROID_ABI=${ANDROID_ABI} + -DANDROID_STL=${ANDROID_STL}) + endif() + + ExternalProject_Add(pybind11_install + GIT_REPOSITORY "https://github.com/pybind/pybind11.git" + GIT_TAG "v${pybind11_VERSION}" + GIT_CONFIG advice.detachedHead=false + GIT_SHALLOW TRUE + PREFIX "${_EXT_BUILD_ROOT}/pybind11" + BUILD_BYPRODUCTS ${pybind11_INCLUDE_DIR} + CMAKE_ARGS ${pybind11_CMAKE_ARGS} + EXCLUDE_FROM_ALL TRUE + BUILD_COMMAND "" + INSTALL_COMMAND + ${CMAKE_COMMAND} --build . + --config ${CMAKE_BUILD_TYPE} + --target install + --parallel + ) + + add_dependencies(pybind11::module pybind11_install) + if(OCIO_VERBOSE) + message(STATUS "Installing pybind11: ${pybind11_INCLUDE_DIR} (version \"${pybind11_VERSION}\")") + endif() + endif() +endif() + +############################################################################### +### Configure target ### + +if(_pybind11_TARGET_CREATE) + set_target_properties(pybind11::module PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${pybind11_INCLUDE_DIR} + ) + + mark_as_advanced(pybind11_INCLUDE_DIR pybind11_VERSION) +endif() \ No newline at end of file diff --git a/share/cmake/modules/install/Installpystring.cmake b/share/cmake/modules/install/Installpystring.cmake new file mode 100644 index 0000000000..f60f490cde --- /dev/null +++ b/share/cmake/modules/install/Installpystring.cmake @@ -0,0 +1,134 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright Contributors to the OpenColorIO Project. +# +# Install pystring +# +# Variables defined by this module: +# pystring_FOUND - Indicate whether the library was found or not +# pystring_LIBRARY - Path to the library file +# pystring_INCLUDE_DIR - Location of the header files +# pystring_VERSION - Library's version +# +# Global targets defined by this module: +# pystring::pystring +# + + +############################################################################### +### Configure target ### + +if(NOT TARGET pystring::pystring) + add_library(pystring::pystring UNKNOWN IMPORTED GLOBAL) + set(_pystring_TARGET_CREATE TRUE) +endif() + +############################################################################### +### Install package from source ### + +if(NOT pystring_FOUND AND OCIO_INSTALL_EXT_PACKAGES AND NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL NONE) + include(ExternalProject) + + set(_EXT_DIST_ROOT "${CMAKE_BINARY_DIR}/ext/dist") + set(_EXT_BUILD_ROOT "${CMAKE_BINARY_DIR}/ext/build") + + # Set find_package standard args + set(pystring_FOUND TRUE) + if(OCIO_pystring_RECOMMENDED_VERSION) + set(pystring_VERSION ${OCIO_pystring_RECOMMENDED_VERSION}) + else() + set(pystring_VERSION ${pystring_FIND_VERSION}) + endif() + set(pystring_INCLUDE_DIR "${_EXT_DIST_ROOT}/${CMAKE_INSTALL_INCLUDEDIR}") + + set(pystring_LIBRARY + "${_EXT_DIST_ROOT}/${CMAKE_INSTALL_LIBDIR}/${CMAKE_STATIC_LIBRARY_PREFIX}pystring${CMAKE_STATIC_LIBRARY_SUFFIX}") + + if(_pystring_TARGET_CREATE) + if(MSVC) + set(pystring_CXX_FLAGS "${pystring_CXX_FLAGS} /EHsc") + endif() + + string(STRIP "${pystring_CXX_FLAGS}" pystring_CXX_FLAGS) + + set(pystring_CMAKE_ARGS + ${pystring_CMAKE_ARGS} + -DCMAKE_CXX_VISIBILITY_PRESET=${CMAKE_CXX_VISIBILITY_PRESET} + -DCMAKE_VISIBILITY_INLINES_HIDDEN=${CMAKE_VISIBILITY_INLINES_HIDDEN} + -DCMAKE_POSITION_INDEPENDENT_CODE=ON + -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} + -DCMAKE_CXX_FLAGS=${pystring_CXX_FLAGS} + -DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD} + -DCMAKE_INSTALL_MESSAGE=${CMAKE_INSTALL_MESSAGE} + -DCMAKE_INSTALL_PREFIX=${_EXT_DIST_ROOT} + -DCMAKE_INSTALL_BINDIR=${CMAKE_INSTALL_BINDIR} + -DCMAKE_INSTALL_LIBDIR=${CMAKE_INSTALL_LIBDIR} + -DCMAKE_INSTALL_INCLUDEDIR=${CMAKE_INSTALL_INCLUDEDIR} + -DCMAKE_OBJECT_PATH_MAX=${CMAKE_OBJECT_PATH_MAX} + ) + + if(CMAKE_TOOLCHAIN_FILE) + set(pystring_CMAKE_ARGS + ${pystring_CMAKE_ARGS} -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}) + endif() + + if(APPLE) + string(REPLACE ";" "$" ESCAPED_CMAKE_OSX_ARCHITECTURES "${CMAKE_OSX_ARCHITECTURES}") + + set(pystring_CMAKE_ARGS + ${pystring_CMAKE_ARGS} + -DCMAKE_OSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET} + -DCMAKE_OSX_ARCHITECTURES=${ESCAPED_CMAKE_OSX_ARCHITECTURES} + ) + endif() + + + if (ANDROID) + set(pystring_CMAKE_ARGS + ${pystring_CMAKE_ARGS} + -DANDROID_PLATFORM=${ANDROID_PLATFORM} + -DANDROID_ABI=${ANDROID_ABI} + -DANDROID_STL=${ANDROID_STL}) + endif() + + # Hack to let imported target be built from ExternalProject_Add + file(MAKE_DIRECTORY ${pystring_INCLUDE_DIR}) + + ExternalProject_Add(pystring_install + GIT_REPOSITORY "https://github.com/imageworks/pystring.git" + GIT_TAG "v${pystring_VERSION}" + GIT_CONFIG advice.detachedHead=false + GIT_SHALLOW TRUE + PREFIX "${_EXT_BUILD_ROOT}/pystring" + BUILD_BYPRODUCTS ${pystring_LIBRARY} + CMAKE_ARGS ${pystring_CMAKE_ARGS} + EXCLUDE_FROM_ALL TRUE + PATCH_COMMAND + ${CMAKE_COMMAND} -E copy + "${CMAKE_SOURCE_DIR}/share/cmake/projects/Buildpystring.cmake" + "CMakeLists.txt" + BUILD_COMMAND "" + INSTALL_COMMAND + ${CMAKE_COMMAND} --build . + --config ${CMAKE_BUILD_TYPE} + --target install + --parallel + ) + + add_dependencies(pystring::pystring pystring_install) + if(OCIO_VERBOSE) + message(STATUS "Installing pystring: ${pystring_LIBRARY} (version \"${pystring_VERSION}\")") + endif() + endif() +endif() + +############################################################################### +### Configure target ### + +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() diff --git a/share/cmake/modules/install/Installyaml-cpp.cmake b/share/cmake/modules/install/Installyaml-cpp.cmake new file mode 100644 index 0000000000..f58ff12b3a --- /dev/null +++ b/share/cmake/modules/install/Installyaml-cpp.cmake @@ -0,0 +1,153 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright Contributors to the OpenColorIO Project. +# +# Install yaml-cpp +# +# Variables defined by this module: +# yaml-cpp_FOUND - Indicate whether the library was found or not +# yaml-cpp_LIBRARY - Path to the library file +# yaml-cpp_INCLUDE_DIR - Location of the header files +# yaml-cpp_VERSION - Library's version +# +# Global targets defined by this module: +# yaml-cpp::yaml-cpp +# + +############################################################################### +### Create target (if previous 'find_package' call hasn't) ### + +if(NOT TARGET yaml-cpp) + add_library(yaml-cpp UNKNOWN IMPORTED GLOBAL) + set(_yaml-cpp_TARGET_CREATE TRUE) +endif() + +############################################################################### +### Install package from source ### + +if(NOT yaml-cpp_FOUND AND OCIO_INSTALL_EXT_PACKAGES AND NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL NONE) + include(ExternalProject) + include(GNUInstallDirs) + + set(_EXT_DIST_ROOT "${CMAKE_BINARY_DIR}/ext/dist") + set(_EXT_BUILD_ROOT "${CMAKE_BINARY_DIR}/ext/build") + + # Set find_package standard args + set(yaml-cpp_FOUND TRUE) + if(OCIO_yaml-cpp_RECOMMENDED_VERSION) + set(yaml-cpp_VERSION ${OCIO_yaml-cpp_RECOMMENDED_VERSION}) + else() + set(yaml-cpp_VERSION ${yaml-cpp_FIND_VERSION}) + endif() + set(yaml-cpp_INCLUDE_DIR "${_EXT_DIST_ROOT}/${CMAKE_INSTALL_INCLUDEDIR}") + + # Starting from 0.7.0, this is included on all platforms, we could also + # override CMAKE_DEBUG_POSTFIX to bypass it. + if(BUILD_TYPE_DEBUG) + string(APPEND _yaml-cpp_LIB_SUFFIX "d") + endif() + + # Set the expected library name + set(yaml-cpp_LIBRARY + "${_EXT_DIST_ROOT}/${CMAKE_INSTALL_LIBDIR}/${CMAKE_STATIC_LIBRARY_PREFIX}yaml-cpp${_yaml-cpp_LIB_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX}") + + if(_yaml-cpp_TARGET_CREATE) + if(MSVC) + set(yaml-cpp_CXX_FLAGS "${yaml-cpp_CXX_FLAGS} /EHsc") + endif() + + if(UNIX) + if(USE_CLANG) + # Remove some global 'shadow' warnings. + set(yaml-cpp_CXX_FLAGS "${yaml-cpp_CXX_FLAGS} -Wno-shadow") + endif() + endif() + + string(STRIP "${yaml-cpp_CXX_FLAGS}" yaml-cpp_CXX_FLAGS) + + set(yaml-cpp_CMAKE_ARGS + ${yaml-cpp_CMAKE_ARGS} + -DCMAKE_POLICY_DEFAULT_CMP0063=NEW + -DCMAKE_CXX_VISIBILITY_PRESET=${CMAKE_CXX_VISIBILITY_PRESET} + -DCMAKE_VISIBILITY_INLINES_HIDDEN=${CMAKE_VISIBILITY_INLINES_HIDDEN} + -DCMAKE_POSITION_INDEPENDENT_CODE=ON + -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} + -DCMAKE_CXX_FLAGS=${yaml-cpp_CXX_FLAGS} + -DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD} + -DCMAKE_INSTALL_MESSAGE=${CMAKE_INSTALL_MESSAGE} + -DCMAKE_INSTALL_PREFIX=${_EXT_DIST_ROOT} + -DCMAKE_INSTALL_BINDIR=${CMAKE_INSTALL_BINDIR} + -DCMAKE_INSTALL_DATADIR=${CMAKE_INSTALL_DATADIR} + -DCMAKE_INSTALL_LIBDIR=${CMAKE_INSTALL_LIBDIR} + -DCMAKE_INSTALL_INCLUDEDIR=${CMAKE_INSTALL_INCLUDEDIR} + -DCMAKE_OBJECT_PATH_MAX=${CMAKE_OBJECT_PATH_MAX} + -DBUILD_SHARED_LIBS=OFF + -DYAML_BUILD_SHARED_LIBS=OFF + -DYAML_CPP_BUILD_TESTS=OFF + -DYAML_CPP_BUILD_TOOLS=OFF + -DYAML_CPP_BUILD_CONTRIB=OFF + ) + + if(CMAKE_TOOLCHAIN_FILE) + set(yaml-cpp_CMAKE_ARGS + ${yaml-cpp_CMAKE_ARGS} -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}) + endif() + + if(APPLE) + string(REPLACE ";" "$" ESCAPED_CMAKE_OSX_ARCHITECTURES "${CMAKE_OSX_ARCHITECTURES}") + + set(yaml-cpp_CMAKE_ARGS + ${yaml-cpp_CMAKE_ARGS} + -DCMAKE_OSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET} + -DCMAKE_OSX_ARCHITECTURES=${ESCAPED_CMAKE_OSX_ARCHITECTURES} + ) + endif() + + + if (ANDROID) + set(yaml-cpp_CMAKE_ARGS + ${yaml-cpp_CMAKE_ARGS} + -DANDROID_PLATFORM=${ANDROID_PLATFORM} + -DANDROID_ABI=${ANDROID_ABI} + -DANDROID_STL=${ANDROID_STL}) + endif() + + set(yaml-cpp_GIT_TAG "yaml-cpp-${yaml-cpp_VERSION}") + + # Hack to let imported target be built from ExternalProject_Add + file(MAKE_DIRECTORY ${yaml-cpp_INCLUDE_DIR}) + + ExternalProject_Add(yaml-cpp_install + GIT_REPOSITORY "https://github.com/jbeder/yaml-cpp.git" + GIT_TAG ${yaml-cpp_GIT_TAG} + GIT_CONFIG advice.detachedHead=false + GIT_SHALLOW TRUE + PREFIX "${_EXT_BUILD_ROOT}/yaml-cpp" + BUILD_BYPRODUCTS ${yaml-cpp_LIBRARY} + CMAKE_ARGS ${yaml-cpp_CMAKE_ARGS} + EXCLUDE_FROM_ALL TRUE + BUILD_COMMAND "" + INSTALL_COMMAND + ${CMAKE_COMMAND} --build . + --config ${CMAKE_BUILD_TYPE} + --target install + --parallel + ) + + add_dependencies(yaml-cpp yaml-cpp_install) + if(OCIO_VERBOSE) + message(STATUS "Installing yaml-cpp: ${yaml-cpp_LIBRARY} (version \"${yaml-cpp_VERSION}\")") + endif() + endif() +endif() + +############################################################################### +### Configure target ### + +if(_yaml-cpp_TARGET_CREATE) + set_target_properties(yaml-cpp PROPERTIES + IMPORTED_LOCATION ${yaml-cpp_LIBRARY} + INTERFACE_INCLUDE_DIRECTORIES ${yaml-cpp_INCLUDE_DIR} + ) + + mark_as_advanced(yaml-cpp_INCLUDE_DIR yaml-cpp_LIBRARY yaml-cpp_VERSION) +endif() diff --git a/share/cmake/utils/CheckSupportGL.cmake b/share/cmake/utils/CheckSupportGL.cmake index 0f2678da11..35a1146981 100644 --- a/share/cmake/utils/CheckSupportGL.cmake +++ b/share/cmake/utils/CheckSupportGL.cmake @@ -7,28 +7,30 @@ include(PackageUtils) include(SelectLibraryConfigurations) +include(Colors) +include(ocio_handle_dependency) if((OCIO_BUILD_TESTS AND OCIO_BUILD_GPU_TESTS) OR OCIO_BUILD_APPS) set(OCIO_GL_ENABLED ON) set(OCIO_USE_GLVND OFF) set(OCIO_EGL_HEADLESS OFF) - find_package(OpenGL COMPONENTS OpenGL) + ocio_handle_dependency(OpenGL COMPONENTS OpenGL) if(NOT OpenGL_OpenGL_FOUND AND NOT OPENGL_GLU_FOUND) package_root_message(OpenGL) set(OCIO_GL_ENABLED OFF) endif() if(NOT APPLE) - # On some Linux platform, the glew-config.cmake is found first so make it explicit - # to fall back on the regular search if not found. - find_package(GLEW CONFIG QUIET) + # On some Linux platform, the glew-config.cmake is found first. + # PREFER_CONFIG assure that config mode will be used first and fallback to module mode. + ocio_handle_dependency( GLEW PREFER_CONFIG + MIN_VERSION 2.1.0 + RECOMMENDED_VERSION 2.1.0 + RECOMMENDED_VERSION_REASON "Latest version tested with OCIO") if(NOT GLEW_FOUND) - find_package(GLEW) - if(NOT GLEW_FOUND) - package_root_message(GLEW) - set(OCIO_GL_ENABLED OFF) - endif() + package_root_message(GLEW) + set(OCIO_GL_ENABLED OFF) else() # Expected variables GLEW_LIBRARIES and GLEW_INCLUDE_DIRS are missing so create # the mandatory one. @@ -67,7 +69,10 @@ if((OCIO_BUILD_TESTS AND OCIO_BUILD_GPU_TESTS) OR OCIO_BUILD_APPS) endif() endif() - find_package(GLUT) + ocio_handle_dependency( GLUT + MIN_VERSION 3.2.1 + RECOMMENDED_VERSION 3.2.1 + RECOMMENDED_VERSION_REASON "Latest version tested with OCIO") if(NOT GLUT_FOUND) package_root_message(GLUT) set(OCIO_GL_ENABLED OFF) @@ -90,7 +95,7 @@ if((OCIO_BUILD_TESTS AND OCIO_BUILD_GPU_TESTS) OR OCIO_BUILD_APPS) message(STATUS "Can't find EGL without GLVND support; can't render headlessly") set(OCIO_USE_HEADLESS OFF) else() - find_package(OpenGL COMPONENTS EGL) + ocio_handle_dependency(OpenGL COMPONENTS EGL) if(NOT OpenGL_EGL_FOUND) message(WARNING "EGL component missing; can't render headlessly") set(OCIO_USE_HEADLESS OFF) diff --git a/share/cmake/utils/Colors.cmake b/share/cmake/utils/Colors.cmake new file mode 100644 index 0000000000..888ac6e5b9 --- /dev/null +++ b/share/cmake/utils/Colors.cmake @@ -0,0 +1,16 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright Contributors to the OpenColorIO Project. + +string (ASCII 27 ColorEsc) + +set(ColorReset "${ColorEsc}[m") + +# Error +set(ColorError "${ColorEsc}[31m") +# Green +set(ColorSuccess "${ColorEsc}[32m") +# Yellow +set(ColorWarning "${ColorEsc}[33m") +set(ColorInfo "${ColorEsc}[34m") + +set(ColorBoldWhite "${ColorEsc}[1;37m") \ No newline at end of file diff --git a/share/cmake/utils/CompilerFlags.cmake b/share/cmake/utils/CompilerFlags.cmake index 41d96838f7..b11722f847 100644 --- a/share/cmake/utils/CompilerFlags.cmake +++ b/share/cmake/utils/CompilerFlags.cmake @@ -93,6 +93,8 @@ set_unless_defined(CMAKE_VISIBILITY_INLINES_HIDDEN YES) ############################################################################### # Define if SSE2 can be used. +message(STATUS "") +message(STATUS "Checking for SSE2 support...") include(CheckSupportSSE2) if(NOT HAVE_SSE2) diff --git a/src/cmake/Config.cmake.in b/src/cmake/Config.cmake.in index 6a4932a836..a3b03cc83d 100644 --- a/src/cmake/Config.cmake.in +++ b/src/cmake/Config.cmake.in @@ -54,61 +54,12 @@ if (NOT @BUILD_SHARED_LIBS@) # NOT @BUILD_SHARED_LIBS@ # ZLIB_VERSION is available starting CMake 3.26+. # ZLIB_VERSION_STRING is still available for backward compatibility. # See https://cmake.org/cmake/help/git-stage/module/FindZLIB.html - - # ZLIB_USE_STATIC_LIBS is supported only from CMake 3.24+. - if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.24.0") - if (ZLIB_STATIC_LIBRARY) - set(ZLIB_USE_STATIC_LIBS "${ZLIB_STATIC_LIBRARY}") - endif() - else() # For CMake < 3.24 since ZLIB_USE_STATIC_LIBS is not available. - if(NOT ZLIB_LIBRARY) - if(DEFINED CMAKE_FIND_LIBRARY_PREFIXES) - set(_ZLIB_ORIG_CMAKE_FIND_LIBRARY_PREFIXES "${CMAKE_FIND_LIBRARY_PREFIXES}") - else() - set(_ZLIB_ORIG_CMAKE_FIND_LIBRARY_PREFIXES) - endif() - - if(DEFINED CMAKE_FIND_LIBRARY_SUFFIXES) - set(_ZLIB_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES "${CMAKE_FIND_LIBRARY_SUFFIXES}") - else() - set(_ZLIB_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES) - endif() - - # Prefix/suffix for windows. - if(WIN32) - list(APPEND CMAKE_FIND_LIBRARY_PREFIXES "" "lib") - list(APPEND CMAKE_FIND_LIBRARY_SUFFIXES ".dll.a") - endif() - - # Check if static lib is preferred. - if(ZLIB_STATIC_LIBRARY OR ZLIB_USE_STATIC_LIBS) - if(WIN32) - set(CMAKE_FIND_LIBRARY_SUFFIXES .lib .a ${CMAKE_FIND_LIBRARY_SUFFIXES}) - else() - set(CMAKE_FIND_LIBRARY_SUFFIXES .a) - endif() - endif() - endif() - endif() - + if (@ZLIB_VERSION@) # @ZLIB_VERSION@ find_dependency(ZLIB @ZLIB_VERSION@) else() find_dependency(ZLIB @ZLIB_VERSION_STRING@) endif() - - # Restore the original find library ordering - if(DEFINED _ZLIB_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES) - set(CMAKE_FIND_LIBRARY_SUFFIXES "${_ZLIB_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES}") - else() - set(CMAKE_FIND_LIBRARY_SUFFIXES) - endif() - - if(DEFINED _ZLIB_ORIG_CMAKE_FIND_LIBRARY_PREFIXES) - set(CMAKE_FIND_LIBRARY_PREFIXES "${_ZLIB_ORIG_CMAKE_FIND_LIBRARY_PREFIXES}") - else() - set(CMAKE_FIND_LIBRARY_PREFIXES) - endif() endif() if (NOT MINIZIP::minizip-ng)