-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
136 lines (120 loc) · 5.23 KB
/
CMakeLists.txt
File metadata and controls
136 lines (120 loc) · 5.23 KB
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
cmake_minimum_required(VERSION 3.18)
project(pulserver_extensions LANGUAGES C CXX)
set(CMAKE_C_STANDARD 99)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
find_package(pybind11 CONFIG REQUIRED)
find_package(Python COMPONENTS Development.Module REQUIRED)
# -------------------------
# Reliable pybind11 module helper
# -------------------------
function(add_pybind_module module_name output_subdir)
set(options)
set(oneValueArgs)
set(multiValueArgs SOURCES INCLUDES)
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
# Expand sources: support both explicit files and globs
set(MODULE_SOURCES_LIST "")
foreach(src_pattern IN LISTS ARG_SOURCES)
if("${src_pattern}" MATCHES "\\*")
file(GLOB EXPANDED ${src_pattern})
if(EXPANDED STREQUAL "")
message(FATAL_ERROR "Glob '${src_pattern}' for module '${module_name}' matched no files")
endif()
list(APPEND MODULE_SOURCES_LIST ${EXPANDED})
else()
if(NOT EXISTS ${src_pattern})
message(FATAL_ERROR "Source file '${src_pattern}' does not exist for module '${module_name}'")
endif()
list(APPEND MODULE_SOURCES_LIST ${src_pattern})
endif()
endforeach()
# Get the directory of the first source file
list(GET MODULE_SOURCES_LIST 0 FIRST_SOURCE)
get_filename_component(MODULE_OUTPUT_DIR "${FIRST_SOURCE}" DIRECTORY)
pybind11_add_module(${module_name} ${MODULE_SOURCES_LIST})
target_include_directories(${module_name} PRIVATE ${ARG_INCLUDES})
# Output directory: use the directory of the first source file
set_target_properties(${module_name} PROPERTIES
LIBRARY_OUTPUT_DIRECTORY "${MODULE_OUTPUT_DIR}"
OUTPUT_NAME "${module_name}"
)
endfunction()
# -------------------------
# _cpd module
# -------------------------
# add_pybind_module(_cpd_wrapper ""
# SOURCES
# "${CMAKE_SOURCE_DIR}/python/pulserver/pulseq/_extension/_cpd_wrapper.cpp"
# "${CMAKE_SOURCE_DIR}/external/cpdlib/misc.c"
# "${CMAKE_SOURCE_DIR}/external/cpdlib/udcpd.c"
# "${CMAKE_SOURCE_DIR}/external/cpdlib/vdcpd.c"
# INCLUDES
# ${CMAKE_SOURCE_DIR}/external
# )
# # Install built extensions to the source tree for editable mode
# file(GLOB CPD_WRAPPERS "${CMAKE_CURRENT_BINARY_DIR}/python/pulserver/pulseq/_extension/_cpd_wrapper*${CMAKE_SHARED_LIBRARY_SUFFIX}")
# install(
# FILES ${CPD_WRAPPERS} DESTINATION ${CMAKE_SOURCE_DIR}/python/pulserver/pulseq/_extension
# )
# -------------------------
# _vds module
# -------------------------
# add_pybind_module(_vds_wrapper ""
# SOURCES
# "${CMAKE_SOURCE_DIR}/python/pulserver/pulseq/_extension/_vds_wrapper.cpp"
# "${CMAKE_SOURCE_DIR}/external/vdslib/vds.c"
# INCLUDES
# ${CMAKE_SOURCE_DIR}/external
# #${CMAKE_SOURCE_DIR}/python/pulserver/pulseq/_extension
# )
# # Install built extensions to the source tree for editable mode
# file(GLOB VDS_WRAPPERS "${CMAKE_CURRENT_BINARY_DIR}/python/pulserver/pulseq/_extension/_vds_wrapper*${CMAKE_SHARED_LIBRARY_SUFFIX}")
# install(
# FILES ${VDS_WRAPPERS} DESTINATION ${CMAKE_SOURCE_DIR}/python/pulserver/pulseq/_extension
# )
# -------------------------
# _pulseqlib module
# -------------------------
# Explicit source list (mirrors csrc/CMakeLists.txt). pge needs both the cache
# and seqdesc subsystems because the Python API exposes
# pulseqlib_get_sequence_description / pulseqlib_get_sequence_parameters.
set(PULSEQLIB_C_SOURCES
"${CMAKE_SOURCE_DIR}/csrc/pulseqlib_error.c"
"${CMAKE_SOURCE_DIR}/csrc/pulseqlib_math.c"
"${CMAKE_SOURCE_DIR}/csrc/pulseqlib_parse.c"
"${CMAKE_SOURCE_DIR}/csrc/pulseqlib_dedup.c"
"${CMAKE_SOURCE_DIR}/csrc/pulseqlib_structure.c"
"${CMAKE_SOURCE_DIR}/csrc/pulseqlib_core.c"
"${CMAKE_SOURCE_DIR}/csrc/pulseqlib_cache.c"
"${CMAKE_SOURCE_DIR}/csrc/pulseqlib_waveforms.c"
"${CMAKE_SOURCE_DIR}/csrc/pulseqlib_safety.c"
"${CMAKE_SOURCE_DIR}/csrc/pulseqlib_getters.c"
"${CMAKE_SOURCE_DIR}/csrc/pulseqlib_freqmod.c"
"${CMAKE_SOURCE_DIR}/csrc/pulseqlib_protocol.c"
"${CMAKE_SOURCE_DIR}/csrc/pulseqlib_trajectory.c"
"${CMAKE_SOURCE_DIR}/csrc/pulseqlib_seqdesc.c"
"${CMAKE_SOURCE_DIR}/csrc/pulseqlib_cache_seqdesc.c"
"${CMAKE_SOURCE_DIR}/csrc/pulseqlib_bridge.c"
"${CMAKE_SOURCE_DIR}/csrc/external_kiss_fft.c"
"${CMAKE_SOURCE_DIR}/csrc/external_kiss_fftr.c"
"${CMAKE_SOURCE_DIR}/csrc/external_md5.c"
)
add_pybind_module(_pulseqlib_wrapper ""
SOURCES
"${CMAKE_SOURCE_DIR}/python/pge/core/_extension/_pulseqlib_wrapper.cpp"
${PULSEQLIB_C_SOURCES}
INCLUDES
${CMAKE_SOURCE_DIR}/csrc
${CMAKE_SOURCE_DIR}/extensions
)
# Install built extensions to the source tree for editable mode
file (GLOB PULSEQLIB_WRAPPERS "${CMAKE_CURRENT_BINARY_DIR}/python/pge/core/_extension/_pulseqlib_wrapper*${CMAKE_SHARED_LIBRARY_SUFFIX}")
install(
FILES ${PULSEQLIB_WRAPPERS} DESTINATION ${CMAKE_SOURCE_DIR}/python/pge/core/_extension
)
option(PULSERVER_BUILD_CPP_TESTS "Build lightweight C++ unit tests" OFF)
if(PULSERVER_BUILD_CPP_TESTS)
enable_testing()
add_subdirectory(${CMAKE_SOURCE_DIR}/tests/cpptests ${CMAKE_BINARY_DIR}/cpptests_build)
endif()