Debian Codegraph @

cmake/modules/FindOpenColorIO.cmake

raw
1 # Module to find OpenColorIO
2 #
3 # This module will first look into the directories hinted by the variables:
4 # - OpenColorIO_ROOT
5 #
6 # This module defines the following variables:
7 #
8 # OPENCOLORIO_FOUND - True if OpenColorIO was found.
9 # OPENCOLORIO_INCLUDES - where to find OpenColorIO.h
10 # OPENCOLORIO_LIBRARIES - list of libraries to link against when using OpenColorIO
11 # OPENCOLORIO_DEFINITIONS - Definitions needed when using OpenColorIO
12 #
13 # SPDX-FileCopyrightText: 2008 Contributors to the OpenImageIO project
14 # SPDX-FileCopyrightText: 2021 L. E. Segovia <[email protected]>
15 # SPDX-License-Identifier: BSD-3-Clause
16
17 include (FindPackageHandleStandardArgs)
18 include (FindPackageMessage)
19
20 find_path (OPENCOLORIO_INCLUDE_DIR
21 OpenColorIO.h
22 HINTS
23 ${OPENCOLORIO_INCLUDE_PATH}
24 ENV OPENCOLORIO_INCLUDE_PATH
25 PATHS
26 /sw/include
27 /opt/local/include
28 PATH_SUFFIXES OpenColorIO OpenColorIO1
29 DOC "The directory where OpenColorIO.h resides")
30
31 if (EXISTS "${OPENCOLORIO_INCLUDE_DIR}/OpenColorABI.h")
32 # Search twice, because this symbol changed between OCIO 1.x and 2.x
33 file(STRINGS "${OPENCOLORIO_INCLUDE_DIR}/OpenColorABI.h" TMP
34 REGEX "^#define OCIO_VERSION_STR[ \t].*$")
35 if (NOT TMP)
36 file(STRINGS "${OPENCOLORIO_INCLUDE_DIR}/OpenColorABI.h" TMP
37 REGEX "^#define OCIO_VERSION[ \t].*$")
38 endif ()
39 string (REGEX MATCHALL "([0-9]+)\\.([0-9]+)\\.[0-9]+" OPENCOLORIO_VERSION ${TMP})
40 set (OPENCOLORIO_VERSION_MAJOR ${CMAKE_MATCH_1})
41 set (OPENCOLORIO_VERSION_MINOR ${CMAKE_MATCH_2})
42 endif ()
43
44 find_library (OPENCOLORIO_LIBRARY
45 NAMES
46 OpenColorIO
47 OpenColorIO_${OPENCOLORIO_VERSION_MAJOR}_${OPENCOLORIO_VERSION_MINOR}
48 OpenColorIO${OPENCOLORIO_VERSION_MAJOR}
49 HINTS
50 ${OPENCOLORIO_LIBRARY_PATH}
51 ENV OPENCOLORIO_LIBRARY_PATH
52 PATHS
53 /usr/lib64
54 /usr/local/lib64
55 /sw/lib
56 /opt/local/lib
57 DOC "The OCIO library")
58
59 find_package_handle_standard_args (OpenColorIO
60 REQUIRED_VARS OPENCOLORIO_INCLUDE_DIR OPENCOLORIO_LIBRARY
61 FOUND_VAR OPENCOLORIO_FOUND
62 VERSION_VAR OPENCOLORIO_VERSION
63 )
64
65 if (OpenColorIO_FOUND)
66 set (OPENCOLORIO_INCLUDES ${OPENCOLORIO_INCLUDE_DIR})
67 set (OPENCOLORIO_LIBRARIES ${OPENCOLORIO_LIBRARY})
68 set (OPENCOLORIO_DEFINITIONS "")
69 if (NOT TARGET OpenColorIO::OpenColorIO)
70 add_library(OpenColorIO::OpenColorIO UNKNOWN IMPORTED)
71 set_target_properties(OpenColorIO::OpenColorIO PROPERTIES
72 INTERFACE_INCLUDE_DIRECTORIES "${OPENCOLORIO_INCLUDES}")
73
74 set_property(TARGET OpenColorIO::OpenColorIO APPEND PROPERTY
75 IMPORTED_LOCATION "${OPENCOLORIO_LIBRARIES}")
76 if (LINKSTATIC)
77 target_compile_definitions(OpenColorIO::OpenColorIO
78 INTERFACE "-DOpenColorIO_STATIC")
79 endif()
80 endif ()
81 if (NOT TARGET OpenColorIO::OpenColorIOHeaders)
82 add_library(OpenColorIO::OpenColorIOHeaders INTERFACE IMPORTED)
83 set_target_properties(OpenColorIO::OpenColorIOHeaders PROPERTIES
84 INTERFACE_INCLUDE_DIRECTORIES "${OPENCOLORIO_INCLUDES}")
85 endif ()
86 endif ()
87
88 if (OpenColorIO_FOUND AND LINKSTATIC)
89 # Is this necessary?
90 set (OPENCOLORIO_DEFINITIONS "-DOpenColorIO_STATIC")
91 find_library (TINYXML_LIBRARY NAMES tinyxml)
92 if (TINYXML_LIBRARY)
93 set (OPENCOLORIO_LIBRARIES "${OPENCOLORIO_LIBRARIES};${TINYXML_LIBRARY}" CACHE STRING "" FORCE)
94 endif ()
95 find_library (YAML_LIBRARY NAMES yaml-cpp)
96 if (YAML_LIBRARY)
97 set (OPENCOLORIO_LIBRARIES "${OPENCOLORIO_LIBRARIES};${YAML_LIBRARY}" CACHE STRING "" FORCE)
98 endif ()
99 find_library (LCMS2_LIBRARY NAMES lcms2)
100 if (LCMS2_LIBRARY)
101 set (OPENCOLORIO_LIBRARIES "${OPENCOLORIO_LIBRARIES};${LCMS2_LIBRARY}" CACHE STRING "" FORCE)
102 endif ()
103 endif ()
104