-
Notifications
You must be signed in to change notification settings - Fork 3
/
CMakeLists.txt
119 lines (102 loc) · 4.83 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
cmake_minimum_required(VERSION 3.20)
project(py4pd C)
set(PDCMAKE_DIR
"${CMAKE_SOURCE_DIR}/Resources/pd.cmake/"
CACHE PATH "Path to pd.cmake")
include(${PDCMAKE_DIR}/pd.cmake)
# ╭──────────────────────────────────────╮
# │ Object Definitions │
# ╰──────────────────────────────────────╯
if(NOT DEFINED PYVERSION)
message(FATAL_ERROR "\nPYVERSION is not defined. Use -DPYVERSION=3.11, for example.")
else()
message(STATUS "Using Python version: ${PYVERSION}")
endif()
# ───────── Numpy Array Include ───────
if(WIN32)
execute_process(
COMMAND powershell -Command "py -${PYVERSION} -c \"import numpy; print(numpy.get_include())\""
OUTPUT_VARIABLE NUMPY_INCLUDE_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE
RESULT_VARIABLE EXEC_RESULT)
else()
execute_process(
COMMAND python${PYVERSION} -c "import numpy; print(numpy.get_include())"
OUTPUT_VARIABLE NUMPY_INCLUDE_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE
RESULT_VARIABLE EXEC_RESULT)
endif()
if(EXEC_RESULT)
message(FATAL_ERROR "Failed get NumPy include directory. Have you used 'pip install numpy'?")
endif()
message(STATUS "NumPy include directory: ${NUMPY_INCLUDE_DIR}")
# ──────────── Python Include ────────────
if(WIN32)
execute_process(
COMMAND powershell -Command "py -${PYVERSION} -c \"import sysconfig; print(sysconfig.get_paths()['include'])\""
OUTPUT_VARIABLE PYTHON_INCLUDE_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE
RESULT_VARIABLE EXEC_RESULT)
else()
execute_process(
COMMAND python${PYVERSION} -c "import sysconfig; print(sysconfig.get_paths()['include'])"
OUTPUT_VARIABLE PYTHON_INCLUDE_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE
RESULT_VARIABLE EXEC_RESULT)
endif()
if(EXEC_RESULT)
message(FATAL_ERROR "Failed get Python include directory.")
endif()
# ─────────── Python LD Flags ─────────
if(WIN32)
execute_process(
COMMAND powershell -Command
"py -${PYVERSION} -c \"import sysconfig; print(sysconfig.get_config_var('BINDIR'))\""
OUTPUT_VARIABLE PYTHON_BIN_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE
RESULT_VARIABLE EXEC_RESULT)
# remove the dot (.) from PYVERSION
string(REPLACE "." "" PYVERSION_NO_DOT ${PYVERSION})
set(PYTHON_LD_FLAGS "-L${PYTHON_BIN_DIR} -lpython${PYVERSION_NO_DOT}")
else()
execute_process(
COMMAND python${PYVERSION}-config --ldflags
OUTPUT_VARIABLE PYTHON_LD_FLAGS
OUTPUT_STRIP_TRAILING_WHITESPACE
RESULT_VARIABLE EXEC_RESULT)
if(EXEC_RESULT)
message(FATAL_ERROR "Failed get Python include directory.")
endif()
string(REPLACE " " ";" PYTHON_LD_FLAGS ${PYTHON_LD_FLAGS})
if(APPLE)
list(GET PYTHON_LD_FLAGS 0 PYTHON_LD_FLAGS)
endif()
string(REPLACE " " ";" PYTHON_LD_FLAGS "${PYTHON_LD_FLAGS}")
list(APPEND PYTHON_LD_FLAGS "-lpython${PYVERSION}")
endif()
# split the flags into a list
# ╭──────────────────────────────────────╮
# │ PureData Object │
# ╰──────────────────────────────────────╯
file(GLOB PY4PD_SOURCES ${CMAKE_SOURCE_DIR}/Sources/*.c)
pd_add_external(py4pd "${PY4PD_SOURCES}")
target_include_directories(py4pd PUBLIC ${NUMPY_INCLUDE_DIR})
target_include_directories(py4pd PUBLIC ${PYTHON_INCLUDE_DIR})
target_include_directories(py4pd PUBLIC "/usr/include/python${PYVERSION}")
target_link_libraries(py4pd PUBLIC "${PYTHON_LD_FLAGS}")
# add debug flag
target_compile_options(py4pd PRIVATE -g)
# ╭──────────────────────────────────────╮
# │ Data Files │
# ╰──────────────────────────────────────╯
file(GLOB PY4PD_SRC_FILES ${CMAKE_SOURCE_DIR}/Sources/*.c ${CMAKE_SOURCE_DIR}/Sources/*.h)
pd_add_datafile(py4pd "${PY4PD_SRC_FILES}" DESTINATION "Sources")
file(GLOB PY4PD_SRC_FILES ${CMAKE_SOURCE_DIR}/Sources/py4pd/*.py)
pd_add_datafile(py4pd "${PY4PD_SRC_FILES}" DESTINATION "py4pd")
file(GLOB PY4PD_PY_FILES ${CMAKE_SOURCE_DIR}/Sources/py4pd.py)
pd_add_datafile(py4pd "${PY4PD_PY_FILES}")
file(GLOB PY4PD_HELP_FILES ${CMAKE_SOURCE_DIR}/Resources/*.pd)
pd_add_datafile(py4pd "${PY4PD_HELP_FILES}")
pd_add_datafile(py4pd "${CMAKE_SOURCE_DIR}/Resources/py.py")
pd_add_datafile(py4pd "${CMAKE_SOURCE_DIR}/LICENSE")
pd_add_datafile(py4pd "${CMAKE_SOURCE_DIR}/README.md")