1 # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 # file Copyright.txt or https://cmake.org/licensing for details.
5 # This file is a "template" file used by various FindPython modules.
9 # Initial configuration
13 # numbers and boolean constants
14 cmake_policy (SET CMP0012 NEW)
16 cmake_policy (SET CMP0057 NEW)
18 if (NOT DEFINED _PYTHON_PREFIX)
19 message (FATAL_ERROR "FindPython: INTERNAL ERROR")
21 if (NOT DEFINED _${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR)
22 message (FATAL_ERROR "FindPython: INTERNAL ERROR")
24 if (_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR EQUAL "3")
25 set(_${_PYTHON_PREFIX}_VERSIONS 3.12 3.11 3.10 3.9 3.8 3.7 3.6 3.5 3.4 3.3 3.2 3.1 3.0)
26 elseif (_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR EQUAL "2")
27 set(_${_PYTHON_PREFIX}_VERSIONS 2.7 2.6 2.5 2.4 2.3 2.2 2.1 2.0)
29 message (FATAL_ERROR "FindPython: INTERNAL ERROR")
32 get_property(_${_PYTHON_PREFIX}_CMAKE_ROLE GLOBAL PROPERTY CMAKE_ROLE)
34 include (${CMAKE_CURRENT_LIST_DIR}/../FindPackageHandleStandardArgs.cmake)
39 macro (_PYTHON_DISPLAY_FAILURE _PYTHON_MSG)
40 if (${_PYTHON_PREFIX}_FIND_REQUIRED)
41 message (FATAL_ERROR "${_PYTHON_MSG}")
43 if (NOT ${_PYTHON_PREFIX}_FIND_QUIETLY)
44 message(STATUS "${_PYTHON_MSG}")
48 set (${_PYTHON_PREFIX}_FOUND FALSE)
49 string (TOUPPER "${_PYTHON_PREFIX}" _${_PYTHON_PREFIX}_UPPER_PREFIX)
50 set (${_PYTHON_UPPER_PREFIX}_FOUND FALSE)
54 function (_PYTHON_MARK_AS_INTERNAL)
55 foreach (var IN LISTS ARGV)
56 if (DEFINED CACHE{${var}})
57 set_property (CACHE ${var} PROPERTY TYPE INTERNAL)
63 macro (_PYTHON_SELECT_LIBRARY_CONFIGURATIONS _PYTHON_BASENAME)
64 if(NOT DEFINED ${_PYTHON_BASENAME}_LIBRARY_RELEASE)
65 set(${_PYTHON_BASENAME}_LIBRARY_RELEASE "${_PYTHON_BASENAME}_LIBRARY_RELEASE-NOTFOUND")
67 if(NOT DEFINED ${_PYTHON_BASENAME}_LIBRARY_DEBUG)
68 set(${_PYTHON_BASENAME}_LIBRARY_DEBUG "${_PYTHON_BASENAME}_LIBRARY_DEBUG-NOTFOUND")
71 get_property(_PYTHON_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
72 if (${_PYTHON_BASENAME}_LIBRARY_DEBUG AND ${_PYTHON_BASENAME}_LIBRARY_RELEASE AND
73 NOT ${_PYTHON_BASENAME}_LIBRARY_DEBUG STREQUAL ${_PYTHON_BASENAME}_LIBRARY_RELEASE AND
74 (_PYTHON_isMultiConfig OR CMAKE_BUILD_TYPE))
75 # if the generator is multi-config or if CMAKE_BUILD_TYPE is set for
76 # single-config generators, set optimized and debug libraries
77 set (${_PYTHON_BASENAME}_LIBRARIES "")
78 foreach (_PYTHON_libname IN LISTS ${_PYTHON_BASENAME}_LIBRARY_RELEASE)
79 list( APPEND ${_PYTHON_BASENAME}_LIBRARIES optimized "${_PYTHON_libname}")
81 foreach (_PYTHON_libname IN LISTS ${_PYTHON_BASENAME}_LIBRARY_DEBUG)
82 list( APPEND ${_PYTHON_BASENAME}_LIBRARIES debug "${_PYTHON_libname}")
84 elseif (${_PYTHON_BASENAME}_LIBRARY_RELEASE)
85 set (${_PYTHON_BASENAME}_LIBRARIES "${${_PYTHON_BASENAME}_LIBRARY_RELEASE}")
86 elseif (${_PYTHON_BASENAME}_LIBRARY_DEBUG)
87 set (${_PYTHON_BASENAME}_LIBRARIES "${${_PYTHON_BASENAME}_LIBRARY_DEBUG}")
89 set (${_PYTHON_BASENAME}_LIBRARIES "${_PYTHON_BASENAME}_LIBRARY-NOTFOUND")
94 macro (_PYTHON_FIND_FRAMEWORKS)
95 if (CMAKE_HOST_APPLE OR APPLE)
96 file(TO_CMAKE_PATH "$ENV{CMAKE_FRAMEWORK_PATH}" _pff_CMAKE_FRAMEWORK_PATH)
97 set (_pff_frameworks ${CMAKE_FRAMEWORK_PATH}
98 ${_pff_CMAKE_FRAMEWORK_PATH}
100 /usr/local/Frameworks
101 /opt/homebrew/Frameworks
102 ${CMAKE_SYSTEM_FRAMEWORK_PATH})
103 list (REMOVE_DUPLICATES _pff_frameworks)
104 foreach (_pff_implementation IN LISTS _${_PYTHON_PREFIX}_FIND_IMPLEMENTATIONS)
105 unset (_${_PYTHON_PREFIX}_${_pff_implementation}_FRAMEWORKS)
106 if (_pff_implementation STREQUAL "CPython")
107 foreach (_pff_framework IN LISTS _pff_frameworks)
108 if (EXISTS ${_pff_framework}/Python${_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR}.framework)
109 list (APPEND _${_PYTHON_PREFIX}_${_pff_implementation}_FRAMEWORKS ${_pff_framework}/Python${_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR}.framework)
111 if (EXISTS ${_pff_framework}/Python.framework)
112 list (APPEND _${_PYTHON_PREFIX}_${_pff_implementation}_FRAMEWORKS ${_pff_framework}/Python.framework)
115 elseif (_pff_implementation STREQUAL "IronPython")
116 foreach (_pff_framework IN LISTS _pff_frameworks)
117 if (EXISTS ${_pff_framework}/IronPython.framework)
118 list (APPEND _${_PYTHON_PREFIX}_${_pff_implementation}_FRAMEWORKS ${_pff_framework}/IronPython.framework)
123 unset (_pff_implementation)
124 unset (_pff_frameworks)
125 unset (_pff_framework)
129 function (_PYTHON_GET_FRAMEWORKS _PYTHON_PGF_FRAMEWORK_PATHS)
130 cmake_parse_arguments (PARSE_ARGV 1 _PGF "" "" "IMPLEMENTATIONS;VERSION")
132 if (NOT _PGF_IMPLEMENTATIONS)
133 set (_PGF_IMPLEMENTATIONS ${_${_PYTHON_PREFIX}_FIND_IMPLEMENTATIONS})
136 set (framework_paths)
138 foreach (implementation IN LISTS _PGF_IMPLEMENTATIONS)
139 if (implementation STREQUAL "CPython")
140 foreach (version IN LISTS _PGF_VERSION)
141 foreach (framework IN LISTS _${_PYTHON_PREFIX}_${implementation}_FRAMEWORKS)
142 if (EXISTS "${framework}/Versions/${version}")
143 list (APPEND framework_paths "${framework}/Versions/${version}")
147 elseif (implementation STREQUAL "IronPython")
148 foreach (version IN LISTS _PGF_VERSION)
149 foreach (framework IN LISTS _${_PYTHON_PREFIX}_${implementation}_FRAMEWORKS)
150 # pick-up all available versions
151 file (GLOB versions LIST_DIRECTORIES true RELATIVE "${framework}/Versions/"
152 "${framework}/Versions/${version}*")
153 list (SORT versions ORDER DESCENDING)
154 list (TRANSFORM versions PREPEND "${framework}/Versions/")
155 list (APPEND framework_paths ${versions})
161 set (${_PYTHON_PGF_FRAMEWORK_PATHS} ${framework_paths} PARENT_SCOPE)
164 function (_PYTHON_GET_REGISTRIES _PYTHON_PGR_REGISTRY_PATHS)
165 cmake_parse_arguments (PARSE_ARGV 1 _PGR "" "" "IMPLEMENTATIONS;VERSION")
167 if (NOT _PGR_IMPLEMENTATIONS)
168 set (_PGR_IMPLEMENTATIONS ${_${_PYTHON_PREFIX}_FIND_IMPLEMENTATIONS})
173 foreach (implementation IN LISTS _PGR_IMPLEMENTATIONS)
174 if (implementation STREQUAL "CPython")
175 foreach (version IN LISTS _PGR_VERSION)
176 string (REPLACE "." "" version_no_dots ${version})
177 list (APPEND registries
178 [HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\${version}-${_${_PYTHON_PREFIX}_ARCH}\\InstallPath]
179 [HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\${version}-${_${_PYTHON_PREFIX}_ARCH2}\\InstallPath])
180 if (version VERSION_GREATER_EQUAL "3.5")
181 get_filename_component (arch "[HKEY_CURRENT_USER\\Software\\Python\\PythonCore\\${version};SysArchitecture]" NAME)
182 if (arch MATCHES "(${_${_PYTHON_PREFIX}_ARCH}|${_${_PYTHON_PREFIX}_ARCH2})bit")
183 list (APPEND registries
184 [HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\${version}\\InstallPath])
187 list (APPEND registries
188 [HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\${version}\\InstallPath])
190 list (APPEND registries
191 [HKEY_CURRENT_USER\\SOFTWARE\\Python\\ContinuumAnalytics\\Anaconda${version_no_dots}-${_${_PYTHON_PREFIX}_ARCH}\\InstallPath]
192 [HKEY_CURRENT_USER\\SOFTWARE\\Python\\ContinuumAnalytics\\Anaconda${version_no_dots}-${_${_PYTHON_PREFIX}_ARCH2}\\InstallPath]
193 [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${version}-${_${_PYTHON_PREFIX}_ARCH}\\InstallPath]
194 [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${version}-${_${_PYTHON_PREFIX}_ARCH2}\\InstallPath]
195 [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${version}\\InstallPath]
196 [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\ContinuumAnalytics\\Anaconda${version_no_dots}-${_${_PYTHON_PREFIX}_ARCH}\\InstallPath]
197 [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\ContinuumAnalytics\\Anaconda${version_no_dots}-${_${_PYTHON_PREFIX}_ARCH2}\\InstallPath])
199 elseif (implementation STREQUAL "IronPython")
200 foreach (version IN LISTS _PGR_VERSION)
201 list (APPEND registries [HKEY_LOCAL_MACHINE\\SOFTWARE\\IronPython\\${version}\\InstallPath])
206 set (${_PYTHON_PGR_REGISTRY_PATHS} "${registries}" PARENT_SCOPE)
210 function (_PYTHON_GET_ABIFLAGS _PGABIFLAGS)
212 list (GET _${_PYTHON_PREFIX}_FIND_ABI 0 pydebug)
213 list (GET _${_PYTHON_PREFIX}_FIND_ABI 1 pymalloc)
214 list (GET _${_PYTHON_PREFIX}_FIND_ABI 2 unicode)
216 if (pymalloc STREQUAL "ANY" AND unicode STREQUAL "ANY")
217 set (abiflags "mu" "m" "u" "")
218 elseif (pymalloc STREQUAL "ANY" AND unicode STREQUAL "ON")
219 set (abiflags "mu" "u")
220 elseif (pymalloc STREQUAL "ANY" AND unicode STREQUAL "OFF")
221 set (abiflags "m" "")
222 elseif (pymalloc STREQUAL "ON" AND unicode STREQUAL "ANY")
223 set (abiflags "mu" "m")
224 elseif (pymalloc STREQUAL "ON" AND unicode STREQUAL "ON")
226 elseif (pymalloc STREQUAL "ON" AND unicode STREQUAL "OFF")
228 elseif (pymalloc STREQUAL "ON" AND unicode STREQUAL "ANY")
229 set (abiflags "u" "")
230 elseif (pymalloc STREQUAL "OFF" AND unicode STREQUAL "ON")
234 if (pydebug STREQUAL "ON")
236 list (TRANSFORM abiflags PREPEND "d")
240 elseif (pydebug STREQUAL "ANY")
242 set (flags "${abiflags}")
243 list (TRANSFORM flags PREPEND "d")
244 list (APPEND abiflags "${flags}")
246 set (abiflags "" "d")
250 set (${_PGABIFLAGS} "${abiflags}" PARENT_SCOPE)
253 function (_PYTHON_GET_PATH_SUFFIXES _PYTHON_PGPS_PATH_SUFFIXES)
254 cmake_parse_arguments (PARSE_ARGV 1 _PGPS "INTERPRETER;COMPILER;LIBRARY;INCLUDE" "" "IMPLEMENTATIONS;VERSION")
256 if (NOT _PGPS_IMPLEMENTATIONS)
257 set (_PGPS_IMPLEMENTATIONS ${_${_PYTHON_PREFIX}_FIND_IMPLEMENTATIONS})
260 if (DEFINED _${_PYTHON_PREFIX}_ABIFLAGS)
261 set (abi "${_${_PYTHON_PREFIX}_ABIFLAGS}")
263 set (abi "mu" "m" "u" "")
268 foreach (implementation IN LISTS _PGPS_IMPLEMENTATIONS)
269 if (implementation STREQUAL "CPython")
270 if (_PGPS_INTERPRETER)
271 list (APPEND path_suffixes bin Scripts)
273 foreach (version IN LISTS _PGPS_VERSION)
275 if (CMAKE_LIBRARY_ARCHITECTURE)
276 list (APPEND path_suffixes lib/${CMAKE_LIBRARY_ARCHITECTURE})
278 list (APPEND path_suffixes lib libs)
280 if (CMAKE_LIBRARY_ARCHITECTURE)
281 set (suffixes "${abi}")
283 list (TRANSFORM suffixes PREPEND "lib/python${version}/config-${version}")
284 list (TRANSFORM suffixes APPEND "-${CMAKE_LIBRARY_ARCHITECTURE}")
286 set (suffixes "lib/python${version}/config-${version}-${CMAKE_LIBRARY_ARCHITECTURE}")
288 list (APPEND path_suffixes ${suffixes})
290 set (suffixes "${abi}")
292 list (TRANSFORM suffixes PREPEND "lib/python${version}/config-${version}")
294 set (suffixes "lib/python${version}/config-${version}")
296 list (APPEND path_suffixes ${suffixes})
297 elseif (_PGPS_INCLUDE)
298 set (suffixes "${abi}")
300 list (TRANSFORM suffixes PREPEND "include/python${version}")
302 set (suffixes "include/python${version}")
304 list (APPEND path_suffixes ${suffixes} include)
308 elseif (implementation STREQUAL "IronPython")
309 if (_PGPS_INTERPRETER OR _PGPS_COMPILER)
310 foreach (version IN LISTS _PGPS_VERSION)
311 list (APPEND path_suffixes "share/ironpython${version}")
313 list (APPEND path_suffixes ${_${_PYTHON_PREFIX}_IRON_PYTHON_PATH_SUFFIXES})
315 elseif (implementation STREQUAL "PyPy")
316 if (_PGPS_INTERPRETER)
317 list (APPEND path_suffixes ${_${_PYTHON_PREFIX}_PYPY_EXECUTABLE_PATH_SUFFIXES})
318 elseif (_PGPS_LIBRARY)
319 list (APPEND path_suffixes ${_${_PYTHON_PREFIX}_PYPY_LIBRARY_PATH_SUFFIXES})
320 elseif (_PGPS_INCLUDE)
321 foreach (version IN LISTS _PGPS_VERSION)
322 list (APPEND path_suffixes lib/pypy${version}/include pypy${version}/include)
324 list (APPEND path_suffixes ${_${_PYTHON_PREFIX}_PYPY_INCLUDE_PATH_SUFFIXES})
328 list (REMOVE_DUPLICATES path_suffixes)
330 set (${_PYTHON_PGPS_PATH_SUFFIXES} ${path_suffixes} PARENT_SCOPE)
333 function (_PYTHON_GET_NAMES _PYTHON_PGN_NAMES)
334 cmake_parse_arguments (PARSE_ARGV 1 _PGN "POSIX;INTERPRETER;COMPILER;CONFIG;LIBRARY;WIN32;DEBUG" "" "IMPLEMENTATIONS;VERSION")
336 if (NOT _PGN_IMPLEMENTATIONS)
337 set (_PGN_IMPLEMENTATIONS ${_${_PYTHON_PREFIX}_FIND_IMPLEMENTATIONS})
342 foreach (implementation IN LISTS _PGN_IMPLEMENTATIONS)
343 if (implementation STREQUAL "CPython")
344 if (_PGN_INTERPRETER AND _${_PYTHON_PREFIX}_FIND_UNVERSIONED_NAMES STREQUAL "FIRST")
345 list (APPEND names python${_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR} python)
347 foreach (version IN LISTS _PGN_VERSION)
349 string (REPLACE "." "" version_no_dots ${version})
351 set (name python${version_no_dots})
353 string (APPEND name "_d")
356 list (APPEND names "${name}")
360 if (DEFINED _${_PYTHON_PREFIX}_ABIFLAGS)
361 set (abi "${_${_PYTHON_PREFIX}_ABIFLAGS}")
363 if (_PGN_INTERPRETER OR _PGN_CONFIG)
366 set (abi "mu" "m" "u" "")
371 if (_PGN_CONFIG AND DEFINED CMAKE_LIBRARY_ARCHITECTURE)
372 set (abinames "${abi}")
373 list (TRANSFORM abinames PREPEND "${CMAKE_LIBRARY_ARCHITECTURE}-python${version}")
374 list (TRANSFORM abinames APPEND "-config")
375 list (APPEND names ${abinames})
377 set (abinames "${abi}")
378 list (TRANSFORM abinames PREPEND "python${version}")
380 list (TRANSFORM abinames APPEND "-config")
382 list (APPEND names ${abinames})
385 if (_PGN_CONFIG AND DEFINED CMAKE_LIBRARY_ARCHITECTURE)
386 set (abinames "${CMAKE_LIBRARY_ARCHITECTURE}-python${version}")
388 list (APPEND abinames "python${version}")
390 list (TRANSFORM abinames APPEND "-config")
392 list (APPEND names ${abinames})
396 if (_PGN_INTERPRETER AND _${_PYTHON_PREFIX}_FIND_UNVERSIONED_NAMES STREQUAL "LAST")
397 list (APPEND names python${_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR} python)
399 elseif (implementation STREQUAL "IronPython")
400 if (_PGN_INTERPRETER)
401 if (NOT CMAKE_SYSTEM_NAME STREQUAL "Linux")
402 # Do not use wrapper script on Linux because it is buggy: -c interpreter option cannot be used
403 foreach (version IN LISTS _PGN_VERSION)
404 list (APPEND names "ipy${version}")
407 list (APPEND names ${_${_PYTHON_PREFIX}_IRON_PYTHON_INTERPRETER_NAMES})
408 elseif (_PGN_COMPILER)
409 list (APPEND names ${_${_PYTHON_PREFIX}_IRON_PYTHON_COMPILER_NAMES})
411 elseif (implementation STREQUAL "PyPy")
412 if (_PGN_INTERPRETER)
413 list (APPEND names ${_${_PYTHON_PREFIX}_PYPY_NAMES})
414 elseif (_PGN_LIBRARY)
416 foreach (version IN LISTS _PGN_VERSION)
417 string (REPLACE "." "" version_no_dots ${version})
418 set (name "python${version_no_dots}")
420 string (APPEND name "_d")
422 list (APPEND names "${name}")
427 foreach(version IN LISTS _PGN_VERSION)
428 list (APPEND names "pypy${version}-c")
432 list (APPEND names ${_${_PYTHON_PREFIX}_PYPY_LIB_NAMES})
437 set (${_PYTHON_PGN_NAMES} ${names} PARENT_SCOPE)
440 function (_PYTHON_GET_CONFIG_VAR _PYTHON_PGCV_VALUE NAME)
441 unset (${_PYTHON_PGCV_VALUE} PARENT_SCOPE)
443 if (NOT NAME MATCHES "^(PREFIX|ABIFLAGS|CONFIGDIR|INCLUDES|LIBS|SOABI)$")
447 if (_${_PYTHON_PREFIX}_CONFIG)
448 if (NAME STREQUAL "SOABI")
449 set (config_flag "--extension-suffix")
451 set (config_flag "--${NAME}")
453 string (TOLOWER "${config_flag}" config_flag)
454 execute_process (COMMAND "${_${_PYTHON_PREFIX}_CONFIG}" ${config_flag}
455 RESULT_VARIABLE _result
456 OUTPUT_VARIABLE _values
458 OUTPUT_STRIP_TRAILING_WHITESPACE)
462 if (NAME STREQUAL "INCLUDES")
464 string (REGEX MATCHALL "(-I|-iwithsysroot)[ ]*[^ ]+" _values "${_values}")
465 string (REGEX REPLACE "(-I|-iwithsysroot)[ ]*" "" _values "${_values}")
466 list (REMOVE_DUPLICATES _values)
467 elseif (NAME STREQUAL "SOABI")
468 # clean-up: remove prefix character and suffix
469 if (_values MATCHES "^(\\.${CMAKE_SHARED_LIBRARY_SUFFIX}|\\.so|\\.pyd)$")
472 string (REGEX REPLACE "^[.-](.+)(${CMAKE_SHARED_LIBRARY_SUFFIX}|\\.(so|pyd))$" "\\1" _values "${_values}")
478 if (_${_PYTHON_PREFIX}_EXECUTABLE AND NOT CMAKE_CROSSCOMPILING)
479 if (NAME STREQUAL "PREFIX")
480 execute_process (COMMAND ${_${_PYTHON_PREFIX}_INTERPRETER_LAUNCHER} "${_${_PYTHON_PREFIX}_EXECUTABLE}" -c "import sys\ntry:\n from distutils import sysconfig\n sys.stdout.write(';'.join([sysconfig.PREFIX,sysconfig.EXEC_PREFIX,sysconfig.BASE_EXEC_PREFIX]))\nexcept Exception:\n import sysconfig\n sys.stdout.write(';'.join([sysconfig.get_config_var('base') or '', sysconfig.get_config_var('installed_base') or '']))"
481 RESULT_VARIABLE _result
482 OUTPUT_VARIABLE _values
484 OUTPUT_STRIP_TRAILING_WHITESPACE)
488 list (REMOVE_DUPLICATES _values)
490 elseif (NAME STREQUAL "INCLUDES")
494 set (_scheme "posix_prefix")
496 execute_process (COMMAND ${_${_PYTHON_PREFIX}_INTERPRETER_LAUNCHER} "${_${_PYTHON_PREFIX}_EXECUTABLE}" -c
497 "import sys\ntry:\n from distutils import sysconfig\n sys.stdout.write(';'.join([sysconfig.get_python_inc(plat_specific=True),sysconfig.get_python_inc(plat_specific=False)]))\nexcept Exception:\n import sysconfig\n sys.stdout.write(';'.join([sysconfig.get_path('platinclude'),sysconfig.get_path('platinclude','${_scheme}'),sysconfig.get_path('include'),sysconfig.get_path('include','${_scheme}')]))"
498 RESULT_VARIABLE _result
499 OUTPUT_VARIABLE _values
501 OUTPUT_STRIP_TRAILING_WHITESPACE)
505 list (REMOVE_DUPLICATES _values)
507 elseif (NAME STREQUAL "SOABI")
508 execute_process (COMMAND ${_${_PYTHON_PREFIX}_INTERPRETER_LAUNCHER} "${_${_PYTHON_PREFIX}_EXECUTABLE}" -c
509 "import sys\ntry:\n from distutils import sysconfig\n sys.stdout.write(';'.join([sysconfig.get_config_var('SOABI') or '',sysconfig.get_config_var('EXT_SUFFIX') or '',sysconfig.get_config_var('SO') or '']))\nexcept Exception:\n import sysconfig;sys.stdout.write(';'.join([sysconfig.get_config_var('SOABI') or '',sysconfig.get_config_var('EXT_SUFFIX') or '',sysconfig.get_config_var('SO') or '']))"
510 RESULT_VARIABLE _result
511 OUTPUT_VARIABLE _soabi
513 OUTPUT_STRIP_TRAILING_WHITESPACE)
517 foreach (_item IN LISTS _soabi)
519 set (_values "${_item}")
524 # clean-up: remove prefix character and suffix
525 if (_values MATCHES "^(\\.${CMAKE_SHARED_LIBRARY_SUFFIX}|\\.so|\\.pyd)$")
528 string (REGEX REPLACE "^[.-](.+)(${CMAKE_SHARED_LIBRARY_SUFFIX}|\\.(so|pyd))$" "\\1" _values "${_values}")
533 set (config_flag "${NAME}")
534 if (NAME STREQUAL "CONFIGDIR")
535 set (config_flag "LIBPL")
537 execute_process (COMMAND ${_${_PYTHON_PREFIX}_INTERPRETER_LAUNCHER} "${_${_PYTHON_PREFIX}_EXECUTABLE}" -c
538 "import sys\ntry:\n from distutils import sysconfig\n sys.stdout.write(sysconfig.get_config_var('${config_flag}'))\nexcept Exception:\n import sysconfig\n sys.stdout.write(sysconfig.get_config_var('${config_flag}'))"
539 RESULT_VARIABLE _result
540 OUTPUT_VARIABLE _values
542 OUTPUT_STRIP_TRAILING_WHITESPACE)
549 if (NAME STREQUAL "ABIFLAGS" OR NAME STREQUAL "SOABI")
550 set (${_PYTHON_PGCV_VALUE} "${_values}" PARENT_SCOPE)
554 if (NOT _values OR _values STREQUAL "None")
558 if (NAME STREQUAL "LIBS")
560 string (REGEX MATCHALL "-(l|framework)[ ]*[^ ]+" _values "${_values}")
561 # remove elements relative to python library itself
562 list (FILTER _values EXCLUDE REGEX "-lpython")
563 list (REMOVE_DUPLICATES _values)
566 if (WIN32 AND NAME MATCHES "^(PREFIX|CONFIGDIR|INCLUDES)$")
567 file (TO_CMAKE_PATH "${_values}" _values)
570 set (${_PYTHON_PGCV_VALUE} "${_values}" PARENT_SCOPE)
573 function (_PYTHON_GET_VERSION)
574 cmake_parse_arguments (PARSE_ARGV 0 _PGV "LIBRARY;INCLUDE" "PREFIX" "")
576 unset (${_PGV_PREFIX}VERSION PARENT_SCOPE)
577 unset (${_PGV_PREFIX}VERSION_MAJOR PARENT_SCOPE)
578 unset (${_PGV_PREFIX}VERSION_MINOR PARENT_SCOPE)
579 unset (${_PGV_PREFIX}VERSION_PATCH PARENT_SCOPE)
580 unset (${_PGV_PREFIX}ABI PARENT_SCOPE)
583 # retrieve version and abi from library name
584 if (_${_PYTHON_PREFIX}_LIBRARY_RELEASE)
585 get_filename_component (library_name "${_${_PYTHON_PREFIX}_LIBRARY_RELEASE}" NAME)
586 # extract version from library name
587 if (library_name MATCHES "python([23])([0-9]+)")
588 set (${_PGV_PREFIX}VERSION_MAJOR "${CMAKE_MATCH_1}" PARENT_SCOPE)
589 set (${_PGV_PREFIX}VERSION_MINOR "${CMAKE_MATCH_2}" PARENT_SCOPE)
590 set (${_PGV_PREFIX}VERSION "${CMAKE_MATCH_1}.${CMAKE_MATCH_2}" PARENT_SCOPE)
591 set (${_PGV_PREFIX}ABI "" PARENT_SCOPE)
592 elseif (library_name MATCHES "python([23])\\.([0-9]+)([dmu]*)")
593 set (${_PGV_PREFIX}VERSION_MAJOR "${CMAKE_MATCH_1}" PARENT_SCOPE)
594 set (${_PGV_PREFIX}VERSION_MINOR "${CMAKE_MATCH_2}" PARENT_SCOPE)
595 set (${_PGV_PREFIX}VERSION "${CMAKE_MATCH_1}.${CMAKE_MATCH_2}" PARENT_SCOPE)
596 set (${_PGV_PREFIX}ABI "${CMAKE_MATCH_3}" PARENT_SCOPE)
597 elseif (library_name MATCHES "pypy([23])\\.([0-9]+)-c")
598 set (${_PGV_PREFIX}VERSION_MAJOR "${CMAKE_MATCH_1}" PARENT_SCOPE)
599 set (${_PGV_PREFIX}VERSION_MINOR "${CMAKE_MATCH_2}" PARENT_SCOPE)
600 set (${_PGV_PREFIX}VERSION "${CMAKE_MATCH_1}.${CMAKE_MATCH_2}" PARENT_SCOPE)
601 set (${_PGV_PREFIX}ABI "" PARENT_SCOPE)
602 elseif (library_name MATCHES "pypy(3)?-c")
603 set (version "${CMAKE_MATCH_1}")
604 # try to pick-up a more precise version from the path
605 get_filename_component (library_dir "${_${_PYTHON_PREFIX}_LIBRARY_RELEASE}" DIRECTORY)
606 if (library_dir MATCHES "/pypy([23])\\.([0-9]+)/")
607 set (${_PGV_PREFIX}VERSION_MAJOR "${CMAKE_MATCH_1}" PARENT_SCOPE)
608 set (${_PGV_PREFIX}VERSION_MINOR "${CMAKE_MATCH_2}" PARENT_SCOPE)
609 set (${_PGV_PREFIX}VERSION "${CMAKE_MATCH_1}.${CMAKE_MATCH_2}" PARENT_SCOPE)
610 elseif (version EQUAL "3")
611 set (${_PGV_PREFIX}VERSION_MAJOR "3" PARENT_SCOPE)
612 set (${_PGV_PREFIX}VERSION "3" PARENT_SCOPE)
614 set (${_PGV_PREFIX}VERSION_MAJOR "2" PARENT_SCOPE)
615 set (${_PGV_PREFIX}VERSION "2" PARENT_SCOPE)
617 set (${_PGV_PREFIX}ABI "" PARENT_SCOPE)
621 if (_${_PYTHON_PREFIX}_INCLUDE_DIR)
622 # retrieve version from header file
623 file (STRINGS "${_${_PYTHON_PREFIX}_INCLUDE_DIR}/patchlevel.h" version
624 REGEX "^#define[ \t]+PY_VERSION[ \t]+\"[^\"]+\"")
625 string (REGEX REPLACE "^#define[ \t]+PY_VERSION[ \t]+\"([^\"]+)\".*" "\\1"
626 version "${version}")
627 string (REGEX MATCHALL "[0-9]+" versions "${version}")
628 list (GET versions 0 version_major)
629 list (GET versions 1 version_minor)
630 list (GET versions 2 version_patch)
632 set (${_PGV_PREFIX}VERSION "${version_major}.${version_minor}.${version_patch}" PARENT_SCOPE)
633 set (${_PGV_PREFIX}VERSION_MAJOR ${version_major} PARENT_SCOPE)
634 set (${_PGV_PREFIX}VERSION_MINOR ${version_minor} PARENT_SCOPE)
635 set (${_PGV_PREFIX}VERSION_PATCH ${version_patch} PARENT_SCOPE)
638 if (version_major VERSION_GREATER "2")
639 file (STRINGS "${_${_PYTHON_PREFIX}_INCLUDE_DIR}/pyconfig.h" config REGEX "(Py_DEBUG|WITH_PYMALLOC|Py_UNICODE_SIZE|MS_WIN32)")
641 if (config MATCHES "#[ ]*define[ ]+MS_WIN32")
642 # ABI not used on Windows
646 # pyconfig.h can be a wrapper to a platform specific pyconfig.h
647 # In this case, try to identify ABI from include directory
648 if (_${_PYTHON_PREFIX}_INCLUDE_DIR MATCHES "python${version_major}\\.${version_minor}+([dmu]*)")
649 set (abi "${CMAKE_MATCH_1}")
654 if (config MATCHES "#[ ]*define[ ]+Py_DEBUG[ ]+1")
655 string (APPEND abi "d")
657 if (config MATCHES "#[ ]*define[ ]+WITH_PYMALLOC[ ]+1")
658 string (APPEND abi "m")
660 if (config MATCHES "#[ ]*define[ ]+Py_UNICODE_SIZE[ ]+4")
661 string (APPEND abi "u")
664 set (${_PGV_PREFIX}ABI "${abi}" PARENT_SCOPE)
668 set (${_PGV_PREFIX}ABI "" PARENT_SCOPE)
674 function (_PYTHON_GET_LAUNCHER _PYTHON_PGL_NAME)
675 cmake_parse_arguments (PARSE_ARGV 1 _PGL "INTERPRETER;COMPILER" "" "")
677 unset (${_PYTHON_PGL_NAME} PARENT_SCOPE)
679 if ((_PGL_INTERPRETER AND NOT _${_PYTHON_PREFIX}_EXECUTABLE)
680 OR (_PGL_COMPILER AND NOT _${_PYTHON_PREFIX}_COMPILER))
684 if ("IronPython" IN_LIST _${_PYTHON_PREFIX}_FIND_IMPLEMENTATIONS
685 AND NOT SYSTEM_NAME MATCHES "Windows|Linux")
686 if (_PGL_INTERPRETER)
687 get_filename_component (name "${_${_PYTHON_PREFIX}_EXECUTABLE}" NAME)
688 get_filename_component (ext "${_${_PYTHON_PREFIX}_EXECUTABLE}" LAST_EXT)
689 if (name IN_LIST _${_PYTHON_PREFIX}_IRON_PYTHON_INTERPRETER_NAMES
690 AND ext STREQUAL ".exe")
691 set (${_PYTHON_PGL_NAME} "${${_PYTHON_PREFIX}_DOTNET_LAUNCHER}" PARENT_SCOPE)
694 get_filename_component (name "${_${_PYTHON_PREFIX}_COMPILER}" NAME)
695 get_filename_component (ext "${_${_PYTHON_PREFIX}_COMPILER}" LAST_EXT)
696 if (name IN_LIST _${_PYTHON_PREFIX}_IRON_PYTHON_COMPILER_NAMES
697 AND ext STREQUAL ".exe")
698 set (${_PYTHON_PGL_NAME} "${${_PYTHON_PREFIX}_DOTNET_LAUNCHER}" PARENT_SCOPE)
705 function (_PYTHON_VALIDATE_INTERPRETER)
706 if (NOT _${_PYTHON_PREFIX}_EXECUTABLE)
710 cmake_parse_arguments (PARSE_ARGV 0 _PVI "IN_RANGE;EXACT;CHECK_EXISTS" "VERSION" "")
712 if (_PVI_CHECK_EXISTS AND NOT EXISTS "${_${_PYTHON_PREFIX}_EXECUTABLE}")
713 # interpreter does not exist anymore
714 set (_${_PYTHON_PREFIX}_Interpreter_REASON_FAILURE "Cannot find the interpreter \"${_${_PYTHON_PREFIX}_EXECUTABLE}\"" PARENT_SCOPE)
715 set_property (CACHE _${_PYTHON_PREFIX}_EXECUTABLE PROPERTY VALUE "${_PYTHON_PREFIX}_EXECUTABLE-NOTFOUND")
719 _python_get_launcher (launcher INTERPRETER)
721 # validate ABI compatibility
722 if (DEFINED _${_PYTHON_PREFIX}_FIND_ABI)
723 execute_process (COMMAND ${launcher} "${_${_PYTHON_PREFIX}_EXECUTABLE}" -c
724 "import sys; sys.stdout.write(sys.abiflags)"
725 RESULT_VARIABLE result
728 OUTPUT_STRIP_TRAILING_WHITESPACE)
730 # assume ABI is not supported
733 if (NOT abi IN_LIST _${_PYTHON_PREFIX}_ABIFLAGS)
735 set (_${_PYTHON_PREFIX}_Interpreter_REASON_FAILURE "Wrong ABI for the interpreter \"${_${_PYTHON_PREFIX}_EXECUTABLE}\"" PARENT_SCOPE)
736 set_property (CACHE _${_PYTHON_PREFIX}_EXECUTABLE PROPERTY VALUE "${_PYTHON_PREFIX}_EXECUTABLE-NOTFOUND")
741 if (_PVI_IN_RANGE OR _PVI_VERSION)
742 # retrieve full version
743 execute_process (COMMAND ${launcher} "${_${_PYTHON_PREFIX}_EXECUTABLE}" -c
744 "import sys; sys.stdout.write('.'.join([str(x) for x in sys.version_info[:3]]))"
745 RESULT_VARIABLE result
746 OUTPUT_VARIABLE version
748 OUTPUT_STRIP_TRAILING_WHITESPACE)
750 # interpreter is not usable
751 set (_${_PYTHON_PREFIX}_Interpreter_REASON_FAILURE "Cannot use the interpreter \"${_${_PYTHON_PREFIX}_EXECUTABLE}\"" PARENT_SCOPE)
752 set_property (CACHE _${_PYTHON_PREFIX}_EXECUTABLE PROPERTY VALUE "${_PYTHON_PREFIX}_EXECUTABLE-NOTFOUND")
757 # check against specified version
758 ## compute number of components for version
759 string (REGEX REPLACE "[^.]" "" dots "${_PVI_VERSION}")
760 ## add one dot because there is one dot less than there are components
761 string (LENGTH "${dots}." count)
765 set (version_regex "^[0-9]+")
767 string (APPEND version_regex "\\.[0-9]+\\.[0-9]+")
768 elseif (count EQUAL 2)
769 string (APPEND version_regex "\\.[0-9]+")
771 # extract needed range
772 string (REGEX MATCH "${version_regex}" version "${version}")
774 if (_PVI_EXACT AND NOT version VERSION_EQUAL _PVI_VERSION)
775 # interpreter has wrong version
776 set (_${_PYTHON_PREFIX}_Interpreter_REASON_FAILURE "Wrong version for the interpreter \"${_${_PYTHON_PREFIX}_EXECUTABLE}\"" PARENT_SCOPE)
777 set_property (CACHE _${_PYTHON_PREFIX}_EXECUTABLE PROPERTY VALUE "${_PYTHON_PREFIX}_EXECUTABLE-NOTFOUND")
780 # check that version is OK
781 string(REGEX REPLACE "^([0-9]+)\\.?.*$" "\\1" major_version "${version}")
782 string(REGEX REPLACE "^([0-9]+)\\.?.*$" "\\1" expected_major_version "${_PVI_VERSION}")
783 if (NOT major_version VERSION_EQUAL expected_major_version
784 OR NOT version VERSION_GREATER_EQUAL _PVI_VERSION)
785 set (_${_PYTHON_PREFIX}_Interpreter_REASON_FAILURE "Wrong version for the interpreter \"${_${_PYTHON_PREFIX}_EXECUTABLE}\"" PARENT_SCOPE)
786 set_property (CACHE _${_PYTHON_PREFIX}_EXECUTABLE PROPERTY VALUE "${_PYTHON_PREFIX}_EXECUTABLE-NOTFOUND")
793 # check if version is in the requested range
794 find_package_check_version ("${version}" in_range HANDLE_VERSION_RANGE)
796 # interpreter has invalid version
797 set (_${_PYTHON_PREFIX}_Interpreter_REASON_FAILURE "Wrong version for the interpreter \"${_${_PYTHON_PREFIX}_EXECUTABLE}\"" PARENT_SCOPE)
798 set_property (CACHE _${_PYTHON_PREFIX}_EXECUTABLE PROPERTY VALUE "${_PYTHON_PREFIX}_EXECUTABLE-NOTFOUND")
803 get_filename_component (python_name "${_${_PYTHON_PREFIX}_EXECUTABLE}" NAME)
804 if (NOT python_name STREQUAL "python${_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR}${CMAKE_EXECUTABLE_SUFFIX}")
805 # executable found do not have version in name
806 # ensure major version is OK
807 execute_process (COMMAND ${launcher} "${_${_PYTHON_PREFIX}_EXECUTABLE}" -c
808 "import sys; sys.stdout.write(str(sys.version_info[0]))"
809 RESULT_VARIABLE result
810 OUTPUT_VARIABLE version
812 OUTPUT_STRIP_TRAILING_WHITESPACE)
813 if (result OR NOT version EQUAL _${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR)
814 # interpreter not usable or has wrong major version
816 set (_${_PYTHON_PREFIX}_Interpreter_REASON_FAILURE "Cannot use the interpreter \"${_${_PYTHON_PREFIX}_EXECUTABLE}\"" PARENT_SCOPE)
818 set (_${_PYTHON_PREFIX}_Interpreter_REASON_FAILURE "Wrong major version for the interpreter \"${_${_PYTHON_PREFIX}_EXECUTABLE}\"" PARENT_SCOPE)
820 set_property (CACHE _${_PYTHON_PREFIX}_EXECUTABLE PROPERTY VALUE "${_PYTHON_PREFIX}_EXECUTABLE-NOTFOUND")
826 if (CMAKE_SIZEOF_VOID_P AND ("Development.Module" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS
827 OR "Development.Embed" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS)
828 AND NOT CMAKE_CROSSCOMPILING)
829 # In this case, interpreter must have same architecture as environment
830 execute_process (COMMAND ${launcher} "${_${_PYTHON_PREFIX}_EXECUTABLE}" -c
831 "import sys, struct; sys.stdout.write(str(struct.calcsize(\"P\")))"
832 RESULT_VARIABLE result
835 OUTPUT_STRIP_TRAILING_WHITESPACE)
836 if (result OR NOT size EQUAL CMAKE_SIZEOF_VOID_P)
837 # interpreter not usable or has wrong architecture
839 set (_${_PYTHON_PREFIX}_Interpreter_REASON_FAILURE "Cannot use the interpreter \"${_${_PYTHON_PREFIX}_EXECUTABLE}\"" PARENT_SCOPE)
841 set (_${_PYTHON_PREFIX}_Interpreter_REASON_FAILURE "Wrong architecture for the interpreter \"${_${_PYTHON_PREFIX}_EXECUTABLE}\"" PARENT_SCOPE)
843 set_property (CACHE _${_PYTHON_PREFIX}_EXECUTABLE PROPERTY VALUE "${_PYTHON_PREFIX}_EXECUTABLE-NOTFOUND")
850 function (_PYTHON_VALIDATE_COMPILER)
851 if (NOT _${_PYTHON_PREFIX}_COMPILER)
855 cmake_parse_arguments (PARSE_ARGV 0 _PVC "IN_RANGE;EXACT;CHECK_EXISTS" "VERSION" "")
857 if (_PVC_CHECK_EXISTS AND NOT EXISTS "${_${_PYTHON_PREFIX}_COMPILER}")
858 # Compiler does not exist anymore
859 set (_${_PYTHON_PREFIX}_Compiler_REASON_FAILURE "Cannot find the compiler \"${_${_PYTHON_PREFIX}_COMPILER}\"" PARENT_SCOPE)
860 set_property (CACHE _${_PYTHON_PREFIX}_COMPILER PROPERTY VALUE "${_PYTHON_PREFIX}_COMPILER-NOTFOUND")
864 _python_get_launcher (launcher COMPILER)
866 # retrieve python environment version from compiler
867 set (working_dir "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/PythonCompilerVersion.dir")
868 file (WRITE "${working_dir}/version.py" "import sys; sys.stdout.write('.'.join([str(x) for x in sys.version_info[:3]]))\n")
869 execute_process (COMMAND ${launcher} "${_${_PYTHON_PREFIX}_COMPILER}"
870 ${_${_PYTHON_PREFIX}_IRON_PYTHON_COMPILER_ARCH_FLAGS}
871 /target:exe /embed "${working_dir}/version.py"
872 WORKING_DIRECTORY "${working_dir}"
875 OUTPUT_STRIP_TRAILING_WHITESPACE)
876 get_filename_component (ir_dir "${_${_PYTHON_PREFIX}_COMPILER}" DIRECTORY)
877 execute_process (COMMAND "${CMAKE_COMMAND}" -E env "MONO_PATH=${ir_dir}"
878 ${${_PYTHON_PREFIX}_DOTNET_LAUNCHER} "${working_dir}/version.exe"
879 WORKING_DIRECTORY "${working_dir}"
880 RESULT_VARIABLE result
881 OUTPUT_VARIABLE version
883 file (REMOVE_RECURSE "${working_dir}")
885 # compiler is not usable
886 set (_${_PYTHON_PREFIX}_Compiler_REASON_FAILURE "Cannot use the compiler \"${_${_PYTHON_PREFIX}_COMPILER}\"" PARENT_SCOPE)
887 set_property (CACHE _${_PYTHON_PREFIX}_COMPILER PROPERTY VALUE "${_PYTHON_PREFIX}_COMPILER-NOTFOUND")
891 if (_PVC_VERSION OR _PVC_IN_RANGE)
893 # check against specified version
894 ## compute number of components for version
895 string (REGEX REPLACE "[^.]" "" dots "${_PVC_VERSION}")
896 ## add one dot because there is one dot less than there are components
897 string (LENGTH "${dots}." count)
901 set (version_regex "^[0-9]+")
903 string (APPEND version_regex "\\.[0-9]+\\.[0-9]+")
904 elseif (count EQUAL 2)
905 string (APPEND version_regex "\\.[0-9]+")
907 # extract needed range
908 string (REGEX MATCH "${version_regex}" version "${version}")
910 if (_PVC_EXACT AND NOT version VERSION_EQUAL _PVC_VERSION)
911 # interpreter has wrong version
912 set (_${_PYTHON_PREFIX}_Compiler_REASON_FAILURE "Wrong version for the compiler \"${_${_PYTHON_PREFIX}_COMPILER}\"" PARENT_SCOPE)
913 set_property (CACHE _${_PYTHON_PREFIX}_COMPILER PROPERTY VALUE "${_PYTHON_PREFIX}_COMPILER-NOTFOUND")
916 # check that version is OK
917 string(REGEX REPLACE "^([0-9]+)\\.?.*$" "\\1" major_version "${version}")
918 string(REGEX REPLACE "^([0-9]+)\\.?.*$" "\\1" expected_major_version "${_PVC_VERSION}")
919 if (NOT major_version VERSION_EQUAL expected_major_version
920 OR NOT version VERSION_GREATER_EQUAL _PVC_VERSION)
921 set (_${_PYTHON_PREFIX}_Compiler_REASON_FAILURE "Wrong version for the compiler \"${_${_PYTHON_PREFIX}_COMPILER}\"" PARENT_SCOPE)
922 set_property (CACHE _${_PYTHON_PREFIX}_COMPILER PROPERTY VALUE "${_PYTHON_PREFIX}_COMPILER-NOTFOUND")
929 # check if version is in the requested range
930 find_package_check_version ("${version}" in_range HANDLE_VERSION_RANGE)
932 # interpreter has invalid version
933 set (_${_PYTHON_PREFIX}_Compiler_REASON_FAILURE "Wrong version for the compiler \"${_${_PYTHON_PREFIX}_COMPILER}\"" PARENT_SCOPE)
934 set_property (CACHE _${_PYTHON_PREFIX}_COMPILER PROPERTY VALUE "${_PYTHON_PREFIX}_COMPILER-NOTFOUND")
939 string(REGEX REPLACE "^([0-9]+)\\.?.*$" "\\1" major_version "${version}")
940 if (NOT major_version EQUAL _${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR)
941 # Compiler has wrong major version
942 set (_${_PYTHON_PREFIX}_Compiler_REASON_FAILURE "Wrong major version for the compiler \"${_${_PYTHON_PREFIX}_COMPILER}\"" PARENT_SCOPE)
943 set_property (CACHE _${_PYTHON_PREFIX}_COMPILER PROPERTY VALUE "${_PYTHON_PREFIX}_COMPILER-NOTFOUND")
950 function (_PYTHON_VALIDATE_LIBRARY)
951 if (NOT _${_PYTHON_PREFIX}_LIBRARY_RELEASE)
952 unset (_${_PYTHON_PREFIX}_LIBRARY_DEBUG)
956 cmake_parse_arguments (PARSE_ARGV 0 _PVL "IN_RANGE;EXACT;CHECK_EXISTS" "VERSION" "")
958 if (_PVL_CHECK_EXISTS AND NOT EXISTS "${_${_PYTHON_PREFIX}_LIBRARY_RELEASE}")
959 # library does not exist anymore
960 set (_${_PYTHON_PREFIX}_Development_REASON_FAILURE "Cannot find the library \"${_${_PYTHON_PREFIX}_LIBRARY_RELEASE}\"" PARENT_SCOPE)
961 set_property (CACHE _${_PYTHON_PREFIX}_LIBRARY_RELEASE PROPERTY VALUE "${_PYTHON_PREFIX}_LIBRARY_RELEASE-NOTFOUND")
963 set_property (CACHE _${_PYTHON_PREFIX}_LIBRARY_DEBUG PROPERTY VALUE "${_PYTHON_PREFIX}_LIBRARY_DEBUG-NOTFOUND")
965 set_property (CACHE _${_PYTHON_PREFIX}_INCLUDE_DIR PROPERTY VALUE "${_PYTHON_PREFIX}_INCLUDE_DIR-NOTFOUND")
969 # retrieve version and abi from library name
970 _python_get_version (LIBRARY PREFIX lib_)
972 if (DEFINED _${_PYTHON_PREFIX}_FIND_ABI AND NOT lib_ABI IN_LIST _${_PYTHON_PREFIX}_ABIFLAGS)
974 set (_${_PYTHON_PREFIX}_Development_REASON_FAILURE "Wrong ABI for the library \"${_${_PYTHON_PREFIX}_LIBRARY_RELEASE}\"" PARENT_SCOPE)
975 set_property (CACHE _${_PYTHON_PREFIX}_LIBRARY_RELEASE PROPERTY VALUE "${_PYTHON_PREFIX}_LIBRARY_RELEASE-NOTFOUND")
977 if (_PVL_VERSION OR _PVL_IN_RANGE)
979 # library have only major.minor information
980 string (REGEX MATCH "[0-9](\\.[0-9]+)?" version "${_PVL_VERSION}")
981 if ((_PVL_EXACT AND NOT lib_VERSION VERSION_EQUAL version) OR (lib_VERSION VERSION_LESS version))
982 # library has wrong version
983 set (_${_PYTHON_PREFIX}_Development_REASON_FAILURE "Wrong version for the library \"${_${_PYTHON_PREFIX}_LIBRARY_RELEASE}\"" PARENT_SCOPE)
984 set_property (CACHE _${_PYTHON_PREFIX}_LIBRARY_RELEASE PROPERTY VALUE "${_PYTHON_PREFIX}_LIBRARY_RELEASE-NOTFOUND")
988 if (_${_PYTHON_PREFIX}_LIBRARY_RELEASE AND _PVL_IN_RANGE)
989 # check if library version is in the requested range
990 find_package_check_version ("${lib_VERSION}" in_range HANDLE_VERSION_RANGE)
992 # library has wrong version
993 set (_${_PYTHON_PREFIX}_Development_REASON_FAILURE "Wrong version for the library \"${_${_PYTHON_PREFIX}_LIBRARY_RELEASE}\"" PARENT_SCOPE)
994 set_property (CACHE _${_PYTHON_PREFIX}_LIBRARY_RELEASE PROPERTY VALUE "${_PYTHON_PREFIX}_LIBRARY_RELEASE-NOTFOUND")
998 if (NOT lib_VERSION_MAJOR VERSION_EQUAL _${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR)
999 # library has wrong major version
1000 set (_${_PYTHON_PREFIX}_Development_REASON_FAILURE "Wrong major version for the library \"${_${_PYTHON_PREFIX}_LIBRARY_RELEASE}\"" PARENT_SCOPE)
1001 set_property (CACHE _${_PYTHON_PREFIX}_LIBRARY_RELEASE PROPERTY VALUE "${_PYTHON_PREFIX}_LIBRARY_RELEASE-NOTFOUND")
1006 if (NOT _${_PYTHON_PREFIX}_LIBRARY_RELEASE)
1008 set_property (CACHE _${_PYTHON_PREFIX}_LIBRARY_DEBUG PROPERTY VALUE "${_PYTHON_PREFIX}_LIBRARY_DEBUG-NOTFOUND")
1010 unset (_${_PYTHON_PREFIX}_RUNTIME_LIBRARY_RELEASE CACHE)
1011 unset (_${_PYTHON_PREFIX}_RUNTIME_LIBRARY_DEBUG CACHE)
1012 set_property (CACHE _${_PYTHON_PREFIX}_INCLUDE_DIR PROPERTY VALUE "${_PYTHON_PREFIX}_INCLUDE_DIR-NOTFOUND")
1017 function (_PYTHON_VALIDATE_INCLUDE_DIR)
1018 if (NOT _${_PYTHON_PREFIX}_INCLUDE_DIR)
1022 cmake_parse_arguments (PARSE_ARGV 0 _PVID "IN_RANGE;EXACT;CHECK_EXISTS" "VERSION" "")
1024 if (_PVID_CHECK_EXISTS AND NOT EXISTS "${_${_PYTHON_PREFIX}_INCLUDE_DIR}")
1025 # include file does not exist anymore
1026 set (_${_PYTHON_PREFIX}_Development_REASON_FAILURE "Cannot find the directory \"${_${_PYTHON_PREFIX}_INCLUDE_DIR}\"" PARENT_SCOPE)
1027 set_property (CACHE _${_PYTHON_PREFIX}_INCLUDE_DIR PROPERTY VALUE "${_PYTHON_PREFIX}_INCLUDE_DIR-NOTFOUND")
1031 # retrieve version from header file
1032 _python_get_version (INCLUDE PREFIX inc_)
1034 if (DEFINED _${_PYTHON_PREFIX}_FIND_ABI AND NOT inc_ABI IN_LIST _${_PYTHON_PREFIX}_ABIFLAGS)
1036 set (_${_PYTHON_PREFIX}_Development_REASON_FAILURE "Wrong ABI for the directory \"${_${_PYTHON_PREFIX}_INCLUDE_DIR}\"" PARENT_SCOPE)
1037 set_property (CACHE _${_PYTHON_PREFIX}_INCLUDE_DIR PROPERTY VALUE "${_PYTHON_PREFIX}_INCLUDE_DIR-NOTFOUND")
1039 if (_PVID_VERSION OR _PVID_IN_RANGE)
1041 if ((_PVID_EXACT AND NOT inc_VERSION VERSION_EQUAL expected_version) OR (inc_VERSION VERSION_LESS expected_version))
1042 # include dir has wrong version
1043 set (_${_PYTHON_PREFIX}_Development_REASON_FAILURE "Wrong version for the directory \"${_${_PYTHON_PREFIX}_INCLUDE_DIR}\"" PARENT_SCOPE)
1044 set_property (CACHE _${_PYTHON_PREFIX}_INCLUDE_DIR PROPERTY VALUE "${_PYTHON_PREFIX}_INCLUDE_DIR-NOTFOUND")
1048 if (_${_PYTHON_PREFIX}_INCLUDE_DIR AND PVID_IN_RANGE)
1049 # check if include dir is in the request range
1050 find_package_check_version ("${inc_VERSION}" in_range HANDLE_VERSION_RANGE)
1052 # include dir has wrong version
1053 set (_${_PYTHON_PREFIX}_Development_REASON_FAILURE "Wrong version for the directory \"${_${_PYTHON_PREFIX}_INCLUDE_DIR}\"" PARENT_SCOPE)
1054 set_property (CACHE _${_PYTHON_PREFIX}_INCLUDE_DIR PROPERTY VALUE "${_PYTHON_PREFIX}_INCLUDE_DIR-NOTFOUND")
1058 if (NOT inc_VERSION_MAJOR VERSION_EQUAL _${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR)
1059 # include dir has wrong major version
1060 set (_${_PYTHON_PREFIX}_Development_REASON_FAILURE "Wrong major version for the directory \"${_${_PYTHON_PREFIX}_INCLUDE_DIR}\"" PARENT_SCOPE)
1061 set_property (CACHE _${_PYTHON_PREFIX}_INCLUDE_DIR PROPERTY VALUE "${_PYTHON_PREFIX}_INCLUDE_DIR-NOTFOUND")
1068 function (_PYTHON_FIND_RUNTIME_LIBRARY _PYTHON_LIB)
1069 string (REPLACE "_RUNTIME" "" _PYTHON_LIB "${_PYTHON_LIB}")
1070 # look at runtime part on systems supporting it
1071 if (CMAKE_SYSTEM_NAME STREQUAL "Windows" OR
1072 (CMAKE_SYSTEM_NAME MATCHES "MSYS|CYGWIN"
1073 AND ${_PYTHON_LIB} MATCHES "${CMAKE_IMPORT_LIBRARY_SUFFIX}$"))
1074 set (CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_SHARED_LIBRARY_SUFFIX})
1075 # MSYS has a special syntax for runtime libraries
1076 if (CMAKE_SYSTEM_NAME MATCHES "MSYS")
1077 list (APPEND CMAKE_FIND_LIBRARY_PREFIXES "msys-")
1079 find_library (${ARGV})
1084 function (_PYTHON_SET_LIBRARY_DIRS _PYTHON_SLD_RESULT)
1085 unset (_PYTHON_DIRS)
1086 set (_PYTHON_LIBS ${ARGN})
1087 foreach (_PYTHON_LIB IN LISTS _PYTHON_LIBS)
1089 get_filename_component (_PYTHON_DIR "${${_PYTHON_LIB}}" DIRECTORY)
1090 list (APPEND _PYTHON_DIRS "${_PYTHON_DIR}")
1093 list (REMOVE_DUPLICATES _PYTHON_DIRS)
1094 set (${_PYTHON_SLD_RESULT} ${_PYTHON_DIRS} PARENT_SCOPE)
1098 function (_PYTHON_SET_DEVELOPMENT_MODULE_FOUND module)
1099 if ("Development.${module}" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS)
1100 string(TOUPPER "${module}" id)
1101 set (module_found TRUE)
1103 if ("LIBRARY" IN_LIST _${_PYTHON_PREFIX}_FIND_DEVELOPMENT_${id}_ARTIFACTS
1104 AND NOT _${_PYTHON_PREFIX}_LIBRARY_RELEASE)
1105 set (module_found FALSE)
1107 if ("INCLUDE_DIR" IN_LIST _${_PYTHON_PREFIX}_FIND_DEVELOPMENT_${id}_ARTIFACTS
1108 AND NOT _${_PYTHON_PREFIX}_INCLUDE_DIR)
1109 set (module_found FALSE)
1112 set (${_PYTHON_PREFIX}_Development.${module}_FOUND ${module_found} PARENT_SCOPE)
1117 if (${_PYTHON_PREFIX}_FIND_VERSION_RANGE)
1118 # range must include internal major version
1119 if (${_PYTHON_PREFIX}_FIND_VERSION_MIN_MAJOR VERSION_GREATER _${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR
1120 OR ((${_PYTHON_PREFIX}_FIND_VERSION_RANGE_MAX STREQUAL "INCLUDE"
1121 AND ${_PYTHON_PREFIX}_FIND_VERSION_MAX VERSION_LESS _${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR)
1122 OR (${_PYTHON_PREFIX}_FIND_VERSION_RANGE_MAX STREQUAL "EXCLUDE"
1123 AND ${_PYTHON_PREFIX}_FIND_VERSION_MAX VERSION_LESS_EQUAL _${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR)))
1124 _python_display_failure ("Could NOT find ${_PYTHON_PREFIX}: Wrong version range specified is \"${${_PYTHON_PREFIX}_FIND_VERSION_RANGE}\", but expected version range must include major version \"${_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR}\"")
1130 if (DEFINED ${_PYTHON_PREFIX}_FIND_VERSION_MAJOR
1131 AND NOT ${_PYTHON_PREFIX}_FIND_VERSION_MAJOR VERSION_EQUAL _${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR)
1132 # If major version is specified, it must be the same as internal major version
1133 _python_display_failure ("Could NOT find ${_PYTHON_PREFIX}: Wrong major version specified is \"${${_PYTHON_PREFIX}_FIND_VERSION_MAJOR}\", but expected major version is \"${_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR}\"")
1142 if (NOT ${_PYTHON_PREFIX}_FIND_COMPONENTS)
1143 set (${_PYTHON_PREFIX}_FIND_COMPONENTS Interpreter)
1144 set (${_PYTHON_PREFIX}_FIND_REQUIRED_Interpreter TRUE)
1146 if ("NumPy" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS)
1147 list (APPEND ${_PYTHON_PREFIX}_FIND_COMPONENTS "Interpreter" "Development.Module")
1149 if ("Development" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS)
1150 list (APPEND ${_PYTHON_PREFIX}_FIND_COMPONENTS "Development.Module" "Development.Embed")
1152 list (REMOVE_DUPLICATES ${_PYTHON_PREFIX}_FIND_COMPONENTS)
1153 foreach (_${_PYTHON_PREFIX}_COMPONENT IN ITEMS Interpreter Compiler Development Development.Module Development.Embed NumPy)
1154 set (${_PYTHON_PREFIX}_${_${_PYTHON_PREFIX}_COMPONENT}_FOUND FALSE)
1156 if (${_PYTHON_PREFIX}_FIND_REQUIRED_Development)
1157 set (${_PYTHON_PREFIX}_FIND_REQUIRED_Development.Module TRUE)
1158 set (${_PYTHON_PREFIX}_FIND_REQUIRED_Development.Embed TRUE)
1161 unset (_${_PYTHON_PREFIX}_FIND_DEVELOPMENT_ARTIFACTS)
1162 unset (_${_PYTHON_PREFIX}_FIND_DEVELOPMENT_MODULE_ARTIFACTS)
1163 unset (_${_PYTHON_PREFIX}_FIND_DEVELOPMENT_EMBED_ARTIFACTS)
1164 if ("Development.Module" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS)
1165 if (CMAKE_SYSTEM_NAME MATCHES "^(Windows.*|CYGWIN|MSYS)$")
1166 list (APPEND _${_PYTHON_PREFIX}_FIND_DEVELOPMENT_MODULE_ARTIFACTS "LIBRARY")
1168 list (APPEND _${_PYTHON_PREFIX}_FIND_DEVELOPMENT_MODULE_ARTIFACTS "INCLUDE_DIR")
1170 if ("Development.Embed" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS)
1171 list (APPEND _${_PYTHON_PREFIX}_FIND_DEVELOPMENT_EMBED_ARTIFACTS "LIBRARY" "INCLUDE_DIR")
1173 set (_${_PYTHON_PREFIX}_FIND_DEVELOPMENT_ARTIFACTS ${_${_PYTHON_PREFIX}_FIND_DEVELOPMENT_MODULE_ARTIFACTS} ${_${_PYTHON_PREFIX}_FIND_DEVELOPMENT_EMBED_ARTIFACTS})
1174 list (REMOVE_DUPLICATES _${_PYTHON_PREFIX}_FIND_DEVELOPMENT_ARTIFACTS)
1176 # Set versions to search
1177 ## default: search any version
1178 set (_${_PYTHON_PREFIX}_FIND_VERSIONS ${_${_PYTHON_PREFIX}_VERSIONS})
1179 unset (_${_PYTHON_PREFIX}_FIND_VERSION_EXACT)
1181 if (${_PYTHON_PREFIX}_FIND_VERSION_RANGE)
1182 unset (_${_PYTHON_PREFIX}_FIND_VERSIONS)
1183 foreach (_${_PYTHON_PREFIX}_VERSION IN LISTS _${_PYTHON_PREFIX}_VERSIONS)
1184 if ((${_PYTHON_PREFIX}_FIND_VERSION_RANGE_MIN STREQUAL "INCLUDE"
1185 AND _${_PYTHON_PREFIX}_VERSION VERSION_GREATER_EQUAL ${_PYTHON_PREFIX}_FIND_VERSION_MIN)
1186 AND ((${_PYTHON_PREFIX}_FIND_VERSION_RANGE_MAX STREQUAL "INCLUDE"
1187 AND _${_PYTHON_PREFIX}_VERSION VERSION_LESS_EQUAL ${_PYTHON_PREFIX}_FIND_VERSION_MAX)
1188 OR (${_PYTHON_PREFIX}_FIND_VERSION_RANGE_MAX STREQUAL "EXCLUDE"
1189 AND _${_PYTHON_PREFIX}_VERSION VERSION_LESS ${_PYTHON_PREFIX}_FIND_VERSION_MAX)))
1190 list (APPEND _${_PYTHON_PREFIX}_FIND_VERSIONS ${_${_PYTHON_PREFIX}_VERSION})
1194 if (${_PYTHON_PREFIX}_FIND_VERSION_COUNT GREATER 1)
1195 if (${_PYTHON_PREFIX}_FIND_VERSION_EXACT)
1196 set (_${_PYTHON_PREFIX}_FIND_VERSION_EXACT "EXACT")
1197 set (_${_PYTHON_PREFIX}_FIND_VERSIONS ${${_PYTHON_PREFIX}_FIND_VERSION_MAJOR}.${${_PYTHON_PREFIX}_FIND_VERSION_MINOR})
1199 unset (_${_PYTHON_PREFIX}_FIND_VERSIONS)
1200 # add all compatible versions
1201 foreach (_${_PYTHON_PREFIX}_VERSION IN LISTS _${_PYTHON_PREFIX}_VERSIONS)
1202 if (_${_PYTHON_PREFIX}_VERSION VERSION_GREATER_EQUAL "${${_PYTHON_PREFIX}_FIND_VERSION_MAJOR}.${${_PYTHON_PREFIX}_FIND_VERSION_MINOR}")
1203 list (APPEND _${_PYTHON_PREFIX}_FIND_VERSIONS ${_${_PYTHON_PREFIX}_VERSION})
1210 # Set ABIs to search
1211 ## default: search any ABI
1212 if (_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR VERSION_LESS "3")
1214 unset (_${_PYTHON_PREFIX}_FIND_ABI)
1215 set (_${_PYTHON_PREFIX}_ABIFLAGS "")
1217 unset (_${_PYTHON_PREFIX}_FIND_ABI)
1218 unset (_${_PYTHON_PREFIX}_ABIFLAGS)
1219 if (DEFINED ${_PYTHON_PREFIX}_FIND_ABI)
1221 string (TOUPPER "${${_PYTHON_PREFIX}_FIND_ABI}" _${_PYTHON_PREFIX}_FIND_ABI)
1222 list (TRANSFORM _${_PYTHON_PREFIX}_FIND_ABI REPLACE "^(TRUE|Y(ES)?|1)$" "ON")
1223 list (TRANSFORM _${_PYTHON_PREFIX}_FIND_ABI REPLACE "^(FALSE|N(O)?|0)$" "OFF")
1224 if (NOT _${_PYTHON_PREFIX}_FIND_ABI MATCHES "^(ON|OFF|ANY);(ON|OFF|ANY);(ON|OFF|ANY)$")
1225 message (AUTHOR_WARNING "Find${_PYTHON_PREFIX}: ${${_PYTHON_PREFIX}_FIND_ABI}: invalid value for '${_PYTHON_PREFIX}_FIND_ABI'. Ignore it")
1226 unset (_${_PYTHON_PREFIX}_FIND_ABI)
1228 _python_get_abiflags (_${_PYTHON_PREFIX}_ABIFLAGS)
1231 unset (${_PYTHON_PREFIX}_SOABI)
1233 # Define lookup strategy
1234 cmake_policy (GET CMP0094 _${_PYTHON_PREFIX}_LOOKUP_POLICY)
1235 if (_${_PYTHON_PREFIX}_LOOKUP_POLICY STREQUAL "NEW")
1236 set (_${_PYTHON_PREFIX}_FIND_STRATEGY "LOCATION")
1238 set (_${_PYTHON_PREFIX}_FIND_STRATEGY "VERSION")
1240 if (DEFINED ${_PYTHON_PREFIX}_FIND_STRATEGY)
1241 if (NOT ${_PYTHON_PREFIX}_FIND_STRATEGY MATCHES "^(VERSION|LOCATION)$")
1242 message (AUTHOR_WARNING "Find${_PYTHON_PREFIX}: ${${_PYTHON_PREFIX}_FIND_STRATEGY}: invalid value for '${_PYTHON_PREFIX}_FIND_STRATEGY'. 'VERSION' or 'LOCATION' expected.")
1243 set (_${_PYTHON_PREFIX}_FIND_STRATEGY "VERSION")
1245 set (_${_PYTHON_PREFIX}_FIND_STRATEGY "${${_PYTHON_PREFIX}_FIND_STRATEGY}")
1249 # Python and Anaconda distributions: define which architectures can be used
1250 if (CMAKE_SIZEOF_VOID_P)
1251 math (EXPR _${_PYTHON_PREFIX}_ARCH "${CMAKE_SIZEOF_VOID_P} * 8")
1252 if ("Development.Module" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS
1253 OR "Development.Embed" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS)
1254 # In this case, search only for 64bit or 32bit
1255 set (_${_PYTHON_PREFIX}_ARCH2 ${_${_PYTHON_PREFIX}_ARCH})
1257 if (_${_PYTHON_PREFIX}_ARCH EQUAL "32")
1258 set (_${_PYTHON_PREFIX}_ARCH2 64)
1260 set (_${_PYTHON_PREFIX}_ARCH2 32)
1264 # architecture unknown, search for both 64bit and 32bit
1265 set (_${_PYTHON_PREFIX}_ARCH 64)
1266 set (_${_PYTHON_PREFIX}_ARCH2 32)
1269 # IronPython support
1270 unset (_${_PYTHON_PREFIX}_IRON_PYTHON_INTERPRETER_NAMES)
1271 unset (_${_PYTHON_PREFIX}_IRON_PYTHON_COMPILER_NAMES)
1272 unset (_${_PYTHON_PREFIX}_IRON_PYTHON_COMPILER_ARCH_FLAGS)
1273 if (CMAKE_SIZEOF_VOID_P)
1274 if (_${_PYTHON_PREFIX}_ARCH EQUAL "32")
1275 set (_${_PYTHON_PREFIX}_IRON_PYTHON_COMPILER_ARCH_FLAGS "/platform:x86")
1277 set (_${_PYTHON_PREFIX}_IRON_PYTHON_COMPILER_ARCH_FLAGS "/platform:x64")
1280 if (NOT CMAKE_SYSTEM_NAME STREQUAL "Linux")
1281 # Do not use wrapper script on Linux because it is buggy: -c interpreter option cannot be used
1282 list (APPEND _${_PYTHON_PREFIX}_IRON_PYTHON_INTERPRETER_NAMES "ipy${_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR}" "ipy64" "ipy32" "ipy")
1283 list (APPEND _${_PYTHON_PREFIX}_IRON_PYTHON_COMPILER_NAMES "ipyc")
1285 list (APPEND _${_PYTHON_PREFIX}_IRON_PYTHON_INTERPRETER_NAMES "ipy.exe")
1286 list (APPEND _${_PYTHON_PREFIX}_IRON_PYTHON_COMPILER_NAMES "ipyc.exe")
1287 set (_${_PYTHON_PREFIX}_IRON_PYTHON_PATH_SUFFIXES net45 net40 bin)
1290 if (_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR EQUAL "3")
1291 set (_${_PYTHON_PREFIX}_PYPY_NAMES pypy3)
1292 set (_${_PYTHON_PREFIX}_PYPY_LIB_NAMES pypy3-c)
1294 # special name for runtime part
1295 list (APPEND _${_PYTHON_PREFIX}_PYPY_LIB_NAMES libpypy3-c)
1297 set (_${_PYTHON_PREFIX}_PYPY_INCLUDE_PATH_SUFFIXES lib/pypy3/include pypy3/include)
1299 set (_${_PYTHON_PREFIX}_PYPY_NAMES pypy)
1300 set (_${_PYTHON_PREFIX}_PYPY_LIB_NAMES pypy-c)
1302 # special name for runtime part
1303 list (APPEND _${_PYTHON_PREFIX}_PYPY_LIB_NAMES libpypy-c)
1305 set (_${_PYTHON_PREFIX}_PYPY_INCLUDE_PATH_SUFFIXES lib/pypy/include pypy/include)
1307 list (APPEND _${_PYTHON_PREFIX}_PYPY_INCLUDE_PATH_SUFFIXES libexec/include)
1308 set (_${_PYTHON_PREFIX}_PYPY_EXECUTABLE_PATH_SUFFIXES bin)
1309 set (_${_PYTHON_PREFIX}_PYPY_LIBRARY_PATH_SUFFIXES lib libs bin)
1310 list (APPEND _${_PYTHON_PREFIX}_PYPY_INCLUDE_PATH_SUFFIXES include)
1312 # Python Implementations handling
1313 unset (_${_PYTHON_PREFIX}_FIND_IMPLEMENTATIONS)
1314 if (DEFINED ${_PYTHON_PREFIX}_FIND_IMPLEMENTATIONS)
1315 foreach (_${_PYTHON_PREFIX}_IMPLEMENTATION IN LISTS ${_PYTHON_PREFIX}_FIND_IMPLEMENTATIONS)
1316 if (NOT _${_PYTHON_PREFIX}_IMPLEMENTATION MATCHES "^(CPython|IronPython|PyPy)$")
1317 message (AUTHOR_WARNING "Find${_PYTHON_PREFIX}: ${_${_PYTHON_PREFIX}_IMPLEMENTATION}: invalid value for '${_PYTHON_PREFIX}_FIND_IMPLEMENTATIONS'. 'CPython', 'IronPython' or 'PyPy' expected. Value will be ignored.")
1319 list (APPEND _${_PYTHON_PREFIX}_FIND_IMPLEMENTATIONS ${_${_PYTHON_PREFIX}_IMPLEMENTATION})
1324 set (_${_PYTHON_PREFIX}_FIND_IMPLEMENTATIONS CPython IronPython)
1326 set (_${_PYTHON_PREFIX}_FIND_IMPLEMENTATIONS CPython)
1330 # compute list of names for header file
1331 unset (_${_PYTHON_PREFIX}_INCLUDE_NAMES)
1332 foreach (_${_PYTHON_PREFIX}_IMPLEMENTATION IN LISTS _${_PYTHON_PREFIX}_FIND_IMPLEMENTATIONS)
1333 if (_${_PYTHON_PREFIX}_IMPLEMENTATION STREQUAL "CPython")
1334 list (APPEND _${_PYTHON_PREFIX}_INCLUDE_NAMES "Python.h")
1335 elseif (_${_PYTHON_PREFIX}_IMPLEMENTATION STREQUAL "PyPy")
1336 list (APPEND _${_PYTHON_PREFIX}_INCLUDE_NAMES "PyPy.h" "pypy_decl.h")
1341 # Apple frameworks handling
1342 _python_find_frameworks ()
1344 set (_${_PYTHON_PREFIX}_FIND_FRAMEWORK "FIRST")
1346 if (DEFINED ${_PYTHON_PREFIX}_FIND_FRAMEWORK)
1347 if (NOT ${_PYTHON_PREFIX}_FIND_FRAMEWORK MATCHES "^(FIRST|LAST|NEVER)$")
1348 message (AUTHOR_WARNING "Find${_PYTHON_PREFIX}: ${${_PYTHON_PREFIX}_FIND_FRAMEWORK}: invalid value for '${_PYTHON_PREFIX}_FIND_FRAMEWORK'. 'FIRST', 'LAST' or 'NEVER' expected. 'FIRST' will be used instead.")
1350 set (_${_PYTHON_PREFIX}_FIND_FRAMEWORK ${${_PYTHON_PREFIX}_FIND_FRAMEWORK})
1352 elseif (DEFINED CMAKE_FIND_FRAMEWORK)
1353 if (CMAKE_FIND_FRAMEWORK STREQUAL "ONLY")
1354 message (AUTHOR_WARNING "Find${_PYTHON_PREFIX}: CMAKE_FIND_FRAMEWORK: 'ONLY' value is not supported. 'FIRST' will be used instead.")
1355 elseif (NOT CMAKE_FIND_FRAMEWORK MATCHES "^(FIRST|LAST|NEVER)$")
1356 message (AUTHOR_WARNING "Find${_PYTHON_PREFIX}: ${CMAKE_FIND_FRAMEWORK}: invalid value for 'CMAKE_FIND_FRAMEWORK'. 'FIRST', 'LAST' or 'NEVER' expected. 'FIRST' will be used instead.")
1358 set (_${_PYTHON_PREFIX}_FIND_FRAMEWORK ${CMAKE_FIND_FRAMEWORK})
1362 # Save CMAKE_FIND_APPBUNDLE
1363 if (DEFINED CMAKE_FIND_APPBUNDLE)
1364 set (_${_PYTHON_PREFIX}_CMAKE_FIND_APPBUNDLE ${CMAKE_FIND_APPBUNDLE})
1366 unset (_${_PYTHON_PREFIX}_CMAKE_FIND_APPBUNDLE)
1368 # To avoid app bundle lookup
1369 set (CMAKE_FIND_APPBUNDLE "NEVER")
1371 # Save CMAKE_FIND_FRAMEWORK
1372 if (DEFINED CMAKE_FIND_FRAMEWORK)
1373 set (_${_PYTHON_PREFIX}_CMAKE_FIND_FRAMEWORK ${CMAKE_FIND_FRAMEWORK})
1375 unset (_${_PYTHON_PREFIX}_CMAKE_FIND_FRAMEWORK)
1377 # To avoid framework lookup
1378 set (CMAKE_FIND_FRAMEWORK "NEVER")
1380 # Windows Registry handling
1381 if (DEFINED ${_PYTHON_PREFIX}_FIND_REGISTRY)
1382 if (NOT ${_PYTHON_PREFIX}_FIND_REGISTRY MATCHES "^(FIRST|LAST|NEVER)$")
1383 message (AUTHOR_WARNING "Find${_PYTHON_PREFIX}: ${${_PYTHON_PREFIX}_FIND_REGISTRY}: invalid value for '${_PYTHON_PREFIX}_FIND_REGISTRY'. 'FIRST', 'LAST' or 'NEVER' expected. 'FIRST' will be used instead.")
1384 set (_${_PYTHON_PREFIX}_FIND_REGISTRY "FIRST")
1386 set (_${_PYTHON_PREFIX}_FIND_REGISTRY ${${_PYTHON_PREFIX}_FIND_REGISTRY})
1389 set (_${_PYTHON_PREFIX}_FIND_REGISTRY "FIRST")
1392 # virtual environments recognition
1393 if (DEFINED ENV{VIRTUAL_ENV} OR DEFINED ENV{CONDA_PREFIX})
1394 if (DEFINED ${_PYTHON_PREFIX}_FIND_VIRTUALENV)
1395 if (NOT ${_PYTHON_PREFIX}_FIND_VIRTUALENV MATCHES "^(FIRST|ONLY|STANDARD)$")
1396 message (AUTHOR_WARNING "Find${_PYTHON_PREFIX}: ${${_PYTHON_PREFIX}_FIND_VIRTUALENV}: invalid value for '${_PYTHON_PREFIX}_FIND_VIRTUALENV'. 'FIRST', 'ONLY' or 'STANDARD' expected. 'FIRST' will be used instead.")
1397 set (_${_PYTHON_PREFIX}_FIND_VIRTUALENV "FIRST")
1399 set (_${_PYTHON_PREFIX}_FIND_VIRTUALENV ${${_PYTHON_PREFIX}_FIND_VIRTUALENV})
1402 set (_${_PYTHON_PREFIX}_FIND_VIRTUALENV FIRST)
1405 set (_${_PYTHON_PREFIX}_FIND_VIRTUALENV STANDARD)
1409 # Python naming handling
1410 if (DEFINED ${_PYTHON_PREFIX}_FIND_UNVERSIONED_NAMES)
1411 if (NOT ${_PYTHON_PREFIX}_FIND_UNVERSIONED_NAMES MATCHES "^(FIRST|LAST|NEVER)$")
1412 message (AUTHOR_WARNING "Find${_PYTHON_PREFIX}: ${_${_PYTHON_PREFIX}_FIND_UNVERSIONED_NAMES}: invalid value for '${_PYTHON_PREFIX}_FIND_UNVERSIONED_NAMES'. 'FIRST', 'LAST' or 'NEVER' expected. 'LAST' will be used instead.")
1413 set (_${_PYTHON_PREFIX}_FIND_UNVERSIONED_NAMES LAST)
1415 set (_${_PYTHON_PREFIX}_FIND_UNVERSIONED_NAMES ${${_PYTHON_PREFIX}_FIND_UNVERSIONED_NAMES})
1418 set (_${_PYTHON_PREFIX}_FIND_UNVERSIONED_NAMES LAST)
1422 # Compute search signature
1423 # This signature will be used to check validity of cached variables on new search
1424 set (_${_PYTHON_PREFIX}_SIGNATURE "${${_PYTHON_PREFIX}_ROOT_DIR}:${_${_PYTHON_PREFIX}_FIND_IMPLEMENTATIONS}:${_${_PYTHON_PREFIX}_FIND_STRATEGY}:${${_PYTHON_PREFIX}_FIND_VIRTUALENV}${_${_PYTHON_PREFIX}_FIND_UNVERSIONED_NAMES}")
1426 string (APPEND _${_PYTHON_PREFIX}_SIGNATURE ":${${_PYTHON_PREFIX}_USE_STATIC_LIBS}:")
1428 if (CMAKE_HOST_APPLE)
1429 string (APPEND _${_PYTHON_PREFIX}_SIGNATURE ":${_${_PYTHON_PREFIX}_FIND_FRAMEWORK}")
1431 if (CMAKE_HOST_WIN32)
1432 string (APPEND _${_PYTHON_PREFIX}_SIGNATURE ":${_${_PYTHON_PREFIX}_FIND_REGISTRY}")
1435 function (_PYTHON_CHECK_DEVELOPMENT_SIGNATURE module)
1436 if ("Development.${module}" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS)
1437 string (TOUPPER "${module}" id)
1438 set (signature "${_${_PYTHON_PREFIX}_SIGNATURE}:")
1439 if ("LIBRARY" IN_LIST _${_PYTHON_PREFIX}_FIND_DEVELOPMENT_${id}_ARTIFACTS)
1440 list (APPEND signature "${_${_PYTHON_PREFIX}_LIBRARY_RELEASE}:")
1442 if ("INCLUDE_DIR" IN_LIST _${_PYTHON_PREFIX}_FIND_DEVELOPMENT_${id}_ARTIFACTS)
1443 list (APPEND signature "${_${_PYTHON_PREFIX}_INCLUDE_DIR}:")
1445 string (MD5 signature "${signature}")
1446 if (signature STREQUAL _${_PYTHON_PREFIX}_DEVELOPMENT_${id}_SIGNATURE)
1447 if ("LIBRARY" IN_LIST _${_PYTHON_PREFIX}_FIND_DEVELOPMENT_${id}_ARTIFACTS)
1448 if (${_PYTHON_PREFIX}_FIND_VERSION_EXACT)
1449 _python_validate_library (VERSION ${${_PYTHON_PREFIX}_FIND_VERSION} EXACT CHECK_EXISTS)
1450 elseif (${_PYTHON_PREFIX}_FIND_VERSION_RANGE)
1451 _python_validate_library (IN_RANGE CHECK_EXISTS)
1452 elseif (DEFINED ${_PYTHON_PREFIX}_FIND_VERSION)
1453 _python_validate_library (VERSION ${${_PYTHON_PREFIX}_FIND_VERSION} CHECK_EXISTS)
1455 _python_validate_library (CHECK_EXISTS)
1458 if ("INCLUDE_DIR" IN_LIST _${_PYTHON_PREFIX}_FIND_DEVELOPMENT_${id}_ARTIFACTS)
1459 if (${_PYTHON_PREFIX}_FIND_VERSION_EXACT)
1460 _python_validate_include_dir (VERSION ${${_PYTHON_PREFIX}_FIND_VERSION} EXACT CHECK_EXISTS)
1461 elseif (${_PYTHON_PREFIX}_FIND_VERSION_RANGE)
1462 _python_validate_include_dir (IN_RANGE CHECK_EXISTS)
1463 elseif (${_PYTHON_PREFIX}_FIND_VERSION)
1464 _python_validate_include_dir (VERSION ${${_PYTHON_PREFIX}_FIND_VERSION} CHECK_EXISTS)
1466 _python_validate_include_dir (CHECK_EXISTS)
1470 if ("LIBRARY" IN_LIST _${_PYTHON_PREFIX}_FIND_DEVELOPMENT_${id}_ARTIFACTS)
1471 unset (_${_PYTHON_PREFIX}_LIBRARY_RELEASE CACHE)
1472 unset (_${_PYTHON_PREFIX}_LIBRARY_DEBUG CACHE)
1474 if ("INCLUDE_DIR" IN_LIST _${_PYTHON_PREFIX}_FIND_DEVELOPMENT_${id}_ARTIFACTS)
1475 unset (_${_PYTHON_PREFIX}_INCLUDE_DIR CACHE)
1478 if (("LIBRARY" IN_LIST _${_PYTHON_PREFIX}_FIND_DEVELOPMENT_${id}_ARTIFACTS
1479 AND NOT _${_PYTHON_PREFIX}_LIBRARY_RELEASE)
1480 OR ("INCLUDE_DIR" IN_LIST _${_PYTHON_PREFIX}_FIND_DEVELOPMENT_${id}_ARTIFACTS
1481 AND NOT _${_PYTHON_PREFIX}_INCLUDE_DIR))
1482 unset (_${_PYTHON_PREFIX}_CONFIG CACHE)
1483 unset (_${_PYTHON_PREFIX}_DEVELOPMENT_${id}_SIGNATURE CACHE)
1488 function (_PYTHON_COMPUTE_DEVELOPMENT_SIGNATURE module)
1489 string (TOUPPER "${module}" id)
1490 if (${_PYTHON_PREFIX}_Development.${module}_FOUND)
1491 set (signature "${_${_PYTHON_PREFIX}_SIGNATURE}:")
1492 if ("LIBRARY" IN_LIST _${_PYTHON_PREFIX}_FIND_DEVELOPMENT_${id}_ARTIFACTS)
1493 list (APPEND signature "${_${_PYTHON_PREFIX}_LIBRARY_RELEASE}:")
1495 if ("INCLUDE_DIR" IN_LIST _${_PYTHON_PREFIX}_FIND_DEVELOPMENT_${id}_ARTIFACTS)
1496 list (APPEND signature "${_${_PYTHON_PREFIX}_INCLUDE_DIR}:")
1498 string (MD5 signature "${signature}")
1499 set (_${_PYTHON_PREFIX}_DEVELOPMENT_${id}_SIGNATURE "${signature}" CACHE INTERNAL "")
1501 unset (_${_PYTHON_PREFIX}_DEVELOPMENT_${id}_SIGNATURE CACHE)
1506 unset (_${_PYTHON_PREFIX}_REQUIRED_VARS)
1507 unset (_${_PYTHON_PREFIX}_CACHED_VARS)
1508 unset (_${_PYTHON_PREFIX}_Interpreter_REASON_FAILURE)
1509 unset (_${_PYTHON_PREFIX}_Compiler_REASON_FAILURE)
1510 unset (_${_PYTHON_PREFIX}_Development_REASON_FAILURE)
1511 unset (_${_PYTHON_PREFIX}_NumPy_REASON_FAILURE)
1515 ## For IronPython on platforms other than Windows, search for the .Net interpreter
1516 if ("IronPython" IN_LIST _${_PYTHON_PREFIX}_FIND_IMPLEMENTATIONS
1518 find_program (${_PYTHON_PREFIX}_DOTNET_LAUNCHER
1523 # first step, search for the interpreter
1524 if ("Interpreter" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS)
1525 list (APPEND _${_PYTHON_PREFIX}_CACHED_VARS _${_PYTHON_PREFIX}_EXECUTABLE
1526 _${_PYTHON_PREFIX}_INTERPRETER_PROPERTIES)
1527 if (${_PYTHON_PREFIX}_FIND_REQUIRED_Interpreter)
1528 list (APPEND _${_PYTHON_PREFIX}_REQUIRED_VARS ${_PYTHON_PREFIX}_EXECUTABLE)
1531 if (DEFINED ${_PYTHON_PREFIX}_EXECUTABLE
1532 AND IS_ABSOLUTE "${${_PYTHON_PREFIX}_EXECUTABLE}")
1533 if (NOT ${_PYTHON_PREFIX}_EXECUTABLE STREQUAL _${_PYTHON_PREFIX}_EXECUTABLE)
1534 # invalidate cache properties
1535 unset (_${_PYTHON_PREFIX}_INTERPRETER_PROPERTIES CACHE)
1537 set (_${_PYTHON_PREFIX}_EXECUTABLE "${${_PYTHON_PREFIX}_EXECUTABLE}" CACHE INTERNAL "")
1538 elseif (DEFINED _${_PYTHON_PREFIX}_EXECUTABLE)
1539 # compute interpreter signature and check validity of definition
1540 string (MD5 __${_PYTHON_PREFIX}_INTERPRETER_SIGNATURE "${_${_PYTHON_PREFIX}_SIGNATURE}:${_${_PYTHON_PREFIX}_EXECUTABLE}")
1541 if (__${_PYTHON_PREFIX}_INTERPRETER_SIGNATURE STREQUAL _${_PYTHON_PREFIX}_INTERPRETER_SIGNATURE)
1542 # check version validity
1543 if (${_PYTHON_PREFIX}_FIND_VERSION_EXACT)
1544 _python_validate_interpreter (VERSION ${${_PYTHON_PREFIX}_FIND_VERSION} EXACT CHECK_EXISTS)
1545 elseif (${_PYTHON_PREFIX}_FIND_VERSION_RANGE)
1546 _python_validate_interpreter (IN_RANGE CHECK_EXISTS)
1547 elseif (DEFINED ${_PYTHON_PREFIX}_FIND_VERSION)
1548 _python_validate_interpreter (VERSION ${${_PYTHON_PREFIX}_FIND_VERSION} CHECK_EXISTS)
1550 _python_validate_interpreter (CHECK_EXISTS)
1553 unset (_${_PYTHON_PREFIX}_EXECUTABLE CACHE)
1555 if (NOT _${_PYTHON_PREFIX}_EXECUTABLE)
1556 unset (_${_PYTHON_PREFIX}_INTERPRETER_SIGNATURE CACHE)
1557 unset (_${_PYTHON_PREFIX}_INTERPRETER_PROPERTIES CACHE)
1561 if (NOT _${_PYTHON_PREFIX}_EXECUTABLE)
1562 set (_${_PYTHON_PREFIX}_HINTS "${${_PYTHON_PREFIX}_ROOT_DIR}" ENV ${_PYTHON_PREFIX}_ROOT_DIR)
1564 if (_${_PYTHON_PREFIX}_FIND_STRATEGY STREQUAL "LOCATION")
1565 # build all executable names
1566 _python_get_names (_${_PYTHON_PREFIX}_NAMES VERSION ${_${_PYTHON_PREFIX}_FIND_VERSIONS} POSIX INTERPRETER)
1567 _python_get_path_suffixes (_${_PYTHON_PREFIX}_PATH_SUFFIXES VERSION ${_${_PYTHON_PREFIX}_FIND_VERSIONS} INTERPRETER)
1570 _python_get_frameworks (_${_PYTHON_PREFIX}_FRAMEWORK_PATHS VERSION ${_${_PYTHON_PREFIX}_FIND_VERSIONS})
1572 _python_get_registries (_${_PYTHON_PREFIX}_REGISTRY_PATHS VERSION ${_${_PYTHON_PREFIX}_FIND_VERSIONS})
1574 set (_${_PYTHON_PREFIX}_VALIDATE_OPTIONS ${_${_PYTHON_PREFIX}_FIND_VERSION_EXACT})
1575 if (${_PYTHON_PREFIX}_FIND_VERSION_RANGE)
1576 list (APPEND _${_PYTHON_PREFIX}_VALIDATE_OPTIONS IN_RANGE)
1577 elseif (DEFINED ${_PYTHON_PREFIX}_FIND_VERSION)
1578 list (APPEND _${_PYTHON_PREFIX}_VALIDATE_OPTIONS VERSION ${${_PYTHON_PREFIX}_FIND_VERSION})
1582 # Virtual environments handling
1583 if (_${_PYTHON_PREFIX}_FIND_VIRTUALENV MATCHES "^(FIRST|ONLY)$")
1584 find_program (_${_PYTHON_PREFIX}_EXECUTABLE
1585 NAMES ${_${_PYTHON_PREFIX}_NAMES}
1587 HINTS ${_${_PYTHON_PREFIX}_HINTS}
1588 PATHS ENV VIRTUAL_ENV ENV CONDA_PREFIX
1589 PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES}
1591 NO_CMAKE_ENVIRONMENT_PATH
1592 NO_SYSTEM_ENVIRONMENT_PATH
1593 NO_CMAKE_SYSTEM_PATH)
1595 _python_validate_interpreter (${_${_PYTHON_PREFIX}_VALIDATE_OPTIONS})
1596 if (_${_PYTHON_PREFIX}_EXECUTABLE)
1599 if (_${_PYTHON_PREFIX}_FIND_VIRTUALENV STREQUAL "ONLY")
1604 # Apple frameworks handling
1605 if (CMAKE_HOST_APPLE AND _${_PYTHON_PREFIX}_FIND_FRAMEWORK STREQUAL "FIRST")
1606 find_program (_${_PYTHON_PREFIX}_EXECUTABLE
1607 NAMES ${_${_PYTHON_PREFIX}_NAMES}
1609 HINTS ${_${_PYTHON_PREFIX}_HINTS}
1610 PATHS ${_${_PYTHON_PREFIX}_FRAMEWORK_PATHS}
1611 PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES}
1613 NO_CMAKE_ENVIRONMENT_PATH
1614 NO_SYSTEM_ENVIRONMENT_PATH
1615 NO_CMAKE_SYSTEM_PATH)
1616 _python_validate_interpreter (${${_PYTHON_PREFIX}_VALIDATE_OPTIONS})
1617 if (_${_PYTHON_PREFIX}_EXECUTABLE)
1622 if (CMAKE_HOST_WIN32 AND _${_PYTHON_PREFIX}_FIND_REGISTRY STREQUAL "FIRST")
1623 find_program (_${_PYTHON_PREFIX}_EXECUTABLE
1624 NAMES ${_${_PYTHON_PREFIX}_NAMES}
1626 HINTS ${_${_PYTHON_PREFIX}_HINTS}
1627 PATHS ${_${_PYTHON_PREFIX}_REGISTRY_PATHS}
1628 PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES}
1629 NO_SYSTEM_ENVIRONMENT_PATH
1630 NO_CMAKE_SYSTEM_PATH)
1631 _python_validate_interpreter (${${_PYTHON_PREFIX}_VALIDATE_OPTIONS})
1632 if (_${_PYTHON_PREFIX}_EXECUTABLE)
1638 find_program (_${_PYTHON_PREFIX}_EXECUTABLE
1639 NAMES ${_${_PYTHON_PREFIX}_NAMES}
1641 HINTS ${_${_PYTHON_PREFIX}_HINTS}
1642 PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES}
1643 NO_SYSTEM_ENVIRONMENT_PATH
1644 NO_CMAKE_SYSTEM_PATH)
1645 _python_validate_interpreter (${${_PYTHON_PREFIX}_VALIDATE_OPTIONS})
1646 if (_${_PYTHON_PREFIX}_EXECUTABLE)
1649 # try using standard paths
1650 find_program (_${_PYTHON_PREFIX}_EXECUTABLE
1651 NAMES ${_${_PYTHON_PREFIX}_NAMES}
1653 PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES})
1654 _python_validate_interpreter (${${_PYTHON_PREFIX}_VALIDATE_OPTIONS})
1655 if (_${_PYTHON_PREFIX}_EXECUTABLE)
1659 # Apple frameworks handling
1660 if (CMAKE_HOST_APPLE AND _${_PYTHON_PREFIX}_FIND_FRAMEWORK STREQUAL "LAST")
1661 find_program (_${_PYTHON_PREFIX}_EXECUTABLE
1662 NAMES ${_${_PYTHON_PREFIX}_NAMES}
1664 PATHS ${_${_PYTHON_PREFIX}_FRAMEWORK_PATHS}
1665 PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES}
1667 _python_validate_interpreter (${${_PYTHON_PREFIX}_VALIDATE_OPTIONS})
1668 if (_${_PYTHON_PREFIX}_EXECUTABLE)
1673 if (CMAKE_HOST_WIN32 AND _${_PYTHON_PREFIX}_FIND_REGISTRY STREQUAL "LAST")
1674 find_program (_${_PYTHON_PREFIX}_EXECUTABLE
1675 NAMES ${_${_PYTHON_PREFIX}_NAMES}
1677 PATHS ${_${_PYTHON_PREFIX}_REGISTRY_PATHS}
1678 PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES}
1680 _python_validate_interpreter (${${_PYTHON_PREFIX}_VALIDATE_OPTIONS})
1681 if (_${_PYTHON_PREFIX}_EXECUTABLE)
1689 # look-up for various versions and locations
1690 set (_${_PYTHON_PREFIX}_VALIDATE_OPTIONS EXACT)
1691 if (${_PYTHON_PREFIX}_FIND_VERSION_RANGE)
1692 list (APPEND _${_PYTHON_PREFIX}_VALIDATE_OPTIONS IN_RANGE)
1695 foreach (_${_PYTHON_PREFIX}_VERSION IN LISTS _${_PYTHON_PREFIX}_FIND_VERSIONS)
1696 _python_get_names (_${_PYTHON_PREFIX}_NAMES VERSION ${_${_PYTHON_PREFIX}_VERSION} POSIX INTERPRETER)
1697 _python_get_path_suffixes (_${_PYTHON_PREFIX}_PATH_SUFFIXES VERSION ${_${_PYTHON_PREFIX}_VERSION} INTERPRETER)
1699 _python_get_frameworks (_${_PYTHON_PREFIX}_FRAMEWORK_PATHS VERSION ${_${_PYTHON_PREFIX}_VERSION})
1700 _python_get_registries (_${_PYTHON_PREFIX}_REGISTRY_PATHS VERSION ${_${_PYTHON_PREFIX}_VERSION})
1702 # Virtual environments handling
1703 if (_${_PYTHON_PREFIX}_FIND_VIRTUALENV MATCHES "^(FIRST|ONLY)$")
1704 find_program (_${_PYTHON_PREFIX}_EXECUTABLE
1705 NAMES ${_${_PYTHON_PREFIX}_NAMES}
1707 HINTS ${_${_PYTHON_PREFIX}_HINTS}
1708 PATHS ENV VIRTUAL_ENV ENV CONDA_PREFIX
1709 PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES}
1711 NO_CMAKE_ENVIRONMENT_PATH
1712 NO_SYSTEM_ENVIRONMENT_PATH
1713 NO_CMAKE_SYSTEM_PATH)
1714 _python_validate_interpreter (VERSION ${_${_PYTHON_PREFIX}_VERSION} ${_${_PYTHON_PREFIX}_VALIDATE_OPTIONS})
1715 if (_${_PYTHON_PREFIX}_EXECUTABLE)
1718 if (_${_PYTHON_PREFIX}_FIND_VIRTUALENV STREQUAL "ONLY")
1723 # Apple frameworks handling
1724 if (CMAKE_HOST_APPLE AND _${_PYTHON_PREFIX}_FIND_FRAMEWORK STREQUAL "FIRST")
1725 find_program (_${_PYTHON_PREFIX}_EXECUTABLE
1726 NAMES ${_${_PYTHON_PREFIX}_NAMES}
1728 HINTS ${_${_PYTHON_PREFIX}_HINTS}
1729 PATHS ${_${_PYTHON_PREFIX}_FRAMEWORK_PATHS}
1730 PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES}
1732 NO_CMAKE_ENVIRONMENT_PATH
1733 NO_SYSTEM_ENVIRONMENT_PATH
1734 NO_CMAKE_SYSTEM_PATH)
1738 if (CMAKE_HOST_WIN32 AND _${_PYTHON_PREFIX}_FIND_REGISTRY STREQUAL "FIRST")
1739 find_program (_${_PYTHON_PREFIX}_EXECUTABLE
1740 NAMES ${_${_PYTHON_PREFIX}_NAMES}
1742 HINTS ${_${_PYTHON_PREFIX}_HINTS}
1743 PATHS ${_${_PYTHON_PREFIX}_REGISTRY_PATHS}
1744 PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES}
1745 NO_SYSTEM_ENVIRONMENT_PATH
1746 NO_CMAKE_SYSTEM_PATH)
1749 _python_validate_interpreter (VERSION ${_${_PYTHON_PREFIX}_VERSION} ${_${_PYTHON_PREFIX}_VALIDATE_OPTIONS})
1750 if (_${_PYTHON_PREFIX}_EXECUTABLE)
1755 find_program (_${_PYTHON_PREFIX}_EXECUTABLE
1756 NAMES ${_${_PYTHON_PREFIX}_NAMES}
1758 HINTS ${_${_PYTHON_PREFIX}_HINTS}
1759 PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES}
1760 NO_SYSTEM_ENVIRONMENT_PATH
1761 NO_CMAKE_SYSTEM_PATH)
1762 _python_validate_interpreter (VERSION ${_${_PYTHON_PREFIX}_VERSION} ${_${_PYTHON_PREFIX}_VALIDATE_OPTIONS})
1763 if (_${_PYTHON_PREFIX}_EXECUTABLE)
1766 # try using standard paths.
1767 # NAMES_PER_DIR is not defined on purpose to have a chance to find
1769 # For example, typical systems have 'python' for version 2.* and 'python3'
1770 # for version 3.*. So looking for names per dir will find, potentially,
1771 # systematically 'python' (i.e. version 2) even if version 3 is searched.
1772 find_program (_${_PYTHON_PREFIX}_EXECUTABLE
1773 NAMES ${_${_PYTHON_PREFIX}_NAMES}
1774 PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES})
1775 _python_validate_interpreter (VERSION ${_${_PYTHON_PREFIX}_VERSION} ${_${_PYTHON_PREFIX}_VALIDATE_OPTIONS})
1776 if (_${_PYTHON_PREFIX}_EXECUTABLE)
1780 # Apple frameworks handling
1781 if (CMAKE_HOST_APPLE AND _${_PYTHON_PREFIX}_FIND_FRAMEWORK STREQUAL "LAST")
1782 find_program (_${_PYTHON_PREFIX}_EXECUTABLE
1783 NAMES ${_${_PYTHON_PREFIX}_NAMES}
1785 PATHS ${_${_PYTHON_PREFIX}_FRAMEWORK_PATHS}
1786 PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES}
1791 if (CMAKE_HOST_WIN32 AND _${_PYTHON_PREFIX}_FIND_REGISTRY STREQUAL "LAST")
1792 find_program (_${_PYTHON_PREFIX}_EXECUTABLE
1793 NAMES ${_${_PYTHON_PREFIX}_NAMES}
1795 PATHS ${_${_PYTHON_PREFIX}_REGISTRY_PATHS}
1796 PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES}
1800 _python_validate_interpreter (VERSION ${_${_PYTHON_PREFIX}_VERSION} ${_${_PYTHON_PREFIX}_VALIDATE_OPTIONS})
1801 if (_${_PYTHON_PREFIX}_EXECUTABLE)
1806 if (NOT _${_PYTHON_PREFIX}_EXECUTABLE AND
1807 NOT _${_PYTHON_PREFIX}_FIND_VIRTUALENV STREQUAL "ONLY")
1808 # No specific version found. Retry with generic names and standard paths.
1809 # NAMES_PER_DIR is not defined on purpose to have a chance to find
1811 # For example, typical systems have 'python' for version 2.* and 'python3'
1812 # for version 3.*. So looking for names per dir will find, potentially,
1813 # systematically 'python' (i.e. version 2) even if version 3 is searched.
1814 _python_get_names (_${_PYTHON_PREFIX}_NAMES POSIX INTERPRETER)
1815 find_program (_${_PYTHON_PREFIX}_EXECUTABLE
1816 NAMES ${_${_PYTHON_PREFIX}_NAMES})
1817 _python_validate_interpreter ()
1822 set (${_PYTHON_PREFIX}_EXECUTABLE "${_${_PYTHON_PREFIX}_EXECUTABLE}")
1823 _python_get_launcher (_${_PYTHON_PREFIX}_INTERPRETER_LAUNCHER INTERPRETER)
1825 # retrieve exact version of executable found
1826 if (_${_PYTHON_PREFIX}_EXECUTABLE)
1827 execute_process (COMMAND ${_${_PYTHON_PREFIX}_INTERPRETER_LAUNCHER} "${_${_PYTHON_PREFIX}_EXECUTABLE}" -c
1828 "import sys; sys.stdout.write('.'.join([str(x) for x in sys.version_info[:3]]))"
1829 RESULT_VARIABLE _${_PYTHON_PREFIX}_RESULT
1830 OUTPUT_VARIABLE ${_PYTHON_PREFIX}_VERSION
1832 OUTPUT_STRIP_TRAILING_WHITESPACE)
1833 if (NOT _${_PYTHON_PREFIX}_RESULT)
1834 set (_${_PYTHON_PREFIX}_EXECUTABLE_USABLE TRUE)
1836 # Interpreter is not usable
1837 set (_${_PYTHON_PREFIX}_EXECUTABLE_USABLE FALSE)
1838 unset (${_PYTHON_PREFIX}_VERSION)
1839 set (_${_PYTHON_PREFIX}_Interpreter_REASON_FAILURE "Cannot run the interpreter \"${_${_PYTHON_PREFIX}_EXECUTABLE}\"")
1843 if (_${_PYTHON_PREFIX}_EXECUTABLE AND _${_PYTHON_PREFIX}_EXECUTABLE_USABLE)
1844 if (_${_PYTHON_PREFIX}_INTERPRETER_PROPERTIES)
1845 set (${_PYTHON_PREFIX}_Interpreter_FOUND TRUE)
1847 list (GET _${_PYTHON_PREFIX}_INTERPRETER_PROPERTIES 0 ${_PYTHON_PREFIX}_INTERPRETER_ID)
1849 list (GET _${_PYTHON_PREFIX}_INTERPRETER_PROPERTIES 1 ${_PYTHON_PREFIX}_VERSION_MAJOR)
1850 list (GET _${_PYTHON_PREFIX}_INTERPRETER_PROPERTIES 2 ${_PYTHON_PREFIX}_VERSION_MINOR)
1851 list (GET _${_PYTHON_PREFIX}_INTERPRETER_PROPERTIES 3 ${_PYTHON_PREFIX}_VERSION_PATCH)
1853 list (GET _${_PYTHON_PREFIX}_INTERPRETER_PROPERTIES 4 _${_PYTHON_PREFIX}_ARCH)
1854 set (_${_PYTHON_PREFIX}_ARCH2 ${_${_PYTHON_PREFIX}_ARCH})
1856 list (GET _${_PYTHON_PREFIX}_INTERPRETER_PROPERTIES 5 _${_PYTHON_PREFIX}_ABIFLAGS)
1857 list (GET _${_PYTHON_PREFIX}_INTERPRETER_PROPERTIES 6 ${_PYTHON_PREFIX}_SOABI)
1859 list (GET _${_PYTHON_PREFIX}_INTERPRETER_PROPERTIES 7 ${_PYTHON_PREFIX}_STDLIB)
1860 list (GET _${_PYTHON_PREFIX}_INTERPRETER_PROPERTIES 8 ${_PYTHON_PREFIX}_STDARCH)
1861 list (GET _${_PYTHON_PREFIX}_INTERPRETER_PROPERTIES 9 ${_PYTHON_PREFIX}_SITELIB)
1862 list (GET _${_PYTHON_PREFIX}_INTERPRETER_PROPERTIES 10 ${_PYTHON_PREFIX}_SITEARCH)
1864 string (REGEX MATCHALL "[0-9]+" _${_PYTHON_PREFIX}_VERSIONS "${${_PYTHON_PREFIX}_VERSION}")
1865 list (GET _${_PYTHON_PREFIX}_VERSIONS 0 ${_PYTHON_PREFIX}_VERSION_MAJOR)
1866 list (GET _${_PYTHON_PREFIX}_VERSIONS 1 ${_PYTHON_PREFIX}_VERSION_MINOR)
1867 list (GET _${_PYTHON_PREFIX}_VERSIONS 2 ${_PYTHON_PREFIX}_VERSION_PATCH)
1869 if (${_PYTHON_PREFIX}_VERSION_MAJOR VERSION_EQUAL _${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR)
1870 set (${_PYTHON_PREFIX}_Interpreter_FOUND TRUE)
1872 # Use interpreter version and ABI for future searches to ensure consistency
1873 set (_${_PYTHON_PREFIX}_FIND_VERSIONS ${${_PYTHON_PREFIX}_VERSION_MAJOR}.${${_PYTHON_PREFIX}_VERSION_MINOR})
1874 execute_process (COMMAND ${_${_PYTHON_PREFIX}_INTERPRETR_LAUNCHER} "${_${_PYTHON_PREFIX}_EXECUTABLE}" -c
1875 "import sys; sys.stdout.write(sys.abiflags)"
1876 RESULT_VARIABLE _${_PYTHON_PREFIX}_RESULT
1877 OUTPUT_VARIABLE _${_PYTHON_PREFIX}_ABIFLAGS
1879 OUTPUT_STRIP_TRAILING_WHITESPACE)
1880 if (_${_PYTHON_PREFIX}_RESULT)
1881 # assunme ABI is not supported
1882 set (_${_PYTHON_PREFIX}_ABIFLAGS "")
1886 if (${_PYTHON_PREFIX}_Interpreter_FOUND)
1887 unset (_${_PYTHON_PREFIX}_Interpreter_REASON_FAILURE)
1889 # compute and save interpreter signature
1890 string (MD5 __${_PYTHON_PREFIX}_INTERPRETER_SIGNATURE "${_${_PYTHON_PREFIX}_SIGNATURE}:${_${_PYTHON_PREFIX}_EXECUTABLE}")
1891 set (_${_PYTHON_PREFIX}_INTERPRETER_SIGNATURE "${__${_PYTHON_PREFIX}_INTERPRETER_SIGNATURE}" CACHE INTERNAL "")
1893 if (NOT CMAKE_SIZEOF_VOID_P)
1894 # determine interpreter architecture
1895 execute_process (COMMAND ${_${_PYTHON_PREFIX}_INTERPRETER_LAUNCHER} "${_${_PYTHON_PREFIX}_EXECUTABLE}" -c
1896 "import sys; sys.stdout.write(str(sys.maxsize > 2**32))"
1897 RESULT_VARIABLE _${_PYTHON_PREFIX}_RESULT
1898 OUTPUT_VARIABLE ${_PYTHON_PREFIX}_IS64BIT
1899 ERROR_VARIABLE ${_PYTHON_PREFIX}_IS64BIT)
1900 if (NOT _${_PYTHON_PREFIX}_RESULT)
1901 if (${_PYTHON_PREFIX}_IS64BIT)
1902 set (_${_PYTHON_PREFIX}_ARCH 64)
1903 set (_${_PYTHON_PREFIX}_ARCH2 64)
1905 set (_${_PYTHON_PREFIX}_ARCH 32)
1906 set (_${_PYTHON_PREFIX}_ARCH2 32)
1911 # retrieve interpreter identity
1912 execute_process (COMMAND ${_${_PYTHON_PREFIX}_INTERPRETER_LAUNCHER} "${_${_PYTHON_PREFIX}_EXECUTABLE}" -V
1913 RESULT_VARIABLE _${_PYTHON_PREFIX}_RESULT
1914 OUTPUT_VARIABLE ${_PYTHON_PREFIX}_INTERPRETER_ID
1915 ERROR_VARIABLE ${_PYTHON_PREFIX}_INTERPRETER_ID)
1916 if (NOT _${_PYTHON_PREFIX}_RESULT)
1917 if (${_PYTHON_PREFIX}_INTERPRETER_ID MATCHES "Anaconda")
1918 set (${_PYTHON_PREFIX}_INTERPRETER_ID "Anaconda")
1919 elseif (${_PYTHON_PREFIX}_INTERPRETER_ID MATCHES "Enthought")
1920 set (${_PYTHON_PREFIX}_INTERPRETER_ID "Canopy")
1921 elseif (${_PYTHON_PREFIX}_INTERPRETER_ID MATCHES "PyPy ([0-9.]+)")
1922 set (${_PYTHON_PREFIX}_INTERPRETER_ID "PyPy")
1923 set (${_PYTHON_PREFIX}_PyPy_VERSION "${CMAKE_MATCH_1}")
1925 string (REGEX REPLACE "^([^ ]+).*" "\\1" ${_PYTHON_PREFIX}_INTERPRETER_ID "${${_PYTHON_PREFIX}_INTERPRETER_ID}")
1926 if (${_PYTHON_PREFIX}_INTERPRETER_ID STREQUAL "Python")
1927 # try to get a more precise ID
1928 execute_process (COMMAND ${_${_PYTHON_PREFIX}_INTERPRETER_LAUNCHER} "${_${_PYTHON_PREFIX}_EXECUTABLE}" -c
1929 "import sys; sys.stdout.write(sys.copyright)"
1930 RESULT_VARIABLE _${_PYTHON_PREFIX}_RESULT
1931 OUTPUT_VARIABLE ${_PYTHON_PREFIX}_COPYRIGHT
1933 if (${_PYTHON_PREFIX}_COPYRIGHT MATCHES "ActiveState")
1934 set (${_PYTHON_PREFIX}_INTERPRETER_ID "ActivePython")
1939 set (${_PYTHON_PREFIX}_INTERPRETER_ID Python)
1942 # retrieve various package installation directories
1943 execute_process (COMMAND ${_${_PYTHON_PREFIX}_INTERPRETER_LAUNCHER} "${_${_PYTHON_PREFIX}_EXECUTABLE}" -c
1944 "import sys\ntry:\n from distutils import sysconfig\n sys.stdout.write(';'.join([sysconfig.get_python_lib(plat_specific=False,standard_lib=True),sysconfig.get_python_lib(plat_specific=True,standard_lib=True),sysconfig.get_python_lib(plat_specific=False,standard_lib=False),sysconfig.get_python_lib(plat_specific=True,standard_lib=False)]))\nexcept Exception:\n import sysconfig\n sys.stdout.write(';'.join([sysconfig.get_path('stdlib'),sysconfig.get_path('platstdlib'),sysconfig.get_path('purelib'),sysconfig.get_path('platlib')]))"
1945 RESULT_VARIABLE _${_PYTHON_PREFIX}_RESULT
1946 OUTPUT_VARIABLE _${_PYTHON_PREFIX}_LIBPATHS
1948 if (NOT _${_PYTHON_PREFIX}_RESULT)
1949 list (GET _${_PYTHON_PREFIX}_LIBPATHS 0 ${_PYTHON_PREFIX}_STDLIB)
1950 list (GET _${_PYTHON_PREFIX}_LIBPATHS 1 ${_PYTHON_PREFIX}_STDARCH)
1951 list (GET _${_PYTHON_PREFIX}_LIBPATHS 2 ${_PYTHON_PREFIX}_SITELIB)
1952 list (GET _${_PYTHON_PREFIX}_LIBPATHS 3 ${_PYTHON_PREFIX}_SITEARCH)
1954 unset (${_PYTHON_PREFIX}_STDLIB)
1955 unset (${_PYTHON_PREFIX}_STDARCH)
1956 unset (${_PYTHON_PREFIX}_SITELIB)
1957 unset (${_PYTHON_PREFIX}_SITEARCH)
1960 _python_get_config_var (${_PYTHON_PREFIX}_SOABI SOABI)
1962 # store properties in the cache to speed-up future searches
1963 set (_${_PYTHON_PREFIX}_INTERPRETER_PROPERTIES
1964 "${${_PYTHON_PREFIX}_INTERPRETER_ID};${${_PYTHON_PREFIX}_VERSION_MAJOR};${${_PYTHON_PREFIX}_VERSION_MINOR};${${_PYTHON_PREFIX}_VERSION_PATCH};${_${_PYTHON_PREFIX}_ARCH};${_${_PYTHON_PREFIX}_ABIFLAGS};${${_PYTHON_PREFIX}_SOABI};${${_PYTHON_PREFIX}_STDLIB};${${_PYTHON_PREFIX}_STDARCH};${${_PYTHON_PREFIX}_SITELIB};${${_PYTHON_PREFIX}_SITEARCH}" CACHE INTERNAL "${_PYTHON_PREFIX} Properties")
1966 unset (_${_PYTHON_PREFIX}_INTERPRETER_SIGNATURE CACHE)
1967 unset (${_PYTHON_PREFIX}_INTERPRETER_ID)
1972 if (${_PYTHON_PREFIX}_ARTIFACTS_INTERACTIVE)
1973 set (${_PYTHON_PREFIX}_EXECUTABLE "${_${_PYTHON_PREFIX}_EXECUTABLE}" CACHE FILEPATH "${_PYTHON_PREFIX} Interpreter")
1976 _python_mark_as_internal (_${_PYTHON_PREFIX}_EXECUTABLE
1977 _${_PYTHON_PREFIX}_INTERPRETER_PROPERTIES
1978 _${_PYTHON_PREFIX}_INTERPRETER_SIGNATURE)
1982 # second step, search for compiler (IronPython)
1983 if ("Compiler" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS)
1984 list (APPEND _${_PYTHON_PREFIX}_CACHED_VARS _${_PYTHON_PREFIX}_COMPILER)
1985 if (${_PYTHON_PREFIX}_FIND_REQUIRED_Compiler)
1986 list (APPEND _${_PYTHON_PREFIX}_REQUIRED_VARS ${_PYTHON_PREFIX}_COMPILER)
1989 if (NOT "IronPython" IN_LIST _${_PYTHON_PREFIX}_FIND_IMPLEMENTATIONS)
1990 unset (_${_PYTHON_PREFIX}_COMPILER CACHE)
1991 unset (_${_PYTHON_PREFIX}_COMPILER_SIGNATURE CACHE)
1992 elseif (DEFINED ${_PYTHON_PREFIX}_COMPILER
1993 AND IS_ABSOLUTE "${${_PYTHON_PREFIX}_COMPILER}")
1994 set (_${_PYTHON_PREFIX}_COMPILER "${${_PYTHON_PREFIX}_COMPILER}" CACHE INTERNAL "")
1995 elseif (DEFINED _${_PYTHON_PREFIX}_COMPILER)
1996 # compute compiler signature and check validity of definition
1997 string (MD5 __${_PYTHON_PREFIX}_COMPILER_SIGNATURE "${_${_PYTHON_PREFIX}_SIGNATURE}:${_${_PYTHON_PREFIX}_COMPILER}")
1998 if (__${_PYTHON_PREFIX}_COMPILER_SIGNATURE STREQUAL _${_PYTHON_PREFIX}_COMPILER_SIGNATURE)
1999 # check version validity
2000 if (${_PYTHON_PREFIX}_FIND_VERSION_EXACT)
2001 _python_validate_compiler (VERSION ${${_PYTHON_PREFIX}_FIND_VERSION} EXACT CHECK_EXISTS)
2002 elseif (${_PYTHON_PREFIX}_FIND_VERSION_RANGE)
2003 _python_validate_compiler (IN_RANGE CHECK_EXISTS)
2004 elseif (DEFINED ${_PYTHON_PREFIX}_FIND_VERSION)
2005 _python_validate_compiler (VERSION ${${_PYTHON_PREFIX}_FIND_VERSION} CHECK_EXISTS)
2007 _python_validate_compiler (CHECK_EXISTS)
2010 unset (_${_PYTHON_PREFIX}_COMPILER CACHE)
2011 unset (_${_PYTHON_PREFIX}_COMPILER_SIGNATURE CACHE)
2015 if ("IronPython" IN_LIST _${_PYTHON_PREFIX}_FIND_IMPLEMENTATIONS
2016 AND NOT _${_PYTHON_PREFIX}_COMPILER)
2017 # IronPython specific artifacts
2018 # If IronPython interpreter is found, use its path
2019 unset (_${_PYTHON_PREFIX}_IRON_ROOT)
2020 if (${_PYTHON_PREFIX}_Interpreter_FOUND AND ${_PYTHON_PREFIX}_INTERPRETER_ID STREQUAL "IronPython")
2021 get_filename_component (_${_PYTHON_PREFIX}_IRON_ROOT "${${_PYTHON_PREFIX}_EXECUTABLE}" DIRECTORY)
2024 if (_${_PYTHON_PREFIX}_FIND_STRATEGY STREQUAL "LOCATION")
2025 _python_get_names (_${_PYTHON_PREFIX}_COMPILER_NAMES
2026 IMPLEMENTATIONS IronPython
2027 VERSION ${_${_PYTHON_PREFIX}_FIND_VERSIONS}
2030 _python_get_path_suffixes (_${_PYTHON_PREFIX}_PATH_SUFFIXES
2031 IMPLEMENTATIONS IronPython
2032 VERSION ${_${_PYTHON_PREFIX}_FIND_VERSIONS}
2035 _python_get_frameworks (_${_PYTHON_PREFIX}_FRAMEWORK_PATHS
2036 IMPLEMENTATIONS IronPython
2037 VERSION ${_${_PYTHON_PREFIX}_FIND_VERSIONS})
2038 _python_get_registries (_${_PYTHON_PREFIX}_REGISTRY_PATHS
2039 IMPLEMENTATIONS IronPython
2040 VERSION ${_${_PYTHON_PREFIX}_FIND_VERSIONS})
2042 set (_${_PYTHON_PREFIX}_VALIDATE_OPTIONS ${_${_PYTHON_PREFIX}_FIND_VERSION_EXACT})
2043 if (${_PYTHON_PREFIX}_FIND_VERSION_RANGE)
2044 list (APPEND _${_PYTHON_PREFIX}_VALIDATE_OPTIONS IN_RANGE)
2045 elseif (DEFINED ${_PYTHON_PREFIX}_FIND_VERSION)
2046 list (APPEND _${_PYTHON_PREFIX}_VALIDATE_OPTIONS VERSION ${${_PYTHON_PREFIX}_FIND_VERSION})
2050 # Apple frameworks handling
2051 if (CMAKE_HOST_APPLE AND _${_PYTHON_PREFIX}_FIND_FRAMEWORK STREQUAL "FIRST")
2052 find_program (_${_PYTHON_PREFIX}_COMPILER
2053 NAMES ${_${_PYTHON_PREFIX}_COMPILER_NAMES}
2055 HINTS ${_${_PYTHON_PREFIX}_IRON_ROOT} ${_${_PYTHON_PREFIX}_HINTS}
2056 PATHS ${_${_PYTHON_PREFIX}_FRAMEWORK_PATHS}
2057 PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES}
2059 NO_CMAKE_ENVIRONMENT_PATH
2060 NO_SYSTEM_ENVIRONMENT_PATH
2061 NO_CMAKE_SYSTEM_PATH)
2062 _python_validate_compiler (${_${_PYTHON_PREFIX}_VALIDATE_OPTIONS})
2063 if (_${_PYTHON_PREFIX}_COMPILER)
2068 if (CMAKE_HOST_WIN32 AND _${_PYTHON_PREFIX}_FIND_REGISTRY STREQUAL "FIRST")
2069 find_program (_${_PYTHON_PREFIX}_COMPILER
2070 NAMES ${_${_PYTHON_PREFIX}_COMPILER_NAMES}
2072 HINTS ${_${_PYTHON_PREFIX}_IRON_ROOT} ${_${_PYTHON_PREFIX}_HINTS}
2073 PATHS ${_${_PYTHON_PREFIX}_REGISTRY_PATHS}
2074 PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES}
2075 NO_SYSTEM_ENVIRONMENT_PATH
2076 NO_CMAKE_SYSTEM_PATH)
2077 _python_validate_compiler (${_${_PYTHON_PREFIX}_VALIDATE_OPTIONS})
2078 if (_${_PYTHON_PREFIX}_COMPILER)
2084 find_program (_${_PYTHON_PREFIX}_COMPILER
2085 NAMES ${_${_PYTHON_PREFIX}_COMPILER_NAMES}
2087 HINTS ${_${_PYTHON_PREFIX}_IRON_ROOT} ${_${_PYTHON_PREFIX}_HINTS}
2088 PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES}
2089 NO_SYSTEM_ENVIRONMENT_PATH
2090 NO_CMAKE_SYSTEM_PATH)
2091 _python_validate_compiler (${_${_PYTHON_PREFIX}_VALIDATE_OPTIONS})
2092 if (_${_PYTHON_PREFIX}_COMPILER)
2096 # try using standard paths
2097 find_program (_${_PYTHON_PREFIX}_COMPILER
2098 NAMES ${_${_PYTHON_PREFIX}_COMPILER_NAMES}
2100 PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES})
2101 _python_validate_compiler (${_${_PYTHON_PREFIX}_VALIDATE_OPTIONS})
2102 if (_${_PYTHON_PREFIX}_COMPILER)
2106 # Apple frameworks handling
2107 if (CMAKE_HOST_APPLE AND _${_PYTHON_PREFIX}_FIND_FRAMEWORK STREQUAL "LAST")
2108 find_program (_${_PYTHON_PREFIX}_COMPILER
2109 NAMES ${_${_PYTHON_PREFIX}_COMPILER_NAMES}
2111 PATHS ${_${_PYTHON_PREFIX}_FRAMEWORK_PATHS}
2112 PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES}
2114 _python_validate_compiler (${_${_PYTHON_PREFIX}_VALIDATE_OPTIONS})
2115 if (_${_PYTHON_PREFIX}_COMPILER)
2120 if (CMAKE_HOST_WIN32 AND _${_PYTHON_PREFIX}_FIND_REGISTRY STREQUAL "LAST")
2121 find_program (_${_PYTHON_PREFIX}_COMPILER
2122 NAMES ${_${_PYTHON_PREFIX}_COMPILER_NAMES}
2124 PATHS ${_${_PYTHON_PREFIX}_REGISTRY_PATHS}
2125 PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES}
2127 _python_validate_compiler (${_${_PYTHON_PREFIX}_VALIDATE_OPTIONS})
2128 if (_${_PYTHON_PREFIX}_COMPILER)
2136 # try using root dir and registry
2137 set (_${_PYTHON_PREFIX}_VALIDATE_OPTIONS EXACT)
2138 if (${_PYTHON_PREFIX}_FIND_VERSION_RANGE)
2139 list (APPEND _${_PYTHON_PREFIX}_VALIDATE_OPTIONS IN_RANGE)
2142 foreach (_${_PYTHON_PREFIX}_VERSION IN LISTS _${_PYTHON_PREFIX}_FIND_VERSIONS)
2143 _python_get_names (_${_PYTHON_PREFIX}_COMPILER_NAMES
2144 IMPLEMENTATIONS IronPython
2145 VERSION ${_${_PYTHON_PREFIX}_FIND_VERSIONS}
2148 _python_get_path_suffixes (_${_PYTHON_PREFIX}_PATH_SUFFIXES
2149 IMPLEMENTATIONS IronPython
2150 VERSION ${_${_PYTHON_PREFIX}_FIND_VERSION}
2153 _python_get_frameworks (_${_PYTHON_PREFIX}_FRAMEWORK_PATHS
2154 IMPLEMENTATIONS IronPython
2155 VERSION ${_${_PYTHON_PREFIX}_VERSION})
2156 _python_get_registries (_${_PYTHON_PREFIX}_REGISTRY_PATHS
2157 IMPLEMENTATIONS IronPython
2158 VERSION ${_${_PYTHON_PREFIX}_VERSION})
2160 # Apple frameworks handling
2161 if (CMAKE_HOST_APPLE AND _${_PYTHON_PREFIX}_FIND_FRAMEWORK STREQUAL "FIRST")
2162 find_program (_${_PYTHON_PREFIX}_COMPILER
2163 NAMES ${_${_PYTHON_PREFIX}_COMPILER_NAMES}
2165 HINTS ${_${_PYTHON_PREFIX}_IRON_ROOT} ${_${_PYTHON_PREFIX}_HINTS}
2166 PATHS ${_${_PYTHON_PREFIX}_FRAMEWORK_PATHS}
2167 PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES}
2169 NO_CMAKE_ENVIRONMENT_PATH
2170 NO_SYSTEM_ENVIRONMENT_PATH
2171 NO_CMAKE_SYSTEM_PATH)
2172 _python_validate_compiler (VERSION ${_${_PYTHON_PREFIX}_VERSION} ${_${_PYTHON_PREFIX}_VALIDATE_OPTIONS})
2173 if (_${_PYTHON_PREFIX}_COMPILER)
2178 if (CMAKE_HOST_WIN32 AND _${_PYTHON_PREFIX}_FIND_REGISTRY STREQUAL "FIRST")
2179 find_program (_${_PYTHON_PREFIX}_COMPILER
2180 NAMES ${_${_PYTHON_PREFIX}_COMPILER_NAMES}
2182 HINTS ${_${_PYTHON_PREFIX}_IRON_ROOT} ${_${_PYTHON_PREFIX}_HINTS}
2183 PATHS ${_${_PYTHON_PREFIX}_REGISTRY_PATHS}
2184 PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES}
2185 NO_SYSTEM_ENVIRONMENT_PATH
2186 NO_CMAKE_SYSTEM_PATH)
2187 _python_validate_compiler (VERSION ${_${_PYTHON_PREFIX}_VERSION} ${_${_PYTHON_PREFIX}_VALIDATE_OPTIONS})
2188 if (_${_PYTHON_PREFIX}_COMPILER)
2194 find_program (_${_PYTHON_PREFIX}_COMPILER
2195 NAMES ${_${_PYTHON_PREFIX}_COMPILER_NAMES}
2197 HINTS ${_${_PYTHON_PREFIX}_IRON_ROOT} ${_${_PYTHON_PREFIX}_HINTS}
2198 PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES}
2199 NO_SYSTEM_ENVIRONMENT_PATH
2200 NO_CMAKE_SYSTEM_PATH)
2201 _python_validate_compiler (VERSION ${_${_PYTHON_PREFIX}_VERSION} ${_${_PYTHON_PREFIX}_VALIDATE_OPTIONS})
2202 if (_${_PYTHON_PREFIX}_COMPILER)
2206 # Apple frameworks handling
2207 if (CMAKE_HOST_APPLE AND _${_PYTHON_PREFIX}_FIND_FRAMEWORK STREQUAL "LAST")
2208 find_program (_${_PYTHON_PREFIX}_COMPILER
2209 NAMES ${_${_PYTHON_PREFIX}_COMPILER_NAMES}
2211 PATHS ${_${_PYTHON_PREFIX}_FRAMEWORK_PATHS}
2212 PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES}
2214 _python_validate_compiler (VERSION ${_${_PYTHON_PREFIX}_VERSION} ${_${_PYTHON_PREFIX}_VALIDATE_OPTIONS})
2215 if (_${_PYTHON_PREFIX}_COMPILER)
2220 if (CMAKE_HOST_WIN32 AND _${_PYTHON_PREFIX}_FIND_REGISTRY STREQUAL "LAST")
2221 find_program (_${_PYTHON_PREFIX}_COMPILER
2222 NAMES ${_${_PYTHON_PREFIX}_COMPILER_NAMES}
2224 PATHS ${_${_PYTHON_PREFIX}_REGISTRY_PATHS}
2225 PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES}
2227 _python_validate_compiler (VERSION ${_${_PYTHON_PREFIX}_VERSION} ${_${_PYTHON_PREFIX}_VALIDATE_OPTIONS})
2228 if (_${_PYTHON_PREFIX}_COMPILER)
2234 # no specific version found, re-try in standard paths
2235 _python_get_names (_${_PYTHON_PREFIX}_COMPILER_NAMES
2236 IMPLEMENTATIONS IronPython
2237 VERSION ${_${_PYTHON_PREFIX}_FIND_VERSIONS}
2239 _python_get_path_suffixes (_${_PYTHON_PREFIX}_PATH_SUFFIXES
2240 IMPLEMENTATIONS IronPython
2241 VERSION ${_${_PYTHON_PREFIX}_FIND_VERSIONS}
2243 find_program (_${_PYTHON_PREFIX}_COMPILER
2244 NAMES ${_${_PYTHON_PREFIX}_COMPILER_NAMES}
2245 HINTS ${_${_PYTHON_PREFIX}_IRON_ROOT} ${_${_PYTHON_PREFIX}_HINTS}
2246 PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES})
2247 _python_validate_compiler ()
2251 set (${_PYTHON_PREFIX}_COMPILER "${_${_PYTHON_PREFIX}_COMPILER}")
2253 if (_${_PYTHON_PREFIX}_COMPILER)
2254 # retrieve python environment version from compiler
2255 _python_get_launcher (_${_PYTHON_PREFIX}_COMPILER_LAUNCHER COMPILER)
2256 set (_${_PYTHON_PREFIX}_VERSION_DIR "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/PythonCompilerVersion.dir")
2257 file (WRITE "${_${_PYTHON_PREFIX}_VERSION_DIR}/version.py" "import sys; sys.stdout.write('.'.join([str(x) for x in sys.version_info[:3]]))\n")
2258 execute_process (COMMAND ${_${_PYTHON_PREFIX}_COMPILER_LAUNCHER} "${_${_PYTHON_PREFIX}_COMPILER}"
2259 ${_${_PYTHON_PREFIX}_IRON_PYTHON_COMPILER_ARCH_FLAGS}
2260 /target:exe /embed "${_${_PYTHON_PREFIX}_VERSION_DIR}/version.py"
2261 WORKING_DIRECTORY "${_${_PYTHON_PREFIX}_VERSION_DIR}"
2264 get_filename_component (_${_PYTHON_PREFIX}_IR_DIR "${_${_PYTHON_PREFIX}_COMPILER}" DIRECTORY)
2265 execute_process (COMMAND "${CMAKE_COMMAND}" -E env "MONO_PATH=${_${_PYTHON_PREFIX}_IR_DIR}"
2266 ${${_PYTHON_PREFIX}_DOTNET_LAUNCHER} "${_${_PYTHON_PREFIX}_VERSION_DIR}/version.exe"
2267 WORKING_DIRECTORY "${_${_PYTHON_PREFIX}_VERSION_DIR}"
2268 RESULT_VARIABLE _${_PYTHON_PREFIX}_RESULT
2269 OUTPUT_VARIABLE _${_PYTHON_PREFIX}_VERSION
2271 if (NOT _${_PYTHON_PREFIX}_RESULT)
2272 set (_${_PYTHON_PREFIX}_COMPILER_USABLE TRUE)
2273 string (REGEX MATCHALL "[0-9]+" _${_PYTHON_PREFIX}_VERSIONS "${_${_PYTHON_PREFIX}_VERSION}")
2274 list (GET _${_PYTHON_PREFIX}_VERSIONS 0 _${_PYTHON_PREFIX}_VERSION_MAJOR)
2275 list (GET _${_PYTHON_PREFIX}_VERSIONS 1 _${_PYTHON_PREFIX}_VERSION_MINOR)
2276 list (GET _${_PYTHON_PREFIX}_VERSIONS 2 _${_PYTHON_PREFIX}_VERSION_PATCH)
2278 if (NOT ${_PYTHON_PREFIX}_Interpreter_FOUND)
2279 # set public version information
2280 set (${_PYTHON_PREFIX}_VERSION ${_${_PYTHON_PREFIX}_VERSION})
2281 set (${_PYTHON_PREFIX}_VERSION_MAJOR ${_${_PYTHON_PREFIX}_VERSION_MAJOR})
2282 set (${_PYTHON_PREFIX}_VERSION_MINOR ${_${_PYTHON_PREFIX}_VERSION_MINOR})
2283 set (${_PYTHON_PREFIX}_VERSION_PATCH ${_${_PYTHON_PREFIX}_VERSION_PATCH})
2286 # compiler not usable
2287 set (_${_PYTHON_PREFIX}_COMPILER_USABLE FALSE)
2288 set (_${_PYTHON_PREFIX}_Compiler_REASON_FAILURE "Cannot run the compiler \"${_${_PYTHON_PREFIX}_COMPILER}\"")
2290 file (REMOVE_RECURSE "${_${_PYTHON_PREFIX}_VERSION_DIR}")
2293 if (_${_PYTHON_PREFIX}_COMPILER AND _${_PYTHON_PREFIX}_COMPILER_USABLE)
2294 if (${_PYTHON_PREFIX}_Interpreter_FOUND)
2295 # Compiler must be compatible with interpreter
2296 if ("${_${_PYTHON_PREFIX}_VERSION_MAJOR}.${_${_PYTHON_PREFIX}_VERSION_MINOR}" VERSION_EQUAL "${${_PYTHON_PREFIX}_VERSION_MAJOR}.${${_PYTHON_PREFIX}_VERSION_MINOR}")
2297 set (${_PYTHON_PREFIX}_Compiler_FOUND TRUE)
2299 elseif (${_PYTHON_PREFIX}_VERSION_MAJOR VERSION_EQUAL _${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR)
2300 set (${_PYTHON_PREFIX}_Compiler_FOUND TRUE)
2301 # Use compiler version for future searches to ensure consistency
2302 set (_${_PYTHON_PREFIX}_FIND_VERSIONS ${${_PYTHON_PREFIX}_VERSION_MAJOR}.${${_PYTHON_PREFIX}_VERSION_MINOR})
2306 if (${_PYTHON_PREFIX}_Compiler_FOUND)
2307 unset (_${_PYTHON_PREFIX}_Compiler_REASON_FAILURE)
2309 # compute and save compiler signature
2310 string (MD5 __${_PYTHON_PREFIX}_COMPILER_SIGNATURE "${_${_PYTHON_PREFIX}_SIGNATURE}:${_${_PYTHON_PREFIX}_COMPILER}")
2311 set (_${_PYTHON_PREFIX}_COMPILER_SIGNATURE "${__${_PYTHON_PREFIX}_COMPILER_SIGNATURE}" CACHE INTERNAL "")
2313 set (${_PYTHON_PREFIX}_COMPILER_ID IronPython)
2315 unset (_${_PYTHON_PREFIX}_COMPILER_SIGNATURE CACHE)
2316 unset (${_PYTHON_PREFIX}_COMPILER_ID)
2319 if (${_PYTHON_PREFIX}_ARTIFACTS_INTERACTIVE)
2320 set (${_PYTHON_PREFIX}_COMPILER "${_${_PYTHON_PREFIX}_COMPILER}" CACHE FILEPATH "${_PYTHON_PREFIX} Compiler")
2323 _python_mark_as_internal (_${_PYTHON_PREFIX}_COMPILER
2324 _${_PYTHON_PREFIX}_COMPILER_SIGNATURE)
2327 # third step, search for the development artifacts
2328 if (${_PYTHON_PREFIX}_FIND_REQUIRED_Development.Module)
2329 if ("LIBRARY" IN_LIST _${_PYTHON_PREFIX}_FIND_DEVELOPMENT_MODULE_ARTIFACTS)
2330 list (APPEND _${_PYTHON_PREFIX}_REQUIRED_VARS ${_PYTHON_PREFIX}_LIBRARIES)
2332 if ("INCLUDE_DIR" IN_LIST _${_PYTHON_PREFIX}_FIND_DEVELOPMENT_MODULE_ARTIFACTS)
2333 list (APPEND _${_PYTHON_PREFIX}_REQUIRED_VARS ${_PYTHON_PREFIX}_INCLUDE_DIRS)
2336 if (${_PYTHON_PREFIX}_FIND_REQUIRED_Development.Embed)
2337 if ("LIBRARY" IN_LIST _${_PYTHON_PREFIX}_FIND_DEVELOPMENT_EMBED_ARTIFACTS)
2338 list (APPEND _${_PYTHON_PREFIX}_REQUIRED_VARS ${_PYTHON_PREFIX}_LIBRARIES)
2340 if ("INCLUDE_DIR" IN_LIST _${_PYTHON_PREFIX}_FIND_DEVELOPMENT_EMBED_ARTIFACTS)
2341 list (APPEND _${_PYTHON_PREFIX}_REQUIRED_VARS ${_PYTHON_PREFIX}_INCLUDE_DIRS)
2344 list (REMOVE_DUPLICATES _${_PYTHON_PREFIX}_REQUIRED_VARS)
2345 ## Development environment is not compatible with IronPython interpreter
2346 if (("Development.Module" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS
2347 OR "Development.Embed" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS)
2348 AND ((${_PYTHON_PREFIX}_Interpreter_FOUND
2349 AND NOT ${_PYTHON_PREFIX}_INTERPRETER_ID STREQUAL "IronPython")
2350 OR NOT ${_PYTHON_PREFIX}_Interpreter_FOUND))
2351 if (${_PYTHON_PREFIX}_Interpreter_FOUND)
2352 # reduce possible implementations to the interpreter one
2353 if (${_PYTHON_PREFIX}_INTERPRETER_ID STREQUAL "PyPy")
2354 set (_${_PYTHON_PREFIX}_FIND_IMPLEMENTATIONS "PyPy")
2356 set (_${_PYTHON_PREFIX}_FIND_IMPLEMENTATIONS "CPython")
2359 list (REMOVE_ITEM _${_PYTHON_PREFIX}_FIND_IMPLEMENTATIONS "IronPython")
2361 if ("LIBRARY" IN_LIST _${_PYTHON_PREFIX}_FIND_DEVELOPMENT_ARTIFACTS)
2362 list (APPEND _${_PYTHON_PREFIX}_CACHED_VARS _${_PYTHON_PREFIX}_LIBRARY_RELEASE
2363 _${_PYTHON_PREFIX}_RUNTIME_LIBRARY_RELEASE
2364 _${_PYTHON_PREFIX}_LIBRARY_DEBUG
2365 _${_PYTHON_PREFIX}_RUNTIME_LIBRARY_DEBUG)
2367 if ("INCLUDE_DIR" IN_LIST _${_PYTHON_PREFIX}_FIND_DEVELOPMENT_ARTIFACTS)
2368 list (APPEND _${_PYTHON_PREFIX}_CACHED_VARS _${_PYTHON_PREFIX}_INCLUDE_DIR)
2371 _python_check_development_signature (Module)
2372 _python_check_development_signature (Embed)
2374 if (DEFINED ${_PYTHON_PREFIX}_LIBRARY
2375 AND IS_ABSOLUTE "${${_PYTHON_PREFIX}_LIBRARY}")
2376 set (_${_PYTHON_PREFIX}_LIBRARY_RELEASE "${${_PYTHON_PREFIX}_LIBRARY}" CACHE INTERNAL "")
2377 unset (_${_PYTHON_PREFIX}_LIBRARY_DEBUG CACHE)
2378 unset (_${_PYTHON_PREFIX}_INCLUDE_DIR CACHE)
2380 if (DEFINED ${_PYTHON_PREFIX}_INCLUDE_DIR
2381 AND IS_ABSOLUTE "${${_PYTHON_PREFIX}_INCLUDE_DIR}")
2382 set (_${_PYTHON_PREFIX}_INCLUDE_DIR "${${_PYTHON_PREFIX}_INCLUDE_DIR}" CACHE INTERNAL "")
2385 # Support preference of static libs by adjusting CMAKE_FIND_LIBRARY_SUFFIXES
2386 unset (_${_PYTHON_PREFIX}_CMAKE_FIND_LIBRARY_SUFFIXES)
2387 if (DEFINED ${_PYTHON_PREFIX}_USE_STATIC_LIBS AND NOT WIN32)
2388 set(_${_PYTHON_PREFIX}_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
2389 if(${_PYTHON_PREFIX}_USE_STATIC_LIBS)
2390 set (CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_STATIC_LIBRARY_SUFFIX})
2392 list (REMOVE_ITEM CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_STATIC_LIBRARY_SUFFIX})
2396 if (NOT _${_PYTHON_PREFIX}_LIBRARY_RELEASE OR NOT _${_PYTHON_PREFIX}_INCLUDE_DIR)
2397 # if python interpreter is found, use it to look-up for artifacts
2398 # to ensure consistency between interpreter and development environments.
2399 # If not, try to locate a compatible config tool
2400 if ((NOT ${_PYTHON_PREFIX}_Interpreter_FOUND OR CMAKE_CROSSCOMPILING)
2401 AND "CPython" IN_LIST _${_PYTHON_PREFIX}_FIND_IMPLEMENTATIONS)
2402 set (_${_PYTHON_PREFIX}_HINTS "${${_PYTHON_PREFIX}_ROOT_DIR}" ENV ${_PYTHON_PREFIX}_ROOT_DIR)
2403 unset (_${_PYTHON_PREFIX}_VIRTUALENV_PATHS)
2404 if (_${_PYTHON_PREFIX}_FIND_VIRTUALENV MATCHES "^(FIRST|ONLY)$")
2405 set (_${_PYTHON_PREFIX}_VIRTUALENV_PATHS ENV VIRTUAL_ENV ENV CONDA_PREFIX)
2408 if (_${_PYTHON_PREFIX}_FIND_STRATEGY STREQUAL "LOCATION")
2409 _python_get_names (_${_PYTHON_PREFIX}_CONFIG_NAMES VERSION ${_${_PYTHON_PREFIX}_FIND_VERSIONS} POSIX CONFIG)
2411 _python_get_frameworks (_${_PYTHON_PREFIX}_FRAMEWORK_PATHS VERSION ${_${_PYTHON_PREFIX}_FIND_VERSIONS})
2413 # Apple frameworks handling
2414 if (CMAKE_HOST_APPLE AND _${_PYTHON_PREFIX}_FIND_FRAMEWORK STREQUAL "FIRST")
2415 find_program (_${_PYTHON_PREFIX}_CONFIG
2416 NAMES ${_${_PYTHON_PREFIX}_CONFIG_NAMES}
2418 HINTS ${_${_PYTHON_PREFIX}_HINTS}
2419 PATHS ${_${_PYTHON_PREFIX}_VIRTUALENV_PATHS}
2420 ${_${_PYTHON_PREFIX}_FRAMEWORK_PATHS}
2423 NO_CMAKE_ENVIRONMENT_PATH
2424 NO_SYSTEM_ENVIRONMENT_PATH
2425 NO_CMAKE_SYSTEM_PATH)
2428 find_program (_${_PYTHON_PREFIX}_CONFIG
2429 NAMES ${_${_PYTHON_PREFIX}_CONFIG_NAMES}
2431 HINTS ${_${_PYTHON_PREFIX}_HINTS}
2432 PATHS ${_${_PYTHON_PREFIX}_VIRTUALENV_PATHS}
2435 # Apple frameworks handling
2436 if (CMAKE_HOST_APPLE AND _${_PYTHON_PREFIX}_FIND_FRAMEWORK STREQUAL "LAST")
2437 find_program (_${_PYTHON_PREFIX}_CONFIG
2438 NAMES ${_${_PYTHON_PREFIX}_CONFIG_NAMES}
2440 PATHS ${_${_PYTHON_PREFIX}_FRAMEWORK_PATHS}
2445 if (_${_PYTHON_PREFIX}_CONFIG)
2446 execute_process (COMMAND "${_${_PYTHON_PREFIX}_CONFIG}" --help
2447 RESULT_VARIABLE _${_PYTHON_PREFIX}_RESULT
2448 OUTPUT_VARIABLE __${_PYTHON_PREFIX}_HELP
2450 OUTPUT_STRIP_TRAILING_WHITESPACE)
2451 if (_${_PYTHON_PREFIX}_RESULT)
2452 # assume config tool is not usable
2453 unset (_${_PYTHON_PREFIX}_CONFIG CACHE)
2457 if (_${_PYTHON_PREFIX}_CONFIG)
2458 execute_process (COMMAND "${_${_PYTHON_PREFIX}_CONFIG}" --abiflags
2459 RESULT_VARIABLE _${_PYTHON_PREFIX}_RESULT
2460 OUTPUT_VARIABLE __${_PYTHON_PREFIX}_ABIFLAGS
2462 OUTPUT_STRIP_TRAILING_WHITESPACE)
2463 if (_${_PYTHON_PREFIX}_RESULT)
2464 # assume ABI is not supported
2465 set (__${_PYTHON_PREFIX}_ABIFLAGS "")
2467 if (DEFINED _${_PYTHON_PREFIX}_FIND_ABI AND NOT __${_PYTHON_PREFIX}_ABIFLAGS IN_LIST _${_PYTHON_PREFIX}_ABIFLAGS)
2469 unset (_${_PYTHON_PREFIX}_CONFIG CACHE)
2473 if (_${_PYTHON_PREFIX}_CONFIG AND DEFINED CMAKE_LIBRARY_ARCHITECTURE)
2474 # check that config tool match library architecture
2475 execute_process (COMMAND "${_${_PYTHON_PREFIX}_CONFIG}" --configdir
2476 RESULT_VARIABLE _${_PYTHON_PREFIX}_RESULT
2477 OUTPUT_VARIABLE _${_PYTHON_PREFIX}_CONFIGDIR
2479 OUTPUT_STRIP_TRAILING_WHITESPACE)
2480 if (_${_PYTHON_PREFIX}_RESULT)
2481 unset (_${_PYTHON_PREFIX}_CONFIG CACHE)
2483 string(FIND "${_${_PYTHON_PREFIX}_CONFIGDIR}" "${CMAKE_LIBRARY_ARCHITECTURE}" _${_PYTHON_PREFIX}_RESULT)
2484 if (_${_PYTHON_PREFIX}_RESULT EQUAL -1)
2485 unset (_${_PYTHON_PREFIX}_CONFIG CACHE)
2490 foreach (_${_PYTHON_PREFIX}_VERSION IN LISTS _${_PYTHON_PREFIX}_FIND_VERSIONS)
2491 # try to use pythonX.Y-config tool
2492 _python_get_names (_${_PYTHON_PREFIX}_CONFIG_NAMES VERSION ${_${_PYTHON_PREFIX}_VERSION} POSIX CONFIG)
2495 _python_get_frameworks (_${_PYTHON_PREFIX}_FRAMEWORK_PATHS VERSION ${_${_PYTHON_PREFIX}_VERSION})
2497 # Apple frameworks handling
2498 if (CMAKE_HOST_APPLE AND _${_PYTHON_PREFIX}_FIND_FRAMEWORK STREQUAL "FIRST")
2499 find_program (_${_PYTHON_PREFIX}_CONFIG
2500 NAMES ${_${_PYTHON_PREFIX}_CONFIG_NAMES}
2502 HINTS ${_${_PYTHON_PREFIX}_HINTS}
2503 PATHS ${_${_PYTHON_PREFIX}_VIRTUALENV_PATHS}
2504 ${_${_PYTHON_PREFIX}_FRAMEWORK_PATHS}
2507 NO_CMAKE_ENVIRONMENT_PATH
2508 NO_SYSTEM_ENVIRONMENT_PATH
2509 NO_CMAKE_SYSTEM_PATH)
2512 find_program (_${_PYTHON_PREFIX}_CONFIG
2513 NAMES ${_${_PYTHON_PREFIX}_CONFIG_NAMES}
2515 HINTS ${_${_PYTHON_PREFIX}_HINTS}
2516 PATHS ${_${_PYTHON_PREFIX}_VIRTUALENV_PATHS}
2519 # Apple frameworks handling
2520 if (CMAKE_HOST_APPLE AND _${_PYTHON_PREFIX}_FIND_FRAMEWORK STREQUAL "LAST")
2521 find_program (_${_PYTHON_PREFIX}_CONFIG
2522 NAMES ${_${_PYTHON_PREFIX}_CONFIG_NAMES}
2524 PATHS ${_${_PYTHON_PREFIX}_FRAMEWORK_PATHS}
2529 unset (_${_PYTHON_PREFIX}_CONFIG_NAMES)
2531 if (_${_PYTHON_PREFIX}_CONFIG)
2532 execute_process (COMMAND "${_${_PYTHON_PREFIX}_CONFIG}" --help
2533 RESULT_VARIABLE _${_PYTHON_PREFIX}_RESULT
2534 OUTPUT_VARIABLE __${_PYTHON_PREFIX}_HELP
2536 OUTPUT_STRIP_TRAILING_WHITESPACE)
2537 if (_${_PYTHON_PREFIX}_RESULT)
2538 # assume config tool is not usable
2539 unset (_${_PYTHON_PREFIX}_CONFIG CACHE)
2543 if (NOT _${_PYTHON_PREFIX}_CONFIG)
2547 execute_process (COMMAND "${_${_PYTHON_PREFIX}_CONFIG}" --abiflags
2548 RESULT_VARIABLE _${_PYTHON_PREFIX}_RESULT
2549 OUTPUT_VARIABLE __${_PYTHON_PREFIX}_ABIFLAGS
2551 OUTPUT_STRIP_TRAILING_WHITESPACE)
2552 if (_${_PYTHON_PREFIX}_RESULT)
2553 # assume ABI is not supported
2554 set (__${_PYTHON_PREFIX}_ABIFLAGS "")
2556 if (DEFINED _${_PYTHON_PREFIX}_FIND_ABI AND NOT __${_PYTHON_PREFIX}_ABIFLAGS IN_LIST _${_PYTHON_PREFIX}_ABIFLAGS)
2558 unset (_${_PYTHON_PREFIX}_CONFIG CACHE)
2562 if (_${_PYTHON_PREFIX}_CONFIG AND DEFINED CMAKE_LIBRARY_ARCHITECTURE)
2563 # check that config tool match library architecture
2564 execute_process (COMMAND "${_${_PYTHON_PREFIX}_CONFIG}" --configdir
2565 RESULT_VARIABLE _${_PYTHON_PREFIX}_RESULT
2566 OUTPUT_VARIABLE _${_PYTHON_PREFIX}_CONFIGDIR
2568 OUTPUT_STRIP_TRAILING_WHITESPACE)
2569 if (_${_PYTHON_PREFIX}_RESULT)
2570 unset (_${_PYTHON_PREFIX}_CONFIG CACHE)
2573 string (FIND "${_${_PYTHON_PREFIX}_CONFIGDIR}" "${CMAKE_LIBRARY_ARCHITECTURE}" _${_PYTHON_PREFIX}_RESULT)
2574 if (_${_PYTHON_PREFIX}_RESULT EQUAL -1)
2575 unset (_${_PYTHON_PREFIX}_CONFIG CACHE)
2580 if (_${_PYTHON_PREFIX}_CONFIG)
2588 if ("LIBRARY" IN_LIST _${_PYTHON_PREFIX}_FIND_DEVELOPMENT_ARTIFACTS)
2589 if (NOT _${_PYTHON_PREFIX}_LIBRARY_RELEASE)
2590 if ((${_PYTHON_PREFIX}_Interpreter_FOUND AND NOT CMAKE_CROSSCOMPILING) OR _${_PYTHON_PREFIX}_CONFIG)
2591 # retrieve root install directory
2592 _python_get_config_var (_${_PYTHON_PREFIX}_PREFIX PREFIX)
2594 # enforce current ABI
2595 _python_get_config_var (_${_PYTHON_PREFIX}_ABIFLAGS ABIFLAGS)
2597 set (_${_PYTHON_PREFIX}_HINTS "${_${_PYTHON_PREFIX}_PREFIX}")
2600 ## compute some paths and artifact names
2601 if (_${_PYTHON_PREFIX}_CONFIG)
2602 string (REGEX REPLACE "^.+python([0-9.]+)[a-z]*-config" "\\1" _${_PYTHON_PREFIX}_VERSION "${_${_PYTHON_PREFIX}_CONFIG}")
2604 set (_${_PYTHON_PREFIX}_VERSION "${${_PYTHON_PREFIX}_VERSION_MAJOR}.${${_PYTHON_PREFIX}_VERSION_MINOR}")
2606 _python_get_path_suffixes (_${_PYTHON_PREFIX}_PATH_SUFFIXES VERSION ${_${_PYTHON_PREFIX}_VERSION} LIBRARY)
2607 _python_get_names (_${_PYTHON_PREFIX}_LIB_NAMES VERSION ${_${_PYTHON_PREFIX}_VERSION} WIN32 POSIX LIBRARY)
2609 _python_get_config_var (_${_PYTHON_PREFIX}_CONFIGDIR CONFIGDIR)
2610 list (APPEND _${_PYTHON_PREFIX}_HINTS "${_${_PYTHON_PREFIX}_CONFIGDIR}")
2612 list (APPEND _${_PYTHON_PREFIX}_HINTS "${${_PYTHON_PREFIX}_ROOT_DIR}" ENV ${_PYTHON_PREFIX}_ROOT_DIR)
2614 find_library (_${_PYTHON_PREFIX}_LIBRARY_RELEASE
2615 NAMES ${_${_PYTHON_PREFIX}_LIB_NAMES}
2617 HINTS ${_${_PYTHON_PREFIX}_HINTS}
2618 PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES}
2619 NO_SYSTEM_ENVIRONMENT_PATH
2620 NO_CMAKE_SYSTEM_PATH)
2623 # Rely on HINTS and standard paths if interpreter or config tool failed to locate artifacts
2624 if (NOT _${_PYTHON_PREFIX}_LIBRARY_RELEASE)
2625 set (_${_PYTHON_PREFIX}_HINTS "${${_PYTHON_PREFIX}_ROOT_DIR}" ENV ${_PYTHON_PREFIX}_ROOT_DIR)
2627 unset (_${_PYTHON_PREFIX}_VIRTUALENV_PATHS)
2628 if (_${_PYTHON_PREFIX}_FIND_VIRTUALENV MATCHES "^(FIRST|ONLY)$")
2629 set (_${_PYTHON_PREFIX}_VIRTUALENV_PATHS ENV VIRTUAL_ENV ENV CONDA_PREFIX)
2632 if (_${_PYTHON_PREFIX}_FIND_STRATEGY STREQUAL "LOCATION")
2634 _python_get_names (_${_PYTHON_PREFIX}_LIB_NAMES VERSION ${_${_PYTHON_PREFIX}_FIND_VERSIONS} WIN32 POSIX LIBRARY)
2635 _python_get_names (_${_PYTHON_PREFIX}_LIB_NAMES_DEBUG VERSION ${_${_PYTHON_PREFIX}_FIND_VERSIONS} WIN32 DEBUG)
2637 _python_get_path_suffixes (_${_PYTHON_PREFIX}_PATH_SUFFIXES VERSION ${_${_PYTHON_PREFIX}_FIND_VERSIONS} LIBRARY)
2640 _python_get_frameworks (_${_PYTHON_PREFIX}_FRAMEWORK_PATHS VERSION ${_${_PYTHON_PREFIX}_LIB_FIND_VERSIONS})
2642 _python_get_registries (_${_PYTHON_PREFIX}_REGISTRY_PATHS VERSION ${_${_PYTHON_PREFIX}_FIND_VERSIONS} )
2644 if (APPLE AND _${_PYTHON_PREFIX}_FIND_FRAMEWORK STREQUAL "FIRST")
2645 find_library (_${_PYTHON_PREFIX}_LIBRARY_RELEASE
2646 NAMES ${_${_PYTHON_PREFIX}_LIB_NAMES}
2648 HINTS ${_${_PYTHON_PREFIX}_HINTS}
2649 PATHS ${_${_PYTHON_PREFIX}_VIRTUALENV_PATHS}
2650 ${_${_PYTHON_PREFIX}_FRAMEWORK_PATHS}
2651 PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES}
2653 NO_CMAKE_ENVIRONMENT_PATH
2654 NO_SYSTEM_ENVIRONMENT_PATH
2655 NO_CMAKE_SYSTEM_PATH)
2658 if (WIN32 AND _${_PYTHON_PREFIX}_FIND_REGISTRY STREQUAL "FIRST")
2659 find_library (_${_PYTHON_PREFIX}_LIBRARY_RELEASE
2660 NAMES ${_${_PYTHON_PREFIX}_LIB_NAMES}
2662 HINTS ${_${_PYTHON_PREFIX}_HINTS}
2663 PATHS ${_${_PYTHON_PREFIX}_VIRTUALENV_PATHS}
2664 ${_${_PYTHON_PREFIX}_REGISTRY_PATHS}
2665 PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES}
2666 NO_SYSTEM_ENVIRONMENT_PATH
2667 NO_CMAKE_SYSTEM_PATH)
2670 # search in HINTS locations
2671 find_library (_${_PYTHON_PREFIX}_LIBRARY_RELEASE
2672 NAMES ${_${_PYTHON_PREFIX}_LIB_NAMES}
2674 HINTS ${_${_PYTHON_PREFIX}_HINTS}
2675 PATHS ${_${_PYTHON_PREFIX}_VIRTUALENV_PATHS}
2676 PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES}
2677 NO_SYSTEM_ENVIRONMENT_PATH
2678 NO_CMAKE_SYSTEM_PATH)
2680 if (APPLE AND _${_PYTHON_PREFIX}_FIND_FRAMEWORK STREQUAL "LAST")
2681 set (__${_PYTHON_PREFIX}_FRAMEWORK_PATHS ${_${_PYTHON_PREFIX}_FRAMEWORK_PATHS})
2683 unset (__${_PYTHON_PREFIX}_FRAMEWORK_PATHS)
2686 if (WIN32 AND _${_PYTHON_PREFIX}_FIND_REGISTRY STREQUAL "LAST")
2687 set (__${_PYTHON_PREFIX}_REGISTRY_PATHS ${_${_PYTHON_PREFIX}_REGISTRY_PATHS})
2689 unset (__${_PYTHON_PREFIX}_REGISTRY_PATHS)
2692 # search in all default paths
2693 find_library (_${_PYTHON_PREFIX}_LIBRARY_RELEASE
2694 NAMES ${_${_PYTHON_PREFIX}_LIB_NAMES}
2696 PATHS ${__${_PYTHON_PREFIX}_FRAMEWORK_PATHS}
2697 ${__${_PYTHON_PREFIX}_REGISTRY_PATHS}
2698 PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES})
2700 foreach (_${_PYTHON_PREFIX}_LIB_VERSION IN LISTS _${_PYTHON_PREFIX}_FIND_VERSIONS)
2701 _python_get_names (_${_PYTHON_PREFIX}_LIB_NAMES VERSION ${_${_PYTHON_PREFIX}_LIB_VERSION} WIN32 POSIX LIBRARY)
2702 _python_get_names (_${_PYTHON_PREFIX}_LIB_NAMES_DEBUG VERSION ${_${_PYTHON_PREFIX}_LIB_VERSION} WIN32 DEBUG)
2704 _python_get_frameworks (_${_PYTHON_PREFIX}_FRAMEWORK_PATHS VERSION ${_${_PYTHON_PREFIX}_LIB_VERSION})
2705 _python_get_registries (_${_PYTHON_PREFIX}_REGISTRY_PATHS VERSION ${_${_PYTHON_PREFIX}_LIB_VERSION})
2707 _python_get_path_suffixes (_${_PYTHON_PREFIX}_PATH_SUFFIXES VERSION ${_${_PYTHON_PREFIX}_LIB_VERSION} LIBRARY)
2709 if (APPLE AND _${_PYTHON_PREFIX}_FIND_FRAMEWORK STREQUAL "FIRST")
2710 find_library (_${_PYTHON_PREFIX}_LIBRARY_RELEASE
2711 NAMES ${_${_PYTHON_PREFIX}_LIB_NAMES}
2713 HINTS ${_${_PYTHON_PREFIX}_HINTS}
2714 PATHS ${_${_PYTHON_PREFIX}_VIRTUALENV_PATHS}
2715 ${_${_PYTHON_PREFIX}_FRAMEWORK_PATHS}
2716 PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES}
2718 NO_CMAKE_ENVIRONMENT_PATH
2719 NO_SYSTEM_ENVIRONMENT_PATH
2720 NO_CMAKE_SYSTEM_PATH)
2723 if (WIN32 AND _${_PYTHON_PREFIX}_FIND_REGISTRY STREQUAL "FIRST")
2724 find_library (_${_PYTHON_PREFIX}_LIBRARY_RELEASE
2725 NAMES ${_${_PYTHON_PREFIX}_LIB_NAMES}
2727 HINTS ${_${_PYTHON_PREFIX}_HINTS}
2728 PATHS ${_${_PYTHON_PREFIX}_VIRTUALENV_PATHS}
2729 ${_${_PYTHON_PREFIX}_REGISTRY_PATHS}
2730 PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES}
2731 NO_SYSTEM_ENVIRONMENT_PATH
2732 NO_CMAKE_SYSTEM_PATH)
2735 # search in HINTS locations
2736 find_library (_${_PYTHON_PREFIX}_LIBRARY_RELEASE
2737 NAMES ${_${_PYTHON_PREFIX}_LIB_NAMES}
2739 HINTS ${_${_PYTHON_PREFIX}_HINTS}
2740 PATHS ${_${_PYTHON_PREFIX}_VIRTUALENV_PATHS}
2741 PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES}
2742 NO_SYSTEM_ENVIRONMENT_PATH
2743 NO_CMAKE_SYSTEM_PATH)
2745 if (APPLE AND _${_PYTHON_PREFIX}_FIND_FRAMEWORK STREQUAL "LAST")
2746 set (__${_PYTHON_PREFIX}_FRAMEWORK_PATHS ${_${_PYTHON_PREFIX}_FRAMEWORK_PATHS})
2748 unset (__${_PYTHON_PREFIX}_FRAMEWORK_PATHS)
2751 if (WIN32 AND _${_PYTHON_PREFIX}_FIND_REGISTRY STREQUAL "LAST")
2752 set (__${_PYTHON_PREFIX}_REGISTRY_PATHS ${_${_PYTHON_PREFIX}_REGISTRY_PATHS})
2754 unset (__${_PYTHON_PREFIX}_REGISTRY_PATHS)
2757 # search in all default paths
2758 find_library (_${_PYTHON_PREFIX}_LIBRARY_RELEASE
2759 NAMES ${_${_PYTHON_PREFIX}_LIB_NAMES}
2761 PATHS ${__${_PYTHON_PREFIX}_FRAMEWORK_PATHS}
2762 ${__${_PYTHON_PREFIX}_REGISTRY_PATHS}
2763 PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES})
2765 if (_${_PYTHON_PREFIX}_LIBRARY_RELEASE)
2773 # finalize library version information
2774 _python_get_version (LIBRARY PREFIX _${_PYTHON_PREFIX}_)
2775 if (_${_PYTHON_PREFIX}_VERSION EQUAL "${_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR}")
2776 # not able to extract full version from library name
2777 if (${_PYTHON_PREFIX}_Interpreter_FOUND)
2778 # update from interpreter
2779 set (_${_PYTHON_PREFIX}_VERSION ${${_PYTHON_PREFIX}_VERSION})
2780 set (_${_PYTHON_PREFIX}_VERSION_MAJOR ${${_PYTHON_PREFIX}_VERSION_MAJOR})
2781 set (_${_PYTHON_PREFIX}_VERSION_MINOR ${${_PYTHON_PREFIX}_VERSION_MINOR})
2782 set (_${_PYTHON_PREFIX}_VERSION_PATCH ${${_PYTHON_PREFIX}_VERSION_PATCH})
2786 set (${_PYTHON_PREFIX}_LIBRARY_RELEASE "${_${_PYTHON_PREFIX}_LIBRARY_RELEASE}")
2788 if (_${_PYTHON_PREFIX}_LIBRARY_RELEASE AND NOT EXISTS "${_${_PYTHON_PREFIX}_LIBRARY_RELEASE}")
2789 set (_${_PYTHON_PREFIX}_Development_REASON_FAILURE "Cannot find the library \"${_${_PYTHON_PREFIX}_LIBRARY_RELEASE}\"")
2790 set_property (CACHE _${_PYTHON_PREFIX}_LIBRARY_RELEASE PROPERTY VALUE "${_PYTHON_PREFIX}_LIBRARY_RELEASE-NOTFOUND")
2793 set (_${_PYTHON_PREFIX}_HINTS "${${_PYTHON_PREFIX}_ROOT_DIR}" ENV ${_PYTHON_PREFIX}_ROOT_DIR)
2795 if (WIN32 AND _${_PYTHON_PREFIX}_LIBRARY_RELEASE)
2796 # search for debug library
2797 # use release library location as a hint
2798 _python_get_names (_${_PYTHON_PREFIX}_LIB_NAMES_DEBUG VERSION ${_${_PYTHON_PREFIX}_VERSION} WIN32 DEBUG)
2799 get_filename_component (_${_PYTHON_PREFIX}_PATH "${_${_PYTHON_PREFIX}_LIBRARY_RELEASE}" DIRECTORY)
2800 find_library (_${_PYTHON_PREFIX}_LIBRARY_DEBUG
2801 NAMES ${_${_PYTHON_PREFIX}_LIB_NAMES_DEBUG}
2803 HINTS "${_${_PYTHON_PREFIX}_PATH}" ${_${_PYTHON_PREFIX}_HINTS}
2805 # second try including CMAKE variables to catch-up non conventional layouts
2806 find_library (_${_PYTHON_PREFIX}_LIBRARY_DEBUG
2807 NAMES ${_${_PYTHON_PREFIX}_LIB_NAMES_DEBUG}
2809 NO_SYSTEM_ENVIRONMENT_PATH
2810 NO_CMAKE_SYSTEM_PATH)
2813 # retrieve runtime libraries
2814 if (_${_PYTHON_PREFIX}_LIBRARY_RELEASE)
2815 _python_get_names (_${_PYTHON_PREFIX}_LIB_NAMES VERSION ${_${_PYTHON_PREFIX}_VERSION} WIN32 POSIX LIBRARY)
2816 get_filename_component (_${_PYTHON_PREFIX}_PATH "${_${_PYTHON_PREFIX}_LIBRARY_RELEASE}" DIRECTORY)
2817 get_filename_component (_${_PYTHON_PREFIX}_PATH2 "${_${_PYTHON_PREFIX}_PATH}" DIRECTORY)
2818 _python_find_runtime_library (_${_PYTHON_PREFIX}_RUNTIME_LIBRARY_RELEASE
2819 NAMES ${_${_PYTHON_PREFIX}_LIB_NAMES}
2821 HINTS "${_${_PYTHON_PREFIX}_PATH}"
2822 "${_${_PYTHON_PREFIX}_PATH2}" ${_${_PYTHON_PREFIX}_HINTS}
2825 if (_${_PYTHON_PREFIX}_LIBRARY_DEBUG)
2826 _python_get_names (_${_PYTHON_PREFIX}_LIB_NAMES_DEBUG VERSION ${_${_PYTHON_PREFIX}_VERSION} WIN32 DEBUG)
2827 get_filename_component (_${_PYTHON_PREFIX}_PATH "${_${_PYTHON_PREFIX}_LIBRARY_DEBUG}" DIRECTORY)
2828 get_filename_component (_${_PYTHON_PREFIX}_PATH2 "${_${_PYTHON_PREFIX}_PATH}" DIRECTORY)
2829 _python_find_runtime_library (_${_PYTHON_PREFIX}_RUNTIME_LIBRARY_DEBUG
2830 NAMES ${_${_PYTHON_PREFIX}_LIB_NAMES_DEBUG}
2832 HINTS "${_${_PYTHON_PREFIX}_PATH}"
2833 "${_${_PYTHON_PREFIX}_PATH2}" ${_${_PYTHON_PREFIX}_HINTS}
2838 if ("INCLUDE_DIR" IN_LIST _${_PYTHON_PREFIX}_FIND_DEVELOPMENT_ARTIFACTS)
2839 while (NOT _${_PYTHON_PREFIX}_INCLUDE_DIR)
2840 if ("LIBRARY" IN_LIST _${_PYTHON_PREFIX}_FIND_DEVELOPMENT_ARTIFACTS
2841 AND NOT _${_PYTHON_PREFIX}_LIBRARY_RELEASE)
2842 # Don't search for include dir if no library was founded
2846 if ((${_PYTHON_PREFIX}_Interpreter_FOUND AND NOT CMAKE_CROSSCOMPILING) OR _${_PYTHON_PREFIX}_CONFIG)
2847 _python_get_config_var (_${_PYTHON_PREFIX}_INCLUDE_DIRS INCLUDES)
2849 find_path (_${_PYTHON_PREFIX}_INCLUDE_DIR
2850 NAMES ${_${_PYTHON_PREFIX}_INCLUDE_NAMES}
2851 HINTS ${_${_PYTHON_PREFIX}_INCLUDE_DIRS}
2852 NO_SYSTEM_ENVIRONMENT_PATH
2853 NO_CMAKE_SYSTEM_PATH)
2856 # Rely on HINTS and standard paths if interpreter or config tool failed to locate artifacts
2857 if (NOT _${_PYTHON_PREFIX}_INCLUDE_DIR)
2858 unset (_${_PYTHON_PREFIX}_VIRTUALENV_PATHS)
2859 if (_${_PYTHON_PREFIX}_FIND_VIRTUALENV MATCHES "^(FIRST|ONLY)$")
2860 set (_${_PYTHON_PREFIX}_VIRTUALENV_PATHS ENV VIRTUAL_ENV ENV CONDA_PREFIX)
2862 unset (_${_PYTHON_PREFIX}_INCLUDE_HINTS)
2864 if ("LIBRARY" IN_LIST _${_PYTHON_PREFIX}_FIND_DEVELOPMENT_ARTIFACTS
2865 AND _${_PYTHON_PREFIX}_LIBRARY_RELEASE)
2866 # Use the library's install prefix as a hint
2867 if (_${_PYTHON_PREFIX}_LIBRARY_RELEASE MATCHES "^(.+/Frameworks/Python.framework/Versions/[0-9.]+)")
2868 list (APPEND _${_PYTHON_PREFIX}_INCLUDE_HINTS "${CMAKE_MATCH_1}")
2869 elseif (_${_PYTHON_PREFIX}_LIBRARY_RELEASE MATCHES "^(.+)/lib(64|32)?/python[0-9.]+/config")
2870 list (APPEND _${_PYTHON_PREFIX}_INCLUDE_HINTS "${CMAKE_MATCH_1}")
2871 elseif (DEFINED CMAKE_LIBRARY_ARCHITECTURE AND ${_${_PYTHON_PREFIX}_LIBRARY_RELEASE} MATCHES "^(.+)/lib/${CMAKE_LIBRARY_ARCHITECTURE}")
2872 list (APPEND _${_PYTHON_PREFIX}_INCLUDE_HINTS "${CMAKE_MATCH_1}")
2874 # assume library is in a directory under root
2875 get_filename_component (_${_PYTHON_PREFIX}_PREFIX "${_${_PYTHON_PREFIX}_LIBRARY_RELEASE}" DIRECTORY)
2876 get_filename_component (_${_PYTHON_PREFIX}_PREFIX "${_${_PYTHON_PREFIX}_PREFIX}" DIRECTORY)
2877 list (APPEND _${_PYTHON_PREFIX}_INCLUDE_HINTS "${_${_PYTHON_PREFIX}_PREFIX}")
2881 _python_get_frameworks (_${_PYTHON_PREFIX}_FRAMEWORK_PATHS VERSION ${_${_PYTHON_PREFIX}_VERSION})
2882 _python_get_registries (_${_PYTHON_PREFIX}_REGISTRY_PATHS VERSION ${_${_PYTHON_PREFIX}_VERSION})
2883 _python_get_path_suffixes (_${_PYTHON_PREFIX}_PATH_SUFFIXES VERSION ${_${_PYTHON_PREFIX}_VERSION} INCLUDE)
2885 if (APPLE AND _${_PYTHON_PREFIX}_FIND_FRAMEWORK STREQUAL "FIRST")
2886 find_path (_${_PYTHON_PREFIX}_INCLUDE_DIR
2887 NAMES ${_${_PYTHON_PREFIX}_INCLUDE_NAMES}
2888 HINTS ${_${_PYTHON_PREFIX}_INCLUDE_HINTS} ${_${_PYTHON_PREFIX}_HINTS}
2889 PATHS ${_${_PYTHON_PREFIX}_VIRTUALENV_PATHS}
2890 ${_${_PYTHON_PREFIX}_FRAMEWORK_PATHS}
2891 PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES}
2893 NO_CMAKE_ENVIRONMENT_PATH
2894 NO_SYSTEM_ENVIRONMENT_PATH
2895 NO_CMAKE_SYSTEM_PATH)
2898 if (WIN32 AND _${_PYTHON_PREFIX}_FIND_REGISTRY STREQUAL "FIRST")
2899 find_path (_${_PYTHON_PREFIX}_INCLUDE_DIR
2900 NAMES ${_${_PYTHON_PREFIX}_INCLUDE_NAMES}
2901 HINTS ${_${_PYTHON_PREFIX}_INCLUDE_HINTS} ${_${_PYTHON_PREFIX}_HINTS}
2902 PATHS ${_${_PYTHON_PREFIX}_VIRTUALENV_PATHS}
2903 ${_${_PYTHON_PREFIX}_REGISTRY_PATHS}
2904 PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES}
2905 NO_SYSTEM_ENVIRONMENT_PATH
2906 NO_CMAKE_SYSTEM_PATH)
2909 if (APPLE AND _${_PYTHON_PREFIX}_FIND_FRAMEWORK STREQUAL "LAST")
2910 set (__${_PYTHON_PREFIX}_FRAMEWORK_PATHS ${_${_PYTHON_PREFIX}_FRAMEWORK_PATHS})
2912 unset (__${_PYTHON_PREFIX}_FRAMEWORK_PATHS)
2915 if (WIN32 AND _${_PYTHON_PREFIX}_FIND_REGISTRY STREQUAL "LAST")
2916 set (__${_PYTHON_PREFIX}_REGISTRY_PATHS ${_${_PYTHON_PREFIX}_REGISTRY_PATHS})
2918 unset (__${_PYTHON_PREFIX}_REGISTRY_PATHS)
2921 find_path (_${_PYTHON_PREFIX}_INCLUDE_DIR
2922 NAMES ${_${_PYTHON_PREFIX}_INCLUDE_NAMES}
2923 HINTS ${_${_PYTHON_PREFIX}_INCLUDE_HINTS} ${_${_PYTHON_PREFIX}_HINTS}
2924 PATHS ${_${_PYTHON_PREFIX}_VIRTUALENV_PATHS}
2925 ${__${_PYTHON_PREFIX}_FRAMEWORK_PATHS}
2926 ${__${_PYTHON_PREFIX}_REGISTRY_PATHS}
2927 PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES}
2928 NO_SYSTEM_ENVIRONMENT_PATH
2929 NO_CMAKE_SYSTEM_PATH)
2932 # search header file in standard locations
2933 find_path (_${_PYTHON_PREFIX}_INCLUDE_DIR
2934 NAMES ${_${_PYTHON_PREFIX}_INCLUDE_NAMES})
2939 set (${_PYTHON_PREFIX}_INCLUDE_DIRS "${_${_PYTHON_PREFIX}_INCLUDE_DIR}")
2941 if (_${_PYTHON_PREFIX}_INCLUDE_DIR AND NOT EXISTS "${_${_PYTHON_PREFIX}_INCLUDE_DIR}")
2942 set (_${_PYTHON_PREFIX}_Development_REASON_FAILURE "Cannot find the directory \"${_${_PYTHON_PREFIX}_INCLUDE_DIR}\"")
2943 set_property (CACHE _${_PYTHON_PREFIX}_INCLUDE_DIR PROPERTY VALUE "${_PYTHON_PREFIX}_INCLUDE_DIR-NOTFOUND")
2946 if (_${_PYTHON_PREFIX}_INCLUDE_DIR)
2947 # retrieve version from header file
2948 _python_get_version (INCLUDE PREFIX _${_PYTHON_PREFIX}_INC_)
2949 if ("LIBRARY" IN_LIST _${_PYTHON_PREFIX}_FIND_DEVELOPMENT_ARTIFACTS
2950 AND _${_PYTHON_PREFIX}_LIBRARY_RELEASE)
2951 if ("${_${_PYTHON_PREFIX}_INC_VERSION_MAJOR}.${_${_PYTHON_PREFIX}_INC_VERSION_MINOR}"
2952 VERSION_EQUAL _${_PYTHON_PREFIX}_VERSION)
2954 set (_${_PYTHON_PREFIX}_VERSION ${_${_PYTHON_PREFIX}_INC_VERSION})
2955 set (_${_PYTHON_PREFIX}_VERSION_PATCH ${_${_PYTHON_PREFIX}_INC_VERSION_PATCH})
2956 elseif (_${_PYTHON_PREFIX}_VERSION VERSION_EQUAL _${_PYTHON_PREFIX}_INC_VERSION_MAJOR)
2957 # library specify only major version, use include file for full version information
2958 set (_${_PYTHON_PREFIX}_VERSION ${_${_PYTHON_PREFIX}_INC_VERSION})
2959 set (_${_PYTHON_PREFIX}_VERSION_MINOR ${_${_PYTHON_PREFIX}_INC_VERSION_MINOR})
2960 set (_${_PYTHON_PREFIX}_VERSION_PATCH ${_${_PYTHON_PREFIX}_INC_VERSION_PATCH})
2963 set (_${_PYTHON_PREFIX}_VERSION ${_${_PYTHON_PREFIX}_INC_VERSION})
2964 set (_${_PYTHON_PREFIX}_VERSION_MAJOR ${_${_PYTHON_PREFIX}_INC_VERSION_MAJOR})
2965 set (_${_PYTHON_PREFIX}_VERSION_MINOR ${_${_PYTHON_PREFIX}_INC_VERSION_MINOR})
2966 set (_${_PYTHON_PREFIX}_VERSION_PATCH ${_${_PYTHON_PREFIX}_INC_VERSION_PATCH})
2971 if (NOT ${_PYTHON_PREFIX}_Interpreter_FOUND AND NOT ${_PYTHON_PREFIX}_Compiler_FOUND)
2972 # set public version information
2973 set (${_PYTHON_PREFIX}_VERSION ${_${_PYTHON_PREFIX}_VERSION})
2974 set (${_PYTHON_PREFIX}_VERSION_MAJOR ${_${_PYTHON_PREFIX}_VERSION_MAJOR})
2975 set (${_PYTHON_PREFIX}_VERSION_MINOR ${_${_PYTHON_PREFIX}_VERSION_MINOR})
2976 set (${_PYTHON_PREFIX}_VERSION_PATCH ${_${_PYTHON_PREFIX}_VERSION_PATCH})
2979 # define public variables
2980 if ("LIBRARY" IN_LIST _${_PYTHON_PREFIX}_FIND_DEVELOPMENT_ARTIFACTS)
2981 set (${_PYTHON_PREFIX}_LIBRARY_DEBUG "${_${_PYTHON_PREFIX}_LIBRARY_DEBUG}")
2982 _python_select_library_configurations (${_PYTHON_PREFIX})
2984 set (${_PYTHON_PREFIX}_RUNTIME_LIBRARY_RELEASE "${_${_PYTHON_PREFIX}_RUNTIME_LIBRARY_RELEASE}")
2985 set (${_PYTHON_PREFIX}_RUNTIME_LIBRARY_DEBUG "${_${_PYTHON_PREFIX}_RUNTIME_LIBRARY_DEBUG}")
2987 if (_${_PYTHON_PREFIX}_RUNTIME_LIBRARY_RELEASE)
2988 set (${_PYTHON_PREFIX}_RUNTIME_LIBRARY "${_${_PYTHON_PREFIX}_RUNTIME_LIBRARY_RELEASE}")
2989 elseif (_${_PYTHON_PREFIX}_RUNTIME_LIBRARY_DEBUG)
2990 set (${_PYTHON_PREFIX}_RUNTIME_LIBRARY "${_${_PYTHON_PREFIX}_RUNTIME_LIBRARY_DEBUG}")
2992 set (${_PYTHON_PREFIX}_RUNTIME_LIBRARY "${_PYTHON_PREFIX}_RUNTIME_LIBRARY-NOTFOUND")
2995 _python_set_library_dirs (${_PYTHON_PREFIX}_LIBRARY_DIRS
2996 _${_PYTHON_PREFIX}_LIBRARY_RELEASE
2997 _${_PYTHON_PREFIX}_LIBRARY_DEBUG)
2999 if (_${_PYTHON_PREFIX}_LIBRARY_RELEASE MATCHES "${CMAKE_SHARED_LIBRARY_SUFFIX}$")
3000 set (${_PYTHON_PREFIX}_RUNTIME_LIBRARY_DIRS ${${_PYTHON_PREFIX}_LIBRARY_DIRS})
3003 _python_set_library_dirs (${_PYTHON_PREFIX}_RUNTIME_LIBRARY_DIRS
3004 _${_PYTHON_PREFIX}_RUNTIME_LIBRARY_RELEASE
3005 _${_PYTHON_PREFIX}_RUNTIME_LIBRARY_DEBUG)
3009 if (_${_PYTHON_PREFIX}_LIBRARY_RELEASE OR _${_PYTHON_PREFIX}_INCLUDE_DIR)
3010 if (${_PYTHON_PREFIX}_Interpreter_FOUND OR ${_PYTHON_PREFIX}_Compiler_FOUND)
3011 # development environment must be compatible with interpreter/compiler
3012 if ("${_${_PYTHON_PREFIX}_VERSION_MAJOR}.${_${_PYTHON_PREFIX}_VERSION_MINOR}" VERSION_EQUAL "${${_PYTHON_PREFIX}_VERSION_MAJOR}.${${_PYTHON_PREFIX}_VERSION_MINOR}"
3013 AND "${_${_PYTHON_PREFIX}_INC_VERSION_MAJOR}.${_${_PYTHON_PREFIX}_INC_VERSION_MINOR}" VERSION_EQUAL "${_${_PYTHON_PREFIX}_VERSION_MAJOR}.${_${_PYTHON_PREFIX}_VERSION_MINOR}")
3014 _python_set_development_module_found (Module)
3015 _python_set_development_module_found (Embed)
3017 elseif (${_PYTHON_PREFIX}_VERSION_MAJOR VERSION_EQUAL _${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR
3018 AND "${_${_PYTHON_PREFIX}_INC_VERSION_MAJOR}.${_${_PYTHON_PREFIX}_INC_VERSION_MINOR}" VERSION_EQUAL "${_${_PYTHON_PREFIX}_VERSION_MAJOR}.${_${_PYTHON_PREFIX}_VERSION_MINOR}")
3019 _python_set_development_module_found (Module)
3020 _python_set_development_module_found (Embed)
3022 if (DEFINED _${_PYTHON_PREFIX}_FIND_ABI AND
3023 (NOT _${_PYTHON_PREFIX}_ABI IN_LIST _${_PYTHON_PREFIX}_ABIFLAGS
3024 OR NOT _${_PYTHON_PREFIX}_INC_ABI IN_LIST _${_PYTHON_PREFIX}_ABIFLAGS))
3025 set (${_PYTHON_PREFIX}_Development.Module_FOUND FALSE)
3026 set (${_PYTHON_PREFIX}_Development.Embed_FOUND FALSE)
3030 if (( ${_PYTHON_PREFIX}_Development.Module_FOUND
3031 AND ${_PYTHON_PREFIX}_Development.Embed_FOUND)
3032 OR (NOT "Development.Module" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS
3033 AND ${_PYTHON_PREFIX}_Development.Embed_FOUND)
3034 OR (NOT "Development.Embed" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS
3035 AND ${_PYTHON_PREFIX}_Development.Module_FOUND))
3036 unset (_${_PYTHON_PREFIX}_Development_REASON_FAILURE)
3039 if ("Development" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS
3040 AND ${_PYTHON_PREFIX}_Development.Module_FOUND
3041 AND ${_PYTHON_PREFIX}_Development.Embed_FOUND)
3042 set (${_PYTHON_PREFIX}_Development_FOUND TRUE)
3045 if ((${_PYTHON_PREFIX}_Development.Module_FOUND
3046 OR ${_PYTHON_PREFIX}_Development.Embed_FOUND)
3047 AND EXISTS "${_${_PYTHON_PREFIX}_INCLUDE_DIR}/PyPy.h")
3048 # retrieve PyPy version
3049 file (STRINGS "${_${_PYTHON_PREFIX}_INCLUDE_DIR}/patchlevel.h" ${_PYTHON_PREFIX}_PyPy_VERSION
3050 REGEX "^#define[ \t]+PYPY_VERSION[ \t]+\"[^\"]+\"")
3051 string (REGEX REPLACE "^#define[ \t]+PYPY_VERSION[ \t]+\"([^\"]+)\".*" "\\1"
3052 ${_PYTHON_PREFIX}_PyPy_VERSION "${${_PYTHON_PREFIX}_PyPy_VERSION}")
3055 unset(${_PYTHON_PREFIX}_LINK_OPTIONS)
3056 if (${_PYTHON_PREFIX}_Development.Embed_FOUND AND APPLE
3057 AND ${_PYTHON_PREFIX}_LIBRARY_RELEASE MATCHES "${CMAKE_SHARED_LIBRARY_SUFFIX}$")
3058 # rpath must be specified if python is part of a framework
3059 unset(_${_PYTHON_PREFIX}_is_prefix)
3060 foreach (_${_PYTHON_PREFIX}_implementation IN LISTS _${_PYTHON_PREFIX}_FIND_IMPLEMENTATIONS)
3061 foreach (_${_PYTHON_PREFIX}_framework IN LISTS _${_PYTHON_PREFIX}_${_${_PYTHON_PREFIX}_implementation}_FRAMEWORKS)
3062 cmake_path (IS_PREFIX _${_PYTHON_PREFIX}_framework "${${_PYTHON_PREFIX}_LIBRARY_RELEASE}" _${_PYTHON_PREFIX}_is_prefix)
3063 if (_${_PYTHON_PREFIX}_is_prefix)
3064 cmake_path (GET _${_PYTHON_PREFIX}_framework PARENT_PATH _${_PYTHON_PREFIX}_framework)
3065 set (${_PYTHON_PREFIX}_LINK_OPTIONS "LINKER:-rpath,${_${_PYTHON_PREFIX}_framework}")
3069 if (_${_PYTHON_PREFIX}_is_prefix)
3073 unset(_${_PYTHON_PREFIX}_implementation)
3074 unset(_${_PYTHON_PREFIX}_framework)
3075 unset(_${_PYTHON_PREFIX}_is_prefix)
3078 if (NOT DEFINED ${_PYTHON_PREFIX}_SOABI)
3079 _python_get_config_var (${_PYTHON_PREFIX}_SOABI SOABI)
3082 _python_compute_development_signature (Module)
3083 _python_compute_development_signature (Embed)
3085 # Restore the original find library ordering
3086 if (DEFINED _${_PYTHON_PREFIX}_CMAKE_FIND_LIBRARY_SUFFIXES)
3087 set (CMAKE_FIND_LIBRARY_SUFFIXES ${_${_PYTHON_PREFIX}_CMAKE_FIND_LIBRARY_SUFFIXES})
3090 if (${_PYTHON_PREFIX}_ARTIFACTS_INTERACTIVE)
3091 if ("LIBRARY" IN_LIST _${_PYTHON_PREFIX}_FIND_DEVELOPMENT_ARTIFACTS)
3092 set (${_PYTHON_PREFIX}_LIBRARY "${_${_PYTHON_PREFIX}_LIBRARY_RELEASE}" CACHE FILEPATH "${_PYTHON_PREFIX} Library")
3094 if ("INCLUDE_DIR" IN_LIST _${_PYTHON_PREFIX}_FIND_DEVELOPMENT_ARTIFACTS)
3095 set (${_PYTHON_PREFIX}_INCLUDE_DIR "${_${_PYTHON_PREFIX}_INCLUDE_DIR}" CACHE FILEPATH "${_PYTHON_PREFIX} Include Directory")
3099 _python_mark_as_internal (_${_PYTHON_PREFIX}_LIBRARY_RELEASE
3100 _${_PYTHON_PREFIX}_LIBRARY_DEBUG
3101 _${_PYTHON_PREFIX}_RUNTIME_LIBRARY_RELEASE
3102 _${_PYTHON_PREFIX}_RUNTIME_LIBRARY_DEBUG
3103 _${_PYTHON_PREFIX}_INCLUDE_DIR
3104 _${_PYTHON_PREFIX}_CONFIG
3105 _${_PYTHON_PREFIX}_DEVELOPMENT_MODULE_SIGNATURE
3106 _${_PYTHON_PREFIX}_DEVELOPMENT_EMBED_SIGNATURE)
3109 if (${_PYTHON_PREFIX}_FIND_REQUIRED_NumPy)
3110 list (APPEND _${_PYTHON_PREFIX}_REQUIRED_VARS ${_PYTHON_PREFIX}_NumPy_INCLUDE_DIRS)
3112 if ("NumPy" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS AND ${_PYTHON_PREFIX}_Interpreter_FOUND)
3113 list (APPEND _${_PYTHON_PREFIX}_CACHED_VARS _${_PYTHON_PREFIX}_NumPy_INCLUDE_DIR)
3115 if (DEFINED ${_PYTHON_PREFIX}_NumPy_INCLUDE_DIR
3116 AND IS_ABSOLUTE "${${_PYTHON_PREFIX}_NumPy_INCLUDE_DIR}")
3117 set (_${_PYTHON_PREFIX}_NumPy_INCLUDE_DIR "${${_PYTHON_PREFIX}_NumPy_INCLUDE_DIR}" CACHE INTERNAL "")
3118 elseif (DEFINED _${_PYTHON_PREFIX}_NumPy_INCLUDE_DIR)
3119 # compute numpy signature. Depends on interpreter and development signatures
3120 string (MD5 __${_PYTHON_PREFIX}_NUMPY_SIGNATURE "${_${_PYTHON_PREFIX}_INTERPRETER_SIGNATURE}:${_${_PYTHON_PREFIX}_DEVELOPMENT_MODULE_SIGNATURE}:${_${_PYTHON_PREFIX}_NumPy_INCLUDE_DIR}")
3121 if (NOT __${_PYTHON_PREFIX}_NUMPY_SIGNATURE STREQUAL _${_PYTHON_PREFIX}_NUMPY_SIGNATURE
3122 OR NOT EXISTS "${_${_PYTHON_PREFIX}_NumPy_INCLUDE_DIR}")
3123 unset (_${_PYTHON_PREFIX}_NumPy_INCLUDE_DIR CACHE)
3124 unset (_${_PYTHON_PREFIX}_NUMPY_SIGNATURE CACHE)
3128 if (NOT _${_PYTHON_PREFIX}_NumPy_INCLUDE_DIR)
3129 execute_process(COMMAND ${${_PYTHON_PREFIX}_INTERPRETER_LAUNCHER} "${_${_PYTHON_PREFIX}_EXECUTABLE}" -c
3130 "import sys\ntry: import numpy; sys.stdout.write(numpy.get_include())\nexcept:pass\n"
3131 RESULT_VARIABLE _${_PYTHON_PREFIX}_RESULT
3132 OUTPUT_VARIABLE _${_PYTHON_PREFIX}_NumPy_PATH
3134 OUTPUT_STRIP_TRAILING_WHITESPACE)
3136 if (NOT _${_PYTHON_PREFIX}_RESULT)
3137 find_path (_${_PYTHON_PREFIX}_NumPy_INCLUDE_DIR
3138 NAMES "numpy/arrayobject.h" "numpy/numpyconfig.h"
3139 HINTS "${_${_PYTHON_PREFIX}_NumPy_PATH}"
3144 set (${_PYTHON_PREFIX}_NumPy_INCLUDE_DIRS "${_${_PYTHON_PREFIX}_NumPy_INCLUDE_DIR}")
3146 if(_${_PYTHON_PREFIX}_NumPy_INCLUDE_DIR AND NOT EXISTS "${_${_PYTHON_PREFIX}_NumPy_INCLUDE_DIR}")
3147 set (_${_PYTHON_PREFIX}_NumPy_REASON_FAILURE "Cannot find the directory \"${_${_PYTHON_PREFIX}_NumPy_INCLUDE_DIR}\"")
3148 set_property (CACHE _${_PYTHON_PREFIX}_NumPy_INCLUDE_DIR PROPERTY VALUE "${_PYTHON_PREFIX}_NumPy_INCLUDE_DIR-NOTFOUND")
3151 if (_${_PYTHON_PREFIX}_NumPy_INCLUDE_DIR)
3152 execute_process (COMMAND ${${_PYTHON_PREFIX}_INTERPRETER_LAUNCHER} "${_${_PYTHON_PREFIX}_EXECUTABLE}" -c
3153 "import sys\ntry: import numpy; sys.stdout.write(numpy.__version__)\nexcept:pass\n"
3154 RESULT_VARIABLE _${_PYTHON_PREFIX}_RESULT
3155 OUTPUT_VARIABLE _${_PYTHON_PREFIX}_NumPy_VERSION)
3156 if (NOT _${_PYTHON_PREFIX}_RESULT)
3157 set (${_PYTHON_PREFIX}_NumPy_VERSION "${_${_PYTHON_PREFIX}_NumPy_VERSION}")
3159 unset (${_PYTHON_PREFIX}_NumPy_VERSION)
3162 # final step: set NumPy founded only if Development.Module component is founded as well
3163 set(${_PYTHON_PREFIX}_NumPy_FOUND ${${_PYTHON_PREFIX}_Development.Module_FOUND})
3165 set (${_PYTHON_PREFIX}_NumPy_FOUND FALSE)
3168 if (${_PYTHON_PREFIX}_NumPy_FOUND)
3169 unset (_${_PYTHON_PREFIX}_NumPy_REASON_FAILURE)
3171 # compute and save numpy signature
3172 string (MD5 __${_PYTHON_PREFIX}_NUMPY_SIGNATURE "${_${_PYTHON_PREFIX}_INTERPRETER_SIGNATURE}:${_${_PYTHON_PREFIX}_DEVELOPMENT_MODULE_SIGNATURE}:${${_PYTHON_PREFIX}_NumPyINCLUDE_DIR}")
3173 set (_${_PYTHON_PREFIX}_NUMPY_SIGNATURE "${__${_PYTHON_PREFIX}_NUMPY_SIGNATURE}" CACHE INTERNAL "")
3175 unset (_${_PYTHON_PREFIX}_NUMPY_SIGNATURE CACHE)
3178 if (${_PYTHON_PREFIX}_ARTIFACTS_INTERACTIVE)
3179 set (${_PYTHON_PREFIX}_NumPy_INCLUDE_DIR "${_${_PYTHON_PREFIX}_NumPy_INCLUDE_DIR}" CACHE FILEPATH "${_PYTHON_PREFIX} NumPy Include Directory")
3182 _python_mark_as_internal (_${_PYTHON_PREFIX}_NumPy_INCLUDE_DIR
3183 _${_PYTHON_PREFIX}_NUMPY_SIGNATURE)
3187 if (${_PYTHON_PREFIX}_VERSION_MAJOR AND
3188 NOT ${_PYTHON_PREFIX}_VERSION_MAJOR VERSION_EQUAL _${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR)
3189 _python_display_failure ("Could NOT find ${_PYTHON_PREFIX}: Found unsuitable major version \"${${_PYTHON_PREFIX}_VERSION_MAJOR}\", but required major version is exact version \"${_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR}\"")
3195 unset (_${_PYTHON_PREFIX}_REASON_FAILURE)
3196 foreach (_${_PYTHON_PREFIX}_COMPONENT IN ITEMS Interpreter Compiler Development NumPy)
3197 if (_${_PYTHON_PREFIX}_${_${_PYTHON_PREFIX}_COMPONENT}_REASON_FAILURE)
3198 string (APPEND _${_PYTHON_PREFIX}_REASON_FAILURE "\n ${_${_PYTHON_PREFIX}_COMPONENT}: ${_${_PYTHON_PREFIX}_${_${_PYTHON_PREFIX}_COMPONENT}_REASON_FAILURE}")
3199 unset (_${_PYTHON_PREFIX}_${_${_PYTHON_PREFIX}_COMPONENT}_REASON_FAILURE)
3203 find_package_handle_standard_args (${_PYTHON_PREFIX}
3204 REQUIRED_VARS ${_${_PYTHON_PREFIX}_REQUIRED_VARS}
3205 VERSION_VAR ${_PYTHON_PREFIX}_VERSION
3206 HANDLE_VERSION_RANGE
3208 REASON_FAILURE_MESSAGE "${_${_PYTHON_PREFIX}_REASON_FAILURE}")
3210 # Create imported targets and helper functions
3211 if(_${_PYTHON_PREFIX}_CMAKE_ROLE STREQUAL "PROJECT")
3212 if ("Interpreter" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS
3213 AND ${_PYTHON_PREFIX}_Interpreter_FOUND
3214 AND NOT TARGET ${_PYTHON_PREFIX}::Interpreter)
3215 add_executable (${_PYTHON_PREFIX}::Interpreter IMPORTED)
3216 set_property (TARGET ${_PYTHON_PREFIX}::Interpreter
3217 PROPERTY IMPORTED_LOCATION "${${_PYTHON_PREFIX}_EXECUTABLE}")
3220 if ("Compiler" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS
3221 AND ${_PYTHON_PREFIX}_Compiler_FOUND
3222 AND NOT TARGET ${_PYTHON_PREFIX}::Compiler)
3223 add_executable (${_PYTHON_PREFIX}::Compiler IMPORTED)
3224 set_property (TARGET ${_PYTHON_PREFIX}::Compiler
3225 PROPERTY IMPORTED_LOCATION "${${_PYTHON_PREFIX}_COMPILER}")
3228 if (("Development.Module" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS
3229 AND ${_PYTHON_PREFIX}_Development.Module_FOUND)
3230 OR ("Development.Embed" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS
3231 AND ${_PYTHON_PREFIX}_Development.Embed_FOUND))
3233 macro (__PYTHON_IMPORT_LIBRARY __name)
3234 if (${_PYTHON_PREFIX}_LIBRARY_RELEASE MATCHES "${CMAKE_SHARED_LIBRARY_SUFFIX}$"
3235 OR ${_PYTHON_PREFIX}_RUNTIME_LIBRARY_RELEASE)
3236 set (_${_PYTHON_PREFIX}_LIBRARY_TYPE SHARED)
3238 set (_${_PYTHON_PREFIX}_LIBRARY_TYPE STATIC)
3241 if (NOT TARGET ${__name})
3242 add_library (${__name} ${_${_PYTHON_PREFIX}_LIBRARY_TYPE} IMPORTED)
3245 set_property (TARGET ${__name}
3246 PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${${_PYTHON_PREFIX}_INCLUDE_DIRS}")
3248 if (${_PYTHON_PREFIX}_LIBRARY_RELEASE AND ${_PYTHON_PREFIX}_RUNTIME_LIBRARY_RELEASE)
3249 # System manage shared libraries in two parts: import and runtime
3250 if (${_PYTHON_PREFIX}_LIBRARY_RELEASE AND ${_PYTHON_PREFIX}_LIBRARY_DEBUG)
3251 set_property (TARGET ${__name} PROPERTY IMPORTED_CONFIGURATIONS RELEASE DEBUG)
3252 set_target_properties (${__name}
3253 PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "C"
3254 IMPORTED_IMPLIB_RELEASE "${${_PYTHON_PREFIX}_LIBRARY_RELEASE}"
3255 IMPORTED_LOCATION_RELEASE "${${_PYTHON_PREFIX}_RUNTIME_LIBRARY_RELEASE}")
3256 set_target_properties (${__name}
3257 PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG "C"
3258 IMPORTED_IMPLIB_DEBUG "${${_PYTHON_PREFIX}_LIBRARY_DEBUG}"
3259 IMPORTED_LOCATION_DEBUG "${${_PYTHON_PREFIX}_RUNTIME_LIBRARY_DEBUG}")
3261 set_target_properties (${__name}
3262 PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES "C"
3263 IMPORTED_IMPLIB "${${_PYTHON_PREFIX}_LIBRARIES}"
3264 IMPORTED_LOCATION "${${_PYTHON_PREFIX}_RUNTIME_LIBRARY_RELEASE}")
3267 if (${_PYTHON_PREFIX}_LIBRARY_RELEASE AND ${_PYTHON_PREFIX}_LIBRARY_DEBUG)
3268 set_property (TARGET ${__name} PROPERTY IMPORTED_CONFIGURATIONS RELEASE DEBUG)
3269 set_target_properties (${__name}
3270 PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "C"
3271 IMPORTED_LOCATION_RELEASE "${${_PYTHON_PREFIX}_LIBRARY_RELEASE}")
3272 set_target_properties (${__name}
3273 PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG "C"
3274 IMPORTED_LOCATION_DEBUG "${${_PYTHON_PREFIX}_LIBRARY_DEBUG}")
3276 set_target_properties (${__name}
3277 PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES "C"
3278 IMPORTED_LOCATION "${${_PYTHON_PREFIX}_LIBRARY_RELEASE}")
3282 if (_${_PYTHON_PREFIX}_LIBRARY_TYPE STREQUAL "STATIC")
3283 # extend link information with dependent libraries
3284 _python_get_config_var (_${_PYTHON_PREFIX}_LINK_LIBRARIES LIBS)
3285 if (_${_PYTHON_PREFIX}_LINK_LIBRARIES)
3286 set_property (TARGET ${__name}
3287 PROPERTY INTERFACE_LINK_LIBRARIES ${_${_PYTHON_PREFIX}_LINK_LIBRARIES})
3291 if (${_PYTHON_PREFIX}_LINK_OPTIONS
3292 AND _${_PYTHON_PREFIX}_LIBRARY_TYPE STREQUAL "SHARED")
3293 set_property (TARGET ${__name} PROPERTY INTERFACE_LINK_OPTIONS "${${_PYTHON_PREFIX}_LINK_OPTIONS}")
3297 if (${_PYTHON_PREFIX}_Development.Embed_FOUND)
3298 __python_import_library (${_PYTHON_PREFIX}::Python)
3301 if (${_PYTHON_PREFIX}_Development.Module_FOUND)
3302 if ("LIBRARY" IN_LIST _${_PYTHON_PREFIX}_FIND_DEVELOPMENT_MODULE_ARTIFACTS)
3303 # On Windows/CYGWIN/MSYS, Python::Module is the same as Python::Python
3304 # but ALIAS cannot be used because the imported library is not GLOBAL.
3305 __python_import_library (${_PYTHON_PREFIX}::Module)
3307 if (NOT TARGET ${_PYTHON_PREFIX}::Module)
3308 add_library (${_PYTHON_PREFIX}::Module INTERFACE IMPORTED)
3310 set_property (TARGET ${_PYTHON_PREFIX}::Module
3311 PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${${_PYTHON_PREFIX}_INCLUDE_DIRS}")
3313 # When available, enforce shared library generation with undefined symbols
3315 set_property (TARGET ${_PYTHON_PREFIX}::Module
3316 PROPERTY INTERFACE_LINK_OPTIONS "LINKER:-undefined,dynamic_lookup")
3318 if (CMAKE_SYSTEM_NAME STREQUAL "SunOS")
3319 set_property (TARGET ${_PYTHON_PREFIX}::Module
3320 PROPERTY INTERFACE_LINK_OPTIONS "LINKER:-z,nodefs")
3322 if (CMAKE_SYSTEM_NAME STREQUAL "AIX")
3323 set_property (TARGET ${_PYTHON_PREFIX}::Module
3324 PROPERTY INTERFACE_LINK_OPTIONS "LINKER:-b,erok")
3330 # PYTHON_ADD_LIBRARY (<name> [STATIC|SHARED|MODULE] src1 src2 ... srcN)
3331 # It is used to build modules for python.
3333 function (__${_PYTHON_PREFIX}_ADD_LIBRARY prefix name)
3334 cmake_parse_arguments (PARSE_ARGV 2 PYTHON_ADD_LIBRARY "STATIC;SHARED;MODULE;WITH_SOABI" "" "")
3336 if (PYTHON_ADD_LIBRARY_STATIC)
3338 elseif (PYTHON_ADD_LIBRARY_SHARED)
3344 if (type STREQUAL "MODULE" AND NOT TARGET ${prefix}::Module)
3345 message (SEND_ERROR "${prefix}_ADD_LIBRARY: dependent target '${prefix}::Module' is not defined.\n Did you miss to request COMPONENT 'Development.Module'?")
3348 if (NOT type STREQUAL "MODULE" AND NOT TARGET ${prefix}::Python)
3349 message (SEND_ERROR "${prefix}_ADD_LIBRARY: dependent target '${prefix}::Python' is not defined.\n Did you miss to request COMPONENT 'Development.Embed'?")
3353 add_library (${name} ${type} ${PYTHON_ADD_LIBRARY_UNPARSED_ARGUMENTS})
3355 get_property (type TARGET ${name} PROPERTY TYPE)
3357 if (type STREQUAL "MODULE_LIBRARY")
3358 target_link_libraries (${name} PRIVATE ${prefix}::Module)
3359 # customize library name to follow module name rules
3360 set_property (TARGET ${name} PROPERTY PREFIX "")
3361 if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
3362 set_property (TARGET ${name} PROPERTY SUFFIX ".pyd")
3365 if (PYTHON_ADD_LIBRARY_WITH_SOABI AND ${prefix}_SOABI)
3366 get_property (suffix TARGET ${name} PROPERTY SUFFIX)
3368 set (suffix "${CMAKE_SHARED_MODULE_SUFFIX}")
3370 set_property (TARGET ${name} PROPERTY SUFFIX ".${${prefix}_SOABI}${suffix}")
3373 if (PYTHON_ADD_LIBRARY_WITH_SOABI)
3374 message (AUTHOR_WARNING "Find${prefix}: Option `WITH_SOABI` is only supported for `MODULE` library type.")
3376 target_link_libraries (${name} PRIVATE ${prefix}::Python)
3381 if ("NumPy" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS AND ${_PYTHON_PREFIX}_NumPy_FOUND
3382 AND NOT TARGET ${_PYTHON_PREFIX}::NumPy AND TARGET ${_PYTHON_PREFIX}::Module)
3383 add_library (${_PYTHON_PREFIX}::NumPy INTERFACE IMPORTED)
3384 set_property (TARGET ${_PYTHON_PREFIX}::NumPy
3385 PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${${_PYTHON_PREFIX}_NumPy_INCLUDE_DIRS}")
3386 target_link_libraries (${_PYTHON_PREFIX}::NumPy INTERFACE ${_PYTHON_PREFIX}::Module)
3392 # Restore CMAKE_FIND_APPBUNDLE
3393 if (DEFINED _${_PYTHON_PREFIX}_CMAKE_FIND_APPBUNDLE)
3394 set (CMAKE_FIND_APPBUNDLE ${_${_PYTHON_PREFIX}_CMAKE_FIND_APPBUNDLE})
3395 unset (_${_PYTHON_PREFIX}_CMAKE_FIND_APPBUNDLE)
3397 unset (CMAKE_FIND_APPBUNDLE)
3399 # Restore CMAKE_FIND_FRAMEWORK
3400 if (DEFINED _${_PYTHON_PREFIX}_CMAKE_FIND_FRAMEWORK)
3401 set (CMAKE_FIND_FRAMEWORK ${_${_PYTHON_PREFIX}_CMAKE_FIND_FRAMEWORK})
3402 unset (_${_PYTHON_PREFIX}_CMAKE_FIND_FRAMEWORK)
3404 unset (CMAKE_FIND_FRAMEWORK)