1
1
cmake_minimum_required (VERSION 3.14)
2
- if (POLICY CMP0078)
3
- cmake_policy (SET CMP0078 NEW)
4
- endif ()
5
-
6
- if (POLICY CMP0025)
7
- cmake_policy (SET CMP0025 NEW)
8
- endif ()
9
-
10
- if (POLICY CMP0057)
11
- cmake_policy (SET CMP0057 NEW)
12
- endif ()
13
-
14
- if (POLICY CMP0086)
15
- cmake_policy (SET CMP0086 NEW)
16
- endif ()
17
-
18
- if (POLICY CMP0068)
19
- cmake_policy (SET CMP0068 NEW)
20
- endif ()
21
-
22
- if (POLICY CMP0046)
23
- cmake_policy (SET CMP0046 NEW)
24
- endif ()
25
-
26
- if (POLICY CMP0148)
27
- cmake_policy (SET CMP0148 OLD)
28
- endif ()
29
2
30
3
project ("basilisk" )
31
4
@@ -133,9 +106,6 @@ function(sub_dir_list result curdir)
133
106
PARENT_SCOPE)
134
107
endfunction (sub_dir_list)
135
108
136
- # add header search directories
137
- include_directories ("${CMAKE_SOURCE_DIR} " )
138
-
139
109
function (generate_package_libraries INIT_DIRECTORY AllLibs)
140
110
# Find all _GeneralModuleFiles and put them into library targets so they aren't rewrapped, built with every module.
141
111
@@ -172,7 +142,7 @@ function(generate_package_libraries INIT_DIRECTORY AllLibs)
172
142
# Link all necessary libraries
173
143
target_link_libraries (${LIB_NAME} PUBLIC ArchitectureUtilities)
174
144
target_link_libraries (${LIB_NAME} PRIVATE ModuleIdGenerator)
175
- target_link_libraries (${LIB_NAME} PRIVATE ${PYTHON_LIBRARIES} )
145
+ target_link_libraries (${LIB_NAME} PRIVATE Python3::Module )
176
146
target_link_libraries (${LIB_NAME} PRIVATE Eigen3::Eigen3)
177
147
178
148
# define build location, IDE generation specifications
@@ -208,11 +178,6 @@ function(find_package_targets PKG_DIR ALL_TARGET_LIST)
208
178
endfunction (find_package_targets)
209
179
210
180
function (generate_package_targets TARGET_LIST LIB_DEP_LIST MODULE_DIR)
211
-
212
- find_package (SWIG REQUIRED)
213
- include (UseSWIG REQUIRED)
214
- find_package (PythonLibs 3 REQUIRED)
215
-
216
181
if (TARGET_LIST)
217
182
string (REPLACE "/" ";" DirList "${TARGET_LIST} " )
218
183
list (GET DirList 1 SUBMODULE)
@@ -290,7 +255,6 @@ function(generate_package_targets TARGET_LIST LIB_DEP_LIST MODULE_DIR)
290
255
include ("${PARENT_DIR} /Custom.cmake" )
291
256
endif ()
292
257
293
- target_include_directories (${TARGET_NAME} PRIVATE ${PYTHON_INCLUDE_PATH} ) # Exposes python.h to wrap.c(xx) file
294
258
target_include_directories (
295
259
${TARGET_NAME} PRIVATE ${CMAKE_SOURCE_DIR} /${PARENT_DIR} ) # Exposes module .h files to the PYTHON_wrap.c(xx) file
296
260
# (not located in src)
@@ -305,7 +269,7 @@ function(generate_package_targets TARGET_LIST LIB_DEP_LIST MODULE_DIR)
305
269
foreach (LIB ${LIB_DEP_LIST} )
306
270
target_link_libraries (${TARGET_NAME} PRIVATE ${LIB} )
307
271
endforeach ()
308
- target_link_libraries (${TARGET_NAME} PRIVATE ${PYTHON_LIBRARIES} )
272
+ target_link_libraries (${TARGET_NAME} PRIVATE Python3::Module )
309
273
310
274
if (${MODULE_DIR} STREQUAL "ExternalModules" )
311
275
set_target_properties (${TARGET_NAME} PROPERTIES FOLDER ${MODULE_DIR} )
@@ -339,9 +303,29 @@ function(generate_package_targets TARGET_LIST LIB_DEP_LIST MODULE_DIR)
339
303
endforeach ()
340
304
endfunction (generate_package_targets)
341
305
306
+ # add header search directories
307
+ include_directories ("${CMAKE_SOURCE_DIR} " )
308
+
342
309
# Start of main projection configuration
343
- find_package (PythonInterp 3 REQUIRED)
344
- find_package (PythonLibs 3 REQUIRED)
310
+ find_package (Python3 REQUIRED COMPONENTS Interpreter Development)
311
+
312
+ # Hack the Python3 module link options to *not* use `-undefined dynamic_lookup`.
313
+ # Instead, pass an explicit allowlist of symbols that may be left undefined.
314
+ # This trick is adapted from:
315
+ # https://github.com/wjakob/nanobind/blob/0a6f8f36006dadff4b6279f58ce2188be20c9ada/cmake/nanobind-config.cmake#L33-L42
316
+ # The allowlist is obtained from:
317
+ # https://github.com/python/cpython/issues/97524#issuecomment-1460492751
318
+ if (APPLE )
319
+ set_target_properties (Python3::Module PROPERTIES
320
+ INTERFACE_LINK_OPTIONS
321
+ "-Wl,@${CMAKE_CURRENT_SOURCE_DIR} /cmake/cpython-exported-symbols"
322
+ )
323
+ endif ()
324
+
325
+ find_package (SWIG REQUIRED)
326
+ include (UseSWIG)
327
+
328
+ set (SWIG_USE_SWIG_DEPENDENCIES True )
345
329
346
330
include (FetchContent)
347
331
FetchContent_Declare(
@@ -625,7 +609,7 @@ file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/Basilisk/architecture")
625
609
file (MAKE_DIRECTORY "${CMAKE_BINARY_DIR} /Basilisk/simulation" )
626
610
file (MAKE_DIRECTORY "${CMAKE_BINARY_DIR} /Basilisk/fswAlgorithms" )
627
611
628
- if (WIN32 AND (PYTHON_VERSION VERSION_GREATER 3.8))
612
+ if (WIN32 AND (Python3_VERSION VERSION_GREATER 3.8))
629
613
file (WRITE "${CMAKE_BINARY_DIR} /Basilisk/__init__.py"
630
614
"#init file written by the build\n " "import sys, os\n " "from Basilisk import __path__\n "
631
615
"bskPath = __path__[0]\n " "os.add_dll_directory(bskPath)\n " )
@@ -667,18 +651,5 @@ file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/Basilisk/supportData")
667
651
file (GLOB dataFiles "${CMAKE_SOURCE_DIR} /../supportData/*" )
668
652
create_symlinks("${CMAKE_BINARY_DIR} /Basilisk/supportData" ${dataFiles} )
669
653
670
- # run python script to modify swig gen code
671
- add_custom_target (OverwriteSwig ALL )
672
- set (ARG utilities/overwriteSwig.py ${CMAKE_BINARY_DIR} ${SWIG_VERSION} )
673
- add_custom_command (
674
- TARGET OverwriteSwig
675
- COMMAND ${PYTHON_EXECUTABLE} ${ARG}
676
- WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} /../src/)
677
- if (TARGET _thrusterDynamicEffector)
678
- add_dependencies (OverwriteSwig _thrusterDynamicEffector _vscmgStateEffector _reactionWheelStateEffector)
679
- elseif (TARGET thrusterDynamicEffector)
680
- add_dependencies (OverwriteSwig thrusterDynamicEffector vscmgStateEffector reactionWheelStateEffector)
681
- endif ()
682
-
683
654
# Tests targets
684
655
add_subdirectory ("architecture/utilities/tests" )
0 commit comments