PyDependences.cmake 2.06 KB
Newer Older
1
2
3
4
5
6
7
# Python dependencies

# find Python platform with/without a given path
include("multipython/FindCustomPython3")
if(BA_PY_PLATFORM)
    message(STATUS "PyDependences: Custom Python platform path = '${BA_PY_PLATFORM}'")
    find_custom_python3(PATHS "${BA_PY_PLATFORM}" VERBOSE)
8
else()
9
10
    message(STATUS "PyDependences: Using default Python platform")
    find_custom_python3(DEFAULT_PATH VERBOSE)
11
endif()
12

13
set(pyversion ${Python3_VERSION_MAJOR}.${Python3_VERSION_MINOR})
14
set(pydst "${destination_root}python/${pyversion}")
15
set(destination_python
16
17
18
    "${pydst}/dist-packages/")
set(destination_pypackage ${pydst}/wheel)

19
message(STATUS "Python destination directory: ${destination_python}")
20
message(STATUS "Python package destination directory: ${destination_pypackage}")
21

22
23
24
25
26
27
28
29
30
# check presence of some Python modules
message(STATUS "Searching required Python packages...")
foreach(pkg build numpy setuptools wheel matplotlib)
    message(STATUS "Python package ${pkg}")
    execute_process(
        COMMAND ${Python3_EXECUTABLE}
        ${CMAKE_SOURCE_DIR}/cmake/tests/find_pkg.py ${pkg}
        RESULT_VARIABLE PKG_FOUND)
    if(NOT PKG_FOUND EQUAL 0)
31
        message(FATAL_ERROR "Python package '${pkg}' not found")
32
33
34
35
36
37
38
39
40
41
    endif()
endforeach()

# configure SWIG bindings
if(CONFIGURE_BINDINGS)
    find_package(SWIG 4.0 REQUIRED)
    include(${SWIG_USE_FILE})
    message(STATUS "Found SWIG version ${SWIG_VERSION} at ${SWIG_EXECUTABLE} "
        "with flags '${SWIG_FLAGS}'; CMake definitions in ${SWIG_USE_FILE}")

42
43
44
45
46
    # cache SWIG-related variables
    foreach(var_ SWIG_EXECUTABLE SWIG_VERSION SWIG_FLAGS SWIG_USE_FILE)
        set(${var_} ${${var_}} CACHE INTERNAL "")
    endforeach()

47
48
49
    if(CONFIGURE_PYTHON_DOCS)
        find_package(Doxygen REQUIRED)
    endif()
50
endif()
51
52
53
54
55
56
57
58
59
60

if(BA_PY_PACKAGE)
    # define a target to make a Python wheel
    include("multipython/MakePythonWheel")
    make_python_wheel(
        Py3_VERSION ${Python3_VERSION}
        Py3_EXECUTABLE "${Python3_EXECUTABLE}"
        Py3_INCLUDE_DIRS "${Python3_INCLUDE_DIRS}"
        Py3_LIBRARY_DIRS "${Python3_LIBRARY_DIRS}"
        )
61
endif()