-
-
Notifications
You must be signed in to change notification settings - Fork 91
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
144 lines (119 loc) · 4.49 KB
/
CMakeLists.txt
File metadata and controls
144 lines (119 loc) · 4.49 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
137
138
139
140
141
142
143
144
cmake_minimum_required(VERSION 3.15...3.26)
project(${SKBUILD_PROJECT_NAME} LANGUAGES C)
find_package(
Python
COMPONENTS Interpreter Development.Module NumPy
REQUIRED)
include(FetchContent)
if(DEFINED EMSCRIPTEN)
set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_RULE_MESSAGES ON)
# might be needed for emscripten
set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS TRUE)
endif()
# Try system/conda first
find_library(CSPICE_LIB NAMES cspice)
if(CSPICE_LIB)
message(STATUS "Found system CSPICE: ${CSPICE_LIB}")
add_library(CSPICE::cspice UNKNOWN IMPORTED)
set_target_properties(CSPICE::cspice PROPERTIES IMPORTED_LOCATION "${CSPICE_LIB}")
# look for the headers
find_path(CSPICE_INCLUDE_DIR NAMES SpiceUsr.h PATH_SUFFIXES cspice)
if (CSPICE_INCLUDE_DIR)
message(STATUS "Found system CSPICE include: ${CSPICE_INCLUDE_DIR}")
set_target_properties(CSPICE::cspice PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${CSPICE_INCLUDE_DIR}")
else()
message(WARNING "CSPICE library found, but headers not found")
endif()
else()
message(STATUS "System CSPICE not found, falling back to FetchContent")
# we need to use this for the INSTALL_RPATH property
set(manual_patch_cspice_origin 'yes')
# Put CSPICE libs inside our package
if(DEFINED EMSCRIPTEN)
set(CMAKE_INSTALL_LIBDIR "spiceypy.libs/" CACHE INTERNAL "")
else()
set(CMAKE_INSTALL_LIBDIR "spiceypy/utils/" CACHE INTERNAL "")
endif()
if(MSVC)
# Force DLLs to install alongside LIBs instead of bin/
set(CMAKE_INSTALL_BINDIR "spiceypy/utils/" CACHE INTERNAL "")
endif()
# Put CSPICE headers somewhere harmless in our package
set(CMAKE_INSTALL_INCLUDEDIR ${SKBUILD_NULL_DIR} CACHE INTERNAL "")
# Also redirect data root to avoid polluting share/ etc.
set(CMAKE_INSTALL_DATAROOTDIR ${SKBUILD_NULL_DIR} CACHE INTERNAL "")
# Bring in your CSPICE CMake project
FetchContent_Declare(
cspice
GIT_REPOSITORY https://github.com/AndrewAnnex/cspice-cmake-spiceypy.git
GIT_TAG 658aa8b0116dc5e33a084c0aeb6eb9f9fc8fc1b3
)
FetchContent_MakeAvailable(cspice)
# disable versioned/
set_target_properties(cspice PROPERTIES
VERSION "" # no libmyclibrary.so.X.Y.Z
SOVERSION "" # no libmyclibrary.so.X
NO_SONAME ON # don't encode a soname
)
endif()
##############################################################################
# cyice specifics below if not on EMSCRIPTEN
if(NOT DEFINED EMSCRIPTEN)
# Convert pyx to c
set(PYX_FILE ${CMAKE_CURRENT_SOURCE_DIR}/src/spiceypy/cyice/cyice.pyx)
set(PXD_FILE ${CMAKE_CURRENT_SOURCE_DIR}/src/spiceypy/cyice/cyice.pxd)
set(C_FILE ${CMAKE_CURRENT_BINARY_DIR}/spiceypy/cyice/cyice.c)
add_custom_command(
OUTPUT ${C_FILE}
COMMAND Python::Interpreter -m cython ${PYX_FILE} --output-file ${C_FILE}
DEPENDS ${PYX_FILE} ${PXD_FILE}
COMMENT "Cythonizing ${PYX_FILE} to ${C_FILE}"
VERBATIM)
# Make Python extension using full dotted name for emscripten
python_add_library(cyice MODULE ${C_FILE} WITH_SOABI)
# Adjust properties using the same target name
set_target_properties(cyice PROPERTIES
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/spiceypy/cyice"
OUTPUT_NAME "cyice"
)
# Link to the CSPICE target exposed by the subproject
target_include_directories(cyice PRIVATE ${Python_NumPy_INCLUDE_DIRS})
# Set numpy options to ensure no deprecated apis older than 1.7
target_compile_definitions(cyice
PRIVATE
NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION
)
# Link CSPICE + math lib (only on UNIX)
if(UNIX AND NOT WIN32 AND NOT MINGW)
target_link_libraries(cyice PRIVATE CSPICE::cspice m)
else()
target_link_libraries(cyice PRIVATE CSPICE::cspice)
endif()
# Fix runtime search paths so extension finds libcspice in same dir if we manually install cspice
if(DEFINED manual_patch_cspice_origin)
if(APPLE)
set_target_properties(cyice PROPERTIES
INSTALL_RPATH "@loader_path/../utils"
BUILD_WITH_INSTALL_RPATH ON
)
elseif(UNIX AND NOT DEFINED EMSCRIPTEN)
set_target_properties(cyice PROPERTIES
INSTALL_RPATH "$ORIGIN/../utils"
BUILD_WITH_INSTALL_RPATH ON
)
elseif(DEFINED EMSCRIPTEN)
message(NOTICE "SETTING RPATH for emscripten")
set_target_properties(cyice PROPERTIES
INSTALL_RPATH "$ORIGIN/../../spiceypy.libs"
BUILD_RPATH "$ORIGIN/../../spiceypy.libs"
BUILD_WITH_INSTALL_RPATH ON
)
target_link_options(cyice PRIVATE
-Wl,-rpath,$ORIGIN/../../spiceypy.libs
)
endif()
endif()
# install cyice
install(TARGETS cyice DESTINATION spiceypy/cyice/)
endif()