summaryrefslogtreecommitdiff
path: root/media-libs/openimageio/files/openimageio-1.6.18-make-python-and-boost-detection-more-generic.patch
blob: ad1a8aeb316d3837cc6edc803355100d193f4744 (plain)
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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
From 2d62c7f5068f678317c506d108698a78a90e5ba0 Mon Sep 17 00:00:00 2001
From: Jonathan Scruggs <j.scruggs@gmail.com>
Date: Thu, 28 Sep 2017 15:20:24 +0100
Subject: [PATCH 2/2] oiio/RB-1.6: Make python and boost detection more generic

* Fix boost and python detection for certain systems.
* Clean up boost and python detection.
* Remove redundant code.

Backported from:
https://github.com/OpenImageIO/oiio/commit/fca7ed62bd679a8221147dcddb23a516796dab90
---
 CMakeLists.txt                   |  38 +------------
 src/cmake/externalpackages.cmake |  61 +-------------------
 src/python/CMakeLists.txt        | 119 ++++++++++++++++-----------------------
 3 files changed, 53 insertions(+), 165 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index b29efac6..dd314d07 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -180,7 +180,6 @@ set (USE_OPENGL ON CACHE BOOL "Include OpenGL support")
 set (USE_QT ON CACHE BOOL "Include Qt support")
 set (FORCE_OPENGL_1 OFF CACHE BOOL "Force iv to use OpenGL's fixed pipeline")
 set (USE_PYTHON ON CACHE BOOL "Build the Python bindings")
-set (USE_PYTHON3 OFF CACHE BOOL "Build the Python3 bindings")
 set (USE_FIELD3D ON CACHE BOOL "Use Field3D if found")
 set (USE_FFMPEG ON CACHE BOOL "Use FFmpeg if found")
 set (JPEG_PATH "" CACHE STRING "Custom JPEG path")
@@ -197,8 +196,7 @@ set (USE_LIBRAW ON CACHE BOOL "Use LibRaw if found")
 set (LIBRAW_PATH "" CACHE STRING "Custom LibRaw path")
 set (NOTHREADS OFF CACHE BOOL "Compile with no threads or locking")
 set (OIIO_THREAD_ALLOW_DCLP ON CACHE BOOL "OIIO threads may use DCLP for speed")
-set (PYTHON_VERSION 2.6)
-set (PYTHON3_VERSION 3.2)
+set (PYTHON_VERSION "2.7" CACHE STRING "Target version of python to find")
 set (USE_NUKE ON CACHE BOOL "Build Nuke plugins, if Nuke is found")
 set (Nuke_ROOT "" CACHE STRING "Where to find Nuke installation")
 set (NUKE_VERSION 7.0)
@@ -321,32 +319,7 @@ include_directories (
 
 
 ###########################################################################
-# Set install paths for the python modules
-# TODO: Figure out how to get the correct python directory
-
-if (UNIX AND NOT SELF_CONTAINED_INSTALL_TREE)
-    # TODO: Figure out how to get the correct python directory
-    set (DEFAULT_PYLIB_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/python/site-packages")
-    set (DEFAULT_PYLIB3_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/python3/site-packages")
-else ()
-    # Here is the "self-contained install tree" case: the expectation here
-    # is that everything related to this project will go into its own
-    # directory, not into some standard system heirarchy.
-    set (DEFAULT_PYLIB_INSTALL_DIR "python")
-    set (DEFAULT_PYLIB3_INSTALL_DIR "python3")
-endif ()
-if (EXEC_INSTALL_PREFIX)
-    # Tack on an extra prefix to support multi-arch builds.
-    set (DEFAULT_PYLIB_INSTALL_DIR "${EXEC_INSTALL_PREFIX}/${DEFAULT_PYLIB_INSTALL_DIR}")
-    set (DEFAULT_PYLIB3_INSTALL_DIR "${EXEC_INSTALL_PREFIX}/${DEFAULT_PYLIB3_INSTALL_DIR}")
-endif ()
-# Set up cmake cache variables corresponding to the defaults deduced above, so
-# that the user can override them as desired:
-set (PYLIB_INSTALL_DIR ${DEFAULT_PYLIB_INSTALL_DIR} CACHE STRING
-     "Install location for python libraries (relative to CMAKE_INSTALL_PREFIX or absolute)")
-set (PYLIB3_INSTALL_DIR ${DEFAULT_PYLIB3_INSTALL_DIR} CACHE STRING
-     "Install location for python3 libraries (relative to CMAKE_INSTALL_PREFIX or absolute)")
-
+# Set default install options
 set (PLUGIN_SEARCH_PATH "" CACHE STRING "Default plugin search path")
 
 set (INSTALL_DOCS ON CACHE BOOL "Install documentation")
@@ -442,14 +415,9 @@ if (NOT EMBEDPLUGINS)
     add_subdirectory (src/zfile.imageio)
 endif ()
 
-if (USE_PYTHON AND oiio_boost_PYTHON_FOUND AND NOT BUILD_OIIOUTIL_ONLY)
+if (USE_PYTHON AND NOT BUILD_OIIOUTIL_ONLY)
     add_subdirectory (src/python)
 endif ()
-if (USE_PYTHON3 AND NOT BUILD_OIIOUTIL_ONLY)
-    #build the python3 module in a different binary directory since it will
-    #have the same name as the python2 module (e.g. OpenImageIO.so)
-    add_subdirectory (src/python src/python3)
-endif ()
 
 add_subdirectory (src/include)
 add_subdirectory (src/doc)
diff --git a/src/cmake/externalpackages.cmake b/src/cmake/externalpackages.cmake
index 4799df22..2576dee5 100644
--- a/src/cmake/externalpackages.cmake
+++ b/src/cmake/externalpackages.cmake
@@ -102,10 +102,7 @@ if (NOT Boost_FIND_QUIETLY)
 endif ()
 
 if (NOT DEFINED Boost_ADDITIONAL_VERSIONS)
-  set (Boost_ADDITIONAL_VERSIONS "1.60" "1.59" "1.58" "1.57" "1.56"
-                                 "1.55" "1.54" "1.53" "1.52" "1.51" "1.50"
-                                 "1.49" "1.48" "1.47" "1.46" "1.45" "1.44"
-                                 "1.43" "1.43.0" "1.42" "1.42.0")
+  set (Boost_ADDITIONAL_VERSIONS "1.65.1" "1.65" "1.63" "1.62")
 endif ()
 if (LINKSTATIC)
     set (Boost_USE_STATIC_LIBS   ON)
@@ -117,51 +114,7 @@ if (BOOST_CUSTOM)
     # Boost_VERSION, Boost_INCLUDE_DIRS, Boost_LIBRARY_DIRS, Boost_LIBRARIES.
 else ()
     set (Boost_COMPONENTS filesystem regex system thread)
-    find_package (Boost 1.42 REQUIRED
-                  COMPONENTS ${Boost_COMPONENTS}
-                 )
-
-    # Try to figure out if this boost distro has Boost::python.  If we
-    # include python in the component list above, cmake will abort if
-    # it's not found.  So we resort to checking for the boost_python
-    # library's existance to get a soft failure.
-    find_library (oiio_boost_python_lib boost_python
-                  PATHS ${Boost_LIBRARY_DIRS} NO_DEFAULT_PATH)
-    mark_as_advanced (oiio_boost_python_lib)
-    if (NOT oiio_boost_python_lib AND Boost_SYSTEM_LIBRARY_RELEASE)
-        get_filename_component (oiio_boost_PYTHON_rel
-                                ${Boost_SYSTEM_LIBRARY_RELEASE} NAME
-                               )
-        string (REGEX REPLACE "^(lib)?(.+)_system(.+)$" "\\2_python\\3"
-                oiio_boost_PYTHON_rel ${oiio_boost_PYTHON_rel}
-               )
-        find_library (oiio_boost_PYTHON_LIBRARY_RELEASE
-                      NAMES ${oiio_boost_PYTHON_rel} lib${oiio_boost_PYTHON_rel}
-                      HINTS ${Boost_LIBRARY_DIRS}
-                      NO_DEFAULT_PATH
-                     )
-        mark_as_advanced (oiio_boost_PYTHON_LIBRARY_RELEASE)
-    endif ()
-    if (NOT oiio_boost_python_lib AND Boost_SYSTEM_LIBRARY_DEBUG)
-        get_filename_component (oiio_boost_PYTHON_dbg
-                                ${Boost_SYSTEM_LIBRARY_DEBUG} NAME
-                               )
-        string (REGEX REPLACE "^(lib)?(.+)_system(.+)$" "\\2_python\\3"
-                oiio_boost_PYTHON_dbg ${oiio_boost_PYTHON_dbg}
-               )
-        find_library (oiio_boost_PYTHON_LIBRARY_DEBUG
-                      NAMES ${oiio_boost_PYTHON_dbg} lib${oiio_boost_PYTHON_dbg}
-                      HINTS ${Boost_LIBRARY_DIRS}
-                      NO_DEFAULT_PATH
-                     )
-        mark_as_advanced (oiio_boost_PYTHON_LIBRARY_DEBUG)
-    endif ()
-    if (oiio_boost_python_lib OR
-        oiio_boost_PYTHON_LIBRARY_RELEASE OR oiio_boost_PYTHON_LIBRARY_DEBUG)
-        set (oiio_boost_PYTHON_FOUND ON)
-    else ()
-        set (oiio_boost_PYTHON_FOUND OFF)
-    endif ()
+    find_package (Boost 1.62 REQUIRED COMPONENTS ${Boost_COMPONENTS})
 endif ()
 
 # On Linux, Boost 1.55 and higher seems to need to link against -lrt
@@ -176,16 +129,6 @@ if (NOT Boost_FIND_QUIETLY)
     message (STATUS "Boost include dirs ${Boost_INCLUDE_DIRS}")
     message (STATUS "Boost library dirs ${Boost_LIBRARY_DIRS}")
     message (STATUS "Boost libraries    ${Boost_LIBRARIES}")
-    message (STATUS "Boost python found ${oiio_boost_PYTHON_FOUND}")
-endif ()
-if (NOT oiio_boost_PYTHON_FOUND)
-    # If Boost python components were not found, turn off all python support.
-    message (STATUS "Boost python support not found -- will not build python components!")
-    if (APPLE AND USE_PYTHON)
-        message (STATUS "   If your Boost is from Macports, you need the +python26 variant to get Python support.")
-    endif ()
-    set (USE_PYTHON OFF)
-    set (PYTHONLIBS_FOUND OFF)
 endif ()
 
 include_directories (SYSTEM "${Boost_INCLUDE_DIRS}")
diff --git a/src/python/CMakeLists.txt b/src/python/CMakeLists.txt
index 81a4a890..e58d372d 100644
--- a/src/python/CMakeLists.txt
+++ b/src/python/CMakeLists.txt
@@ -1,54 +1,30 @@
-#if the CMAKE_CURRENT_BINARY_DIR is python3, then build the python3 module,
-#otherwise the python2 module
-string (REGEX MATCH "python3\$" _py3_subdir ${CMAKE_CURRENT_BINARY_DIR})
+# Attempt to find the desired version, but fall back to other
+# additional versions.
+find_package (PythonInterp ${PYTHON_VERSION} REQUIRED)
 
-if (_py3_subdir)
-    set (BUILD_PY3 ON)
-else ()
-    set (BUILD_PY3 OFF)
-endif ()
-
-if (NOT BOOST_CUSTOM AND NOT BUILD_PY3)
-    #Unset those, otherwise find_package(PythonLibs) will pick up old stuff
-    #if it has been run before
-    unset(Python_ADDITIONAL_VERSIONS)
-    unset(PYTHON_LIBRARY)
-    unset(PYTHON_LIBRARY CACHE)
-    unset(PYTHON_INCLUDE_DIR)
-    unset(PYTHON_INCLUDE_DIR CACHE)
-    unset(PYTHON_INCLUDE_PATH)
-    unset(PYTHON_INCLUDE_PATH CACHE)
-    find_package (PythonLibs ${PYTHON_VERSION} REQUIRED)
-    find_package (Boost 1.42 REQUIRED COMPONENTS python)
-elseif (BOOST_CUSTOM AND NOT BUILD_PY3)
-    find_package (PythonLibs ${PYTHON_VERSION} REQUIRED)
-else ()
-    #BOOST_CUSTOM is ignored for python3
+# The version that was found may not be the default or user
+# defined one.
+set (PYTHON_VERSION_FOUND ${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR})
 
-    #Unset those, otherwise find_package(PythonLibs) will pick up old stuff
-    #if it has been run before
-    unset(PYTHON_LIBRARY)
-    unset(PYTHON_LIBRARY CACHE)
-    unset(PYTHON_INCLUDE_DIR)
-    unset(PYTHON_INCLUDE_DIR CACHE)
-    unset(PYTHON_INCLUDE_PATH)
-    unset(PYTHON_INCLUDE_PATH CACHE)
+if (NOT ${PYTHON_VERSION} EQUAL ${PYTHON_VERSION_FOUND} )
+    message (WARNING "The requested version ${PYTHON_VERSION} was not found.") 
+    message (WARNING "Using ${PYTHON_VERSION_FOUND} instead.")
+endif ()
 
-    #cmake 2.8 does not look for python 3.4
-    set(Python_ADDITIONAL_VERSIONS 3.4)
-    find_package (PythonInterp ${PYTHON3_VERSION} REQUIRED)
-    find_package (PythonLibs ${PYTHON3_VERSION} REQUIRED)
+find_package (PythonLibs ${PYTHON_VERSION_FOUND} REQUIRED)
 
-    #Finding the python3 component for boost is a little tricky, since it has
-    #different names on different systems. Try the most common ones
-    #(boost_python3, boost_python-py34, …).
-    foreach (_boost_py3_lib python3 python-py34 python-py33 python-py32)
-        find_package (Boost 1.42 QUIET COMPONENTS ${_boost_py3_lib})
-        string (TOUPPER ${_boost_py3_lib} boost_py3_lib_name)
-        if (Boost_${boost_py3_lib_name}_FOUND)
-            #Not the most beautiful thing to do, but that gets them included in
-            #the target_link_libraries(…) call farther down
-            set (Boost_PYTHON_LIBRARIES ${Boost_${boost_py3_lib_name}_LIBRARIES})
+if (NOT BOOST_CUSTOM)
+    # Finding the python component for boost is a little tricky, since it has
+    # different names on different systems. Try the most common ones.
+    foreach (_py_lib python-${PYTHON_VERSION_FOUND} python
+             python${PYTHON_VERSION_MAJOR}
+             python-py${PYTHON_VERSION_MAJOR}${PYTHON_VERSION_MINOR})
+        find_package (Boost QUIET COMPONENTS ${_py_lib})
+        string (TOUPPER ${_py_lib} _py_lib_name)
+        if (Boost_${_py_lib_name}_FOUND)
+            # Not the most beautiful thing to do, but that gets them included in
+            # the target_link_libraries(…) call farther down
+            set (Boost_PYTHON_LIBRARIES ${Boost_${_py_lib_name}_LIBRARIES})
             break ()
         endif ()
     endforeach ()
@@ -58,18 +34,19 @@ if (APPLE)
 #    set (PYTHON_LIBRARIES /opt/local/lib)
 endif ()
 
+if (NOT DEFINED PYTHON_SITE_DIR)
+    set (PYTHON_SITE_DIR "${CMAKE_INSTALL_LIBDIR}/python${PYTHON_VERSION_FOUND}/site-packages")
+endif ()
+
 # Disable some warnings for Clang, it's a little too picky with boost
 if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
     add_definitions ("-Wno-array-bounds")
 endif ()
 
-if (BUILD_PY3)
-    set (target_name Py3OpenImageIO)
-else ()
-    set (target_name PyOpenImageIO)
-endif ()
+set (target_name PyOpenImageIO)
 
-if (BOOST_CUSTOM OR Boost_FOUND AND PYTHONLIBS_FOUND)
+# Test if automatically found or manually set with BOOST_CUSTOM
+if (DEFINED Boost_PYTHON_LIBRARIES)
 
     set (python_srcs py_imageinput.cpp py_imageoutput.cpp
          py_imagecache.cpp py_imagespec.cpp py_roi.cpp
@@ -81,8 +58,12 @@ if (BOOST_CUSTOM OR Boost_FOUND AND PYTHONLIBS_FOUND)
         message (STATUS "Python found ${PYTHONLIBS_FOUND} ")
         message (STATUS "Python include dirs ${PYTHON_INCLUDE_PATH}")
         message (STATUS "Python libraries    ${PYTHON_LIBRARIES}")
+        message (STATUS "Python site packages dir ${PYTHON_SITE_DIR}")
         message (STATUS "Python to include 'lib' prefix: ${PYLIB_LIB_PREFIX}")
         message (STATUS "Python to include SO version: ${PYLIB_INCLUDE_SONAME}")
+        message (STATUS "Python version ${PYTHON_VERSION_STRING}")
+        message (STATUS "Python version major: ${PYTHON_VERSION_MAJOR} minor: ${PYTHON_VERSION_MINOR}")
+        message (STATUS "Boost python libraries ${Boost_PYTHON_LIBRARIES}")
     endif ()
 
     include_directories (${PYTHON_INCLUDE_PATH} ${Boost_INCLUDE_DIRS})
@@ -91,7 +72,7 @@ if (BOOST_CUSTOM OR Boost_FOUND AND PYTHONLIBS_FOUND)
         target_link_libraries (${target_name} OpenImageIO ${Boost_LIBRARIES} ${Boost_PYTHON_LIBRARIES} ${CMAKE_DL_LIBS})
         set_target_properties (${target_name} PROPERTIES LINK_FLAGS "-undefined dynamic_lookup")
     else ()
-        target_link_libraries (${target_name} OpenImageIO ${Boost_LIBRARIES} ${Boost_PYTHON_LIBRARIES} ${PYTHON_LIBRARIES} ${CMAKE_DL_LIBS})
+        target_link_libraries (${target_name} OpenImageIO ${SANITIZE_LIBRARIES} ${Boost_LIBRARIES} ${Boost_PYTHON_LIBRARIES} ${PYTHON_LIBRARIES} ${CMAKE_DL_LIBS})
     endif ()
 
     # Exclude the 'lib' prefix from the name
@@ -123,21 +104,17 @@ if (BOOST_CUSTOM OR Boost_FOUND AND PYTHONLIBS_FOUND)
                                SUFFIX ".pyd")
     endif()
     
-    if (BUILD_PY3)
-        install (TARGETS ${target_name}
-                 RUNTIME DESTINATION ${PYLIB3_INSTALL_DIR} COMPONENT user
-                 LIBRARY DESTINATION ${PYLIB3_INSTALL_DIR} COMPONENT user)
-    else ()
-        install (TARGETS ${target_name}
-                 RUNTIME DESTINATION ${PYLIB_INSTALL_DIR} COMPONENT user
-                 LIBRARY DESTINATION ${PYLIB_INSTALL_DIR} COMPONENT user)
-    endif ()
-elseif (BUILD_PY3)
-    if (NOT PYTHONLIBS_FOUND)
-        message (STATUS "Python3 libraries not found")
-    endif ()
-    if (NOT Boost_FOUND)
-        message (STATUS "Boost python3 component not found")
-    endif ()
-    set(USE_PYTHON3 OFF)
+    install (TARGETS ${target_name}
+             RUNTIME DESTINATION ${PYTHON_SITE_DIR} COMPONENT user
+             LIBRARY DESTINATION ${PYTHON_SITE_DIR} COMPONENT user)
+else ()
+    # If Boost python components were not found, turn off all python support.
+    message (STATUS "Boost python support not found!")
+    if (APPLE AND USE_PYTHON)
+        message (STATUS "   If your Boost is from Macports, you need the +python26 variant to get Python support.")
+     endif ()
+     if (BOOST_CUSTOM)
+        message (STATUS "   Please set the variable Boost_PYTHON_LIBRARIES to the location of the boost python libraries.")
+     endif ()
+     message (FATAL_ERROR "Python module cannot be built. Either disable python support or check your boost installation.")
 endif ()
-- 
2.14.2