Support.cmake 107 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file Copyright.txt or https://cmake.org/licensing for details.
  3. #
  4. # This file is a "template" file used by various FindPython modules.
  5. #
  6. cmake_policy (GET CMP0094 _${_PYTHON_PREFIX}_LOOKUP_POLICY)
  7. cmake_policy (VERSION 3.7)
  8. if (_${_PYTHON_PREFIX}_LOOKUP_POLICY)
  9. cmake_policy (SET CMP0094 ${_${_PYTHON_PREFIX}_LOOKUP_POLICY})
  10. endif()
  11. #
  12. # Initial configuration
  13. #
  14. if (NOT DEFINED _PYTHON_PREFIX)
  15. message (FATAL_ERROR "FindPython: INTERNAL ERROR")
  16. endif()
  17. if (NOT DEFINED _${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR)
  18. message (FATAL_ERROR "FindPython: INTERNAL ERROR")
  19. endif()
  20. if (_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR EQUAL 3)
  21. set(_${_PYTHON_PREFIX}_VERSIONS 3.9 3.8 3.7 3.6 3.5 3.4 3.3 3.2 3.1 3.0)
  22. elseif (_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR EQUAL 2)
  23. set(_${_PYTHON_PREFIX}_VERSIONS 2.7 2.6 2.5 2.4 2.3 2.2 2.1 2.0)
  24. else()
  25. message (FATAL_ERROR "FindPython: INTERNAL ERROR")
  26. endif()
  27. get_property(_${_PYTHON_PREFIX}_CMAKE_ROLE GLOBAL PROPERTY CMAKE_ROLE)
  28. #
  29. # helper commands
  30. #
  31. macro (_PYTHON_DISPLAY_FAILURE _PYTHON_MSG)
  32. if (${_PYTHON_PREFIX}_FIND_REQUIRED)
  33. message (FATAL_ERROR "${_PYTHON_MSG}")
  34. else()
  35. if (NOT ${_PYTHON_PREFIX}_FIND_QUIETLY)
  36. message(STATUS "${_PYTHON_MSG}")
  37. endif ()
  38. endif()
  39. set (${_PYTHON_PREFIX}_FOUND FALSE)
  40. string (TOUPPER "${_PYTHON_PREFIX}" _${_PYTHON_PREFIX}_UPPER_PREFIX)
  41. set (${_PYTHON_UPPER_PREFIX}_FOUND FALSE)
  42. return()
  43. endmacro()
  44. macro (_PYTHON_FIND_FRAMEWORKS)
  45. set (${_PYTHON_PREFIX}_FRAMEWORKS)
  46. if (CMAKE_HOST_APPLE OR APPLE)
  47. set (_pff_frameworks ${CMAKE_FRAMEWORK_PATH}
  48. $ENV{CMAKE_FRAMEWORK_PATH}
  49. ~/Library/Frameworks
  50. /usr/local/Frameworks
  51. ${CMAKE_SYSTEM_FRAMEWORK_PATH})
  52. list (REMOVE_DUPLICATES _pff_frameworks)
  53. foreach (_pff_framework IN LISTS _pff_frameworks)
  54. if (EXISTS ${_pff_framework}/Python${_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR}.framework)
  55. list (APPEND ${_PYTHON_PREFIX}_FRAMEWORKS ${_pff_framework}/Python${_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR}.framework)
  56. endif()
  57. if (EXISTS ${_pff_framework}/Python.framework)
  58. list (APPEND ${_PYTHON_PREFIX}_FRAMEWORKS ${_pff_framework}/Python.framework)
  59. endif()
  60. endforeach()
  61. unset (_pff_frameworks)
  62. unset (_pff_framework)
  63. endif()
  64. endmacro()
  65. function (_PYTHON_GET_FRAMEWORKS _PYTHON_PGF_FRAMEWORK_PATHS _PYTHON_VERSION)
  66. set (_PYTHON_FRAMEWORK_PATHS)
  67. foreach (_PYTHON_FRAMEWORK IN LISTS ${_PYTHON_PREFIX}_FRAMEWORKS)
  68. list (APPEND _PYTHON_FRAMEWORK_PATHS
  69. "${_PYTHON_FRAMEWORK}/Versions/${_PYTHON_VERSION}")
  70. endforeach()
  71. set (${_PYTHON_PGF_FRAMEWORK_PATHS} ${_PYTHON_FRAMEWORK_PATHS} PARENT_SCOPE)
  72. endfunction()
  73. function (_PYTHON_GET_REGISTRIES _PYTHON_PGR_REGISTRY_PATHS _PYTHON_VERSION)
  74. string (REPLACE "." "" _PYTHON_VERSION_NO_DOTS ${_PYTHON_VERSION})
  75. set (${_PYTHON_PGR_REGISTRY_PATHS}
  76. [HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\${_PYTHON_VERSION}-${_${_PYTHON_PREFIX}_ARCH}\\InstallPath]
  77. [HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\${_PYTHON_VERSION}-${_${_PYTHON_PREFIX}_ARCH2}\\InstallPath]
  78. [HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\${_PYTHON_VERSION}\\InstallPath]
  79. [HKEY_CURRENT_USER\\SOFTWARE\\Python\\ContinuumAnalytics\\Anaconda${_PYTHON_VERSION_NO_DOTS}-${_${_PYTHON_PREFIX}_ARCH}\\InstallPath]
  80. [HKEY_CURRENT_USER\\SOFTWARE\\Python\\ContinuumAnalytics\\Anaconda${_PYTHON_VERSION_NO_DOTS}-${_${_PYTHON_PREFIX}_ARCH2}\\InstallPath]
  81. [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_PYTHON_VERSION}-${_${_PYTHON_PREFIX}_ARCH}\\InstallPath]
  82. [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_PYTHON_VERSION}-${_${_PYTHON_PREFIX}_ARCH2}\\InstallPath]
  83. [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_PYTHON_VERSION}\\InstallPath]
  84. [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\ContinuumAnalytics\\Anaconda${_PYTHON_VERSION_NO_DOTS}-${_${_PYTHON_PREFIX}_ARCH}\\InstallPath]
  85. [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\ContinuumAnalytics\\Anaconda${_PYTHON_VERSION_NO_DOTS}-${_${_PYTHON_PREFIX}_ARCH2}\\InstallPath]
  86. PARENT_SCOPE)
  87. endfunction()
  88. function (_PYTHON_GET_ABIFLAGS _PGABIFLAGS)
  89. set (abiflags)
  90. list (GET _${_PYTHON_PREFIX}_FIND_ABI 0 pydebug)
  91. list (GET _${_PYTHON_PREFIX}_FIND_ABI 1 pymalloc)
  92. list (GET _${_PYTHON_PREFIX}_FIND_ABI 2 unicode)
  93. if (pymalloc STREQUAL "ANY" AND unicode STREQUAL "ANY")
  94. set (abiflags "mu" "m" "u" "")
  95. elseif (pymalloc STREQUAL "ANY" AND unicode STREQUAL "ON")
  96. set (abiflags "mu" "u")
  97. elseif (pymalloc STREQUAL "ANY" AND unicode STREQUAL "OFF")
  98. set (abiflags "m" "")
  99. elseif (pymalloc STREQUAL "ON" AND unicode STREQUAL "ANY")
  100. set (abiflags "mu" "m")
  101. elseif (pymalloc STREQUAL "ON" AND unicode STREQUAL "ON")
  102. set (abiflags "mu")
  103. elseif (pymalloc STREQUAL "ON" AND unicode STREQUAL "OFF")
  104. set (abiflags "m")
  105. elseif (pymalloc STREQUAL "ON" AND unicode STREQUAL "ANY")
  106. set (abiflags "u" "")
  107. elseif (pymalloc STREQUAL "OFF" AND unicode STREQUAL "ON")
  108. set (abiflags "u")
  109. endif()
  110. if (pydebug STREQUAL "ON")
  111. if (abiflags)
  112. list (TRANSFORM abiflags PREPEND "d")
  113. else()
  114. set (abiflags "d")
  115. endif()
  116. elseif (pydebug STREQUAL "ANY")
  117. if (abiflags)
  118. set (flags "${abiflags}")
  119. list (TRANSFORM flags PREPEND "d")
  120. list (APPEND abiflags "${flags}")
  121. else()
  122. set (abiflags "" "d")
  123. endif()
  124. endif()
  125. set (${_PGABIFLAGS} "${abiflags}" PARENT_SCOPE)
  126. endfunction()
  127. function (_PYTHON_GET_PATH_SUFFIXES _PYTHON_PGPS_PATH_SUFFIXES)
  128. cmake_parse_arguments (PARSE_ARGV 1 _PGPS "LIBRARY;INCLUDE" "VERSION" "")
  129. if (DEFINED _${_PYTHON_PREFIX}_ABIFLAGS)
  130. set (abi "${_${_PYTHON_PREFIX}_ABIFLAGS}")
  131. else()
  132. set (abi "mu" "m" "u" "")
  133. endif()
  134. set (path_suffixes)
  135. if (_PGPS_LIBRARY)
  136. if (CMAKE_LIBRARY_ARCHITECTURE)
  137. list (APPEND path_suffixes lib/${CMAKE_LIBRARY_ARCHITECTURE})
  138. endif()
  139. list (APPEND path_suffixes lib libs)
  140. if (CMAKE_LIBRARY_ARCHITECTURE)
  141. set (suffixes "${abi}")
  142. if (suffixes)
  143. list (TRANSFORM suffixes PREPEND "lib/python${_PGPS_VERSION}/config-${_PGPS_VERSION}")
  144. list (TRANSFORM suffixes APPEND "-${CMAKE_LIBRARY_ARCHITECTURE}")
  145. else()
  146. set (suffixes "lib/python${_PGPS_VERSION}/config-${_PGPS_VERSION}-${CMAKE_LIBRARY_ARCHITECTURE}")
  147. endif()
  148. list (APPEND path_suffixes ${suffixes})
  149. endif()
  150. set (suffixes "${abi}")
  151. if (suffixes)
  152. list (TRANSFORM suffixes PREPEND "lib/python${_PGPS_VERSION}/config-${_PGPS_VERSION}")
  153. else()
  154. set (suffixes "lib/python${_PGPS_VERSION}/config-${_PGPS_VERSION}")
  155. endif()
  156. list (APPEND path_suffixes ${suffixes})
  157. elseif (_PGPS_INCLUDE)
  158. set (suffixes "${abi}")
  159. if (suffixes)
  160. list (TRANSFORM suffixes PREPEND "include/python${_PGPS_VERSION}")
  161. else()
  162. set (suffixes "include/python${_PGPS_VERSION}")
  163. endif()
  164. list (APPEND path_suffixes ${suffixes} include)
  165. endif()
  166. set (${_PYTHON_PGPS_PATH_SUFFIXES} ${path_suffixes} PARENT_SCOPE)
  167. endfunction()
  168. function (_PYTHON_GET_NAMES _PYTHON_PGN_NAMES)
  169. cmake_parse_arguments (PARSE_ARGV 1 _PGN "POSIX;EXECUTABLE;CONFIG;LIBRARY;WIN32;DEBUG" "VERSION" "")
  170. set (names)
  171. if (_PGN_WIN32)
  172. string (REPLACE "." "" _PYTHON_VERSION_NO_DOTS ${_PGN_VERSION})
  173. set (name python${_PYTHON_VERSION_NO_DOTS})
  174. if (_PGN_DEBUG)
  175. string (APPEND name "_d")
  176. endif()
  177. list (APPEND names "${name}")
  178. endif()
  179. if (_PGN_POSIX)
  180. if (DEFINED _${_PYTHON_PREFIX}_ABIFLAGS)
  181. set (abi "${_${_PYTHON_PREFIX}_ABIFLAGS}")
  182. else()
  183. if (_PGN_EXECUTABLE OR _PGN_CONFIG)
  184. set (abi "")
  185. else()
  186. set (abi "mu" "m" "u" "")
  187. endif()
  188. endif()
  189. if (abi)
  190. if (_PGN_CONFIG AND DEFINED CMAKE_LIBRARY_ARCHITECTURE)
  191. set (abinames "${abi}")
  192. list (TRANSFORM abinames PREPEND "${CMAKE_LIBRARY_ARCHITECTURE}-python${_PGN_VERSION}")
  193. list (TRANSFORM abinames APPEND "-config")
  194. list (APPEND names ${abinames})
  195. endif()
  196. set (abinames "${abi}")
  197. list (TRANSFORM abinames PREPEND "python${_PGN_VERSION}")
  198. if (_PGN_CONFIG)
  199. list (TRANSFORM abinames APPEND "-config")
  200. endif()
  201. list (APPEND names ${abinames})
  202. else()
  203. if (_PGN_CONFIG AND DEFINED CMAKE_LIBRARY_ARCHITECTURE)
  204. set (abinames "${CMAKE_LIBRARY_ARCHITECTURE}-python${_PGN_VERSION}")
  205. endif()
  206. list (APPEND abinames "python${_PGN_VERSION}")
  207. if (_PGN_CONFIG)
  208. list (TRANSFORM abinames APPEND "-config")
  209. endif()
  210. list (APPEND names ${abinames})
  211. endif()
  212. endif()
  213. set (${_PYTHON_PGN_NAMES} ${names} PARENT_SCOPE)
  214. endfunction()
  215. function (_PYTHON_GET_CONFIG_VAR _PYTHON_PGCV_VALUE NAME)
  216. unset (${_PYTHON_PGCV_VALUE} PARENT_SCOPE)
  217. if (NOT NAME MATCHES "^(PREFIX|ABIFLAGS|CONFIGDIR|INCLUDES|LIBS)$")
  218. return()
  219. endif()
  220. if (_${_PYTHON_PREFIX}_CONFIG)
  221. set (config_flag "--${NAME}")
  222. string (TOLOWER "${config_flag}" config_flag)
  223. execute_process (COMMAND "${_${_PYTHON_PREFIX}_CONFIG}" ${config_flag}
  224. RESULT_VARIABLE _result
  225. OUTPUT_VARIABLE _values
  226. ERROR_QUIET
  227. OUTPUT_STRIP_TRAILING_WHITESPACE)
  228. if (_result)
  229. unset (_values)
  230. else()
  231. if (NAME STREQUAL "INCLUDES")
  232. # do some clean-up
  233. string (REGEX MATCHALL "(-I|-iwithsysroot)[ ]*[^ ]+" _values "${_values}")
  234. string (REGEX REPLACE "(-I|-iwithsysroot)[ ]*" "" _values "${_values}")
  235. list (REMOVE_DUPLICATES _values)
  236. endif()
  237. endif()
  238. endif()
  239. if (_${_PYTHON_PREFIX}_EXECUTABLE AND NOT CMAKE_CROSSCOMPILING)
  240. if (NAME STREQUAL "PREFIX")
  241. execute_process (COMMAND "${_${_PYTHON_PREFIX}_EXECUTABLE}" -c "import sys; from distutils import sysconfig; sys.stdout.write(';'.join([sysconfig.PREFIX,sysconfig.EXEC_PREFIX,sysconfig.BASE_EXEC_PREFIX]))"
  242. RESULT_VARIABLE _result
  243. OUTPUT_VARIABLE _values
  244. ERROR_QUIET
  245. OUTPUT_STRIP_TRAILING_WHITESPACE)
  246. if (_result)
  247. unset (_values)
  248. else()
  249. list (REMOVE_DUPLICATES _values)
  250. endif()
  251. elseif (NAME STREQUAL "INCLUDES")
  252. execute_process (COMMAND "${_${_PYTHON_PREFIX}_EXECUTABLE}" -c "import sys; from distutils import sysconfig; sys.stdout.write(';'.join([sysconfig.get_python_inc(plat_specific=True),sysconfig.get_python_inc(plat_specific=False)]))"
  253. RESULT_VARIABLE _result
  254. OUTPUT_VARIABLE _values
  255. ERROR_QUIET
  256. OUTPUT_STRIP_TRAILING_WHITESPACE)
  257. if (_result)
  258. unset (_values)
  259. endif()
  260. else()
  261. set (config_flag "${NAME}")
  262. if (NAME STREQUAL "CONFIGDIR")
  263. set (config_flag "LIBPL")
  264. endif()
  265. execute_process (COMMAND "${_${_PYTHON_PREFIX}_EXECUTABLE}" -c "import sys; from distutils import sysconfig; sys.stdout.write(sysconfig.get_config_var('${config_flag}'))"
  266. RESULT_VARIABLE _result
  267. OUTPUT_VARIABLE _values
  268. ERROR_QUIET
  269. OUTPUT_STRIP_TRAILING_WHITESPACE)
  270. if (_result)
  271. unset (_values)
  272. endif()
  273. endif()
  274. endif()
  275. if (config_flag STREQUAL "ABIFLAGS")
  276. set (${_PYTHON_PGCV_VALUE} "${_values}" PARENT_SCOPE)
  277. return()
  278. endif()
  279. if (NOT _values OR _values STREQUAL "None")
  280. return()
  281. endif()
  282. if (NAME STREQUAL "LIBS")
  283. # do some clean-up
  284. string (REGEX MATCHALL "-(l|framework)[ ]*[^ ]+" _values "${_values}")
  285. # remove elements relative to python library itself
  286. list (FILTER _values EXCLUDE REGEX "-lpython")
  287. list (REMOVE_DUPLICATES _values)
  288. endif()
  289. set (${_PYTHON_PGCV_VALUE} "${_values}" PARENT_SCOPE)
  290. endfunction()
  291. function (_PYTHON_GET_VERSION)
  292. cmake_parse_arguments (PARSE_ARGV 0 _PGV "LIBRARY;INCLUDE" "PREFIX" "")
  293. unset (${_PGV_PREFIX}VERSION PARENT_SCOPE)
  294. unset (${_PGV_PREFIX}VERSION_MAJOR PARENT_SCOPE)
  295. unset (${_PGV_PREFIX}VERSION_MINOR PARENT_SCOPE)
  296. unset (${_PGV_PREFIX}VERSION_PATCH PARENT_SCOPE)
  297. unset (${_PGV_PREFIX}ABI PARENT_SCOPE)
  298. if (_PGV_LIBRARY)
  299. # retrieve version and abi from library name
  300. if (_${_PYTHON_PREFIX}_LIBRARY_RELEASE)
  301. # extract version from library name
  302. if (_${_PYTHON_PREFIX}_LIBRARY_RELEASE MATCHES "python([23])([0-9]+)")
  303. set (${_PGV_PREFIX}VERSION_MAJOR "${CMAKE_MATCH_1}" PARENT_SCOPE)
  304. set (${_PGV_PREFIX}VERSION_MINOR "${CMAKE_MATCH_2}" PARENT_SCOPE)
  305. set (${_PGV_PREFIX}VERSION "${CMAKE_MATCH_1}.${CMAKE_MATCH_2}" PARENT_SCOPE)
  306. set (${_PGV_PREFIX}ABI "" PARENT_SCOPE)
  307. elseif (_${_PYTHON_PREFIX}_LIBRARY_RELEASE MATCHES "python([23])\\.([0-9]+)([dmu]*)")
  308. set (${_PGV_PREFIX}VERSION_MAJOR "${CMAKE_MATCH_1}" PARENT_SCOPE)
  309. set (${_PGV_PREFIX}VERSION_MINOR "${CMAKE_MATCH_2}" PARENT_SCOPE)
  310. set (${_PGV_PREFIX}VERSION "${CMAKE_MATCH_1}.${CMAKE_MATCH_2}" PARENT_SCOPE)
  311. set (${_PGV_PREFIX}ABI "${CMAKE_MATCH_3}" PARENT_SCOPE)
  312. endif()
  313. endif()
  314. else()
  315. if (_${_PYTHON_PREFIX}_INCLUDE_DIR)
  316. # retrieve version from header file
  317. file (STRINGS "${_${_PYTHON_PREFIX}_INCLUDE_DIR}/patchlevel.h" version
  318. REGEX "^#define[ \t]+PY_VERSION[ \t]+\"[^\"]+\"")
  319. string (REGEX REPLACE "^#define[ \t]+PY_VERSION[ \t]+\"([^\"]+)\".*" "\\1"
  320. version "${version}")
  321. string (REGEX MATCHALL "[0-9]+" versions "${version}")
  322. list (GET versions 0 version_major)
  323. list (GET versions 1 version_minor)
  324. list (GET versions 2 version_patch)
  325. set (${_PGV_PREFIX}VERSION "${version_major}.${version_minor}" PARENT_SCOPE)
  326. set (${_PGV_PREFIX}VERSION_MAJOR ${version_major} PARENT_SCOPE)
  327. set (${_PGV_PREFIX}VERSION_MINOR ${version_minor} PARENT_SCOPE)
  328. set (${_PGV_PREFIX}VERSION_PATCH ${version_patch} PARENT_SCOPE)
  329. # compute ABI flags
  330. if (version_major VERSION_GREATER 2)
  331. file (STRINGS "${_${_PYTHON_PREFIX}_INCLUDE_DIR}/pyconfig.h" config REGEX "(Py_DEBUG|WITH_PYMALLOC|Py_UNICODE_SIZE|MS_WIN32)")
  332. set (abi)
  333. if (config MATCHES "#[ ]*define[ ]+MS_WIN32")
  334. # ABI not used on Windows
  335. set (abi "")
  336. else()
  337. if (config MATCHES "#[ ]*define[ ]+Py_DEBUG[ ]+1")
  338. string (APPEND abi "d")
  339. endif()
  340. if (config MATCHES "#[ ]*define[ ]+WITH_PYMALLOC[ ]+1")
  341. string (APPEND abi "m")
  342. endif()
  343. if (config MATCHES "#[ ]*define[ ]+Py_UNICODE_SIZE[ ]+4")
  344. string (APPEND abi "u")
  345. endif()
  346. set (${_PGV_PREFIX}ABI "${abi}" PARENT_SCOPE)
  347. endif()
  348. else()
  349. # ABI not supported
  350. set (${_PGV_PREFIX}ABI "" PARENT_SCOPE)
  351. endif()
  352. endif()
  353. endif()
  354. endfunction()
  355. function (_PYTHON_VALIDATE_INTERPRETER)
  356. if (NOT _${_PYTHON_PREFIX}_EXECUTABLE)
  357. return()
  358. endif()
  359. cmake_parse_arguments (PARSE_ARGV 0 _PVI "EXACT;CHECK_EXISTS" "" "")
  360. if (_PVI_UNPARSED_ARGUMENTS)
  361. set (expected_version ${_PVI_UNPARSED_ARGUMENTS})
  362. else()
  363. unset (expected_version)
  364. endif()
  365. if (_PVI_CHECK_EXISTS AND NOT EXISTS "${_${_PYTHON_PREFIX}_EXECUTABLE}")
  366. # interpreter does not exist anymore
  367. set_property (CACHE _${_PYTHON_PREFIX}_EXECUTABLE PROPERTY VALUE "_${_PYTHON_PREFIX}_EXECUTABLE-NOTFOUND")
  368. return()
  369. endif()
  370. # validate ABI compatibility
  371. if (DEFINED _${_PYTHON_PREFIX}_FIND_ABI)
  372. execute_process (COMMAND "${_${_PYTHON_PREFIX}_EXECUTABLE}" -c
  373. "import sys; sys.stdout.write(sys.abiflags)"
  374. RESULT_VARIABLE result
  375. OUTPUT_VARIABLE abi
  376. ERROR_QUIET
  377. OUTPUT_STRIP_TRAILING_WHITESPACE)
  378. if (result)
  379. # assume ABI is not supported
  380. set (abi "")
  381. endif()
  382. if (NOT abi IN_LIST _${_PYTHON_PREFIX}_ABIFLAGS)
  383. # incompatible ABI
  384. set_property (CACHE _${_PYTHON_PREFIX}_EXECUTABLE PROPERTY VALUE "_${_PYTHON_PREFIX}_EXECUTABLE-NOTFOUND")
  385. return()
  386. endif()
  387. endif()
  388. get_filename_component (python_name "${_${_PYTHON_PREFIX}_EXECUTABLE}" NAME)
  389. if (expected_version AND NOT python_name STREQUAL "python${expected_version}${abi}${CMAKE_EXECUTABLE_SUFFIX}")
  390. # executable found must have a specific version
  391. execute_process (COMMAND "${_${_PYTHON_PREFIX}_EXECUTABLE}" -c
  392. "import sys; sys.stdout.write('.'.join([str(x) for x in sys.version_info[:2]]))"
  393. RESULT_VARIABLE result
  394. OUTPUT_VARIABLE version
  395. ERROR_QUIET
  396. OUTPUT_STRIP_TRAILING_WHITESPACE)
  397. if (result OR (_PVI_EXACT AND NOT version VERSION_EQUAL expected_version) OR (version VERSION_LESS expected_version))
  398. # interpreter not usable or has wrong major version
  399. set_property (CACHE _${_PYTHON_PREFIX}_EXECUTABLE PROPERTY VALUE "_${_PYTHON_PREFIX}_EXECUTABLE-NOTFOUND")
  400. return()
  401. endif()
  402. else()
  403. if (NOT python_name STREQUAL "python${_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR}${CMAKE_EXECUTABLE_SUFFIX}")
  404. # executable found do not have version in name
  405. # ensure major version is OK
  406. execute_process (COMMAND "${_${_PYTHON_PREFIX}_EXECUTABLE}" -c
  407. "import sys; sys.stdout.write(str(sys.version_info[0]))"
  408. RESULT_VARIABLE result
  409. OUTPUT_VARIABLE version
  410. ERROR_QUIET
  411. OUTPUT_STRIP_TRAILING_WHITESPACE)
  412. if (result OR NOT version EQUAL _${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR)
  413. # interpreter not usable or has wrong major version
  414. set_property (CACHE _${_PYTHON_PREFIX}_EXECUTABLE PROPERTY VALUE "_${_PYTHON_PREFIX}_EXECUTABLE-NOTFOUND")
  415. return()
  416. endif()
  417. endif()
  418. endif()
  419. if (CMAKE_SIZEOF_VOID_P AND "Development" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS
  420. AND NOT CMAKE_CROSSCOMPILING)
  421. # In this case, interpreter must have same architecture as environment
  422. execute_process (COMMAND "${_${_PYTHON_PREFIX}_EXECUTABLE}" -c
  423. "import sys, struct; sys.stdout.write(str(struct.calcsize(\"P\")))"
  424. RESULT_VARIABLE result
  425. OUTPUT_VARIABLE size
  426. ERROR_QUIET
  427. OUTPUT_STRIP_TRAILING_WHITESPACE)
  428. if (result OR NOT size EQUAL CMAKE_SIZEOF_VOID_P)
  429. # interpreter not usable or has wrong architecture
  430. set_property (CACHE _${_PYTHON_PREFIX}_EXECUTABLE PROPERTY VALUE "_${_PYTHON_PREFIX}_EXECUTABLE-NOTFOUND")
  431. return()
  432. endif()
  433. endif()
  434. endfunction()
  435. function (_PYTHON_VALIDATE_COMPILER expected_version)
  436. if (NOT _${_PYTHON_PREFIX}_COMPILER)
  437. return()
  438. endif()
  439. cmake_parse_arguments (_PVC "EXACT;CHECK_EXISTS" "" "" ${ARGN})
  440. if (_PVC_UNPARSED_ARGUMENTS)
  441. set (major_version FALSE)
  442. set (expected_version ${_PVC_UNPARSED_ARGUMENTS})
  443. else()
  444. set (major_version TRUE)
  445. set (expected_version ${_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR})
  446. set (_PVC_EXACT TRUE)
  447. endif()
  448. if (_PVC_CHECK_EXISTS AND NOT EXISTS "${_${_PYTHON_PREFIX}_COMPILER}")
  449. # Compiler does not exist anymore
  450. set_property (CACHE _${_PYTHON_PREFIX}_COMPILER PROPERTY VALUE "_${_PYTHON_PREFIX}_COMPILER-NOTFOUND")
  451. return()
  452. endif()
  453. # retrieve python environment version from compiler
  454. set (working_dir "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/PythonCompilerVersion.dir")
  455. if (major_version)
  456. # check only major version
  457. file (WRITE "${working_dir}/version.py" "import sys; sys.stdout.write(str(sys.version_info[0]))")
  458. else()
  459. file (WRITE "${working_dir}/version.py" "import sys; sys.stdout.write('.'.join([str(x) for x in sys.version_info[:2]]))\n")
  460. endif()
  461. execute_process (COMMAND "${_${_PYTHON_PREFIX}_COMPILER}" /target:exe /embed "${working_dir}/version.py"
  462. WORKING_DIRECTORY "${working_dir}"
  463. OUTPUT_QUIET
  464. ERROR_QUIET
  465. OUTPUT_STRIP_TRAILING_WHITESPACE)
  466. execute_process (COMMAND "${working_dir}/version"
  467. WORKING_DIRECTORY "${working_dir}"
  468. RESULT_VARIABLE result
  469. OUTPUT_VARIABLE version
  470. ERROR_QUIET)
  471. file (REMOVE_RECURSE "${_${_PYTHON_PREFIX}_VERSION_DIR}")
  472. if (result OR (_PVC_EXACT AND NOT version VERSION_EQUAL expected_version) OR (version VERSION_LESS expected_version))
  473. # Compiler not usable or has wrong version
  474. set_property (CACHE _${_PYTHON_PREFIX}_COMPILER PROPERTY VALUE "_${_PYTHON_PREFIX}_COMPILER-NOTFOUND")
  475. endif()
  476. endfunction()
  477. function (_PYTHON_VALIDATE_LIBRARY)
  478. if (NOT _${_PYTHON_PREFIX}_LIBRARY_RELEASE)
  479. return()
  480. endif()
  481. cmake_parse_arguments (PARSE_ARGV 0 _PVL "EXACT;CHECK_EXISTS" "" "")
  482. if (_PVL_UNPARSED_ARGUMENTS)
  483. set (expected_version ${_PVL_UNPARSED_ARGUMENTS})
  484. else()
  485. unset (expected_version)
  486. endif()
  487. if (_PVL_CHECK_EXISTS AND NOT EXISTS "${_${_PYTHON_PREFIX}_LIBRARY_RELEASE}")
  488. # library does not exist anymore
  489. set_property (CACHE _${_PYTHON_PREFIX}_LIBRARY_RELEASE PROPERTY VALUE "_${_PYTHON_PREFIX}_LIBRARY_RELEASE-NOTFOUND")
  490. if (WIN32)
  491. set_property (CACHE _${_PYTHON_PREFIX}_LIBRARY_DEBUG PROPERTY VALUE "_${_PYTHON_PREFIX}_LIBRARY_DEBUG-NOTFOUND")
  492. endif()
  493. set_property (CACHE _${_PYTHON_PREFIX}_INCLUDE_DIR PROPERTY VALUE "_${_PYTHON_PREFIX}_INCLUDE_DIR-NOTFOUND")
  494. return()
  495. endif()
  496. # retrieve version and abi from library name
  497. _python_get_version (LIBRARY PREFIX lib_)
  498. if (DEFINED _${_PYTHON_PREFIX}_FIND_ABI AND NOT lib_ABI IN_LIST _${_PYTHON_PREFIX}_ABIFLAGS)
  499. # incompatible ABI
  500. set_property (CACHE _${_PYTHON_PREFIX}_LIBRARY_RELEASE PROPERTY VALUE "_${_PYTHON_PREFIX}_LIBRARY_RELEASE-NOTFOUND")
  501. else()
  502. if (expected_version)
  503. if ((_PVL_EXACT AND NOT lib_VERSION VERSION_EQUAL expected_version) OR (lib_VERSION VERSION_LESS expected_version))
  504. # library has wrong version
  505. set_property (CACHE _${_PYTHON_PREFIX}_LIBRARY_RELEASE PROPERTY VALUE "_${_PYTHON_PREFIX}_LIBRARY_RELEASE-NOTFOUND")
  506. endif()
  507. else()
  508. if (NOT lib_VERSION_MAJOR VERSION_EQUAL _${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR)
  509. # library has wrong major version
  510. set_property (CACHE _${_PYTHON_PREFIX}_LIBRARY_RELEASE PROPERTY VALUE "_${_PYTHON_PREFIX}_LIBRARY_RELEASE-NOTFOUND")
  511. endif()
  512. endif()
  513. endif()
  514. if (NOT _${_PYTHON_PREFIX}_LIBRARY_RELEASE)
  515. if (WIN32)
  516. set_property (CACHE _${_PYTHON_PREFIX}_LIBRARY_DEBUG PROPERTY VALUE "_${_PYTHON_PREFIX}_LIBRARY_DEBUG-NOTFOUND")
  517. endif()
  518. set_property (CACHE _${_PYTHON_PREFIX}_INCLUDE_DIR PROPERTY VALUE "_${_PYTHON_PREFIX}_INCLUDE_DIR-NOTFOUND")
  519. endif()
  520. endfunction()
  521. function (_PYTHON_VALIDATE_INCLUDE_DIR)
  522. if (NOT _${_PYTHON_PREFIX}_INCLUDE_DIR)
  523. return()
  524. endif()
  525. cmake_parse_arguments (PARSE_ARGV 0 _PVID "EXACT;CHECK_EXISTS" "" "")
  526. if (_PVID_UNPARSED_ARGUMENTS)
  527. set (expected_version ${_PVID_UNPARSED_ARGUMENTS})
  528. else()
  529. unset (expected_version)
  530. endif()
  531. if (_PVID_CHECK_EXISTS AND NOT EXISTS "${_${_PYTHON_PREFIX}_INCLUDE_DIR}")
  532. # include file does not exist anymore
  533. set_property (CACHE _${_PYTHON_PREFIX}_INCLUDE_DIR PROPERTY VALUE "_${_PYTHON_PREFIX}_INCLUDE_DIR-NOTFOUND")
  534. return()
  535. endif()
  536. # retrieve version from header file
  537. _python_get_version (INCLUDE PREFIX inc_)
  538. if (DEFINED _${_PYTHON_PREFIX}_FIND_ABI AND NOT inc_ABI IN_LIST _${_PYTHON_PREFIX}_ABIFLAGS)
  539. # incompatible ABI
  540. set_property (CACHE _${_PYTHON_PREFIX}_INCLUDE_DIR PROPERTY VALUE "_${_PYTHON_PREFIX}_INCLUDE_DIR-NOTFOUND")
  541. else()
  542. if (expected_version)
  543. if ((_PVID_EXACT AND NOT inc_VERSION VERSION_EQUAL expected_version) OR (inc_VERSION VERSION_LESS expected_version))
  544. # include dir has wrong version
  545. set_property (CACHE _${_PYTHON_PREFIX}_INCLUDE_DIR PROPERTY VALUE "_${_PYTHON_PREFIX}_INCLUDE_DIR-NOTFOUND")
  546. endif()
  547. else()
  548. if (NOT inc_VERSION_MAJOR VERSION_EQUAL _${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR)
  549. # include dir has wrong major version
  550. set_property (CACHE _${_PYTHON_PREFIX}_INCLUDE_DIR PROPERTY VALUE "_${_PYTHON_PREFIX}_INCLUDE_DIR-NOTFOUND")
  551. endif()
  552. endif()
  553. endif()
  554. endfunction()
  555. function (_PYTHON_FIND_RUNTIME_LIBRARY _PYTHON_LIB)
  556. string (REPLACE "_RUNTIME" "" _PYTHON_LIB "${_PYTHON_LIB}")
  557. # look at runtime part on systems supporting it
  558. if (CMAKE_SYSTEM_NAME STREQUAL "Windows" OR
  559. (CMAKE_SYSTEM_NAME MATCHES "MSYS|CYGWIN"
  560. AND ${_PYTHON_LIB} MATCHES "${CMAKE_IMPORT_LIBRARY_SUFFIX}$"))
  561. set (CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_SHARED_LIBRARY_SUFFIX})
  562. # MSYS has a special syntax for runtime libraries
  563. if (CMAKE_SYSTEM_NAME MATCHES "MSYS")
  564. list (APPEND CMAKE_FIND_LIBRARY_PREFIXES "msys-")
  565. endif()
  566. find_library (${ARGV})
  567. endif()
  568. endfunction()
  569. function (_PYTHON_SET_LIBRARY_DIRS _PYTHON_SLD_RESULT)
  570. unset (_PYTHON_DIRS)
  571. set (_PYTHON_LIBS ${ARGN})
  572. foreach (_PYTHON_LIB IN LISTS _PYTHON_LIBS)
  573. if (${_PYTHON_LIB})
  574. get_filename_component (_PYTHON_DIR "${${_PYTHON_LIB}}" DIRECTORY)
  575. list (APPEND _PYTHON_DIRS "${_PYTHON_DIR}")
  576. endif()
  577. endforeach()
  578. if (_PYTHON_DIRS)
  579. list (REMOVE_DUPLICATES _PYTHON_DIRS)
  580. endif()
  581. set (${_PYTHON_SLD_RESULT} ${_PYTHON_DIRS} PARENT_SCOPE)
  582. endfunction()
  583. # If major version is specified, it must be the same as internal major version
  584. if (DEFINED ${_PYTHON_PREFIX}_FIND_VERSION_MAJOR
  585. AND NOT ${_PYTHON_PREFIX}_FIND_VERSION_MAJOR VERSION_EQUAL _${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR)
  586. _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}\"")
  587. endif()
  588. # handle components
  589. if (NOT ${_PYTHON_PREFIX}_FIND_COMPONENTS)
  590. set (${_PYTHON_PREFIX}_FIND_COMPONENTS Interpreter)
  591. set (${_PYTHON_PREFIX}_FIND_REQUIRED_Interpreter TRUE)
  592. endif()
  593. if ("NumPy" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS)
  594. list (APPEND ${_PYTHON_PREFIX}_FIND_COMPONENTS "Interpreter" "Development")
  595. list (REMOVE_DUPLICATES ${_PYTHON_PREFIX}_FIND_COMPONENTS)
  596. endif()
  597. foreach (_${_PYTHON_PREFIX}_COMPONENT IN ITEMS Interpreter Compiler Development NumPy)
  598. set (${_PYTHON_PREFIX}_${_${_PYTHON_PREFIX}_COMPONENT}_FOUND FALSE)
  599. endforeach()
  600. unset (_${_PYTHON_PREFIX}_FIND_VERSIONS)
  601. # Set versions to search
  602. ## default: search any version
  603. set (_${_PYTHON_PREFIX}_FIND_VERSIONS ${_${_PYTHON_PREFIX}_VERSIONS})
  604. if (${_PYTHON_PREFIX}_FIND_VERSION_COUNT GREATER 1)
  605. if (${_PYTHON_PREFIX}_FIND_VERSION_EXACT)
  606. set (_${_PYTHON_PREFIX}_FIND_VERSIONS ${${_PYTHON_PREFIX}_FIND_VERSION_MAJOR}.${${_PYTHON_PREFIX}_FIND_VERSION_MINOR})
  607. else()
  608. unset (_${_PYTHON_PREFIX}_FIND_VERSIONS)
  609. # add all compatible versions
  610. foreach (_${_PYTHON_PREFIX}_VERSION IN LISTS _${_PYTHON_PREFIX}_VERSIONS)
  611. if (_${_PYTHON_PREFIX}_VERSION VERSION_GREATER_EQUAL ${_PYTHON_PREFIX}_FIND_VERSION)
  612. list (APPEND _${_PYTHON_PREFIX}_FIND_VERSIONS ${_${_PYTHON_PREFIX}_VERSION})
  613. endif()
  614. endforeach()
  615. endif()
  616. endif()
  617. # Set ABIs to search
  618. ## default: search any ABI
  619. if (_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR VERSION_LESS 3)
  620. # ABI not supported
  621. unset (_${_PYTHON_PREFIX}_FIND_ABI)
  622. set (_${_PYTHON_PREFIX}_ABIFLAGS "")
  623. else()
  624. unset (_${_PYTHON_PREFIX}_FIND_ABI)
  625. unset (_${_PYTHON_PREFIX}_ABIFLAGS)
  626. if (DEFINED ${_PYTHON_PREFIX}_FIND_ABI)
  627. # normalization
  628. string (TOUPPER "${${_PYTHON_PREFIX}_FIND_ABI}" _${_PYTHON_PREFIX}_FIND_ABI)
  629. list (TRANSFORM _${_PYTHON_PREFIX}_FIND_ABI REPLACE "^(TRUE|Y(ES)?|1)$" "ON")
  630. list (TRANSFORM _${_PYTHON_PREFIX}_FIND_ABI REPLACE "^(FALSE|N(O)?|0)$" "OFF")
  631. if (NOT _${_PYTHON_PREFIX}_FIND_ABI MATCHES "^(ON|OFF|ANY);(ON|OFF|ANY);(ON|OFF|ANY)$")
  632. message (AUTHOR_WARNING "Find${_PYTHON_PREFIX}: ${${_PYTHON_PREFIX}_FIND_ABI}: invalid value for '${_PYTHON_PREFIX}_FIND_ABI'. Ignore it")
  633. unset (_${_PYTHON_PREFIX}_FIND_ABI)
  634. endif()
  635. _python_get_abiflags (_${_PYTHON_PREFIX}_ABIFLAGS)
  636. endif()
  637. endif()
  638. # Define lookup strategy
  639. if (_${_PYTHON_PREFIX}_LOOKUP_POLICY STREQUAL "NEW")
  640. set (_${_PYTHON_PREFIX}_FIND_STRATEGY "LOCATION")
  641. else()
  642. set (_${_PYTHON_PREFIX}_FIND_STRATEGY "VERSION")
  643. endif()
  644. if (DEFINED ${_PYTHON_PREFIX}_FIND_STRATEGY)
  645. if (NOT ${_PYTHON_PREFIX}_FIND_STRATEGY MATCHES "^(VERSION|LOCATION)$")
  646. message (AUTHOR_WARNING "Find${_PYTHON_PREFIX}: ${${_PYTHON_PREFIX}_FIND_STRATEGY}: invalid value for '${_PYTHON_PREFIX}_FIND_STRATEGY'. 'VERSION' or 'LOCATION' expected.")
  647. set (_${_PYTHON_PREFIX}_FIND_STRATEGY "VERSION")
  648. else()
  649. set (_${_PYTHON_PREFIX}_FIND_STRATEGY "${${_PYTHON_PREFIX}_FIND_STRATEGY}")
  650. endif()
  651. endif()
  652. # Python and Anaconda distributions: define which architectures can be used
  653. if (CMAKE_SIZEOF_VOID_P)
  654. # In this case, search only for 64bit or 32bit
  655. math (EXPR _${_PYTHON_PREFIX}_ARCH "${CMAKE_SIZEOF_VOID_P} * 8")
  656. set (_${_PYTHON_PREFIX}_ARCH2 ${_${_PYTHON_PREFIX}_ARCH})
  657. else()
  658. # architecture unknown, search for both 64bit and 32bit
  659. set (_${_PYTHON_PREFIX}_ARCH 64)
  660. set (_${_PYTHON_PREFIX}_ARCH2 32)
  661. endif()
  662. # IronPython support
  663. if (CMAKE_SIZEOF_VOID_P)
  664. # In this case, search only for 64bit or 32bit
  665. math (EXPR _${_PYTHON_PREFIX}_ARCH "${CMAKE_SIZEOF_VOID_P} * 8")
  666. set (_${_PYTHON_PREFIX}_IRON_PYTHON_NAMES ipy${_${_PYTHON_PREFIX}_ARCH} ipy)
  667. else()
  668. # architecture unknown, search for natural interpreter
  669. set (_${_PYTHON_PREFIX}_IRON_PYTHON_NAMES ipy)
  670. endif()
  671. set (_${_PYTHON_PREFIX}_IRON_PYTHON_PATH_SUFFIXES net45 net40)
  672. # Apple frameworks handling
  673. _python_find_frameworks ()
  674. set (_${_PYTHON_PREFIX}_FIND_FRAMEWORK "FIRST")
  675. if (DEFINED ${_PYTHON_PREFIX}_FIND_FRAMEWORK)
  676. if (NOT ${_PYTHON_PREFIX}_FIND_FRAMEWORK MATCHES "^(FIRST|LAST|NEVER)$")
  677. 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.")
  678. else()
  679. set (_${_PYTHON_PREFIX}_FIND_FRAMEWORK ${${_PYTHON_PREFIX}_FIND_FRAMEWORK})
  680. endif()
  681. elseif (DEFINED CMAKE_FIND_FRAMEWORK)
  682. if (CMAKE_FIND_FRAMEWORK STREQUAL "ONLY")
  683. message (AUTHOR_WARNING "Find${_PYTHON_PREFIX}: CMAKE_FIND_FRAMEWORK: 'ONLY' value is not supported. 'FIRST' will be used instead.")
  684. elseif (NOT CMAKE_FIND_FRAMEWORK MATCHES "^(FIRST|LAST|NEVER)$")
  685. 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.")
  686. else()
  687. set (_${_PYTHON_PREFIX}_FIND_FRAMEWORK ${CMAKE_FIND_FRAMEWORK})
  688. endif()
  689. endif()
  690. # Save CMAKE_FIND_APPBUNDLE
  691. if (DEFINED CMAKE_FIND_APPBUNDLE)
  692. set (_${_PYTHON_PREFIX}_CMAKE_FIND_APPBUNDLE ${CMAKE_FIND_APPBUNDLE})
  693. else()
  694. unset (_${_PYTHON_PREFIX}_CMAKE_FIND_APPBUNDLE)
  695. endif()
  696. # To avoid app bundle lookup
  697. set (CMAKE_FIND_APPBUNDLE "NEVER")
  698. # Save CMAKE_FIND_FRAMEWORK
  699. if (DEFINED CMAKE_FIND_FRAMEWORK)
  700. set (_${_PYTHON_PREFIX}_CMAKE_FIND_FRAMEWORK ${CMAKE_FIND_FRAMEWORK})
  701. else()
  702. unset (_${_PYTHON_PREFIX}_CMAKE_FIND_FRAMEWORK)
  703. endif()
  704. # To avoid framework lookup
  705. set (CMAKE_FIND_FRAMEWORK "NEVER")
  706. # Windows Registry handling
  707. if (DEFINED ${_PYTHON_PREFIX}_FIND_REGISTRY)
  708. if (NOT ${_PYTHON_PREFIX}_FIND_REGISTRY MATCHES "^(FIRST|LAST|NEVER)$")
  709. 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.")
  710. set (_${_PYTHON_PREFIX}_FIND_REGISTRY "FIRST")
  711. else()
  712. set (_${_PYTHON_PREFIX}_FIND_REGISTRY ${${_PYTHON_PREFIX}_FIND_REGISTRY})
  713. endif()
  714. else()
  715. set (_${_PYTHON_PREFIX}_FIND_REGISTRY "FIRST")
  716. endif()
  717. # virtual environments handling
  718. if (DEFINED ENV{VIRTUAL_ENV})
  719. if (DEFINED ${_PYTHON_PREFIX}_FIND_VIRTUALENV)
  720. if (NOT ${_PYTHON_PREFIX}_FIND_VIRTUALENV MATCHES "^(FIRST|ONLY|STANDARD)$")
  721. 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.")
  722. set (_${_PYTHON_PREFIX}_FIND_VIRTUALENV "FIRST")
  723. else()
  724. set (_${_PYTHON_PREFIX}_FIND_VIRTUALENV ${${_PYTHON_PREFIX}_FIND_VIRTUALENV})
  725. endif()
  726. else()
  727. set (_${_PYTHON_PREFIX}_FIND_VIRTUALENV FIRST)
  728. endif()
  729. else()
  730. set (_${_PYTHON_PREFIX}_FIND_VIRTUALENV STANDARD)
  731. endif()
  732. # Compute search signature
  733. # This signature will be used to check validity of cached variables on new search
  734. set (_${_PYTHON_PREFIX}_SIGNATURE "${${_PYTHON_PREFIX}_ROOT_DIR}:${${_PYTHON_PREFIX}_FIND_STRATEGY}:${${_PYTHON_PREFIX}_FIND_VIRTUALENV}")
  735. if (NOT WIN32)
  736. string (APPEND _${_PYTHON_PREFIX}_SIGNATURE ":${${_PYTHON_PREFIX}_USE_STATIC_LIBS}:")
  737. endif()
  738. if (CMAKE_HOST_APPLE)
  739. string (APPEND _${_PYTHON_PREFIX}_SIGNATURE ":${${_PYTHON_PREFIX}_FIND_FRAMEWORK}")
  740. endif()
  741. if (CMAKE_HOST_WIN32)
  742. string (APPEND _${_PYTHON_PREFIX}_SIGNATURE ":${${_PYTHON_PREFIX}_FIND_REGISTRY}")
  743. endif()
  744. unset (_${_PYTHON_PREFIX}_REQUIRED_VARS)
  745. unset (_${_PYTHON_PREFIX}_CACHED_VARS)
  746. # first step, search for the interpreter
  747. if ("Interpreter" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS)
  748. list (APPEND _${_PYTHON_PREFIX}_CACHED_VARS _${_PYTHON_PREFIX}_EXECUTABLE)
  749. if (${_PYTHON_PREFIX}_FIND_REQUIRED_Interpreter)
  750. list (APPEND _${_PYTHON_PREFIX}_REQUIRED_VARS ${_PYTHON_PREFIX}_EXECUTABLE)
  751. endif()
  752. if (DEFINED ${_PYTHON_PREFIX}_EXECUTABLE
  753. AND IS_ABSOLUTE "${${_PYTHON_PREFIX}_EXECUTABLE}")
  754. set (_${_PYTHON_PREFIX}_EXECUTABLE "${${_PYTHON_PREFIX}_EXECUTABLE}" CACHE INTERNAL "")
  755. elseif (DEFINED _${_PYTHON_PREFIX}_EXECUTABLE)
  756. # compute interpreter signature and check validity of definition
  757. string (MD5 __${_PYTHON_PREFIX}_INTERPRETER_SIGNATURE "${_${_PYTHON_PREFIX}_SIGNATURE}:${_${_PYTHON_PREFIX}_EXECUTABLE}")
  758. if (__${_PYTHON_PREFIX}_INTERPRETER_SIGNATURE STREQUAL _${_PYTHON_PREFIX}_INTERPRETER_SIGNATURE)
  759. # check version validity
  760. if (${_PYTHON_PREFIX}_FIND_VERSION_EXACT)
  761. _python_validate_interpreter (${${_PYTHON_PREFIX}_FIND_VERSION} EXACT CHECK_EXISTS)
  762. else()
  763. _python_validate_interpreter (${${_PYTHON_PREFIX}_FIND_VERSION} CHECK_EXISTS)
  764. endif()
  765. else()
  766. unset (_${_PYTHON_PREFIX}_EXECUTABLE CACHE)
  767. unset (_${_PYTHON_PREFIX}_INTERPRETER_SIGNATURE CACHE)
  768. endif()
  769. endif()
  770. if (NOT _${_PYTHON_PREFIX}_EXECUTABLE)
  771. set (_${_PYTHON_PREFIX}_HINTS "${${_PYTHON_PREFIX}_ROOT_DIR}" ENV ${_PYTHON_PREFIX}_ROOT_DIR)
  772. if (_${_PYTHON_PREFIX}_FIND_STRATEGY STREQUAL "LOCATION")
  773. unset (_${_PYTHON_PREFIX}_NAMES)
  774. unset (_${_PYTHON_PREFIX}_FRAMEWORK_PATHS)
  775. unset (_${_PYTHON_PREFIX}_REGISTRY_PATHS)
  776. foreach (_${_PYTHON_PREFIX}_VERSION IN LISTS _${_PYTHON_PREFIX}_FIND_VERSIONS)
  777. # build all executable names
  778. _python_get_names (_${_PYTHON_PREFIX}_VERSION_NAMES VERSION ${_${_PYTHON_PREFIX}_VERSION} POSIX EXECUTABLE)
  779. list (APPEND _${_PYTHON_PREFIX}_NAMES ${_${_PYTHON_PREFIX}_VERSION_NAMES})
  780. # Framework Paths
  781. _python_get_frameworks (_${_PYTHON_PREFIX}_VERSION_PATHS ${_${_PYTHON_PREFIX}_VERSION})
  782. list (APPEND _${_PYTHON_PREFIX}_FRAMEWORK_PATHS ${_${_PYTHON_PREFIX}_VERSION_PATHS})
  783. # Registry Paths
  784. _python_get_registries (_${_PYTHON_PREFIX}_VERSION_PATHS ${_${_PYTHON_PREFIX}_VERSION})
  785. list (APPEND _${_PYTHON_PREFIX}_REGISTRY_PATHS ${_${_PYTHON_PREFIX}_VERSION_PATHS}
  786. [HKEY_LOCAL_MACHINE\\SOFTWARE\\IronPython\\${_${_PYTHON_PREFIX}_VERSION}\\InstallPath])
  787. endforeach()
  788. list (APPEND _${_PYTHON_PREFIX}_NAMES python${_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR} python)
  789. while (TRUE)
  790. # Virtual environments handling
  791. if (_${_PYTHON_PREFIX}_FIND_VIRTUALENV MATCHES "^(FIRST|ONLY)$")
  792. find_program (_${_PYTHON_PREFIX}_EXECUTABLE
  793. NAMES ${_${_PYTHON_PREFIX}_NAMES}
  794. NAMES_PER_DIR
  795. HINTS ${_${_PYTHON_PREFIX}_HINTS}
  796. PATHS ENV VIRTUAL_ENV
  797. PATH_SUFFIXES bin Scripts
  798. NO_CMAKE_PATH
  799. NO_CMAKE_ENVIRONMENT_PATH
  800. NO_SYSTEM_ENVIRONMENT_PATH
  801. NO_CMAKE_SYSTEM_PATH)
  802. _python_validate_interpreter (${${_PYTHON_PREFIX}_FIND_VERSION})
  803. if (_${_PYTHON_PREFIX}_EXECUTABLE)
  804. break()
  805. endif()
  806. if (NOT _${_PYTHON_PREFIX}_FIND_VIRTUALENV STREQUAL "ONLY")
  807. break()
  808. endif()
  809. endif()
  810. # Apple frameworks handling
  811. if (CMAKE_HOST_APPLE AND _${_PYTHON_PREFIX}_FIND_FRAMEWORK STREQUAL "FIRST")
  812. find_program (_${_PYTHON_PREFIX}_EXECUTABLE
  813. NAMES ${_${_PYTHON_PREFIX}_NAMES}
  814. NAMES_PER_DIR
  815. HINTS ${_${_PYTHON_PREFIX}_HINTS}
  816. PATHS ${_${_PYTHON_PREFIX}_FRAMEWORK_PATHS}
  817. PATH_SUFFIXES bin
  818. NO_CMAKE_PATH
  819. NO_CMAKE_ENVIRONMENT_PATH
  820. NO_SYSTEM_ENVIRONMENT_PATH
  821. NO_CMAKE_SYSTEM_PATH)
  822. _python_validate_interpreter (${${_PYTHON_PREFIX}_FIND_VERSION})
  823. if (_${_PYTHON_PREFIX}_EXECUTABLE)
  824. break()
  825. endif()
  826. endif()
  827. # Windows registry
  828. if (CMAKE_HOST_WIN32 AND _${_PYTHON_PREFIX}_FIND_REGISTRY STREQUAL "FIRST")
  829. find_program (_${_PYTHON_PREFIX}_EXECUTABLE
  830. NAMES ${_${_PYTHON_PREFIX}_NAMES}
  831. ${_${_PYTHON_PREFIX}_IRON_PYTHON_NAMES}
  832. NAMES_PER_DIR
  833. HINTS ${_${_PYTHON_PREFIX}_HINTS}
  834. PATHS ${_${_PYTHON_PREFIX}_REGISTRY_PATHS}
  835. PATH_SUFFIXES bin ${_${_PYTHON_PREFIX}_IRON_PYTHON_PATH_SUFFIXES}
  836. NO_SYSTEM_ENVIRONMENT_PATH
  837. NO_CMAKE_SYSTEM_PATH)
  838. _python_validate_interpreter (${${_PYTHON_PREFIX}_FIND_VERSION})
  839. if (_${_PYTHON_PREFIX}_EXECUTABLE)
  840. break()
  841. endif()
  842. endif()
  843. # try using HINTS
  844. find_program (_${_PYTHON_PREFIX}_EXECUTABLE
  845. NAMES ${_${_PYTHON_PREFIX}_NAMES}
  846. ${_${_PYTHON_PREFIX}_IRON_PYTHON_NAMES}
  847. NAMES_PER_DIR
  848. HINTS ${_${_PYTHON_PREFIX}_HINTS}
  849. PATH_SUFFIXES bin ${_${_PYTHON_PREFIX}_IRON_PYTHON_PATH_SUFFIXES}
  850. NO_SYSTEM_ENVIRONMENT_PATH
  851. NO_CMAKE_SYSTEM_PATH)
  852. _python_validate_interpreter (${${_PYTHON_PREFIX}_FIND_VERSION})
  853. if (_${_PYTHON_PREFIX}_EXECUTABLE)
  854. break()
  855. endif()
  856. # try using standard paths
  857. find_program (_${_PYTHON_PREFIX}_EXECUTABLE
  858. NAMES ${_${_PYTHON_PREFIX}_NAMES}
  859. ${_${_PYTHON_PREFIX}_IRON_PYTHON_NAMES}
  860. NAMES_PER_DIR
  861. PATH_SUFFIXES bin ${_${_PYTHON_PREFIX}_IRON_PYTHON_PATH_SUFFIXES})
  862. _python_validate_interpreter (${${_PYTHON_PREFIX}_FIND_VERSION})
  863. if (_${_PYTHON_PREFIX}_EXECUTABLE)
  864. break()
  865. endif()
  866. # Apple frameworks handling
  867. if (CMAKE_HOST_APPLE AND _${_PYTHON_PREFIX}_FIND_FRAMEWORK STREQUAL "LAST")
  868. find_program (_${_PYTHON_PREFIX}_EXECUTABLE
  869. NAMES ${_${_PYTHON_PREFIX}_NAMES}
  870. NAMES_PER_DIR
  871. PATHS ${_${_PYTHON_PREFIX}_FRAMEWORK_PATHS}
  872. PATH_SUFFIXES bin
  873. NO_DEFAULT_PATH)
  874. _python_validate_interpreter (${${_PYTHON_PREFIX}_FIND_VERSION})
  875. if (_${_PYTHON_PREFIX}_EXECUTABLE)
  876. break()
  877. endif()
  878. endif()
  879. # Windows registry
  880. if (CMAKE_HOST_WIN32 AND _${_PYTHON_PREFIX}_FIND_REGISTRY STREQUAL "LAST")
  881. find_program (_${_PYTHON_PREFIX}_EXECUTABLE
  882. NAMES ${_${_PYTHON_PREFIX}_NAMES}
  883. ${_${_PYTHON_PREFIX}_IRON_PYTHON_NAMES}
  884. NAMES_PER_DIR
  885. PATHS ${_${_PYTHON_PREFIX}_REGISTRY_PATHS}
  886. PATH_SUFFIXES bin ${_${_PYTHON_PREFIX}_IRON_PYTHON_PATH_SUFFIXES}
  887. NO_DEFAULT_PATH)
  888. _python_validate_interpreter (${${_PYTHON_PREFIX}_FIND_VERSION})
  889. if (_${_PYTHON_PREFIX}_EXECUTABLE)
  890. break()
  891. endif()
  892. endif()
  893. break()
  894. endwhile()
  895. else()
  896. # look-up for various versions and locations
  897. foreach (_${_PYTHON_PREFIX}_VERSION IN LISTS _${_PYTHON_PREFIX}_FIND_VERSIONS)
  898. _python_get_names (_${_PYTHON_PREFIX}_NAMES VERSION ${_${_PYTHON_PREFIX}_VERSION} POSIX EXECUTABLE)
  899. list (APPEND _${_PYTHON_PREFIX}_NAMES python${_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR}
  900. python)
  901. _python_get_frameworks (_${_PYTHON_PREFIX}_FRAMEWORK_PATHS ${_${_PYTHON_PREFIX}_VERSION})
  902. _python_get_registries (_${_PYTHON_PREFIX}_REGISTRY_PATHS ${_${_PYTHON_PREFIX}_VERSION})
  903. # Virtual environments handling
  904. if (_${_PYTHON_PREFIX}_FIND_VIRTUALENV MATCHES "^(FIRST|ONLY)$")
  905. find_program (_${_PYTHON_PREFIX}_EXECUTABLE
  906. NAMES ${_${_PYTHON_PREFIX}_NAMES}
  907. NAMES_PER_DIR
  908. HINTS ${_${_PYTHON_PREFIX}_HINTS}
  909. PATHS ENV VIRTUAL_ENV
  910. PATH_SUFFIXES bin Scripts
  911. NO_CMAKE_PATH
  912. NO_CMAKE_ENVIRONMENT_PATH
  913. NO_SYSTEM_ENVIRONMENT_PATH
  914. NO_CMAKE_SYSTEM_PATH)
  915. _python_validate_interpreter (${_${_PYTHON_PREFIX}_VERSION} EXACT)
  916. if (_${_PYTHON_PREFIX}_EXECUTABLE)
  917. break()
  918. endif()
  919. if (_${_PYTHON_PREFIX}_FIND_VIRTUALENV STREQUAL "ONLY")
  920. continue()
  921. endif()
  922. endif()
  923. # Apple frameworks handling
  924. if (CMAKE_HOST_APPLE AND _${_PYTHON_PREFIX}_FIND_FRAMEWORK STREQUAL "FIRST")
  925. find_program (_${_PYTHON_PREFIX}_EXECUTABLE
  926. NAMES ${_${_PYTHON_PREFIX}_NAMES}
  927. NAMES_PER_DIR
  928. HINTS ${_${_PYTHON_PREFIX}_HINTS}
  929. PATHS ${_${_PYTHON_PREFIX}_FRAMEWORK_PATHS}
  930. PATH_SUFFIXES bin
  931. NO_CMAKE_PATH
  932. NO_CMAKE_ENVIRONMENT_PATH
  933. NO_SYSTEM_ENVIRONMENT_PATH
  934. NO_CMAKE_SYSTEM_PATH)
  935. endif()
  936. # Windows registry
  937. if (CMAKE_HOST_WIN32 AND _${_PYTHON_PREFIX}_FIND_REGISTRY STREQUAL "FIRST")
  938. find_program (_${_PYTHON_PREFIX}_EXECUTABLE
  939. NAMES ${_${_PYTHON_PREFIX}_NAMES}
  940. ${_${_PYTHON_PREFIX}_IRON_PYTHON_NAMES}
  941. NAMES_PER_DIR
  942. HINTS ${_${_PYTHON_PREFIX}_HINTS}
  943. PATHS ${_${_PYTHON_PREFIX}_REGISTRY_PATHS}
  944. [HKEY_LOCAL_MACHINE\\SOFTWARE\\IronPython\\${_${_PYTHON_PREFIX}_VERSION}\\InstallPath]
  945. PATH_SUFFIXES bin ${_${_PYTHON_PREFIX}_IRON_PYTHON_PATH_SUFFIXES}
  946. NO_SYSTEM_ENVIRONMENT_PATH
  947. NO_CMAKE_SYSTEM_PATH)
  948. endif()
  949. _python_validate_interpreter (${_${_PYTHON_PREFIX}_VERSION} EXACT)
  950. if (_${_PYTHON_PREFIX}_EXECUTABLE)
  951. break()
  952. endif()
  953. # try using HINTS
  954. find_program (_${_PYTHON_PREFIX}_EXECUTABLE
  955. NAMES ${_${_PYTHON_PREFIX}_NAMES}
  956. ${_${_PYTHON_PREFIX}_IRON_PYTHON_NAMES}
  957. NAMES_PER_DIR
  958. HINTS ${_${_PYTHON_PREFIX}_HINTS}
  959. PATH_SUFFIXES bin ${_${_PYTHON_PREFIX}_IRON_PYTHON_PATH_SUFFIXES}
  960. NO_SYSTEM_ENVIRONMENT_PATH
  961. NO_CMAKE_SYSTEM_PATH)
  962. _python_validate_interpreter (${_${_PYTHON_PREFIX}_VERSION} EXACT)
  963. if (_${_PYTHON_PREFIX}_EXECUTABLE)
  964. break()
  965. endif()
  966. # try using standard paths.
  967. # NAMES_PER_DIR is not defined on purpose to have a chance to find
  968. # expected version.
  969. # For example, typical systems have 'python' for version 2.* and 'python3'
  970. # for version 3.*. So looking for names per dir will find, potentially,
  971. # systematically 'python' (i.e. version 2) even if version 3 is searched.
  972. if (CMAKE_HOST_WIN32)
  973. find_program (_${_PYTHON_PREFIX}_EXECUTABLE
  974. NAMES ${_${_PYTHON_PREFIX}_NAMES}
  975. python
  976. ${_${_PYTHON_PREFIX}_IRON_PYTHON_NAMES})
  977. else()
  978. find_program (_${_PYTHON_PREFIX}_EXECUTABLE
  979. NAMES ${_${_PYTHON_PREFIX}_NAMES})
  980. endif()
  981. _python_validate_interpreter (${_${_PYTHON_PREFIX}_VERSION} EXACT)
  982. if (_${_PYTHON_PREFIX}_EXECUTABLE)
  983. break()
  984. endif()
  985. # Apple frameworks handling
  986. if (CMAKE_HOST_APPLE AND _${_PYTHON_PREFIX}_FIND_FRAMEWORK STREQUAL "LAST")
  987. find_program (_${_PYTHON_PREFIX}_EXECUTABLE
  988. NAMES ${_${_PYTHON_PREFIX}_NAMES}
  989. NAMES_PER_DIR
  990. PATHS ${_${_PYTHON_PREFIX}_FRAMEWORK_PATHS}
  991. PATH_SUFFIXES bin
  992. NO_DEFAULT_PATH)
  993. endif()
  994. # Windows registry
  995. if (CMAKE_HOST_WIN32 AND _${_PYTHON_PREFIX}_FIND_REGISTRY STREQUAL "LAST")
  996. find_program (_${_PYTHON_PREFIX}_EXECUTABLE
  997. NAMES ${_${_PYTHON_PREFIX}_NAMES}
  998. ${_${_PYTHON_PREFIX}_IRON_PYTHON_NAMES}
  999. NAMES_PER_DIR
  1000. PATHS ${_${_PYTHON_PREFIX}_REGISTRY_PATHS}
  1001. [HKEY_LOCAL_MACHINE\\SOFTWARE\\IronPython\\${_${_PYTHON_PREFIX}_VERSION}\\InstallPath]
  1002. PATH_SUFFIXES bin ${_${_PYTHON_PREFIX}_IRON_PYTHON_PATH_SUFFIXES}
  1003. NO_DEFAULT_PATH)
  1004. endif()
  1005. _python_validate_interpreter (${_${_PYTHON_PREFIX}_VERSION} EXACT)
  1006. if (_${_PYTHON_PREFIX}_EXECUTABLE)
  1007. break()
  1008. endif()
  1009. endforeach()
  1010. if (NOT _${_PYTHON_PREFIX}_EXECUTABLE AND
  1011. NOT _${_PYTHON_PREFIX}_FIND_VIRTUALENV STREQUAL "ONLY")
  1012. # No specific version found. Retry with generic names and standard paths.
  1013. # NAMES_PER_DIR is not defined on purpose to have a chance to find
  1014. # expected version.
  1015. # For example, typical systems have 'python' for version 2.* and 'python3'
  1016. # for version 3.*. So looking for names per dir will find, potentially,
  1017. # systematically 'python' (i.e. version 2) even if version 3 is searched.
  1018. find_program (_${_PYTHON_PREFIX}_EXECUTABLE
  1019. NAMES python${_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR}
  1020. python
  1021. ${_${_PYTHON_PREFIX}_IRON_PYTHON_NAMES})
  1022. _python_validate_interpreter ()
  1023. endif()
  1024. endif()
  1025. endif()
  1026. set (${_PYTHON_PREFIX}_EXECUTABLE "${_${_PYTHON_PREFIX}_EXECUTABLE}")
  1027. # retrieve exact version of executable found
  1028. if (_${_PYTHON_PREFIX}_EXECUTABLE)
  1029. execute_process (COMMAND "${_${_PYTHON_PREFIX}_EXECUTABLE}" -c
  1030. "import sys; sys.stdout.write('.'.join([str(x) for x in sys.version_info[:3]]))"
  1031. RESULT_VARIABLE _${_PYTHON_PREFIX}_RESULT
  1032. OUTPUT_VARIABLE ${_PYTHON_PREFIX}_VERSION
  1033. ERROR_QUIET
  1034. OUTPUT_STRIP_TRAILING_WHITESPACE)
  1035. if (NOT _${_PYTHON_PREFIX}_RESULT)
  1036. set (_${_PYTHON_PREFIX}_EXECUTABLE_USABLE TRUE)
  1037. string (REGEX MATCHALL "[0-9]+" _${_PYTHON_PREFIX}_VERSIONS "${${_PYTHON_PREFIX}_VERSION}")
  1038. list (GET _${_PYTHON_PREFIX}_VERSIONS 0 ${_PYTHON_PREFIX}_VERSION_MAJOR)
  1039. list (GET _${_PYTHON_PREFIX}_VERSIONS 1 ${_PYTHON_PREFIX}_VERSION_MINOR)
  1040. list (GET _${_PYTHON_PREFIX}_VERSIONS 2 ${_PYTHON_PREFIX}_VERSION_PATCH)
  1041. else()
  1042. # Interpreter is not usable
  1043. set (_${_PYTHON_PREFIX}_EXECUTABLE_USABLE FALSE)
  1044. unset (${_PYTHON_PREFIX}_VERSION)
  1045. endif()
  1046. endif()
  1047. if (_${_PYTHON_PREFIX}_EXECUTABLE AND _${_PYTHON_PREFIX}_EXECUTABLE_USABLE
  1048. AND ${_PYTHON_PREFIX}_VERSION_MAJOR VERSION_EQUAL _${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR)
  1049. set (${_PYTHON_PREFIX}_Interpreter_FOUND TRUE)
  1050. # Use interpreter version and ABI for future searches to ensure consistency
  1051. set (_${_PYTHON_PREFIX}_FIND_VERSIONS ${${_PYTHON_PREFIX}_VERSION_MAJOR}.${${_PYTHON_PREFIX}_VERSION_MINOR})
  1052. execute_process (COMMAND "${_${_PYTHON_PREFIX}_EXECUTABLE}" -c "import sys; sys.stdout.write(sys.abiflags)"
  1053. RESULT_VARIABLE _${_PYTHON_PREFIX}_RESULT
  1054. OUTPUT_VARIABLE _${_PYTHON_PREFIX}_ABIFLAGS
  1055. ERROR_QUIET
  1056. OUTPUT_STRIP_TRAILING_WHITESPACE)
  1057. if (_${_PYTHON_PREFIX}_RESULT)
  1058. # assunme ABI is not supported
  1059. set (_${_PYTHON_PREFIX}_ABIFLAGS "")
  1060. endif()
  1061. endif()
  1062. if (${_PYTHON_PREFIX}_Interpreter_FOUND)
  1063. # compute and save interpreter signature
  1064. string (MD5 __${_PYTHON_PREFIX}_INTERPRETER_SIGNATURE "${_${_PYTHON_PREFIX}_SIGNATURE}:${_${_PYTHON_PREFIX}_EXECUTABLE}")
  1065. set (_${_PYTHON_PREFIX}_INTERPRETER_SIGNATURE "${__${_PYTHON_PREFIX}_INTERPRETER_SIGNATURE}" CACHE INTERNAL "")
  1066. if (NOT CMAKE_SIZEOF_VOID_P)
  1067. # determine interpreter architecture
  1068. execute_process (COMMAND "${_${_PYTHON_PREFIX}_EXECUTABLE}" -c "import sys; print(sys.maxsize > 2**32)"
  1069. RESULT_VARIABLE _${_PYTHON_PREFIX}_RESULT
  1070. OUTPUT_VARIABLE ${_PYTHON_PREFIX}_IS64BIT
  1071. ERROR_VARIABLE ${_PYTHON_PREFIX}_IS64BIT)
  1072. if (NOT _${_PYTHON_PREFIX}_RESULT)
  1073. if (${_PYTHON_PREFIX}_IS64BIT)
  1074. set (_${_PYTHON_PREFIX}_ARCH 64)
  1075. set (_${_PYTHON_PREFIX}_ARCH2 64)
  1076. else()
  1077. set (_${_PYTHON_PREFIX}_ARCH 32)
  1078. set (_${_PYTHON_PREFIX}_ARCH2 32)
  1079. endif()
  1080. endif()
  1081. endif()
  1082. # retrieve interpreter identity
  1083. execute_process (COMMAND "${_${_PYTHON_PREFIX}_EXECUTABLE}" -V
  1084. RESULT_VARIABLE _${_PYTHON_PREFIX}_RESULT
  1085. OUTPUT_VARIABLE ${_PYTHON_PREFIX}_INTERPRETER_ID
  1086. ERROR_VARIABLE ${_PYTHON_PREFIX}_INTERPRETER_ID)
  1087. if (NOT _${_PYTHON_PREFIX}_RESULT)
  1088. if (${_PYTHON_PREFIX}_INTERPRETER_ID MATCHES "Anaconda")
  1089. set (${_PYTHON_PREFIX}_INTERPRETER_ID "Anaconda")
  1090. elseif (${_PYTHON_PREFIX}_INTERPRETER_ID MATCHES "Enthought")
  1091. set (${_PYTHON_PREFIX}_INTERPRETER_ID "Canopy")
  1092. else()
  1093. string (REGEX REPLACE "^([^ ]+).*" "\\1" ${_PYTHON_PREFIX}_INTERPRETER_ID "${${_PYTHON_PREFIX}_INTERPRETER_ID}")
  1094. if (${_PYTHON_PREFIX}_INTERPRETER_ID STREQUAL "Python")
  1095. # try to get a more precise ID
  1096. execute_process (COMMAND "${_${_PYTHON_PREFIX}_EXECUTABLE}" -c "import sys; print(sys.copyright)"
  1097. RESULT_VARIABLE _${_PYTHON_PREFIX}_RESULT
  1098. OUTPUT_VARIABLE ${_PYTHON_PREFIX}_COPYRIGHT
  1099. ERROR_QUIET)
  1100. if (${_PYTHON_PREFIX}_COPYRIGHT MATCHES "ActiveState")
  1101. set (${_PYTHON_PREFIX}_INTERPRETER_ID "ActivePython")
  1102. endif()
  1103. endif()
  1104. endif()
  1105. else()
  1106. set (${_PYTHON_PREFIX}_INTERPRETER_ID Python)
  1107. endif()
  1108. # retrieve various package installation directories
  1109. execute_process (COMMAND "${_${_PYTHON_PREFIX}_EXECUTABLE}" -c "import sys; from distutils import sysconfig;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)]))"
  1110. RESULT_VARIABLE _${_PYTHON_PREFIX}_RESULT
  1111. OUTPUT_VARIABLE _${_PYTHON_PREFIX}_LIBPATHS
  1112. ERROR_QUIET)
  1113. if (NOT _${_PYTHON_PREFIX}_RESULT)
  1114. list (GET _${_PYTHON_PREFIX}_LIBPATHS 0 ${_PYTHON_PREFIX}_STDLIB)
  1115. list (GET _${_PYTHON_PREFIX}_LIBPATHS 1 ${_PYTHON_PREFIX}_STDARCH)
  1116. list (GET _${_PYTHON_PREFIX}_LIBPATHS 2 ${_PYTHON_PREFIX}_SITELIB)
  1117. list (GET _${_PYTHON_PREFIX}_LIBPATHS 3 ${_PYTHON_PREFIX}_SITEARCH)
  1118. else()
  1119. unset (${_PYTHON_PREFIX}_STDLIB)
  1120. unset (${_PYTHON_PREFIX}_STDARCH)
  1121. unset (${_PYTHON_PREFIX}_SITELIB)
  1122. unset (${_PYTHON_PREFIX}_SITEARCH)
  1123. endif()
  1124. else()
  1125. unset (_${_PYTHON_PREFIX}_INTERPRETER_SIGNATURE CACHE)
  1126. unset (${_PYTHON_PREFIX}_INTERPRETER_ID)
  1127. endif()
  1128. mark_as_advanced (_${_PYTHON_PREFIX}_EXECUTABLE
  1129. _${_PYTHON_PREFIX}_INTERPRETER_SIGNATURE)
  1130. endif()
  1131. # second step, search for compiler (IronPython)
  1132. if ("Compiler" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS)
  1133. list (APPEND _${_PYTHON_PREFIX}_CACHED_VARS _${_PYTHON_PREFIX}_COMPILER)
  1134. if (${_PYTHON_PREFIX}_FIND_REQUIRED_Compiler)
  1135. list (APPEND _${_PYTHON_PREFIX}_REQUIRED_VARS ${_PYTHON_PREFIX}_COMPILER)
  1136. endif()
  1137. if (DEFINED ${_PYTHON_PREFIX}_COMPILER
  1138. AND IS_ABSOLUTE "${${_PYTHON_PREFIX}_COMPILER}")
  1139. set (_${_PYTHON_PREFIX}_COMPILER "${${_PYTHON_PREFIX}_COMPILER}" CACHE INTERNAL "")
  1140. elseif (DEFINED _${_PYTHON_PREFIX}_COMPILER)
  1141. # compute compiler signature and check validity of definition
  1142. string (MD5 __${_PYTHON_PREFIX}_COMPILER_SIGNATURE "${_${_PYTHON_PREFIX}_SIGNATURE}:${_${_PYTHON_PREFIX}_COMPILER}")
  1143. if (__${_PYTHON_PREFIX}_COMPILER_SIGNATURE STREQUAL _${_PYTHON_PREFIX}_COMPILER_SIGNATURE)
  1144. # check version validity
  1145. if (${_PYTHON_PREFIX}_FIND_VERSION_EXACT)
  1146. _python_validate_compiler (${${_PYTHON_PREFIX}_FIND_VERSION} EXACT CHECK_EXISTS)
  1147. else()
  1148. _python_validate_compiler (${${_PYTHON_PREFIX}_FIND_VERSION} CHECK_EXISTS)
  1149. endif()
  1150. else()
  1151. unset (_${_PYTHON_PREFIX}_COMPILER CACHE)
  1152. unset (_${_PYTHON_PREFIX}_COMPILER_SIGNATURE CACHE)
  1153. endif()
  1154. endif()
  1155. if (NOT _${_PYTHON_PREFIX}_COMPILER)
  1156. # IronPython specific artifacts
  1157. # If IronPython interpreter is found, use its path
  1158. unset (_${_PYTHON_PREFIX}_IRON_ROOT)
  1159. if (${_PYTHON_PREFIX}_Interpreter_FOUND AND ${_PYTHON_PREFIX}_INTERPRETER_ID STREQUAL "IronPython")
  1160. get_filename_component (_${_PYTHON_PREFIX}_IRON_ROOT "${${_PYTHON_PREFIX}_EXECUTABLE}" DIRECTORY)
  1161. endif()
  1162. if (_${_PYTHON_PREFIX}_FIND_STRATEGY STREQUAL "LOCATION")
  1163. set (_${_PYTHON_PREFIX}_REGISTRY_PATHS)
  1164. foreach (_${_PYTHON_PREFIX}_VERSION IN LISTS _${_PYTHON_PREFIX}_FIND_VERSIONS)
  1165. # Registry Paths
  1166. list (APPEND _${_PYTHON_PREFIX}_REGISTRY_PATHS
  1167. [HKEY_LOCAL_MACHINE\\SOFTWARE\\IronPython\\${_${_PYTHON_PREFIX}_VERSION}\\InstallPath])
  1168. endforeach()
  1169. while (TRUE)
  1170. if (_${_PYTHON_PREFIX}_FIND_REGISTRY STREQUAL "FIRST")
  1171. find_program (_${_PYTHON_PREFIX}_COMPILER
  1172. NAMES ipyc
  1173. HINTS ${_${_PYTHON_PREFIX}_IRON_ROOT} ${_${_PYTHON_PREFIX}_HINTS}
  1174. PATHS ${_${_PYTHON_PREFIX}_REGISTRY_PATHS}
  1175. PATH_SUFFIXES ${_${_PYTHON_PREFIX}_IRON_PYTHON_PATH_SUFFIXES}
  1176. NO_SYSTEM_ENVIRONMENT_PATH
  1177. NO_CMAKE_SYSTEM_PATH)
  1178. _python_validate_compiler (${${_PYTHON_PREFIX}_FIND_VERSION})
  1179. if (_${_PYTHON_PREFIX}_COMPILER)
  1180. break()
  1181. endif()
  1182. endif()
  1183. find_program (_${_PYTHON_PREFIX}_COMPILER
  1184. NAMES ipyc
  1185. HINTS ${_${_PYTHON_PREFIX}_IRON_ROOT} ${_${_PYTHON_PREFIX}_HINTS}
  1186. PATH_SUFFIXES ${_${_PYTHON_PREFIX}_IRON_PYTHON_PATH_SUFFIXES}
  1187. NO_SYSTEM_ENVIRONMENT_PATH
  1188. NO_CMAKE_SYSTEM_PATH)
  1189. _python_validate_compiler (${${_PYTHON_PREFIX}_FIND_VERSION})
  1190. if (_${_PYTHON_PREFIX}_COMPILER)
  1191. break()
  1192. endif()
  1193. if (_${_PYTHON_PREFIX}_FIND_REGISTRY STREQUAL "LAST")
  1194. find_program (_${_PYTHON_PREFIX}_COMPILER
  1195. NAMES ipyc
  1196. PATHS ${_${_PYTHON_PREFIX}_REGISTRY_PATHS}
  1197. PATH_SUFFIXES ${_${_PYTHON_PREFIX}_IRON_PYTHON_PATH_SUFFIXES}
  1198. NO_DEFAULT_PATH)
  1199. endif()
  1200. break()
  1201. endwhile()
  1202. else()
  1203. # try using root dir and registry
  1204. foreach (_${_PYTHON_PREFIX}_VERSION IN LISTS _${_PYTHON_PREFIX}_FIND_VERSIONS)
  1205. if (_${_PYTHON_PREFIX}_FIND_REGISTRY STREQUAL "FIRST")
  1206. find_program (_${_PYTHON_PREFIX}_COMPILER
  1207. NAMES ipyc
  1208. HINTS ${_${_PYTHON_PREFIX}_IRON_ROOT} ${_${_PYTHON_PREFIX}_HINTS}
  1209. PATHS [HKEY_LOCAL_MACHINE\\SOFTWARE\\IronPython\\${_${_PYTHON_PREFIX}_VERSION}\\InstallPath]
  1210. PATH_SUFFIXES ${_${_PYTHON_PREFIX}_IRON_PYTHON_PATH_SUFFIXES}
  1211. NO_SYSTEM_ENVIRONMENT_PATH
  1212. NO_CMAKE_SYSTEM_PATH)
  1213. _python_validate_compiler (${_${_PYTHON_PREFIX}_VERSION} EXACT)
  1214. if (_${_PYTHON_PREFIX}_COMPILER)
  1215. break()
  1216. endif()
  1217. endif()
  1218. find_program (_${_PYTHON_PREFIX}_COMPILER
  1219. NAMES ipyc
  1220. HINTS ${_${_PYTHON_PREFIX}_IRON_ROOT} ${_${_PYTHON_PREFIX}_HINTS}
  1221. PATH_SUFFIXES ${_${_PYTHON_PREFIX}_IRON_PYTHON_PATH_SUFFIXES}
  1222. NO_SYSTEM_ENVIRONMENT_PATH
  1223. NO_CMAKE_SYSTEM_PATH)
  1224. _python_validate_compiler (${_${_PYTHON_PREFIX}_VERSION} EXACT)
  1225. if (_${_PYTHON_PREFIX}_COMPILER)
  1226. break()
  1227. endif()
  1228. if (_${_PYTHON_PREFIX}_FIND_REGISTRY STREQUAL "LAST")
  1229. find_program (_${_PYTHON_PREFIX}_COMPILER
  1230. NAMES ipyc
  1231. PATHS [HKEY_LOCAL_MACHINE\\SOFTWARE\\IronPython\\${_${_PYTHON_PREFIX}_VERSION}\\InstallPath]
  1232. PATH_SUFFIXES ${_${_PYTHON_PREFIX}_IRON_PYTHON_PATH_SUFFIXES}
  1233. NO_DEFAULT_PATH)
  1234. _python_validate_compiler (${_${_PYTHON_PREFIX}_VERSION} EXACT)
  1235. if (_${_PYTHON_PREFIX}_COMPILER)
  1236. break()
  1237. endif()
  1238. endif()
  1239. endforeach()
  1240. # no specific version found, re-try in standard paths
  1241. find_program (_${_PYTHON_PREFIX}_COMPILER
  1242. NAMES ipyc
  1243. HINTS ${_${_PYTHON_PREFIX}_IRON_ROOT} ${_${_PYTHON_PREFIX}_HINTS}
  1244. PATH_SUFFIXES ${_${_PYTHON_PREFIX}_IRON_PYTHON_PATH_SUFFIXES})
  1245. endif()
  1246. endif()
  1247. set (${_PYTHON_PREFIX}_COMPILER "${_${_PYTHON_PREFIX}_COMPILER}")
  1248. if (_${_PYTHON_PREFIX}_COMPILER)
  1249. # retrieve python environment version from compiler
  1250. set (_${_PYTHON_PREFIX}_VERSION_DIR "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/PythonCompilerVersion.dir")
  1251. file (WRITE "${_${_PYTHON_PREFIX}_VERSION_DIR}/version.py" "import sys; sys.stdout.write('.'.join([str(x) for x in sys.version_info[:3]]))\n")
  1252. execute_process (COMMAND "${_${_PYTHON_PREFIX}_COMPILER}" /target:exe /embed "${_${_PYTHON_PREFIX}_VERSION_DIR}/version.py"
  1253. WORKING_DIRECTORY "${_${_PYTHON_PREFIX}_VERSION_DIR}"
  1254. OUTPUT_QUIET
  1255. ERROR_QUIET)
  1256. execute_process (COMMAND "${_${_PYTHON_PREFIX}_VERSION_DIR}/version"
  1257. WORKING_DIRECTORY "${_${_PYTHON_PREFIX}_VERSION_DIR}"
  1258. RESULT_VARIABLE _${_PYTHON_PREFIX}_RESULT
  1259. OUTPUT_VARIABLE _${_PYTHON_PREFIX}_VERSION
  1260. ERROR_QUIET)
  1261. if (NOT _${_PYTHON_PREFIX}_RESULT)
  1262. set (_${_PYTHON_PREFIX}_COMPILER_USABLE TRUE)
  1263. string (REGEX MATCHALL "[0-9]+" _${_PYTHON_PREFIX}_VERSIONS "${_${_PYTHON_PREFIX}_VERSION}")
  1264. list (GET _${_PYTHON_PREFIX}_VERSIONS 0 _${_PYTHON_PREFIX}_VERSION_MAJOR)
  1265. list (GET _${_PYTHON_PREFIX}_VERSIONS 1 _${_PYTHON_PREFIX}_VERSION_MINOR)
  1266. list (GET _${_PYTHON_PREFIX}_VERSIONS 2 _${_PYTHON_PREFIX}_VERSION_PATCH)
  1267. if (NOT ${_PYTHON_PREFIX}_Interpreter_FOUND)
  1268. # set public version information
  1269. set (${_PYTHON_PREFIX}_VERSION ${_${_PYTHON_PREFIX}_VERSION})
  1270. set (${_PYTHON_PREFIX}_VERSION_MAJOR ${_${_PYTHON_PREFIX}_VERSION_MAJOR})
  1271. set (${_PYTHON_PREFIX}_VERSION_MINOR ${_${_PYTHON_PREFIX}_VERSION_MINOR})
  1272. set (${_PYTHON_PREFIX}_VERSION_PATCH ${_${_PYTHON_PREFIX}_VERSION_PATCH})
  1273. endif()
  1274. else()
  1275. # compiler not usable
  1276. set (_${_PYTHON_PREFIX}_COMPILER_USABLE FALSE)
  1277. endif()
  1278. file (REMOVE_RECURSE "${_${_PYTHON_PREFIX}_VERSION_DIR}")
  1279. endif()
  1280. if (_${_PYTHON_PREFIX}_COMPILER AND _${_PYTHON_PREFIX}_COMPILER_USABLE)
  1281. if (${_PYTHON_PREFIX}_Interpreter_FOUND)
  1282. # Compiler must be compatible with interpreter
  1283. if (${_${_PYTHON_PREFIX}_VERSION_MAJOR}.${_${_PYTHON_PREFIX}_VERSION_MINOR} VERSION_EQUAL ${${_PYTHON_PREFIX}_VERSION_MAJOR}.${${_PYTHON_PREFIX}_VERSION_MINOR})
  1284. set (${_PYTHON_PREFIX}_Compiler_FOUND TRUE)
  1285. endif()
  1286. elseif (${_PYTHON_PREFIX}_VERSION_MAJOR VERSION_EQUAL _${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR)
  1287. set (${_PYTHON_PREFIX}_Compiler_FOUND TRUE)
  1288. # Use compiler version for future searches to ensure consistency
  1289. set (_${_PYTHON_PREFIX}_FIND_VERSIONS ${${_PYTHON_PREFIX}_VERSION_MAJOR}.${${_PYTHON_PREFIX}_VERSION_MINOR})
  1290. endif()
  1291. endif()
  1292. if (${_PYTHON_PREFIX}_Compiler_FOUND)
  1293. # compute and save compiler signature
  1294. string (MD5 __${_PYTHON_PREFIX}_COMPILER_SIGNATURE "${_${_PYTHON_PREFIX}_SIGNATURE}:${_${_PYTHON_PREFIX}_COMPILER}")
  1295. set (_${_PYTHON_PREFIX}_COMPILER_SIGNATURE "${__${_PYTHON_PREFIX}_COMPILER_SIGNATURE}" CACHE INTERNAL "")
  1296. set (${_PYTHON_PREFIX}_COMPILER_ID IronPython)
  1297. else()
  1298. unset (_${_PYTHON_PREFIX}_COMPILER_SIGNATURE CACHE)
  1299. unset (${_PYTHON_PREFIX}_COMPILER_ID)
  1300. endif()
  1301. mark_as_advanced (_${_PYTHON_PREFIX}_COMPILER
  1302. _${_PYTHON_PREFIX}_COMPILER_SIGNATURE)
  1303. endif()
  1304. # third step, search for the development artifacts
  1305. ## Development environment is not compatible with IronPython interpreter
  1306. if ("Development" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS
  1307. AND NOT ${_PYTHON_PREFIX}_INTERPRETER_ID STREQUAL "IronPython")
  1308. list (APPEND _${_PYTHON_PREFIX}_CACHED_VARS _${_PYTHON_PREFIX}_LIBRARY_RELEASE
  1309. ${_PYTHON_PREFIX}_RUNTIME_LIBRARY_RELEASE
  1310. _${_PYTHON_PREFIX}_LIBRARY_DEBUG
  1311. ${_PYTHON_PREFIX}_RUNTIME_LIBRARY_DEBUG
  1312. _${_PYTHON_PREFIX}_INCLUDE_DIR)
  1313. if (${_PYTHON_PREFIX}_FIND_REQUIRED_Development)
  1314. list (APPEND _${_PYTHON_PREFIX}_REQUIRED_VARS ${_PYTHON_PREFIX}_LIBRARIES
  1315. ${_PYTHON_PREFIX}_INCLUDE_DIRS)
  1316. endif()
  1317. if (DEFINED _${_PYTHON_PREFIX}_LIBRARY_RELEASE OR DEFINED _${_PYTHON_PREFIX}_INCLUDE_DIR)
  1318. # compute development signature and check validity of definition
  1319. string (MD5 __${_PYTHON_PREFIX}_DEVELOPMENT_SIGNATURE "${_${_PYTHON_PREFIX}_SIGNATURE}:${_${_PYTHON_PREFIX}_LIBRARY_RELEASE}:${_${_PYTHON_PREFIX}_INCLUDE_DIR}")
  1320. if (WIN32 AND NOT DEFINED _${_PYTHON_PREFIX}_LIBRARY_DEBUG)
  1321. set (_${_PYTHON_PREFIX}_LIBRARY_DEBUG "_${_PYTHON_PREFIX}_LIBRARY_DEBUG-NOTFOUND" CACHE INTERNAL "")
  1322. endif()
  1323. if (NOT DEFINED _${_PYTHON_PREFIX}_INCLUDE_DIR)
  1324. set (_${_PYTHON_PREFIX}_INCLUDE_DIR "_${_PYTHON_PREFIX}_INCLUDE_DIR-NOTFOUND" CACHE INTERNAL "")
  1325. endif()
  1326. if (__${_PYTHON_PREFIX}_DEVELOPMENT_SIGNATURE STREQUAL _${_PYTHON_PREFIX}_DEVELOPMENT_SIGNATURE)
  1327. # check version validity
  1328. if (${_PYTHON_PREFIX}_FIND_VERSION_EXACT)
  1329. _python_validate_library (${${_PYTHON_PREFIX}_FIND_VERSION} EXACT CHECK_EXISTS)
  1330. _python_validate_include_dir (${${_PYTHON_PREFIX}_FIND_VERSION} EXACT CHECK_EXISTS)
  1331. else()
  1332. _python_validate_library (${${_PYTHON_PREFIX}_FIND_VERSION} CHECK_EXISTS)
  1333. _python_validate_include_dir (${${_PYTHON_PREFIX}_FIND_VERSION} CHECK_EXISTS)
  1334. endif()
  1335. else()
  1336. unset (_${_PYTHON_PREFIX}_LIBRARY_RELEASE CACHE)
  1337. unset (_${_PYTHON_PREFIX}_LIBRARY_DEBUG CACHE)
  1338. unset (_${_PYTHON_PREFIX}_INCLUDE_DIR CACHE)
  1339. unset (_${_PYTHON_PREFIX}_DEVELOPMENT_SIGNATURE CACHE)
  1340. endif()
  1341. endif()
  1342. if (DEFINED ${_PYTHON_PREFIX}_LIBRARY
  1343. AND IS_ABSOLUTE "${${_PYTHON_PREFIX}_LIBRARY}")
  1344. set (_${_PYTHON_PREFIX}_LIBRARY_RELEASE "${${_PYTHON_PREFIX}_LIBRARY}" CACHE INTERNAL "")
  1345. unset (_${_PYTHON_PREFIX}_LIBRARY_DEBUG CACHE)
  1346. unset (_${_PYTHON_PREFIX}_INCLUDE_DIR CACHE)
  1347. endif()
  1348. if (DEFINED ${_PYTHON_PREFIX}_INCLUDE_DIR
  1349. AND IS_ABSOLUTE "${${_PYTHON_PREFIX}_INCLUDE_DIR}")
  1350. set (_${_PYTHON_PREFIX}_INCLUDE_DIR "${${_PYTHON_PREFIX}_INCLUDE_DIR}" CACHE INTERNAL "")
  1351. endif()
  1352. # Support preference of static libs by adjusting CMAKE_FIND_LIBRARY_SUFFIXES
  1353. unset (_${_PYTHON_PREFIX}_CMAKE_FIND_LIBRARY_SUFFIXES)
  1354. if (DEFINED ${_PYTHON_PREFIX}_USE_STATIC_LIBS AND NOT WIN32)
  1355. set(_${_PYTHON_PREFIX}_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
  1356. if(${_PYTHON_PREFIX}_USE_STATIC_LIBS)
  1357. set (CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_STATIC_LIBRARY_SUFFIX})
  1358. else()
  1359. list (REMOVE_ITEM CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_STATIC_LIBRARY_SUFFIX})
  1360. endif()
  1361. endif()
  1362. if (NOT _${_PYTHON_PREFIX}_LIBRARY_RELEASE OR NOT _${_PYTHON_PREFIX}_INCLUDE_DIR)
  1363. # if python interpreter is found, use it to look-up for artifacts
  1364. # to ensure consistency between interpreter and development environments.
  1365. # If not, try to locate a compatible config tool
  1366. if (NOT ${_PYTHON_PREFIX}_Interpreter_FOUND OR CMAKE_CROSSCOMPILING)
  1367. set (_${_PYTHON_PREFIX}_HINTS "${${_PYTHON_PREFIX}_ROOT_DIR}" ENV ${_PYTHON_PREFIX}_ROOT_DIR)
  1368. unset (_${_PYTHON_PREFIX}_VIRTUALENV_PATHS)
  1369. if (_${_PYTHON_PREFIX}_FIND_VIRTUALENV MATCHES "^(FIRST|ONLY)$")
  1370. set (_${_PYTHON_PREFIX}_VIRTUALENV_PATHS ENV VIRTUAL_ENV)
  1371. endif()
  1372. unset (_${_PYTHON_PREFIX}_FRAMEWORK_PATHS)
  1373. if (_${_PYTHON_PREFIX}_FIND_STRATEGY STREQUAL "LOCATION")
  1374. set (_${_PYTHON_PREFIX}_CONFIG_NAMES)
  1375. foreach (_${_PYTHON_PREFIX}_VERSION IN LISTS _${_PYTHON_PREFIX}_FIND_VERSIONS)
  1376. _python_get_names (_${_PYTHON_PREFIX}_VERSION_NAMES VERSION ${_${_PYTHON_PREFIX}_VERSION} POSIX CONFIG)
  1377. list (APPEND _${_PYTHON_PREFIX}_CONFIG_NAMES ${_${_PYTHON_PREFIX}_VERSION_NAMES})
  1378. # Framework Paths
  1379. _python_get_frameworks (_${_PYTHON_PREFIX}_VERSION_PATHS ${_${_PYTHON_PREFIX}_VERSION})
  1380. list (APPEND _${_PYTHON_PREFIX}_FRAMEWORK_PATHS ${_${_PYTHON_PREFIX}_VERSION_PATHS})
  1381. endforeach()
  1382. # Apple frameworks handling
  1383. if (CMAKE_HOST_APPLE AND _${_PYTHON_PREFIX}_FIND_FRAMEWORK STREQUAL "FIRST")
  1384. find_program (_${_PYTHON_PREFIX}_CONFIG
  1385. NAMES ${_${_PYTHON_PREFIX}_CONFIG_NAMES}
  1386. NAMES_PER_DIR
  1387. HINTS ${_${_PYTHON_PREFIX}_HINTS}
  1388. PATHS ${_${_PYTHON_PREFIX}_VIRTUALENV_PATHS}
  1389. ${_${_PYTHON_PREFIX}_FRAMEWORK_PATHS}
  1390. PATH_SUFFIXES bin
  1391. NO_CMAKE_PATH
  1392. NO_CMAKE_ENVIRONMENT_PATH
  1393. NO_SYSTEM_ENVIRONMENT_PATH
  1394. NO_CMAKE_SYSTEM_PATH)
  1395. endif()
  1396. find_program (_${_PYTHON_PREFIX}_CONFIG
  1397. NAMES ${_${_PYTHON_PREFIX}_CONFIG_NAMES}
  1398. NAMES_PER_DIR
  1399. HINTS ${_${_PYTHON_PREFIX}_HINTS}
  1400. PATHS ${_${_PYTHON_PREFIX}_VIRTUALENV_PATHS}
  1401. PATH_SUFFIXES bin)
  1402. # Apple frameworks handling
  1403. if (CMAKE_HOST_APPLE AND _${_PYTHON_PREFIX}_FIND_FRAMEWORK STREQUAL "LAST")
  1404. find_program (_${_PYTHON_PREFIX}_CONFIG
  1405. NAMES ${_${_PYTHON_PREFIX}_CONFIG_NAMES}
  1406. NAMES_PER_DIR
  1407. PATHS ${_${_PYTHON_PREFIX}_FRAMEWORK_PATHS}
  1408. PATH_SUFFIXES bin
  1409. NO_DEFAULT_PATH)
  1410. endif()
  1411. if (_${_PYTHON_PREFIX}_CONFIG)
  1412. execute_process (COMMAND "${_${_PYTHON_PREFIX}_CONFIG}" --help
  1413. RESULT_VARIABLE _${_PYTHON_PREFIX}_RESULT
  1414. OUTPUT_VARIABLE __${_PYTHON_PREFIX}_HELP
  1415. ERROR_QUIET
  1416. OUTPUT_STRIP_TRAILING_WHITESPACE)
  1417. if (_${_PYTHON_PREFIX}_RESULT)
  1418. # assume config tool is not usable
  1419. unset (_${_PYTHON_PREFIX}_CONFIG CACHE)
  1420. endif()
  1421. endif()
  1422. if (_${_PYTHON_PREFIX}_CONFIG)
  1423. execute_process (COMMAND "${_${_PYTHON_PREFIX}_CONFIG}" --abiflags
  1424. RESULT_VARIABLE _${_PYTHON_PREFIX}_RESULT
  1425. OUTPUT_VARIABLE __${_PYTHON_PREFIX}_ABIFLAGS
  1426. ERROR_QUIET
  1427. OUTPUT_STRIP_TRAILING_WHITESPACE)
  1428. if (_${_PYTHON_PREFIX}_RESULT)
  1429. # assume ABI is not supported
  1430. set (__${_PYTHON_PREFIX}_ABIFLAGS "")
  1431. endif()
  1432. if (DEFINED _${_PYTHON_PREFIX}_FIND_ABI AND NOT __${_PYTHON_PREFIX}_ABIFLAGS IN_LIST _${_PYTHON_PREFIX}_ABIFLAGS)
  1433. # Wrong ABI
  1434. unset (_${_PYTHON_PREFIX}_CONFIG CACHE)
  1435. endif()
  1436. endif()
  1437. if (_${_PYTHON_PREFIX}_CONFIG AND DEFINED CMAKE_LIBRARY_ARCHITECTURE)
  1438. # check that config tool match library architecture
  1439. execute_process (COMMAND "${_${_PYTHON_PREFIX}_CONFIG}" --configdir
  1440. RESULT_VARIABLE _${_PYTHON_PREFIX}_RESULT
  1441. OUTPUT_VARIABLE _${_PYTHON_PREFIX}_CONFIGDIR
  1442. ERROR_QUIET
  1443. OUTPUT_STRIP_TRAILING_WHITESPACE)
  1444. if (_${_PYTHON_PREFIX}_RESULT)
  1445. unset (_${_PYTHON_PREFIX}_CONFIG CACHE)
  1446. else()
  1447. string(FIND "${_${_PYTHON_PREFIX}_CONFIGDIR}" "${CMAKE_LIBRARY_ARCHITECTURE}" _${_PYTHON_PREFIX}_RESULT)
  1448. if (_${_PYTHON_PREFIX}_RESULT EQUAL -1)
  1449. unset (_${_PYTHON_PREFIX}_CONFIG CACHE)
  1450. endif()
  1451. endif()
  1452. endif()
  1453. else()
  1454. foreach (_${_PYTHON_PREFIX}_VERSION IN LISTS _${_PYTHON_PREFIX}_FIND_VERSIONS)
  1455. # try to use pythonX.Y-config tool
  1456. _python_get_names (_${_PYTHON_PREFIX}_CONFIG_NAMES VERSION ${_${_PYTHON_PREFIX}_VERSION} POSIX CONFIG)
  1457. # Framework Paths
  1458. _python_get_frameworks (_${_PYTHON_PREFIX}_FRAMEWORK_PATHS ${_${_PYTHON_PREFIX}_VERSION})
  1459. # Apple frameworks handling
  1460. if (CMAKE_HOST_APPLE AND _${_PYTHON_PREFIX}_FIND_FRAMEWORK STREQUAL "FIRST")
  1461. find_program (_${_PYTHON_PREFIX}_CONFIG
  1462. NAMES ${_${_PYTHON_PREFIX}_CONFIG_NAMES}
  1463. NAMES_PER_DIR
  1464. HINTS ${_${_PYTHON_PREFIX}_HINTS}
  1465. PATHS ${_${_PYTHON_PREFIX}_VIRTUALENV_PATHS}
  1466. ${_${_PYTHON_PREFIX}_FRAMEWORK_PATHS}
  1467. PATH_SUFFIXES bin
  1468. NO_CMAKE_PATH
  1469. NO_CMAKE_ENVIRONMENT_PATH
  1470. NO_SYSTEM_ENVIRONMENT_PATH
  1471. NO_CMAKE_SYSTEM_PATH)
  1472. endif()
  1473. find_program (_${_PYTHON_PREFIX}_CONFIG
  1474. NAMES ${_${_PYTHON_PREFIX}_CONFIG_NAMES}
  1475. NAMES_PER_DIR
  1476. HINTS ${_${_PYTHON_PREFIX}_HINTS}
  1477. PATHS ${_${_PYTHON_PREFIX}_VIRTUALENV_PATHS}
  1478. PATH_SUFFIXES bin)
  1479. # Apple frameworks handling
  1480. if (CMAKE_HOST_APPLE AND _${_PYTHON_PREFIX}_FIND_FRAMEWORK STREQUAL "LAST")
  1481. find_program (_${_PYTHON_PREFIX}_CONFIG
  1482. NAMES ${_${_PYTHON_PREFIX}_CONFIG_NAMES}
  1483. NAMES_PER_DIR
  1484. PATHS ${_${_PYTHON_PREFIX}_FRAMEWORK_PATHS}
  1485. PATH_SUFFIXES bin
  1486. NO_DEFAULT_PATH)
  1487. endif()
  1488. unset (_${_PYTHON_PREFIX}_CONFIG_NAMES)
  1489. if (_${_PYTHON_PREFIX}_CONFIG)
  1490. execute_process (COMMAND "${_${_PYTHON_PREFIX}_CONFIG}" --help
  1491. RESULT_VARIABLE _${_PYTHON_PREFIX}_RESULT
  1492. OUTPUT_VARIABLE __${_PYTHON_PREFIX}_HELP
  1493. ERROR_QUIET
  1494. OUTPUT_STRIP_TRAILING_WHITESPACE)
  1495. if (_${_PYTHON_PREFIX}_RESULT)
  1496. # assume config tool is not usable
  1497. unset (_${_PYTHON_PREFIX}_CONFIG CACHE)
  1498. endif()
  1499. endif()
  1500. if (NOT _${_PYTHON_PREFIX}_CONFIG)
  1501. continue()
  1502. endif()
  1503. execute_process (COMMAND "${_${_PYTHON_PREFIX}_CONFIG}" --abiflags
  1504. RESULT_VARIABLE _${_PYTHON_PREFIX}_RESULT
  1505. OUTPUT_VARIABLE __${_PYTHON_PREFIX}_ABIFLAGS
  1506. ERROR_QUIET
  1507. OUTPUT_STRIP_TRAILING_WHITESPACE)
  1508. if (_${_PYTHON_PREFIX}_RESULT)
  1509. # assume ABI is not supported
  1510. set (__${_PYTHON_PREFIX}_ABIFLAGS "")
  1511. endif()
  1512. if (DEFINED _${_PYTHON_PREFIX}_FIND_ABI AND NOT __${_PYTHON_PREFIX}_ABIFLAGS IN_LIST _${_PYTHON_PREFIX}_ABIFLAGS)
  1513. # Wrong ABI
  1514. unset (_${_PYTHON_PREFIX}_CONFIG CACHE)
  1515. continue()
  1516. endif()
  1517. if (_${_PYTHON_PREFIX}_CONFIG AND DEFINED CMAKE_LIBRARY_ARCHITECTURE)
  1518. # check that config tool match library architecture
  1519. execute_process (COMMAND "${_${_PYTHON_PREFIX}_CONFIG}" --configdir
  1520. RESULT_VARIABLE _${_PYTHON_PREFIX}_RESULT
  1521. OUTPUT_VARIABLE _${_PYTHON_PREFIX}_CONFIGDIR
  1522. ERROR_QUIET
  1523. OUTPUT_STRIP_TRAILING_WHITESPACE)
  1524. if (_${_PYTHON_PREFIX}_RESULT)
  1525. unset (_${_PYTHON_PREFIX}_CONFIG CACHE)
  1526. continue()
  1527. endif()
  1528. string (FIND "${_${_PYTHON_PREFIX}_CONFIGDIR}" "${CMAKE_LIBRARY_ARCHITECTURE}" _${_PYTHON_PREFIX}_RESULT)
  1529. if (_${_PYTHON_PREFIX}_RESULT EQUAL -1)
  1530. unset (_${_PYTHON_PREFIX}_CONFIG CACHE)
  1531. continue()
  1532. endif()
  1533. endif()
  1534. if (_${_PYTHON_PREFIX}_CONFIG)
  1535. break()
  1536. endif()
  1537. endforeach()
  1538. endif()
  1539. endif()
  1540. endif()
  1541. if (NOT _${_PYTHON_PREFIX}_LIBRARY_RELEASE)
  1542. if ((${_PYTHON_PREFIX}_Interpreter_FOUND AND NOT CMAKE_CROSSCOMPILING) OR _${_PYTHON_PREFIX}_CONFIG)
  1543. # retrieve root install directory
  1544. _python_get_config_var (_${_PYTHON_PREFIX}_PREFIX PREFIX)
  1545. # enforce current ABI
  1546. _python_get_config_var (_${_PYTHON_PREFIX}_ABIFLAGS ABIFLAGS)
  1547. set (_${_PYTHON_PREFIX}_HINTS "${_${_PYTHON_PREFIX}_PREFIX}")
  1548. # retrieve library
  1549. ## compute some paths and artifact names
  1550. if (_${_PYTHON_PREFIX}_CONFIG)
  1551. string (REGEX REPLACE "^.+python([0-9.]+)[a-z]*-config" "\\1" _${_PYTHON_PREFIX}_VERSION "${_${_PYTHON_PREFIX}_CONFIG}")
  1552. else()
  1553. set (_${_PYTHON_PREFIX}_VERSION "${${_PYTHON_PREFIX}_VERSION_MAJOR}.${${_PYTHON_PREFIX}_VERSION_MINOR}")
  1554. endif()
  1555. _python_get_path_suffixes (_${_PYTHON_PREFIX}_PATH_SUFFIXES VERSION ${_${_PYTHON_PREFIX}_VERSION} LIBRARY)
  1556. _python_get_names (_${_PYTHON_PREFIX}_LIB_NAMES VERSION ${_${_PYTHON_PREFIX}_VERSION} WIN32 POSIX LIBRARY)
  1557. _python_get_config_var (_${_PYTHON_PREFIX}_CONFIGDIR CONFIGDIR)
  1558. list (APPEND _${_PYTHON_PREFIX}_HINTS "${_${_PYTHON_PREFIX}_CONFIGDIR}")
  1559. list (APPEND _${_PYTHON_PREFIX}_HINTS "${${_PYTHON_PREFIX}_ROOT_DIR}" ENV ${_PYTHON_PREFIX}_ROOT_DIR)
  1560. find_library (_${_PYTHON_PREFIX}_LIBRARY_RELEASE
  1561. NAMES ${_${_PYTHON_PREFIX}_LIB_NAMES}
  1562. NAMES_PER_DIR
  1563. HINTS ${_${_PYTHON_PREFIX}_HINTS}
  1564. PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES}
  1565. NO_SYSTEM_ENVIRONMENT_PATH
  1566. NO_CMAKE_SYSTEM_PATH)
  1567. endif()
  1568. # Rely on HINTS and standard paths if interpreter or config tool failed to locate artifacts
  1569. if (NOT _${_PYTHON_PREFIX}_LIBRARY_RELEASE)
  1570. set (_${_PYTHON_PREFIX}_HINTS "${${_PYTHON_PREFIX}_ROOT_DIR}" ENV ${_PYTHON_PREFIX}_ROOT_DIR)
  1571. unset (_${_PYTHON_PREFIX}_VIRTUALENV_PATHS)
  1572. if (_${_PYTHON_PREFIX}_FIND_VIRTUALENV MATCHES "^(FIRST|ONLY)$")
  1573. set (_${_PYTHON_PREFIX}_VIRTUALENV_PATHS ENV VIRTUAL_ENV)
  1574. endif()
  1575. if (_${_PYTHON_PREFIX}_FIND_STRATEGY STREQUAL "LOCATION")
  1576. unset (_${_PYTHON_PREFIX}_LIB_NAMES)
  1577. unset (_${_PYTHON_PREFIX}_LIB_NAMES_DEBUG)
  1578. unset (_${_PYTHON_PREFIX}_FRAMEWORK_PATHS)
  1579. unset (_${_PYTHON_PREFIX}_REGISTRY_PATHS)
  1580. unset (_${_PYTHON_PREFIX}_PATH_SUFFIXES)
  1581. foreach (_${_PYTHON_PREFIX}_LIB_VERSION IN LISTS _${_PYTHON_PREFIX}_FIND_VERSIONS)
  1582. # library names
  1583. _python_get_names (_${_PYTHON_PREFIX}_VERSION_NAMES VERSION ${_${_PYTHON_PREFIX}_LIB_VERSION} WIN32 POSIX LIBRARY)
  1584. list (APPEND _${_PYTHON_PREFIX}_LIB_NAMES ${_${_PYTHON_PREFIX}_VERSION_NAMES})
  1585. _python_get_names (_${_PYTHON_PREFIX}_VERSION_NAMES VERSION ${_${_PYTHON_PREFIX}_LIB_VERSION} WIN32 DEBUG)
  1586. list (APPEND _${_PYTHON_PREFIX}_LIB_NAMES_DEBUG ${_${_PYTHON_PREFIX}_VERSION_NAMES})
  1587. # Framework Paths
  1588. _python_get_frameworks (_${_PYTHON_PREFIX}_VERSION_PATHS ${_${_PYTHON_PREFIX}_LIB_VERSION})
  1589. list (APPEND _${_PYTHON_PREFIX}_FRAMEWORK_PATHS ${_${_PYTHON_PREFIX}_VERSION_PATHS})
  1590. # Registry Paths
  1591. _python_get_registries (_${_PYTHON_PREFIX}_VERSION_PATHS ${_${_PYTHON_PREFIX}_LIB_VERSION})
  1592. list (APPEND _${_PYTHON_PREFIX}_REGISTRY_PATHS ${_${_PYTHON_PREFIX}_VERSION_PATHS})
  1593. # Paths suffixes
  1594. _python_get_path_suffixes (_${_PYTHON_PREFIX}_VERSION_PATHS VERSION ${_${_PYTHON_PREFIX}_LIB_VERSION} LIBRARY)
  1595. list (APPEND _${_PYTHON_PREFIX}_PATH_SUFFIXES ${_${_PYTHON_PREFIX}_VERSION_PATHS})
  1596. endforeach()
  1597. if (APPLE AND _${_PYTHON_PREFIX}_FIND_FRAMEWORK STREQUAL "FIRST")
  1598. find_library (_${_PYTHON_PREFIX}_LIBRARY_RELEASE
  1599. NAMES ${_${_PYTHON_PREFIX}_LIB_NAMES}
  1600. NAMES_PER_DIR
  1601. HINTS ${_${_PYTHON_PREFIX}_HINTS}
  1602. PATHS ${_${_PYTHON_PREFIX}_VIRTUALENV_PATHS}
  1603. ${_${_PYTHON_PREFIX}_FRAMEWORK_PATHS}
  1604. PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES}
  1605. NO_CMAKE_PATH
  1606. NO_CMAKE_ENVIRONMENT_PATH
  1607. NO_SYSTEM_ENVIRONMENT_PATH
  1608. NO_CMAKE_SYSTEM_PATH)
  1609. endif()
  1610. if (WIN32 AND _${_PYTHON_PREFIX}_FIND_REGISTRY STREQUAL "FIRST")
  1611. find_library (_${_PYTHON_PREFIX}_LIBRARY_RELEASE
  1612. NAMES ${_${_PYTHON_PREFIX}_LIB_NAMES}
  1613. NAMES_PER_DIR
  1614. HINTS ${_${_PYTHON_PREFIX}_HINTS}
  1615. PATHS ${_${_PYTHON_PREFIX}_VIRTUALENV_PATHS}
  1616. ${_${_PYTHON_PREFIX}_REGISTRY_PATHS}
  1617. PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES}
  1618. NO_SYSTEM_ENVIRONMENT_PATH
  1619. NO_CMAKE_SYSTEM_PATH)
  1620. endif()
  1621. # search in HINTS locations
  1622. find_library (_${_PYTHON_PREFIX}_LIBRARY_RELEASE
  1623. NAMES ${_${_PYTHON_PREFIX}_LIB_NAMES}
  1624. NAMES_PER_DIR
  1625. HINTS ${_${_PYTHON_PREFIX}_HINTS}
  1626. PATHS ${_${_PYTHON_PREFIX}_VIRTUALENV_PATHS}
  1627. PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES}
  1628. NO_SYSTEM_ENVIRONMENT_PATH
  1629. NO_CMAKE_SYSTEM_PATH)
  1630. if (APPLE AND _${_PYTHON_PREFIX}_FIND_FRAMEWORK STREQUAL "LAST")
  1631. set (__${_PYTHON_PREFIX}_FRAMEWORK_PATHS ${_${_PYTHON_PREFIX}_FRAMEWORK_PATHS})
  1632. else()
  1633. unset (__${_PYTHON_PREFIX}_FRAMEWORK_PATHS)
  1634. endif()
  1635. if (WIN32 AND _${_PYTHON_PREFIX}_FIND_REGISTRY STREQUAL "LAST")
  1636. set (__${_PYTHON_PREFIX}_REGISTRY_PATHS ${_${_PYTHON_PREFIX}_REGISTRY_PATHS})
  1637. else()
  1638. unset (__${_PYTHON_PREFIX}_REGISTRY_PATHS)
  1639. endif()
  1640. # search in all default paths
  1641. find_library (_${_PYTHON_PREFIX}_LIBRARY_RELEASE
  1642. NAMES ${_${_PYTHON_PREFIX}_LIB_NAMES}
  1643. NAMES_PER_DIR
  1644. PATHS ${__${_PYTHON_PREFIX}_FRAMEWORK_PATHS}
  1645. ${__${_PYTHON_PREFIX}_REGISTRY_PATHS}
  1646. PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES})
  1647. else()
  1648. foreach (_${_PYTHON_PREFIX}_LIB_VERSION IN LISTS _${_PYTHON_PREFIX}_FIND_VERSIONS)
  1649. _python_get_names (_${_PYTHON_PREFIX}_LIB_NAMES VERSION ${_${_PYTHON_PREFIX}_LIB_VERSION} WIN32 POSIX LIBRARY)
  1650. _python_get_names (_${_PYTHON_PREFIX}_LIB_NAMES_DEBUG VERSION ${_${_PYTHON_PREFIX}_LIB_VERSION} WIN32 DEBUG)
  1651. _python_get_frameworks (_${_PYTHON_PREFIX}_FRAMEWORK_PATHS ${_${_PYTHON_PREFIX}_LIB_VERSION})
  1652. _python_get_registries (_${_PYTHON_PREFIX}_REGISTRY_PATHS ${_${_PYTHON_PREFIX}_LIB_VERSION})
  1653. _python_get_path_suffixes (_${_PYTHON_PREFIX}_PATH_SUFFIXES VERSION ${_${_PYTHON_PREFIX}_LIB_VERSION} LIBRARY)
  1654. if (APPLE AND _${_PYTHON_PREFIX}_FIND_FRAMEWORK STREQUAL "FIRST")
  1655. find_library (_${_PYTHON_PREFIX}_LIBRARY_RELEASE
  1656. NAMES ${_${_PYTHON_PREFIX}_LIB_NAMES}
  1657. NAMES_PER_DIR
  1658. HINTS ${_${_PYTHON_PREFIX}_HINTS}
  1659. PATHS ${_${_PYTHON_PREFIX}_VIRTUALENV_PATHS}
  1660. ${_${_PYTHON_PREFIX}_FRAMEWORK_PATHS}
  1661. PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES}
  1662. NO_CMAKE_PATH
  1663. NO_CMAKE_ENVIRONMENT_PATH
  1664. NO_SYSTEM_ENVIRONMENT_PATH
  1665. NO_CMAKE_SYSTEM_PATH)
  1666. endif()
  1667. if (WIN32 AND _${_PYTHON_PREFIX}_FIND_REGISTRY STREQUAL "FIRST")
  1668. find_library (_${_PYTHON_PREFIX}_LIBRARY_RELEASE
  1669. NAMES ${_${_PYTHON_PREFIX}_LIB_NAMES}
  1670. NAMES_PER_DIR
  1671. HINTS ${_${_PYTHON_PREFIX}_HINTS}
  1672. PATHS ${_${_PYTHON_PREFIX}_VIRTUALENV_PATHS}
  1673. ${_${_PYTHON_PREFIX}_REGISTRY_PATHS}
  1674. PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES}
  1675. NO_SYSTEM_ENVIRONMENT_PATH
  1676. NO_CMAKE_SYSTEM_PATH)
  1677. endif()
  1678. # search in HINTS locations
  1679. find_library (_${_PYTHON_PREFIX}_LIBRARY_RELEASE
  1680. NAMES ${_${_PYTHON_PREFIX}_LIB_NAMES}
  1681. NAMES_PER_DIR
  1682. HINTS ${_${_PYTHON_PREFIX}_HINTS}
  1683. PATHS ${_${_PYTHON_PREFIX}_VIRTUALENV_PATHS}
  1684. PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES}
  1685. NO_SYSTEM_ENVIRONMENT_PATH
  1686. NO_CMAKE_SYSTEM_PATH)
  1687. if (APPLE AND _${_PYTHON_PREFIX}_FIND_FRAMEWORK STREQUAL "LAST")
  1688. set (__${_PYTHON_PREFIX}_FRAMEWORK_PATHS ${_${_PYTHON_PREFIX}_FRAMEWORK_PATHS})
  1689. else()
  1690. unset (__${_PYTHON_PREFIX}_FRAMEWORK_PATHS)
  1691. endif()
  1692. if (WIN32 AND _${_PYTHON_PREFIX}_FIND_REGISTRY STREQUAL "LAST")
  1693. set (__${_PYTHON_PREFIX}_REGISTRY_PATHS ${_${_PYTHON_PREFIX}_REGISTRY_PATHS})
  1694. else()
  1695. unset (__${_PYTHON_PREFIX}_REGISTRY_PATHS)
  1696. endif()
  1697. # search in all default paths
  1698. find_library (_${_PYTHON_PREFIX}_LIBRARY_RELEASE
  1699. NAMES ${_${_PYTHON_PREFIX}_LIB_NAMES}
  1700. NAMES_PER_DIR
  1701. PATHS ${__${_PYTHON_PREFIX}_FRAMEWORK_PATHS}
  1702. ${__${_PYTHON_PREFIX}_REGISTRY_PATHS}
  1703. PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES})
  1704. if (_${_PYTHON_PREFIX}_LIBRARY_RELEASE)
  1705. break()
  1706. endif()
  1707. endforeach()
  1708. endif()
  1709. endif()
  1710. endif()
  1711. # finalize library version information
  1712. _python_get_version (LIBRARY PREFIX _${_PYTHON_PREFIX}_)
  1713. set (${_PYTHON_PREFIX}_LIBRARY_RELEASE "${_${_PYTHON_PREFIX}_LIBRARY_RELEASE}" CACHE FILEPATH "Path to a library." FORCE)
  1714. if (_${_PYTHON_PREFIX}_LIBRARY_RELEASE AND NOT EXISTS "${_${_PYTHON_PREFIX}_LIBRARY_RELEASE}")
  1715. set_property (CACHE _${_PYTHON_PREFIX}_LIBRARY_RELEASE PROPERTY VALUE "_${_PYTHON_PREFIX}_LIBRARY_RELEASE-NOTFOUND")
  1716. endif()
  1717. set (_${_PYTHON_PREFIX}_HINTS "${${_PYTHON_PREFIX}_ROOT_DIR}" ENV ${_PYTHON_PREFIX}_ROOT_DIR)
  1718. if (WIN32 AND _${_PYTHON_PREFIX}_LIBRARY_RELEASE)
  1719. # search for debug library
  1720. # use release library location as a hint
  1721. _python_get_names (_${_PYTHON_PREFIX}_LIB_NAMES_DEBUG VERSION ${_${_PYTHON_PREFIX}_VERSION} WIN32 DEBUG)
  1722. get_filename_component (_${_PYTHON_PREFIX}_PATH "${_${_PYTHON_PREFIX}_LIBRARY_RELEASE}" DIRECTORY)
  1723. find_library (_${_PYTHON_PREFIX}_LIBRARY_DEBUG
  1724. NAMES ${_${_PYTHON_PREFIX}_LIB_NAMES_DEBUG}
  1725. NAMES_PER_DIR
  1726. HINTS "${_${_PYTHON_PREFIX}_PATH}" ${_${_PYTHON_PREFIX}_HINTS}
  1727. NO_DEFAULT_PATH)
  1728. endif()
  1729. # retrieve runtime libraries
  1730. if (_${_PYTHON_PREFIX}_LIBRARY_RELEASE)
  1731. _python_get_names (_${_PYTHON_PREFIX}_LIB_NAMES VERSION ${_${_PYTHON_PREFIX}_VERSION} WIN32 POSIX LIBRARY)
  1732. get_filename_component (_${_PYTHON_PREFIX}_PATH "${_${_PYTHON_PREFIX}_LIBRARY_RELEASE}" DIRECTORY)
  1733. get_filename_component (_${_PYTHON_PREFIX}_PATH2 "${_${_PYTHON_PREFIX}_PATH}" DIRECTORY)
  1734. _python_find_runtime_library (${_PYTHON_PREFIX}_RUNTIME_LIBRARY_RELEASE
  1735. NAMES ${_${_PYTHON_PREFIX}_LIB_NAMES}
  1736. NAMES_PER_DIR
  1737. HINTS "${_${_PYTHON_PREFIX}_PATH}" "${_${_PYTHON_PREFIX}_PATH2}" ${_${_PYTHON_PREFIX}_HINTS}
  1738. PATH_SUFFIXES bin)
  1739. endif()
  1740. if (_${_PYTHON_PREFIX}_LIBRARY_DEBUG)
  1741. _python_get_names (_${_PYTHON_PREFIX}_LIB_NAMES_DEBUG VERSION ${_${_PYTHON_PREFIX}_VERSION} WIN32 DEBUG)
  1742. get_filename_component (_${_PYTHON_PREFIX}_PATH "${_${_PYTHON_PREFIX}_LIBRARY_DEBUG}" DIRECTORY)
  1743. get_filename_component (_${_PYTHON_PREFIX}_PATH2 "${_${_PYTHON_PREFIX}_PATH}" DIRECTORY)
  1744. _python_find_runtime_library (${_PYTHON_PREFIX}_RUNTIME_LIBRARY_DEBUG
  1745. NAMES ${_${_PYTHON_PREFIX}_LIB_NAMES_DEBUG}
  1746. NAMES_PER_DIR
  1747. HINTS "${_${_PYTHON_PREFIX}_PATH}" "${_${_PYTHON_PREFIX}_PATH2}" ${_${_PYTHON_PREFIX}_HINTS}
  1748. PATH_SUFFIXES bin)
  1749. endif()
  1750. # Don't search for include dir if no library was founded
  1751. if (_${_PYTHON_PREFIX}_LIBRARY_RELEASE AND NOT _${_PYTHON_PREFIX}_INCLUDE_DIR)
  1752. if ((${_PYTHON_PREFIX}_Interpreter_FOUND AND NOT CMAKE_CROSSCOMPILING) OR _${_PYTHON_PREFIX}_CONFIG)
  1753. _python_get_config_var (_${_PYTHON_PREFIX}_INCLUDE_DIRS INCLUDES)
  1754. find_path (_${_PYTHON_PREFIX}_INCLUDE_DIR
  1755. NAMES Python.h
  1756. HINTS ${_${_PYTHON_PREFIX}_INCLUDE_DIRS}
  1757. NO_SYSTEM_ENVIRONMENT_PATH
  1758. NO_CMAKE_SYSTEM_PATH)
  1759. endif()
  1760. # Rely on HINTS and standard paths if interpreter or config tool failed to locate artifacts
  1761. if (NOT _${_PYTHON_PREFIX}_INCLUDE_DIR)
  1762. unset (_${_PYTHON_PREFIX}_VIRTUALENV_PATHS)
  1763. if (_${_PYTHON_PREFIX}_FIND_VIRTUALENV MATCHES "^(FIRST|ONLY)$")
  1764. set (_${_PYTHON_PREFIX}_VIRTUALENV_PATHS ENV VIRTUAL_ENV)
  1765. endif()
  1766. unset (_${_PYTHON_PREFIX}_INCLUDE_HINTS)
  1767. # Use the library's install prefix as a hint
  1768. if (${_${_PYTHON_PREFIX}_LIBRARY_RELEASE} MATCHES "^(.+/Frameworks/Python.framework/Versions/[0-9.]+)")
  1769. list (APPEND _${_PYTHON_PREFIX}_INCLUDE_HINTS "${CMAKE_MATCH_1}")
  1770. elseif (${_${_PYTHON_PREFIX}_LIBRARY_RELEASE} MATCHES "^(.+)/lib(64|32)?/python[0-9.]+/config")
  1771. list (APPEND _${_PYTHON_PREFIX}_INCLUDE_HINTS "${CMAKE_MATCH_1}")
  1772. elseif (DEFINED CMAKE_LIBRARY_ARCHITECTURE AND ${_${_PYTHON_PREFIX}_LIBRARY_RELEASE} MATCHES "^(.+)/lib/${CMAKE_LIBRARY_ARCHITECTURE}")
  1773. list (APPEND _${_PYTHON_PREFIX}_INCLUDE_HINTS "${CMAKE_MATCH_1}")
  1774. else()
  1775. # assume library is in a directory under root
  1776. get_filename_component (_${_PYTHON_PREFIX}_PREFIX "${_${_PYTHON_PREFIX}_LIBRARY_RELEASE}" DIRECTORY)
  1777. get_filename_component (_${_PYTHON_PREFIX}_PREFIX "${_${_PYTHON_PREFIX}_PREFIX}" DIRECTORY)
  1778. list (APPEND _${_PYTHON_PREFIX}_INCLUDE_HINTS "${_${_PYTHON_PREFIX}_PREFIX}")
  1779. endif()
  1780. _python_get_frameworks (_${_PYTHON_PREFIX}_FRAMEWORK_PATHS ${_${_PYTHON_PREFIX}_VERSION})
  1781. _python_get_registries (_${_PYTHON_PREFIX}_REGISTRY_PATHS ${_${_PYTHON_PREFIX}_VERSION})
  1782. _python_get_path_suffixes (_${_PYTHON_PREFIX}_PATH_SUFFIXES VERSION ${_${_PYTHON_PREFIX}_VERSION} INCLUDE)
  1783. if (APPLE AND _${_PYTHON_PREFIX}_FIND_FRAMEWORK STREQUAL "FIRST")
  1784. find_path (_${_PYTHON_PREFIX}_INCLUDE_DIR
  1785. NAMES Python.h
  1786. HINTS ${_${_PYTHON_PREFIX}_INCLUDE_HINTS} ${_${_PYTHON_PREFIX}_HINTS}
  1787. PATHS ${_${_PYTHON_PREFIX}_VIRTUALENV_PATHS}
  1788. ${_${_PYTHON_PREFIX}_FRAMEWORK_PATHS}
  1789. PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES}
  1790. NO_CMAKE_PATH
  1791. NO_CMAKE_ENVIRONMENT_PATH
  1792. NO_SYSTEM_ENVIRONMENT_PATH
  1793. NO_CMAKE_SYSTEM_PATH)
  1794. endif()
  1795. if (WIN32 AND _${_PYTHON_PREFIX}_FIND_REGISTRY STREQUAL "FIRST")
  1796. find_path (_${_PYTHON_PREFIX}_INCLUDE_DIR
  1797. NAMES Python.h
  1798. HINTS ${_${_PYTHON_PREFIX}_INCLUDE_HINTS} ${_${_PYTHON_PREFIX}_HINTS}
  1799. PATHS ${_${_PYTHON_PREFIX}_VIRTUALENV_PATHS}
  1800. ${_${_PYTHON_PREFIX}_REGISTRY_PATHS}
  1801. PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES}
  1802. NO_SYSTEM_ENVIRONMENT_PATH
  1803. NO_CMAKE_SYSTEM_PATH)
  1804. endif()
  1805. if (APPLE AND _${_PYTHON_PREFIX}_FIND_FRAMEWORK STREQUAL "LAST")
  1806. set (__${_PYTHON_PREFIX}_FRAMEWORK_PATHS ${_${_PYTHON_PREFIX}_FRAMEWORK_PATHS})
  1807. else()
  1808. unset (__${_PYTHON_PREFIX}_FRAMEWORK_PATHS)
  1809. endif()
  1810. if (WIN32 AND _${_PYTHON_PREFIX}_FIND_REGISTRY STREQUAL "LAST")
  1811. set (__${_PYTHON_PREFIX}_REGISTRY_PATHS ${_${_PYTHON_PREFIX}_REGISTRY_PATHS})
  1812. else()
  1813. unset (__${_PYTHON_PREFIX}_REGISTRY_PATHS)
  1814. endif()
  1815. find_path (_${_PYTHON_PREFIX}_INCLUDE_DIR
  1816. NAMES Python.h
  1817. HINTS ${_${_PYTHON_PREFIX}_INCLUDE_HINTS} ${_${_PYTHON_PREFIX}_HINTS}
  1818. PATHS ${_${_PYTHON_PREFIX}_VIRTUALENV_PATHS}
  1819. ${__${_PYTHON_PREFIX}_FRAMEWORK_PATHS}
  1820. ${__${_PYTHON_PREFIX}_REGISTRY_PATHS}
  1821. PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES}
  1822. NO_SYSTEM_ENVIRONMENT_PATH
  1823. NO_CMAKE_SYSTEM_PATH)
  1824. endif()
  1825. # search header file in standard locations
  1826. find_path (_${_PYTHON_PREFIX}_INCLUDE_DIR
  1827. NAMES Python.h)
  1828. endif()
  1829. set (${_PYTHON_PREFIX}_INCLUDE_DIRS "${_${_PYTHON_PREFIX}_INCLUDE_DIR}")
  1830. if (_${_PYTHON_PREFIX}_INCLUDE_DIR AND NOT EXISTS "${_${_PYTHON_PREFIX}_INCLUDE_DIR}")
  1831. set_property (CACHE _${_PYTHON_PREFIX}_INCLUDE_DIR PROPERTY VALUE "_${_PYTHON_PREFIX}_INCLUDE_DIR-NOTFOUND")
  1832. endif()
  1833. if (_${_PYTHON_PREFIX}_INCLUDE_DIR)
  1834. # retrieve version from header file
  1835. _python_get_version (INCLUDE PREFIX _${_PYTHON_PREFIX}_INC_)
  1836. # update versioning
  1837. if (_${_PYTHON_PREFIX}_INC_VERSION VERSION_EQUAL ${_${_PYTHON_PREFIX}_VERSION})
  1838. set (_${_PYTHON_PREFIX}_VERSION_PATCH ${_${_PYTHON_PREFIX}_INC_VERSION_PATCH})
  1839. endif()
  1840. endif()
  1841. if (NOT ${_PYTHON_PREFIX}_Interpreter_FOUND AND NOT ${_PYTHON_PREFIX}_Compiler_FOUND)
  1842. # set public version information
  1843. set (${_PYTHON_PREFIX}_VERSION ${_${_PYTHON_PREFIX}_VERSION})
  1844. set (${_PYTHON_PREFIX}_VERSION_MAJOR ${_${_PYTHON_PREFIX}_VERSION_MAJOR})
  1845. set (${_PYTHON_PREFIX}_VERSION_MINOR ${_${_PYTHON_PREFIX}_VERSION_MINOR})
  1846. set (${_PYTHON_PREFIX}_VERSION_PATCH ${_${_PYTHON_PREFIX}_VERSION_PATCH})
  1847. endif()
  1848. # define public variables
  1849. set (${_PYTHON_PREFIX}_LIBRARY_DEBUG "${_${_PYTHON_PREFIX}_LIBRARY_DEBUG}" CACHE FILEPATH "Path to a library." FORCE)
  1850. include (${CMAKE_CURRENT_LIST_DIR}/../SelectLibraryConfigurations.cmake)
  1851. select_library_configurations (${_PYTHON_PREFIX})
  1852. if (${_PYTHON_PREFIX}_RUNTIME_LIBRARY_RELEASE)
  1853. set (${_PYTHON_PREFIX}_RUNTIME_LIBRARY "${${_PYTHON_PREFIX}_RUNTIME_LIBRARY_RELEASE}")
  1854. elseif (${_PYTHON_PREFIX}_RUNTIME_LIBRARY_DEBUG)
  1855. set (${_PYTHON_PREFIX}_RUNTIME_LIBRARY "${${_PYTHON_PREFIX}_RUNTIME_LIBRARY_DEBUG}")
  1856. else()
  1857. set (${_PYTHON_PREFIX}_RUNTIME_LIBRARY "${_PYTHON_PREFIX}_RUNTIME_LIBRARY-NOTFOUND")
  1858. endif()
  1859. _python_set_library_dirs (${_PYTHON_PREFIX}_LIBRARY_DIRS
  1860. ${_PYTHON_PREFIX}_LIBRARY_RELEASE ${_PYTHON_PREFIX}_LIBRARY_DEBUG)
  1861. if (UNIX)
  1862. if (${_PYTHON_PREFIX}_LIBRARY_RELEASE MATCHES "${CMAKE_SHARED_LIBRARY_SUFFIX}$")
  1863. set (${_PYTHON_PREFIX}_RUNTIME_LIBRARY_DIRS ${${_PYTHON_PREFIX}_LIBRARY_DIRS})
  1864. endif()
  1865. else()
  1866. _python_set_library_dirs (${_PYTHON_PREFIX}_RUNTIME_LIBRARY_DIRS
  1867. ${_PYTHON_PREFIX}_RUNTIME_LIBRARY_RELEASE ${_PYTHON_PREFIX}_RUNTIME_LIBRARY_DEBUG)
  1868. endif()
  1869. if (_${_PYTHON_PREFIX}_LIBRARY_RELEASE AND _${_PYTHON_PREFIX}_INCLUDE_DIR)
  1870. if (${_PYTHON_PREFIX}_Interpreter_FOUND OR ${_PYTHON_PREFIX}_Compiler_FOUND)
  1871. # development environment must be compatible with interpreter/compiler
  1872. if (${_${_PYTHON_PREFIX}_VERSION_MAJOR}.${_${_PYTHON_PREFIX}_VERSION_MINOR} VERSION_EQUAL ${${_PYTHON_PREFIX}_VERSION_MAJOR}.${${_PYTHON_PREFIX}_VERSION_MINOR}
  1873. AND ${_${_PYTHON_PREFIX}_INC_VERSION_MAJOR}.${_${_PYTHON_PREFIX}_INC_VERSION_MINOR} VERSION_EQUAL ${_${_PYTHON_PREFIX}_VERSION_MAJOR}.${_${_PYTHON_PREFIX}_VERSION_MINOR})
  1874. set (${_PYTHON_PREFIX}_Development_FOUND TRUE)
  1875. endif()
  1876. elseif (${_PYTHON_PREFIX}_VERSION_MAJOR VERSION_EQUAL _${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR
  1877. AND ${_${_PYTHON_PREFIX}_INC_VERSION_MAJOR}.${_${_PYTHON_PREFIX}_INC_VERSION_MINOR} VERSION_EQUAL ${_${_PYTHON_PREFIX}_VERSION_MAJOR}.${_${_PYTHON_PREFIX}_VERSION_MINOR})
  1878. set (${_PYTHON_PREFIX}_Development_FOUND TRUE)
  1879. endif()
  1880. if (DEFINED _${_PYTHON_PREFIX}_FIND_ABI AND
  1881. (NOT _${_PYTHON_PREFIX}_ABI IN_LIST _${_PYTHON_PREFIX}_ABIFLAGS
  1882. OR NOT _${_PYTHON_PREFIX}_INC_ABI IN_LIST _${_PYTHON_PREFIX}_ABIFLAGS))
  1883. set (${_PYTHON_PREFIX}_Development_FOUND FALSE)
  1884. endif()
  1885. endif()
  1886. if (${_PYTHON_PREFIX}_Development_FOUND)
  1887. # compute and save development signature
  1888. string (MD5 __${_PYTHON_PREFIX}_DEVELOPMENT_SIGNATURE "${_${_PYTHON_PREFIX}_SIGNATURE}:${_${_PYTHON_PREFIX}_LIBRARY_RELEASE}:${_${_PYTHON_PREFIX}_INCLUDE_DIR}")
  1889. set (_${_PYTHON_PREFIX}_DEVELOPMENT_SIGNATURE "${__${_PYTHON_PREFIX}_DEVELOPMENT_SIGNATURE}" CACHE INTERNAL "")
  1890. else()
  1891. unset (_${_PYTHON_PREFIX}_DEVELOPMENT_SIGNATURE CACHE)
  1892. endif()
  1893. # Restore the original find library ordering
  1894. if (DEFINED _${_PYTHON_PREFIX}_CMAKE_FIND_LIBRARY_SUFFIXES)
  1895. set (CMAKE_FIND_LIBRARY_SUFFIXES ${_${_PYTHON_PREFIX}_CMAKE_FIND_LIBRARY_SUFFIXES})
  1896. endif()
  1897. mark_as_advanced (_${_PYTHON_PREFIX}_LIBRARY_RELEASE
  1898. _${_PYTHON_PREFIX}_LIBRARY_DEBUG
  1899. ${_PYTHON_PREFIX}_RUNTIME_LIBRARY_RELEASE
  1900. ${_PYTHON_PREFIX}_RUNTIME_LIBRARY_DEBUG
  1901. _${_PYTHON_PREFIX}_INCLUDE_DIR
  1902. _${_PYTHON_PREFIX}_DEVELOPMENT_SIGNATURE)
  1903. endif()
  1904. if ("NumPy" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS AND ${_PYTHON_PREFIX}_Interpreter_FOUND)
  1905. list (APPEND _${_PYTHON_PREFIX}_CACHED_VARS _${_PYTHON_PREFIX}_NumPy_INCLUDE_DIR)
  1906. if (${_PYTHON_PREFIX}_FIND_REQUIRED_NumPy)
  1907. list (APPEND _${_PYTHON_PREFIX}_REQUIRED_VARS ${_PYTHON_PREFIX}_NumPy_INCLUDE_DIRS)
  1908. endif()
  1909. if (DEFINED ${_PYTHON_PREFIX}_NumPy_INCLUDE_DIR
  1910. AND IS_ABSOLUTE "${${_PYTHON_PREFIX}_NumPy_INCLUDE_DIR}")
  1911. set (_${_PYTHON_PREFIX}_NumPy_INCLUDE_DIR "${${_PYTHON_PREFIX}_NumPy_INCLUDE_DIR}" CACHE INTERNAL "")
  1912. elseif (DEFINED _${_PYTHON_PREFIX}_NumPy_INCLUDE_DIR)
  1913. # compute numpy signature. Depends on interpreter and development signatures
  1914. string (MD5 __${_PYTHON_PREFIX}_NUMPY_SIGNATURE "${_${_PYTHON_PREFIX}_INTERPRETER_SIGNATURE}:${_${_PYTHON_PREFIX}_DEVELOPMENT_SIGNATURE}:${_${_PYTHON_PREFIX}_NumPy_INCLUDE_DIR}")
  1915. if (NOT __${_PYTHON_PREFIX}_NUMPY_SIGNATURE STREQUAL _${_PYTHON_PREFIX}_NUMPY_SIGNATURE
  1916. OR NOT EXISTS "${_${_PYTHON_PREFIX}_NumPy_INCLUDE_DIR}")
  1917. unset (_${_PYTHON_PREFIX}_NumPy_INCLUDE_DIR CACHE)
  1918. unset (_${_PYTHON_PREFIX}_NUMPY_SIGNATURE CACHE)
  1919. endif()
  1920. endif()
  1921. if (NOT _${_PYTHON_PREFIX}_NumPy_INCLUDE_DIR)
  1922. execute_process(
  1923. COMMAND "${${_PYTHON_PREFIX}_EXECUTABLE}" -c
  1924. "from __future__ import print_function\ntry: import numpy; print(numpy.get_include(), end='')\nexcept:pass\n"
  1925. RESULT_VARIABLE _${_PYTHON_PREFIX}_RESULT
  1926. OUTPUT_VARIABLE _${_PYTHON_PREFIX}_NumPy_PATH
  1927. ERROR_QUIET
  1928. OUTPUT_STRIP_TRAILING_WHITESPACE)
  1929. if (NOT _${_PYTHON_PREFIX}_RESULT)
  1930. find_path (_${_PYTHON_PREFIX}_NumPy_INCLUDE_DIR
  1931. NAMES "numpy/arrayobject.h" "numpy/numpyconfig.h"
  1932. HINTS "${_${_PYTHON_PREFIX}_NumPy_PATH}"
  1933. NO_DEFAULT_PATH)
  1934. endif()
  1935. endif()
  1936. set (${_PYTHON_PREFIX}_NumPy_INCLUDE_DIRS "${_${_PYTHON_PREFIX}_NumPy_INCLUDE_DIR}")
  1937. if(_${_PYTHON_PREFIX}_NumPy_INCLUDE_DIR AND NOT EXISTS "${_${_PYTHON_PREFIX}_NumPy_INCLUDE_DIR}")
  1938. set_property (CACHE _${_PYTHON_PREFIX}_NumPy_INCLUDE_DIR PROPERTY VALUE "_${_PYTHON_PREFIX}_NumPy_INCLUDE_DIR-NOTFOUND")
  1939. endif()
  1940. if (_${_PYTHON_PREFIX}_NumPy_INCLUDE_DIR)
  1941. execute_process (
  1942. COMMAND "${${_PYTHON_PREFIX}_EXECUTABLE}" -c
  1943. "from __future__ import print_function\ntry: import numpy; print(numpy.__version__, end='')\nexcept:pass\n"
  1944. RESULT_VARIABLE _${_PYTHON_PREFIX}_RESULT
  1945. OUTPUT_VARIABLE _${_PYTHON_PREFIX}_NumPy_VERSION)
  1946. if (NOT _${_PYTHON_PREFIX}_RESULT)
  1947. set (${_PYTHON_PREFIX}_NumPy_VERSION "${_${_PYTHON_PREFIX}_NumPy_VERSION}")
  1948. else()
  1949. unset (${_PYTHON_PREFIX}_NumPy_VERSION)
  1950. endif()
  1951. # final step: set NumPy founded only if Development component is founded as well
  1952. set(${_PYTHON_PREFIX}_NumPy_FOUND ${${_PYTHON_PREFIX}_Development_FOUND})
  1953. else()
  1954. set (${_PYTHON_PREFIX}_NumPy_FOUND FALSE)
  1955. endif()
  1956. if (${_PYTHON_PREFIX}_NumPy_FOUND)
  1957. # compute and save numpy signature
  1958. string (MD5 __${_PYTHON_PREFIX}_NUMPY_SIGNATURE "${_${_PYTHON_PREFIX}_INTERPRETER_SIGNATURE}:${_${_PYTHON_PREFIX}_DEVELOPMENT_SIGNATURE}:${${_PYTHON_PREFIX}_NumPyINCLUDE_DIR}")
  1959. set (_${_PYTHON_PREFIX}_NUMPY_SIGNATURE "${__${_PYTHON_PREFIX}_NUMPY_SIGNATURE}" CACHE INTERNAL "")
  1960. else()
  1961. unset (_${_PYTHON_PREFIX}_NUMPY_SIGNATURE CACHE)
  1962. endif()
  1963. mark_as_advanced (_${_PYTHON_PREFIX}_NumPy_INCLUDE_DIR)
  1964. endif()
  1965. # final validation
  1966. if (${_PYTHON_PREFIX}_VERSION_MAJOR AND
  1967. NOT ${_PYTHON_PREFIX}_VERSION_MAJOR VERSION_EQUAL _${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR)
  1968. _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}\"")
  1969. endif()
  1970. include (${CMAKE_CURRENT_LIST_DIR}/../FindPackageHandleStandardArgs.cmake)
  1971. find_package_handle_standard_args (${_PYTHON_PREFIX}
  1972. REQUIRED_VARS ${_${_PYTHON_PREFIX}_REQUIRED_VARS}
  1973. VERSION_VAR ${_PYTHON_PREFIX}_VERSION
  1974. HANDLE_COMPONENTS)
  1975. # Create imported targets and helper functions
  1976. if(_${_PYTHON_PREFIX}_CMAKE_ROLE STREQUAL "PROJECT")
  1977. if ("Interpreter" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS
  1978. AND ${_PYTHON_PREFIX}_Interpreter_FOUND
  1979. AND NOT TARGET ${_PYTHON_PREFIX}::Interpreter)
  1980. add_executable (${_PYTHON_PREFIX}::Interpreter IMPORTED)
  1981. set_property (TARGET ${_PYTHON_PREFIX}::Interpreter
  1982. PROPERTY IMPORTED_LOCATION "${${_PYTHON_PREFIX}_EXECUTABLE}")
  1983. endif()
  1984. if ("Compiler" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS
  1985. AND ${_PYTHON_PREFIX}_Compiler_FOUND
  1986. AND NOT TARGET ${_PYTHON_PREFIX}::Compiler)
  1987. add_executable (${_PYTHON_PREFIX}::Compiler IMPORTED)
  1988. set_property (TARGET ${_PYTHON_PREFIX}::Compiler
  1989. PROPERTY IMPORTED_LOCATION "${${_PYTHON_PREFIX}_COMPILER}")
  1990. endif()
  1991. if ("Development" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS
  1992. AND ${_PYTHON_PREFIX}_Development_FOUND)
  1993. macro (__PYTHON_IMPORT_LIBRARY __name)
  1994. if (${_PYTHON_PREFIX}_LIBRARY_RELEASE MATCHES "${CMAKE_SHARED_LIBRARY_SUFFIX}$"
  1995. OR ${_PYTHON_PREFIX}_RUNTIME_LIBRARY_RELEASE)
  1996. set (_${_PYTHON_PREFIX}_LIBRARY_TYPE SHARED)
  1997. else()
  1998. set (_${_PYTHON_PREFIX}_LIBRARY_TYPE STATIC)
  1999. endif()
  2000. if (NOT TARGET ${__name})
  2001. add_library (${__name} ${_${_PYTHON_PREFIX}_LIBRARY_TYPE} IMPORTED)
  2002. endif()
  2003. set_property (TARGET ${__name}
  2004. PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${${_PYTHON_PREFIX}_INCLUDE_DIRS}")
  2005. if (${_PYTHON_PREFIX}_LIBRARY_RELEASE AND ${_PYTHON_PREFIX}_RUNTIME_LIBRARY_RELEASE)
  2006. # System manage shared libraries in two parts: import and runtime
  2007. if (${_PYTHON_PREFIX}_LIBRARY_RELEASE AND ${_PYTHON_PREFIX}_LIBRARY_DEBUG)
  2008. set_property (TARGET ${__name} PROPERTY IMPORTED_CONFIGURATIONS RELEASE DEBUG)
  2009. set_target_properties (${__name}
  2010. PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "C"
  2011. IMPORTED_IMPLIB_RELEASE "${${_PYTHON_PREFIX}_LIBRARY_RELEASE}"
  2012. IMPORTED_LOCATION_RELEASE "${${_PYTHON_PREFIX}_RUNTIME_LIBRARY_RELEASE}")
  2013. set_target_properties (${__name}
  2014. PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG "C"
  2015. IMPORTED_IMPLIB_DEBUG "${${_PYTHON_PREFIX}_LIBRARY_DEBUG}"
  2016. IMPORTED_LOCATION_DEBUG "${${_PYTHON_PREFIX}_RUNTIME_LIBRARY_DEBUG}")
  2017. else()
  2018. set_target_properties (${__name}
  2019. PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES "C"
  2020. IMPORTED_IMPLIB "${${_PYTHON_PREFIX}_LIBRARY}"
  2021. IMPORTED_LOCATION "${${_PYTHON_PREFIX}_RUNTIME_LIBRARY}")
  2022. endif()
  2023. else()
  2024. if (${_PYTHON_PREFIX}_LIBRARY_RELEASE AND ${_PYTHON_PREFIX}_LIBRARY_DEBUG)
  2025. set_property (TARGET ${__name} PROPERTY IMPORTED_CONFIGURATIONS RELEASE DEBUG)
  2026. set_target_properties (${__name}
  2027. PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "C"
  2028. IMPORTED_LOCATION_RELEASE "${${_PYTHON_PREFIX}_LIBRARY_RELEASE}")
  2029. set_target_properties (${__name}
  2030. PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG "C"
  2031. IMPORTED_LOCATION_DEBUG "${${_PYTHON_PREFIX}_LIBRARY_DEBUG}")
  2032. else()
  2033. set_target_properties (${__name}
  2034. PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES "C"
  2035. IMPORTED_LOCATION "${${_PYTHON_PREFIX}_LIBRARY}")
  2036. endif()
  2037. endif()
  2038. if (_${_PYTHON_PREFIX}_LIBRARY_TYPE STREQUAL "STATIC")
  2039. # extend link information with dependent libraries
  2040. _python_get_config_var (_${_PYTHON_PREFIX}_LINK_LIBRARIES LIBS)
  2041. if (_${_PYTHON_PREFIX}_LINK_LIBRARIES)
  2042. set_property (TARGET ${__name}
  2043. PROPERTY INTERFACE_LINK_LIBRARIES ${_${_PYTHON_PREFIX}_LINK_LIBRARIES})
  2044. endif()
  2045. endif()
  2046. endmacro()
  2047. __python_import_library (${_PYTHON_PREFIX}::Python)
  2048. if (CMAKE_SYSTEM_NAME MATCHES "^(Windows.*|CYGWIN|MSYS)$")
  2049. # On Windows/CYGWIN/MSYS, Python::Module is the same as Python::Python
  2050. # but ALIAS cannot be used because the imported library is not GLOBAL.
  2051. __python_import_library (${_PYTHON_PREFIX}::Module)
  2052. else()
  2053. if (NOT TARGET ${_PYTHON_PREFIX}::Module )
  2054. add_library (${_PYTHON_PREFIX}::Module INTERFACE IMPORTED)
  2055. endif()
  2056. set_property (TARGET ${_PYTHON_PREFIX}::Module
  2057. PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${${_PYTHON_PREFIX}_INCLUDE_DIRS}")
  2058. # When available, enforce shared library generation with undefined symbols
  2059. if (APPLE)
  2060. set_property (TARGET ${_PYTHON_PREFIX}::Module
  2061. PROPERTY INTERFACE_LINK_OPTIONS "LINKER:-undefined,dynamic_lookup")
  2062. endif()
  2063. if (CMAKE_SYSTEM_NAME STREQUAL "SunOS")
  2064. set_property (TARGET ${_PYTHON_PREFIX}::Module
  2065. PROPERTY INTERFACE_LINK_OPTIONS "LINKER:-z,nodefs")
  2066. endif()
  2067. if (CMAKE_SYSTEM_NAME STREQUAL "AIX")
  2068. set_property (TARGET ${_PYTHON_PREFIX}::Module
  2069. PROPERTY INTERFACE_LINK_OPTIONS "LINKER:-b,erok")
  2070. endif()
  2071. endif()
  2072. #
  2073. # PYTHON_ADD_LIBRARY (<name> [STATIC|SHARED|MODULE] src1 src2 ... srcN)
  2074. # It is used to build modules for python.
  2075. #
  2076. function (__${_PYTHON_PREFIX}_ADD_LIBRARY prefix name)
  2077. cmake_parse_arguments (PARSE_ARGV 2 PYTHON_ADD_LIBRARY
  2078. "STATIC;SHARED;MODULE" "" "")
  2079. unset (type)
  2080. if (NOT (PYTHON_ADD_LIBRARY_STATIC
  2081. OR PYTHON_ADD_LIBRARY_SHARED
  2082. OR PYTHON_ADD_LIBRARY_MODULE))
  2083. set (type MODULE)
  2084. endif()
  2085. add_library (${name} ${type} ${ARGN})
  2086. get_property (type TARGET ${name} PROPERTY TYPE)
  2087. if (type STREQUAL "MODULE_LIBRARY")
  2088. target_link_libraries (${name} PRIVATE ${prefix}::Module)
  2089. # customize library name to follow module name rules
  2090. set_property (TARGET ${name} PROPERTY PREFIX "")
  2091. if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
  2092. set_property (TARGET ${name} PROPERTY SUFFIX ".pyd")
  2093. endif()
  2094. else()
  2095. target_link_libraries (${name} PRIVATE ${prefix}::Python)
  2096. endif()
  2097. endfunction()
  2098. endif()
  2099. if ("NumPy" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS AND ${_PYTHON_PREFIX}_NumPy_FOUND
  2100. AND NOT TARGET ${_PYTHON_PREFIX}::NumPy AND TARGET ${_PYTHON_PREFIX}::Module)
  2101. add_library (${_PYTHON_PREFIX}::NumPy INTERFACE IMPORTED)
  2102. set_property (TARGET ${_PYTHON_PREFIX}::NumPy
  2103. PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${${_PYTHON_PREFIX}_NumPy_INCLUDE_DIRS}")
  2104. target_link_libraries (${_PYTHON_PREFIX}::NumPy INTERFACE ${_PYTHON_PREFIX}::Module)
  2105. endif()
  2106. endif()
  2107. # final clean-up
  2108. # Restore CMAKE_FIND_APPBUNDLE
  2109. if (DEFINED _${_PYTHON_PREFIX}_CMAKE_FIND_APPBUNDLE)
  2110. set (CMAKE_FIND_APPBUNDLE ${_${_PYTHON_PREFIX}_CMAKE_FIND_APPBUNDLE})
  2111. unset (_${_PYTHON_PREFIX}_CMAKE_FIND_APPBUNDLE)
  2112. else()
  2113. unset (CMAKE_FIND_APPBUNDLE)
  2114. endif()
  2115. # Restore CMAKE_FIND_FRAMEWORK
  2116. if (DEFINED _${_PYTHON_PREFIX}_CMAKE_FIND_FRAMEWORK)
  2117. set (CMAKE_FIND_FRAMEWORK ${_${_PYTHON_PREFIX}_CMAKE_FIND_FRAMEWORK})
  2118. unset (_${_PYTHON_PREFIX}_CMAKE_FIND_FRAMEWORK)
  2119. else()
  2120. unset (CMAKE_FIND_FRAMEWORK)
  2121. endif()
  2122. unset (_${_PYTHON_PREFIX}_CONFIG CACHE)