summaryrefslogtreecommitdiff
path: root/src/pyglue/CMakeLists.txt
diff options
context:
space:
mode:
Diffstat (limited to 'src/pyglue/CMakeLists.txt')
-rw-r--r--src/pyglue/CMakeLists.txt106
1 files changed, 106 insertions, 0 deletions
diff --git a/src/pyglue/CMakeLists.txt b/src/pyglue/CMakeLists.txt
new file mode 100644
index 0000000..07188ea
--- /dev/null
+++ b/src/pyglue/CMakeLists.txt
@@ -0,0 +1,106 @@
+if(CMAKE_FIRST_RUN)
+ message(STATUS "Python library to include 'lib' prefix: ${OCIO_PYGLUE_LIB_PREFIX}")
+endif()
+
+if(CMAKE_FIRST_RUN)
+ message(STATUS "Python ${PYTHON_VERSION} okay (UCS: ${PYTHON_UCS}), will build the Python bindings against ${PYTHON_INCLUDE}")
+ message(STATUS "Python variant path is ${PYTHON_VARIANT_PATH}")
+endif()
+
+if(CMAKE_COMPILER_IS_GNUCXX)
+ # Python breaks strict-aliasing rules. Disable the warning here.
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-strict-aliasing")
+endif()
+
+if(NOT WIN32)
+ find_package(PythonLibs)
+ if(NOT PYTHONLIBS_FOUND)
+ message(FATAL "Python libraries were not found, exiting.")
+ endif()
+ SET(PYTHON_INCLUDES ${PYTHON_INCLUDE_DIRS})
+endif()
+
+add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/src/pyglue/PyDoc.h
+ COMMAND ${PYTHON} ${CMAKE_SOURCE_DIR}/src/pyglue/createPyDocH.py ${CMAKE_BINARY_DIR}/src/pyglue/PyDoc.h
+ COMMENT "Creating PyDoc.h")
+
+file( GLOB pyglue_src_files "${CMAKE_SOURCE_DIR}/src/pyglue/*.cpp" )
+
+add_library(PyOpenColorIO MODULE ${pyglue_src_files} ${CMAKE_BINARY_DIR}/src/pyglue/PyDoc.h)
+
+if(OCIO_USE_BOOST_PTR)
+ include_directories(
+ ${PYTHON_INCLUDE}
+ ${Boost_INCLUDE_DIR}
+ ${CMAKE_SOURCE_DIR}/export/
+ ${CMAKE_BINARY_DIR}/export/
+ ${CMAKE_CURRENT_BINARY_DIR}
+ )
+else()
+ include_directories(
+ ${PYTHON_INCLUDE}
+ ${CMAKE_SOURCE_DIR}/export/
+ ${CMAKE_BINARY_DIR}/export/
+ ${CMAKE_CURRENT_BINARY_DIR}
+ )
+endif()
+
+# Exclude the 'lib' prefix from the name.
+if(NOT OCIO_PYGLUE_LIB_PREFIX)
+ set_property(TARGET PyOpenColorIO
+ PROPERTY PREFIX ""
+ )
+endif()
+
+if(WIN32)
+ if(OCIO_PYGLUE_LINK)
+ target_link_libraries(PyOpenColorIO OpenColorIO
+ debug ${PYTHON_LIB}/python26_d.lib
+ optimized ${PYTHON_LIB}/python26.lib)
+ else()
+ target_link_libraries(PyOpenColorIO OpenColorIO)
+ endif(OCIO_PYGLUE_LINK)
+else()
+ if(OCIO_PYGLUE_LINK)
+ message(STATUS "Linking python bindings against: ${PYTHON_LIBRARY}")
+ message(STATUS "Python library dirs: ${PYTHON_LIBRARY_DIRS}")
+ link_directories(${PYTHON_LIBRARY})
+ target_link_libraries(PyOpenColorIO OpenColorIO
+ ${PYTHON_LIBRARIES})
+ else()
+ target_link_libraries(PyOpenColorIO OpenColorIO)
+ endif(OCIO_PYGLUE_LINK)
+endif()
+
+# PyOpenColorIO so serves dual roles:
+# - First, to provide the C API function necessary to act as a cpython module,
+# (extern "C" PyMODINIT_FUNC initPyOpenColorIO(void)
+# - Second, to act as a normal shared library, providing the C++ API functions
+# to convert between C++ and python representation of the OCIO object.
+#
+# To fulfill this second role, as a shared libary, we must continue to define
+# so version.
+#
+# TODO: This wont let the normal shared library symbols work on OSX.
+# We should explore whether this should be built as a normal dylib, instead
+# of as a bundle. See https://github.com/imageworks/OpenColorIO/pull/175
+
+if(OCIO_PYGLUE_SONAME)
+ message(STATUS "Setting PyOCIO SOVERSION to: ${SOVERSION}")
+ set_target_properties(PyOpenColorIO PROPERTIES
+ VERSION ${OCIO_VERSION}
+ SOVERSION ${SOVERSION}
+ )
+endif()
+
+if(APPLE)
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -undefined dynamic_lookup")
+endif()
+
+
+message("PYTHON_VARIANT_PATH: ${PYTHON_VARIANT_PATH}")
+
+install(TARGETS PyOpenColorIO DESTINATION ${CMAKE_INSTALL_EXEC_PREFIX}/${PYTHON_VARIANT_PATH})
+
+install(FILES ${CMAKE_SOURCE_DIR}/export/PyOpenColorIO/PyOpenColorIO.h
+ DESTINATION ${CMAKE_INSTALL_PREFIX}/include/PyOpenColorIO/)