Skip to content

Commit

Permalink
Allow choice of specific python release (#1410)
Browse files Browse the repository at this point in the history
* Allow choice of specific python release

If you're building on a system with multiple versions of Python available,
it can be very hard to make OCIO build against a specific version. In
particular, https://cmake.org/cmake/help/latest/module/FindPython.html
explains that FindPython looks preferably for version 3 of Python.

Signed-off-by: Larry Gritz <lg@larrygritz.com>

* Amendments based on review comments:

* Rename OCIO_PREFERRED_PYTHON_VERSION -> OCIO_PYTHON_VERSION.
* Move the cached variable to the top level CMakeLists.txt instead of in
  FindExtPackages.cmake.
* Warning if OCIO_PYTHON_VERSION is set but OCIO_BUILD_PYTHON is off.

Signed-off-by: Larry Gritz <lg@larrygritz.com>

Co-authored-by: Patrick Hodoul <patrick.hodoul@autodesk.com>
  • Loading branch information
lgritz and hodoulp authored Jun 20, 2021
1 parent 6772990 commit 12ee9db
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ option(OCIO_BUILD_FROZEN_DOCS "Specify whether to build frozen documentation, ne
option(OCIO_BUILD_DOCS "Specify whether to build documentation" ${OCIO_BUILD_FROZEN_DOCS})

option(OCIO_BUILD_PYTHON "Specify whether to build python bindings" ON)
set (OCIO_PYTHON_VERSION "" CACHE STRING
"Preferred Python version (if any) in case multiple are available")

option(OCIO_BUILD_JAVA "Specify whether to build java bindings" OFF)

option(OCIO_WARNING_AS_ERROR "Set build error level for CI testing" OFF)
Expand Down
24 changes: 11 additions & 13 deletions share/cmake/modules/FindExtPackages.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,9 @@ if(OCIO_BUILD_APPS)
find_package(lcms2 2.2 REQUIRED)
endif()

if(OCIO_BUILD_PYTHON)

# NOTE: Depending of the compiler version pybind11 2.4.3 does not compile
# with C++17 so, if you change the pybind11 version update the code to
# compile pybind11 and dependencies with C++17 or higher i.e. remove the
# cap of C++ version in FindPybind11.cmake and
# src/bindings/python/CMakeLists.txt.

# pybind11
# https://github.com/pybind/pybind11
find_package(pybind11 2.6.1 REQUIRED)
endif()
if (OCIO_PYTHON_VERSION AND NOT OCIO_BUILD_PYTHON)
message (WARNING "OCIO_PYTHON_VERSION=${OCIO_PYTHON_VERSION} but OCIO_BUILD_PYTHON is off.")
endif ()

if(OCIO_BUILD_PYTHON OR OCIO_BUILD_DOCS)

Expand All @@ -76,5 +67,12 @@ if(OCIO_BUILD_PYTHON OR OCIO_BUILD_DOCS)
endif()

# Python
find_package(Python REQUIRED COMPONENTS ${_Python_COMPONENTS})
find_package(Python ${OCIO_PYTHON_VERSION} REQUIRED
COMPONENTS ${_Python_COMPONENTS})

if(OCIO_BUILD_PYTHON)
# pybind11
# https://github.com/pybind/pybind11
find_package(pybind11 2.6.1 REQUIRED)
endif()
endif()

0 comments on commit 12ee9db

Please sign in to comment.