File: ITKSetPython3Vars.cmake

package info (click to toggle)
insighttoolkit5 5.4.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 704,404 kB
  • sloc: cpp: 783,697; ansic: 628,724; xml: 44,704; fortran: 34,250; python: 22,874; sh: 4,078; pascal: 2,636; lisp: 2,158; makefile: 461; yacc: 328; asm: 205; perl: 203; lex: 146; tcl: 132; javascript: 98; csh: 81
file content (48 lines) | stat: -rw-r--r-- 2,094 bytes parent folder | download | duplicates (2)
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
# If the cmake variable "PYTHON_DEVELOPMENT_REQUIRED" is set to ON
# then the development environments are found.

# CMake will use FindPython3 and can be controlled accordingly (i.e. setting Python3_ROOT_DIR or
# Python3_FIND_REGISTRY (useful if using PATH to specify Python3 version on Windows).
# Additionally, setting Python3_EXECUTABLE can be used to set the Python version explicitly, but
# may become less reliable with newer versions of CMake (as opposed setting FindPython3 HINTS).  Current
# implementation gives preference to active virtualenvs.

cmake_policy(SET CMP0094 NEW) # makes FindPython3 prefer activated virtualenv Python to latest version
set(PYTHON_REQUIRED_VERSION 3.8)
set(Python_ADDITIONAL_VERSIONS
    3.12
    3.11
    3.10
    3.9
    3.8)
if(PYTHON_DEVELOPMENT_REQUIRED)
  if(DEFINED Python3_EXECUTABLE) # if already specified
    set(_specified_Python3_EXECUTABLE ${Python3_EXECUTABLE})
  endif()
  # set(Python3_FIND_REGISTRY LAST) # default is FIRST. Do we need/want this?
  find_package(Python3 ${PYTHON_REQUIRED_VERSION} COMPONENTS Interpreter Development.Module ${SKBUILD_SABI_COMPONENT})
  if(DEFINED _specified_Python3_EXECUTABLE)
    set(Python3_EXECUTABLE
        ${_specified_Python3_EXECUTABLE}
        CACHE INTERNAL "Path to the Python interpreter" FORCE)
  endif()
else() # if not PYTHON_DEVELOPMENT_REQUIRED, just find some version of Python (don't need to be as specific)
  find_package(Python3 ${PYTHON_REQUIRED_VERSION} COMPONENTS Interpreter)
endif()
if(ITK_WRAP_PYTHON)
  set(ITK_WRAP_PYTHON_VERSION "${Python3_VERSION}")
else()
  set(ITK_WRAP_PYTHON_VERSION "ITK_WRAP_PYTHON=OFF")
endif()
if(NOT Python3_EXECUTABLE AND _specified_Python3_EXECUTABLE
)# workaround for cases where FindPython3 fails to set correctly
  set(Python3_EXECUTABLE
      ${_specified_Python3_EXECUTABLE}
      CACHE INTERNAL "Path to the Python interpreter" FORCE)
endif()

# Add user-visible cache entry
set(Python3_ROOT_DIR
    ${Python3_ROOT_DIR}
    CACHE PATH "Which installation or virtual environment of Python to use" FORCE)
mark_as_advanced(Python3_ROOT_DIR)