-
Notifications
You must be signed in to change notification settings - Fork 437
/
CMakeLists.txt
242 lines (206 loc) · 6.7 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
# SPDX-License-Identifier: BSD-3-Clause
# Copyright Contributors to the OpenColorIO Project.
if(OCIO_BUILD_DOCS)
###########################################################################
### Setup PYTHONPATH ###
include(GetPythonPreCommand)
# Sets Python_PRE_CMD, which sets PATH and PYTHONPATH for Python
get_python_pre_command()
###########################################################################
### Extract docstrings from C++ headers for Python bindings ###
set(PYOCIO_DOCSTRINGS_DIR "${CMAKE_BINARY_DIR}/docs/_doxygen")
set(PYOCIO_DOCSTRINGS_H "${PYOCIO_DOCSTRINGS_DIR}/docstrings.h")
set(DOXYGEN_INDEX_XML "${PYOCIO_DOCSTRINGS_DIR}/xml/index.xml")
set(EXTRACT_DOCSTRINGS_PY "${CMAKE_SOURCE_DIR}/share/docs/extract_docstrings.py")
# Run docstring extraction if docstrings.h is behind doxygen XML
add_custom_command(OUTPUT ${PYOCIO_DOCSTRINGS_H}
COMMAND
${Python_PRE_CMD} "${Python_EXECUTABLE}" "${EXTRACT_DOCSTRINGS_PY}" xml docstrings.h
WORKING_DIRECTORY
${PYOCIO_DOCSTRINGS_DIR}
DEPENDS
doxygen_extraction
${DOXYGEN_INDEX_XML}
${EXTRACT_DOCSTRINGS_PY}
COMMENT "Extracting Python docstrings from C++ headers"
)
add_custom_target(docstring_extraction
DEPENDS ${PYOCIO_DOCSTRINGS_H}
)
else()
# Use stand-in docstrings.h file when docs are not built
set(PYOCIO_DOCSTRINGS_DIR "${CMAKE_SOURCE_DIR}/share/docs")
message(WARNING
"Building PyOpenColorIO with OCIO_BUILD_DOCS disabled will result in "
"incomplete Python docstrings."
)
endif()
###############################################################################
# Python libs
set(SOURCES
apphelpers/PyColorSpaceHelpers.cpp
apphelpers/PyDisplayViewHelpers.cpp
apphelpers/PyLegacyViewingPipeline.cpp
apphelpers/PyMixingHelpers.cpp
transforms/PyAllocationTransform.cpp
transforms/PyBuiltinTransform.cpp
transforms/PyCDLTransform.cpp
transforms/PyColorSpaceTransform.cpp
transforms/PyDisplayViewTransform.cpp
transforms/PyExponentTransform.cpp
transforms/PyExponentWithLinearTransform.cpp
transforms/PyExposureContrastTransform.cpp
transforms/PyFileTransform.cpp
transforms/PyFixedFunctionTransform.cpp
transforms/PyGradingPrimaryTransform.cpp
transforms/PyGradingRGBCurveTransform.cpp
transforms/PyGradingToneTransform.cpp
transforms/PyGroupTransform.cpp
transforms/PyLogAffineTransform.cpp
transforms/PyLogCameraTransform.cpp
transforms/PyLogTransform.cpp
transforms/PyLookTransform.cpp
transforms/PyLut1DTransform.cpp
transforms/PyLut3DTransform.cpp
transforms/PyMatrixTransform.cpp
transforms/PyRangeTransform.cpp
PyBaker.cpp
PyBuiltinConfigRegistry.cpp
PyBuiltinTransformRegistry.cpp
PyColorSpace.cpp
PyColorSpaceSet.cpp
PyConfig.cpp
PyConfigIOProxy.cpp
PyContext.cpp
PyCPUProcessor.cpp
PyDynamicProperty.cpp
PyFileRules.cpp
PyFormatMetadata.cpp
PyGPUProcessor.cpp
PyGpuShaderCreator.cpp
PyGpuShaderDesc.cpp
PyGradingData.cpp
PyImageDesc.cpp
PyLook.cpp
PyNamedTransform.cpp
PyOpenColorIO.cpp
PyPackedImageDesc.cpp
PyPlanarImageDesc.cpp
PyProcessor.cpp
PyProcessorMetadata.cpp
PySystemMonitors.cpp
PyTransform.cpp
PyTypes.cpp
PyUtils.cpp
PyViewingRules.cpp
PyViewTransform.cpp
)
# Reason not to use pybind11_add_module ?
# https://pybind11.readthedocs.io/en/stable/compiling.html#pybind11-add-module
add_library(PyOpenColorIO MODULE ${SOURCES})
if(OCIO_BUILD_DOCS)
add_dependencies(PyOpenColorIO
docstring_extraction
)
endif()
set_target_properties(PyOpenColorIO PROPERTIES
PREFIX ""
)
if(WIN32)
# Windows uses .pyd extension for python modules
set_target_properties(PyOpenColorIO PROPERTIES
SUFFIX ".pyd"
)
endif()
# NOTE: Depending of the compiler version pybind11 2.4.3 does not compile with C++17 so revert to c++11
set(APP_CXX_STANDARD ${CMAKE_CXX_STANDARD})
if(${CMAKE_CXX_STANDARD} GREATER_EQUAL 17)
set(APP_CXX_STANDARD 11)
endif()
set(CUSTOM_COMPILE_FLAGS ${PLATFORM_COMPILE_FLAGS})
# The Python binding contains deprecated methods for backward compatibility reason,
# so disable the warning.
if(USE_GCC OR USE_CLANG)
set(CUSTOM_COMPILE_FLAGS "${CUSTOM_COMPILE_FLAGS} -Wno-deprecated-declarations")
elseif(USE_MSVC)
set(CUSTOM_COMPILE_FLAGS "${CUSTOM_COMPILE_FLAGS} /wd4996")
endif()
set_target_properties(PyOpenColorIO
PROPERTIES
COMPILE_FLAGS ${CUSTOM_COMPILE_FLAGS}
CXX_STANDARD ${APP_CXX_STANDARD}
)
if(NOT BUILD_SHARED_LIBS)
target_compile_definitions(PyOpenColorIO
PUBLIC
OpenColorIO_SKIP_IMPORTS
)
endif()
if(UNIX)
# A 'module' is a dynamic library on Linux (i.e. '-fPIC' needed),
# but a static library on Windows.
# If supported for the target machine, emit position-independent code
# suitable for dynamic linking.
set_property(TARGET PyOpenColorIO PROPERTY POSITION_INDEPENDENT_CODE ON)
endif()
if (UNIX AND NOT CMAKE_SKIP_RPATH)
# Update the default RPATH so the Python binding dynamic library can find the OpenColorIO
# dynamic library based on the default installation directory structure.
if (APPLE)
set_target_properties(PyOpenColorIO PROPERTIES
INSTALL_RPATH "@loader_path/../..;${CMAKE_INSTALL_RPATH}")
else()
set_target_properties(PyOpenColorIO PROPERTIES
INSTALL_RPATH "$ORIGIN/../..;${CMAKE_INSTALL_RPATH}")
endif()
endif()
# OSX demands that the linker resolve all symbols at build time
# we pass this flag to allow dynamic linking
if(APPLE)
set_target_properties(PyOpenColorIO PROPERTIES
LINK_FLAGS "-undefined dynamic_lookup"
)
endif()
target_include_directories(PyOpenColorIO
PRIVATE
PyOpenColorIO
${CMAKE_CURRENT_BINARY_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}
${pybind11_INCLUDE_DIR}
${PYOCIO_DOCSTRINGS_DIR}
SYSTEM
${Python_INCLUDE_DIRS}
)
# pybind11 recommends intentionally NOT linking against libpython on Linux and
# macOS, to prevent segfaults when potentially working with multiple Python
# installations. See note in:
# https://pybind11.readthedocs.io/en/stable/compiling.html#building-manually
if (WIN32)
set(_PublicLibs ${Python_LIBRARIES})
endif()
target_link_libraries(PyOpenColorIO
PUBLIC
${_PublicLibs}
PRIVATE
OpenColorIO
utils::strings
pybind11::module
)
target_compile_definitions(PyOpenColorIO
PRIVATE
PYOCIO_NAME=PyOpenColorIO
PY_VERSION_MAJOR=${Python_VERSION_MAJOR}
PY_VERSION_MINOR=${Python_VERSION_MINOR}
PY_VERSION_PATCH=${Python_VERSION_PATCH}
)
if(WIN32)
set(_Python_VARIANT_PATH "${CMAKE_INSTALL_LIBDIR}/site-packages")
else()
set(_Python_VARIANT_PATH "${CMAKE_INSTALL_LIBDIR}/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}/site-packages")
endif()
# Create an internal global variable to access it in another scope but not publicly visible
# using ccmake.
set(PYTHON_VARIANT_PATH ${_Python_VARIANT_PATH} CACHE INTERNAL "")
install(TARGETS PyOpenColorIO
LIBRARY DESTINATION ${_Python_VARIANT_PATH}
)