12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- # 防止重复引入
- if(GJDM_Python_ALREADY_INCLUDED)
- return()
- endif()
- set(GJDM_Python_ALREADY_INCLUDED 1)
- set(Python_VERSION_MAJOR 3)
- set(Python_VERSION_MINOR 12)
- set(Python_VERSION_PATCH 0)
- # find_path 搜索包含某个文件的路径
- # 如果在某个路径下发现了该文件,该结果会被存储到该变量中;如果没有找到,存储的结果将会是<VAR>-NOTFOUND
- if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
- set(_python_h_dir "include/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}m")
- elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
- set(_python_h_dir "include")
- endif()
- find_path(Python_DIRS
- NAMES
- "${_python_h_dir}/Python.h"
- PATHS
- ${CMAKE_SOURCE_DIR}/extlib/Python
- NO_SYSTEM_ENVIRONMENT_PATH
- NO_CMAKE_SYSTEM_PATH
- )
- find_path(Python_INCLUDE_DIRS
- NAMES
- Python.h
- HINTS
- ${Python_DIRS}/${_python_h_dir}
- )
- if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
- set(Python_EXECUTABLE "${Python_DIRS}/python.exe")
- else()
- set(Python_EXECUTABLE "${Python_DIRS}/bin/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}")
- endif()
- set(Python_VERSION "${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}.${Python_VERSION_PATCH}")
- find_path(Python_LIBRARY_DIRS
- NAMES
- python${Python_VERSION_MAJOR}${Python_VERSION_MINOR}.lib libpython${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}m.so
- HINTS
- ${Python_DIRS}/libs ${Python_DIRS}/lib
- )
- set(Python_LIBRARIES GJDM::PYTHON)
- add_library(GJDM::PYTHON SHARED IMPORTED)
- set_property(TARGET GJDM::PYTHON PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${Python_INCLUDE_DIRS})
- set_property(TARGET GJDM::PYTHON APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
- if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
- add_library(GJDM::FFI SHARED IMPORTED)
- set_property(TARGET GJDM::FFI APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
- set_target_properties(GJDM::FFI PROPERTIES
- IMPORTED_LOCATION_RELEASE "${Python_LIBRARY_DIRS}/libffi.so.8.1.0"
- IMPORTED_SONAME_RELEASE "libffi.so.8"
- )
- set_target_properties(GJDM::PYTHON PROPERTIES
- IMPORTED_LOCATION_RELEASE "${Python_LIBRARY_DIRS}/libpython${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}m.so.1.0"
- IMPORTED_SONAME_RELEASE "libpython${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}m.so"
- )
- elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
- set_target_properties(GJDM::PYTHON PROPERTIES
- IMPORTED_IMPLIB_RELEASE "${Python_LIBRARY_DIRS}/python${Python_VERSION_MAJOR}${Python_VERSION_MINOR}.lib"
- IMPORTED_LOCATION_RELEASE "${Python_DIRS}/python${Python_VERSION_MAJOR}${Python_VERSION_MINOR}.dll"
- )
- endif()
- include(FindPackageHandleStandardArgs)
- # 如果找到所有需要的变量,并且版本匹配,则将Python_FOUND变量设置为TRUE
- find_package_handle_standard_args(Python
- FOUND_VAR
- Python_FOUND
- REQUIRED_VARS
- Python_DIRS
- Python_INCLUDE_DIRS
- Python_LIBRARY_DIRS
- Python_LIBRARIES
- Python_EXECUTABLE
- VERSION_VAR
- Python_VERSION
- )
|