FindPythonLibs.cmake 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file Copyright.txt or https://cmake.org/licensing for details.
  3. #[=======================================================================[.rst:
  4. FindPythonLibs
  5. --------------
  6. .. versionchanged:: 3.27
  7. This module is available only if policy :policy:`CMP0148` is not set to ``NEW``.
  8. .. deprecated:: 3.12
  9. Use :module:`FindPython3`, :module:`FindPython2` or :module:`FindPython` instead.
  10. Find python libraries
  11. This module finds if Python is installed and determines where the
  12. include files and libraries are. It also determines what the name of
  13. the library is. This code sets the following variables:
  14. ::
  15. PYTHONLIBS_FOUND - have the Python libs been found
  16. PYTHON_LIBRARIES - path to the python library
  17. PYTHON_INCLUDE_PATH - path to where Python.h is found (deprecated)
  18. PYTHON_INCLUDE_DIRS - path to where Python.h is found
  19. PYTHON_DEBUG_LIBRARIES - path to the debug library (deprecated)
  20. PYTHONLIBS_VERSION_STRING - version of the Python libs found (since CMake 2.8.8)
  21. The Python_ADDITIONAL_VERSIONS variable can be used to specify a list
  22. of version numbers that should be taken into account when searching
  23. for Python. You need to set this variable before calling
  24. find_package(PythonLibs).
  25. If you'd like to specify the installation of Python to use, you should
  26. modify the following cache variables:
  27. ::
  28. PYTHON_LIBRARY - path to the python library
  29. PYTHON_INCLUDE_DIR - path to where Python.h is found
  30. If calling both ``find_package(PythonInterp)`` and
  31. ``find_package(PythonLibs)``, call ``find_package(PythonInterp)`` first to
  32. get the currently active Python version by default with a consistent version
  33. of PYTHON_LIBRARIES.
  34. #]=======================================================================]
  35. cmake_policy(PUSH)
  36. cmake_policy(SET CMP0159 NEW) # file(STRINGS) with REGEX updates CMAKE_MATCH_<n>
  37. cmake_policy(GET CMP0148 _FindPythonLibs_CMP0148)
  38. if(_FindPythonLibs_CMP0148 STREQUAL "NEW")
  39. message(FATAL_ERROR "The FindPythonLibs module has been removed by policy CMP0148.")
  40. endif()
  41. if(_FindPythonLibs_testing)
  42. set(_FindPythonLibs_included TRUE)
  43. cmake_policy(POP)
  44. return()
  45. endif()
  46. # Use the executable's path as a hint
  47. set(_Python_LIBRARY_PATH_HINT)
  48. if(IS_ABSOLUTE "${PYTHON_EXECUTABLE}")
  49. if(WIN32)
  50. get_filename_component(_Python_PREFIX "${PYTHON_EXECUTABLE}" PATH)
  51. if(_Python_PREFIX)
  52. set(_Python_LIBRARY_PATH_HINT ${_Python_PREFIX}/libs)
  53. endif()
  54. unset(_Python_PREFIX)
  55. else()
  56. get_filename_component(_Python_PREFIX "${PYTHON_EXECUTABLE}" PATH)
  57. get_filename_component(_Python_PREFIX "${_Python_PREFIX}" PATH)
  58. if(_Python_PREFIX)
  59. set(_Python_LIBRARY_PATH_HINT ${_Python_PREFIX}/lib)
  60. endif()
  61. unset(_Python_PREFIX)
  62. endif()
  63. endif()
  64. block(SCOPE_FOR POLICIES)
  65. cmake_policy(SET CMP0173 OLD)
  66. include(${CMAKE_CURRENT_LIST_DIR}/CMakeFindFrameworks.cmake)
  67. endblock()
  68. # Search for the python framework on Apple.
  69. CMAKE_FIND_FRAMEWORKS(Python)
  70. # Save CMAKE_FIND_FRAMEWORK
  71. if(DEFINED CMAKE_FIND_FRAMEWORK)
  72. set(_PythonLibs_CMAKE_FIND_FRAMEWORK ${CMAKE_FIND_FRAMEWORK})
  73. else()
  74. unset(_PythonLibs_CMAKE_FIND_FRAMEWORK)
  75. endif()
  76. # To avoid picking up the system Python.h pre-maturely.
  77. set(CMAKE_FIND_FRAMEWORK LAST)
  78. set(_PYTHON1_VERSIONS 1.6 1.5)
  79. set(_PYTHON2_VERSIONS 2.7 2.6 2.5 2.4 2.3 2.2 2.1 2.0)
  80. set(_PYTHON3_VERSIONS 3.14 3.13 3.12 3.11 3.10 3.9 3.8 3.7 3.6 3.5 3.4 3.3 3.2 3.1 3.0)
  81. if(PythonLibs_FIND_VERSION)
  82. if(PythonLibs_FIND_VERSION_COUNT GREATER 1)
  83. set(_PYTHON_FIND_MAJ_MIN "${PythonLibs_FIND_VERSION_MAJOR}.${PythonLibs_FIND_VERSION_MINOR}")
  84. unset(_PYTHON_FIND_OTHER_VERSIONS)
  85. if(PythonLibs_FIND_VERSION_EXACT)
  86. if(_PYTHON_FIND_MAJ_MIN STREQUAL PythonLibs_FIND_VERSION)
  87. set(_PYTHON_FIND_OTHER_VERSIONS "${PythonLibs_FIND_VERSION}")
  88. else()
  89. set(_PYTHON_FIND_OTHER_VERSIONS "${PythonLibs_FIND_VERSION}" "${_PYTHON_FIND_MAJ_MIN}")
  90. endif()
  91. else()
  92. foreach(_PYTHON_V ${_PYTHON${PythonLibs_FIND_VERSION_MAJOR}_VERSIONS})
  93. if(NOT _PYTHON_V VERSION_LESS _PYTHON_FIND_MAJ_MIN)
  94. list(APPEND _PYTHON_FIND_OTHER_VERSIONS ${_PYTHON_V})
  95. endif()
  96. endforeach()
  97. endif()
  98. unset(_PYTHON_FIND_MAJ_MIN)
  99. else()
  100. set(_PYTHON_FIND_OTHER_VERSIONS ${_PYTHON${PythonLibs_FIND_VERSION_MAJOR}_VERSIONS})
  101. endif()
  102. else()
  103. set(_PYTHON_FIND_OTHER_VERSIONS ${_PYTHON3_VERSIONS} ${_PYTHON2_VERSIONS} ${_PYTHON1_VERSIONS})
  104. endif()
  105. # Set up the versions we know about, in the order we will search. Always add
  106. # the user supplied additional versions to the front.
  107. # If FindPythonInterp has already found the major and minor version,
  108. # insert that version between the user supplied versions and the stock
  109. # version list.
  110. set(_Python_VERSIONS ${Python_ADDITIONAL_VERSIONS})
  111. if(DEFINED PYTHON_VERSION_MAJOR AND DEFINED PYTHON_VERSION_MINOR)
  112. list(APPEND _Python_VERSIONS ${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR})
  113. endif()
  114. list(APPEND _Python_VERSIONS ${_PYTHON_FIND_OTHER_VERSIONS})
  115. unset(_PYTHON_FIND_OTHER_VERSIONS)
  116. unset(_PYTHON1_VERSIONS)
  117. unset(_PYTHON2_VERSIONS)
  118. unset(_PYTHON3_VERSIONS)
  119. # Python distribution: define which architectures can be used
  120. if (CMAKE_SIZEOF_VOID_P)
  121. # In this case, search only for 64bit or 32bit
  122. math (EXPR _PYTHON_ARCH "${CMAKE_SIZEOF_VOID_P} * 8")
  123. set (_PYTHON_ARCH2 _PYTHON_PREFIX_ARCH})
  124. else()
  125. if (PYTHON_EXECUTABLE)
  126. # determine interpreter architecture
  127. execute_process (COMMAND "${PYTHON_EXECUTABLE}" -c "import sys; print(sys.maxsize > 2**32)"
  128. RESULT_VARIABLE _PYTHON_RESULT
  129. OUTPUT_VARIABLE _PYTHON_IS64BIT
  130. ERROR_VARIABLE _PYTHON_IS64BIT)
  131. if (NOT _PYTHON_RESULT)
  132. if (_PYTHON_IS64BIT)
  133. set (_PYTHON_ARCH 64)
  134. set (_PYTHON_ARCH2 64)
  135. else()
  136. set (_PYTHON_ARCH 32)
  137. set (_PYTHON_ARCH2 32)
  138. endif()
  139. endif()
  140. else()
  141. # architecture unknown, search for both 64bit and 32bit
  142. set (_PYTHON_ARCH 64)
  143. set (_PYTHON_ARCH2 32)
  144. endif()
  145. endif()
  146. foreach(_CURRENT_VERSION ${_Python_VERSIONS})
  147. string(REPLACE "." "" _CURRENT_VERSION_NO_DOTS ${_CURRENT_VERSION})
  148. if(WIN32)
  149. find_library(PYTHON_DEBUG_LIBRARY
  150. NAMES python${_CURRENT_VERSION_NO_DOTS}_d python
  151. NAMES_PER_DIR
  152. HINTS ${_Python_LIBRARY_PATH_HINT}
  153. PATHS
  154. [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}\\InstallPath]/libs/Debug
  155. [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}-${_PYTHON_ARCH}\\InstallPath]/libs/Debug
  156. [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}-${_PYTHON_ARCH2}\\InstallPath]/libs/Debug
  157. [HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}\\InstallPath]/libs/Debug
  158. [HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}-${_PYTHON_ARCH}\\InstallPath]/libs/Debug
  159. [HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}-${_PYTHON_ARCH2}\\InstallPath]/libs/Debug
  160. [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}\\InstallPath]/libs
  161. [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}-${_PYTHON_ARCH}\\InstallPath]/libs
  162. [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}-${_PYTHON_ARCH2}\\InstallPath]/libs
  163. [HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}\\InstallPath]/libs
  164. [HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}-${_PYTHON_ARCH}\\InstallPath]/libs
  165. [HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}-${_PYTHON_ARCH2}\\InstallPath]/libs
  166. )
  167. endif()
  168. set(PYTHON_FRAMEWORK_LIBRARIES)
  169. if(Python_FRAMEWORKS AND NOT PYTHON_LIBRARY)
  170. foreach(dir ${Python_FRAMEWORKS})
  171. list(APPEND PYTHON_FRAMEWORK_LIBRARIES
  172. ${dir}/Versions/${_CURRENT_VERSION}/lib)
  173. endforeach()
  174. endif()
  175. find_library(PYTHON_LIBRARY
  176. NAMES
  177. python${_CURRENT_VERSION_NO_DOTS}
  178. python${_CURRENT_VERSION}mu
  179. python${_CURRENT_VERSION}m
  180. python${_CURRENT_VERSION}u
  181. python${_CURRENT_VERSION}
  182. NAMES_PER_DIR
  183. HINTS
  184. ${_Python_LIBRARY_PATH_HINT}
  185. PATHS
  186. ${PYTHON_FRAMEWORK_LIBRARIES}
  187. [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}\\InstallPath]/libs
  188. [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}-${_PYTHON_ARCH}\\InstallPath]/libs
  189. [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}-${_PYTHON_ARCH2}\\InstallPath]/libs
  190. [HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}\\InstallPath]/libs
  191. [HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}-${_PYTHON_ARCH}\\InstallPath]/libs
  192. [HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}-${_PYTHON_ARCH2}\\InstallPath]/libs
  193. )
  194. # Look for the static library in the Python config directory
  195. find_library(PYTHON_LIBRARY
  196. NAMES python${_CURRENT_VERSION_NO_DOTS} python${_CURRENT_VERSION}
  197. NAMES_PER_DIR
  198. # This is where the static library is usually located
  199. PATH_SUFFIXES python${_CURRENT_VERSION}/config
  200. )
  201. # Don't search for include dir until library location is known
  202. if(PYTHON_LIBRARY)
  203. # Use the library's install prefix as a hint
  204. set(_Python_INCLUDE_PATH_HINT)
  205. # PYTHON_LIBRARY may contain a list because of SelectLibraryConfigurations
  206. # which may have been run previously. If it is the case, the list can be:
  207. # optimized;<FILEPATH_TO_RELEASE_LIBRARY>;debug;<FILEPATH_TO_DEBUG_LIBRARY>
  208. foreach(lib ${PYTHON_LIBRARY} ${PYTHON_DEBUG_LIBRARY})
  209. if(IS_ABSOLUTE "${lib}")
  210. get_filename_component(_Python_PREFIX "${lib}" PATH)
  211. get_filename_component(_Python_PREFIX "${_Python_PREFIX}" PATH)
  212. if(_Python_PREFIX)
  213. list(APPEND _Python_INCLUDE_PATH_HINT ${_Python_PREFIX}/include)
  214. endif()
  215. unset(_Python_PREFIX)
  216. endif()
  217. endforeach()
  218. # Add framework directories to the search paths
  219. set(PYTHON_FRAMEWORK_INCLUDES)
  220. if(Python_FRAMEWORKS AND NOT PYTHON_INCLUDE_DIR)
  221. foreach(dir ${Python_FRAMEWORKS})
  222. list(APPEND PYTHON_FRAMEWORK_INCLUDES
  223. ${dir}/Versions/${_CURRENT_VERSION}/include)
  224. endforeach()
  225. endif()
  226. find_path(PYTHON_INCLUDE_DIR
  227. NAMES Python.h
  228. HINTS
  229. ${_Python_INCLUDE_PATH_HINT}
  230. PATHS
  231. ${PYTHON_FRAMEWORK_INCLUDES}
  232. [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}\\InstallPath]/include
  233. [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}-${_PYTHON_ARCH}\\InstallPath]/include
  234. [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}-${_PYTHON_ARCH2}\\InstallPath]/include
  235. [HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}\\InstallPath]/include
  236. [HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}-${_PYTHON_ARCH}\\InstallPath]/include
  237. [HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}-${_PYTHON_ARCH2}\\InstallPath]/include
  238. PATH_SUFFIXES
  239. python${_CURRENT_VERSION}mu
  240. python${_CURRENT_VERSION}m
  241. python${_CURRENT_VERSION}u
  242. python${_CURRENT_VERSION}
  243. )
  244. endif()
  245. # For backward compatibility, set PYTHON_INCLUDE_PATH.
  246. set(PYTHON_INCLUDE_PATH "${PYTHON_INCLUDE_DIR}")
  247. if(PYTHON_INCLUDE_DIR AND EXISTS "${PYTHON_INCLUDE_DIR}/patchlevel.h")
  248. file(STRINGS "${PYTHON_INCLUDE_DIR}/patchlevel.h" python_version_str
  249. REGEX "^#define[ \t]+PY_VERSION[ \t]+\"[^\"]+\"")
  250. string(REGEX REPLACE "^#define[ \t]+PY_VERSION[ \t]+\"([^\"]+)\".*" "\\1"
  251. PYTHONLIBS_VERSION_STRING "${python_version_str}")
  252. unset(python_version_str)
  253. endif()
  254. if(PYTHON_LIBRARY AND PYTHON_INCLUDE_DIR)
  255. break()
  256. endif()
  257. endforeach()
  258. unset(_Python_INCLUDE_PATH_HINT)
  259. unset(_Python_LIBRARY_PATH_HINT)
  260. mark_as_advanced(
  261. PYTHON_DEBUG_LIBRARY
  262. PYTHON_LIBRARY
  263. PYTHON_INCLUDE_DIR
  264. )
  265. # We use PYTHON_INCLUDE_DIR, PYTHON_LIBRARY and PYTHON_DEBUG_LIBRARY for the
  266. # cache entries because they are meant to specify the location of a single
  267. # library. We now set the variables listed by the documentation for this
  268. # module.
  269. set(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_DIR}")
  270. set(PYTHON_DEBUG_LIBRARIES "${PYTHON_DEBUG_LIBRARY}")
  271. # These variables have been historically named in this module different from
  272. # what select_library_configurations() expects.
  273. set(PYTHON_LIBRARY_DEBUG "${PYTHON_DEBUG_LIBRARY}")
  274. set(PYTHON_LIBRARY_RELEASE "${PYTHON_LIBRARY}")
  275. include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake)
  276. select_library_configurations(PYTHON)
  277. # select_library_configurations() sets ${PREFIX}_FOUND if it has a library.
  278. # Unset this, this prefix doesn't match the module prefix, they are different
  279. # for historical reasons.
  280. unset(PYTHON_FOUND)
  281. # Restore CMAKE_FIND_FRAMEWORK
  282. if(DEFINED _PythonLibs_CMAKE_FIND_FRAMEWORK)
  283. set(CMAKE_FIND_FRAMEWORK ${_PythonLibs_CMAKE_FIND_FRAMEWORK})
  284. unset(_PythonLibs_CMAKE_FIND_FRAMEWORK)
  285. else()
  286. unset(CMAKE_FIND_FRAMEWORK)
  287. endif()
  288. include(FindPackageHandleStandardArgs)
  289. find_package_handle_standard_args(PythonLibs
  290. REQUIRED_VARS PYTHON_LIBRARIES PYTHON_INCLUDE_DIRS
  291. VERSION_VAR PYTHONLIBS_VERSION_STRING)
  292. # PYTHON_ADD_MODULE(<name> src1 src2 ... srcN) is used to build modules for python.
  293. # PYTHON_WRITE_MODULES_HEADER(<filename>) writes a header file you can include
  294. # in your sources to initialize the static python modules
  295. function(PYTHON_ADD_MODULE _NAME )
  296. get_property(_TARGET_SUPPORTS_SHARED_LIBS
  297. GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS)
  298. option(PYTHON_ENABLE_MODULE_${_NAME} "Add module ${_NAME}" TRUE)
  299. option(PYTHON_MODULE_${_NAME}_BUILD_SHARED
  300. "Add module ${_NAME} shared" ${_TARGET_SUPPORTS_SHARED_LIBS})
  301. # Mark these options as advanced
  302. mark_as_advanced(PYTHON_ENABLE_MODULE_${_NAME}
  303. PYTHON_MODULE_${_NAME}_BUILD_SHARED)
  304. if(PYTHON_ENABLE_MODULE_${_NAME})
  305. if(PYTHON_MODULE_${_NAME}_BUILD_SHARED)
  306. set(PY_MODULE_TYPE MODULE)
  307. else()
  308. set(PY_MODULE_TYPE STATIC)
  309. set_property(GLOBAL APPEND PROPERTY PY_STATIC_MODULES_LIST ${_NAME})
  310. endif()
  311. set_property(GLOBAL APPEND PROPERTY PY_MODULES_LIST ${_NAME})
  312. add_library(${_NAME} ${PY_MODULE_TYPE} ${ARGN})
  313. # target_link_libraries(${_NAME} ${PYTHON_LIBRARIES})
  314. if(PYTHON_MODULE_${_NAME}_BUILD_SHARED)
  315. set_target_properties(${_NAME} PROPERTIES PREFIX "${PYTHON_MODULE_PREFIX}")
  316. if(WIN32 AND NOT CYGWIN)
  317. set_target_properties(${_NAME} PROPERTIES SUFFIX ".pyd")
  318. endif()
  319. endif()
  320. endif()
  321. endfunction()
  322. function(PYTHON_WRITE_MODULES_HEADER _filename)
  323. get_property(PY_STATIC_MODULES_LIST GLOBAL PROPERTY PY_STATIC_MODULES_LIST)
  324. get_filename_component(_name "${_filename}" NAME)
  325. string(REPLACE "." "_" _name "${_name}")
  326. string(TOUPPER ${_name} _nameUpper)
  327. set(_filename ${CMAKE_CURRENT_BINARY_DIR}/${_filename})
  328. set(_filenameTmp "${_filename}.in")
  329. file(WRITE ${_filenameTmp} "/*Created by cmake, do not edit, changes will be lost*/\n")
  330. file(APPEND ${_filenameTmp}
  331. "#ifndef ${_nameUpper}
  332. #define ${_nameUpper}
  333. #include <Python.h>
  334. #ifdef __cplusplus
  335. extern \"C\" {
  336. #endif /* __cplusplus */
  337. ")
  338. foreach(_currentModule ${PY_STATIC_MODULES_LIST})
  339. file(APPEND ${_filenameTmp} "extern void init${PYTHON_MODULE_PREFIX}${_currentModule}(void);\n\n")
  340. endforeach()
  341. file(APPEND ${_filenameTmp}
  342. "#ifdef __cplusplus
  343. }
  344. #endif /* __cplusplus */
  345. ")
  346. foreach(_currentModule ${PY_STATIC_MODULES_LIST})
  347. file(APPEND ${_filenameTmp} "int ${_name}_${_currentModule}(void) \n{\n static char name[]=\"${PYTHON_MODULE_PREFIX}${_currentModule}\"; return PyImport_AppendInittab(name, init${PYTHON_MODULE_PREFIX}${_currentModule});\n}\n\n")
  348. endforeach()
  349. file(APPEND ${_filenameTmp} "void ${_name}_LoadAllPythonModules(void)\n{\n")
  350. foreach(_currentModule ${PY_STATIC_MODULES_LIST})
  351. file(APPEND ${_filenameTmp} " ${_name}_${_currentModule}();\n")
  352. endforeach()
  353. file(APPEND ${_filenameTmp} "}\n\n")
  354. file(APPEND ${_filenameTmp} "#ifndef EXCLUDE_LOAD_ALL_FUNCTION\nvoid CMakeLoadAllPythonModules(void)\n{\n ${_name}_LoadAllPythonModules();\n}\n#endif\n\n#endif\n")
  355. # with configure_file() cmake complains that you may not use a file created using file(WRITE) as input file for configure_file()
  356. execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different "${_filenameTmp}" "${_filename}" OUTPUT_QUIET ERROR_QUIET)
  357. endfunction()
  358. cmake_policy(POP)