@@ -12,6 +12,12 @@ set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake;${CMAKE_MODULE_PATH}")
12
12
13
13
set (XEUS_CPP_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR} /include )
14
14
15
+ enable_language (CXX)
16
+ set (CMAKE_CXX_EXTENSIONS NO )
17
+ set (CMAKE_POSITION_INDEPENDENT_CODE ON )
18
+
19
+ include (GNUInstallDirs)
20
+
15
21
# Versionning
16
22
# ===========
17
23
@@ -26,29 +32,15 @@ set(${PROJECT_NAME}_VERSION
26
32
${XEUS_CPP_VERSION_MAJOR} .${XEUS_CPP_VERSION_MINOR} .${XEUS_CPP_VERSION_PATCH} )
27
33
message (STATUS "Building xeus-cpp v${${PROJECT_NAME} _VERSION}" )
28
34
29
- # Configuration
30
- # =============
31
-
32
- include (GNUInstallDirs)
33
-
34
- if (NOT DEFINED XEUS_CPP_KERNELSPEC_PATH)
35
- set (XEUS_CPP_KERNELSPEC_PATH "${CMAKE_INSTALL_PREFIX} /${CMAKE_INSTALL_BINDIR} /" )
36
- endif ()
37
-
38
- configure_file (
39
- "${CMAKE_CURRENT_SOURCE_DIR} /share/jupyter/kernels/xcpp/kernel.json.in"
40
- "${CMAKE_CURRENT_SOURCE_DIR} /share/jupyter/kernels/xcpp/kernel.json"
41
- )
42
-
43
35
# Build options
44
36
# =============
45
37
46
38
option (XEUS_CPP_BUILD_STATIC "Build xeus-cpp static library" ON )
47
39
OPTION (XEUS_CPP_BUILD_SHARED "Split xcpp build into executable and library" ON )
48
40
OPTION (XEUS_CPP_BUILD_EXECUTABLE "Build the xcpp executable" ON )
49
41
50
- OPTION (XEUS_CPP_USE_SHARED_XEUS "Link xcpp with the xeus shared library (instead of the static library)" ON )
51
- OPTION (XEUS_CPP_USE_SHARED_XEUS_CPP "Link xcpp with the xeus shared library (instead of the static library)" ON )
42
+ OPTION (XEUS_CPP_USE_SHARED_XEUS "Link xcpp with the xeus shared library (instead of the static library)" ON )
43
+ OPTION (XEUS_CPP_USE_SHARED_XEUS_CPP "Link xcpp with the xeus shared library (instead of the static library)" ON )
52
44
53
45
# Test options
54
46
OPTION (XEUS_CPP_BUILD_TESTS "xeus-cpp test suite" ON )
@@ -77,7 +69,6 @@ if(EMSCRIPTEN)
77
69
SET (XEUS_CPP_BUILD_TESTS OFF )
78
70
endif ()
79
71
80
-
81
72
# Dependencies
82
73
# ============
83
74
@@ -103,15 +94,17 @@ else()
103
94
add_compile_options (-fexceptions)
104
95
endif ()
105
96
106
- if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Intel" )
97
+ if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR
98
+ CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR
99
+ CMAKE_CXX_COMPILER_ID MATCHES "Intel" )
107
100
if (NOT EMSCRIPTEN)
108
101
add_compile_options (-Wunused-parameter -Wextra -Wreorder)
109
102
endif ()
110
-
111
103
112
104
CHECK_CXX_COMPILER_FLAG("-std=c++17" HAS_CPP_17_FLAG)
113
105
if (HAS_CPP_17_FLAG)
114
- add_compile_options (-std=c++17)
106
+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17" )
107
+ set (CMAKE_CXX_STANDARD 17)
115
108
else ()
116
109
message (FATAL_ERROR "Unsupported compiler -- xeus requires C++17 support!" )
117
110
endif ()
@@ -120,21 +113,85 @@ endif ()
120
113
if (EMSCRIPTEN)
121
114
# ENV (https://github.com/emscripten-core/emscripten/commit/6d9681ad04f60b41ef6345ab06c29bbc9eeb84e0)
122
115
set (EMSCRIPTEN_FEATURES "${EMSCRIPTEN_FEATURES} -s \" EXTRA_EXPORTED_RUNTIME_METHODS=[ENV']\" " )
116
+ set (CMAKE_FIND_LIBRARY_SUFFIXES ".a" )
117
+ endif ()
118
+
119
+ find_package (CppInterOp REQUIRED CONFIG PATHS "${CMAKE_PREFIX_PATH} " "${CMAKE_PREFIX_PATH} /lib" "${CPPINTEROP_DIR} " "${CPPINTEROP_DIR} /lib" )
120
+ if (CppInterOp_FOUND)
121
+ set (CppInterOp_CLANG_VERSION "17" )
122
+ message (STATUS "Found CppInterOp: config=${CppInterOp_CONFIG} dir=${CppInterOp_DIR} (found version=${CppInterOp_VERSION} compatible with Clang ${CppInterOp_CLANG_VERSION} .x)" )
123
123
endif ()
124
124
125
- find_package (Clang REQUIRED)
126
- include (AddLLVM)
127
- include (HandleLLVMOptions)
128
- add_definitions (${LLVM_DEFINITIONS} )
129
125
find_package (argparse REQUIRED)
130
126
find_package (pugixml REQUIRED)
131
127
128
+ set (Python_FIND_VIRTUALENV ONLY)
129
+ find_package (Python COMPONENTS Interpreter Development)
130
+
131
+ # Configuration
132
+ # =============
133
+
134
+ if (NOT DEFINED XEUS_CPP_KERNELSPEC_PATH)
135
+ set (XEUS_CPP_KERNELSPEC_PATH "${CMAKE_INSTALL_PREFIX} /${CMAKE_INSTALL_BINDIR} /" )
136
+ set (XEUS_CPP_RESOURCE_DIR ${CMAKE_INSTALL_PREFIX} /${CMAKE_INSTALL_LIBDIR} /clang/${CppInterOp_CLANG_VERSION} )
137
+ endif ()
138
+
139
+ function (configure_kernel kernel)
140
+ set (XEUS_CPP_CPLUS_INCLUDE_PATH "$ENV{CPLUS_INCLUDE_PATH} " )
141
+ set (XEUS_CPP_PATH "$ENV{PATH} " )
142
+ set (XEUS_CPP_LD_LIBRARY_PATH "$ENV{LD_LIBRARY_PATH} " )
143
+ set (XEUS_CPP_PYTHONPATH "$ENV{PYTHONPATH} " )
144
+ set (XEUS_CPP_VENV_PATH "$ENV{VENV} " )
145
+
146
+ message (STATUS "Debug: Replace in kernels" )
147
+ message (STATUS "Debug: XEUS_CPP_CPLUS_INCLUDE_PATH=${XEUS_CPP_CPLUS_INCLUDE_PATH} " )
148
+ message (STATUS "Debug: XEUS_CPP_PATH=${XEUS_CPP_PATH} " )
149
+ message (STATUS "Debug: XEUS_CPP_LD_LIBRARY_PATH=${XEUS_CPP_LD_LIBRARY_PATH} " )
150
+ message (STATUS "Debug: XEUS_CPP_PYTHONPATH=${XEUS_CPP_PYTHONPATH} " )
151
+ message (STATUS "Debug: XEUS_CPP_VENV_PATH=${XEUS_CPP_VENV_PATH} " )
152
+ message (STATUS "Debug: CMAKE_CURRENT_SOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR} " )
153
+ message (STATUS "Debug: CMAKE_CURRENT_BINARY_DIR=${CMAKE_CURRENT_BINARY_DIR} " )
154
+
155
+ configure_file (
156
+ "${CMAKE_CURRENT_SOURCE_DIR} /${kernel} /kernel.json.in"
157
+ "${CMAKE_CURRENT_BINARY_DIR} /${kernel} /kernel.json"
158
+ )
159
+ file (GLOB files "${CMAKE_CURRENT_SOURCE_DIR} /${kernel} /*.png" )
160
+ foreach (file ${files} )
161
+ configure_file (
162
+ "${file} "
163
+ "${CMAKE_CURRENT_BINARY_DIR} /${kernel} /"
164
+ COPYONLY
165
+ )
166
+ endforeach ()
167
+ file (GLOB files "${CMAKE_CURRENT_SOURCE_DIR} /${kernel} /*.svg" )
168
+ foreach (file ${files} )
169
+ configure_file (
170
+ "${file} "
171
+ "${CMAKE_CURRENT_BINARY_DIR} /${kernel} /"
172
+ COPYONLY
173
+ )
174
+ endforeach ()
175
+ endfunction ()
176
+
177
+ file (GLOB _kernels LIST_DIRECTORIES true RELATIVE "${CMAKE_CURRENT_SOURCE_DIR} " "share/jupyter/kernels/*" )
178
+ foreach (_kernel IN LISTS _kernels)
179
+ message ("Configure kernel: ${_kernel} " )
180
+ configure_kernel("${_kernel} " )
181
+ endforeach ()
182
+
132
183
# Source files
133
184
# ============
134
185
135
186
set (XEUS_CPP_HEADERS
187
+ include /xeus-cpp/xbuffer.hpp
188
+ include /xeus-cpp/xholder.hpp
189
+ include /xeus-cpp/xmagics.hpp
190
+ include /xeus-cpp/xoptions.hpp
136
191
include /xeus-cpp/xeus_cpp_config.hpp
137
192
include /xeus-cpp/xinterpreter.hpp
193
+ include /xeus-cpp/xmanager.hpp
194
+ include /xeus-cpp/xpreamble.hpp
138
195
)
139
196
140
197
set (XEUS_CPP_SRC
@@ -144,10 +201,18 @@ set(XEUS_CPP_SRC
144
201
src/xoptions.cpp
145
202
src/xparser.cpp
146
203
src/xutils.cpp
204
+ src/xdemangle.hpp
205
+ src/xinspect.hpp
206
+ src/xsystem.hpp
207
+ src/xparser.hpp
208
+ src/xmagics/os.hpp
209
+ src/xmagics/os.cpp
147
210
)
148
211
149
212
if (EMSCRIPTEN)
150
213
list (APPEND XEUS_CPP_SRC src/xinterpreter_wasm.cpp)
214
+ else ()
215
+ list (APPEND XEUS_CPP_SRC src/xmagics/pythonexec.hpp src/xmagics/pythonexec.cpp)
151
216
endif ()
152
217
153
218
set (XEUS_CPP_MAIN_SRC
@@ -161,7 +226,8 @@ include(CheckCXXCompilerFlag)
161
226
162
227
string (TOUPPER "${CMAKE_BUILD_TYPE} " U_CMAKE_BUILD_TYPE)
163
228
164
- set (CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX} /lib; ${CMAKE_INSTALL_PREFIX} /${CMAKE_INSTALL_LIBDIR} " )
229
+ set (CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX} /lib;${CMAKE_INSTALL_PREFIX} /${CMAKE_INSTALL_LIBDIR} " )
230
+ list (REMOVE_DUPLICATES CMAKE_INSTALL_RPATH )
165
231
166
232
macro (xeus_cpp_set_common_options target_name)
167
233
if (MSVC )
@@ -215,7 +281,6 @@ macro(xeus_cpp_set_kernel_options target_name)
215
281
find_package (Threads)
216
282
target_link_libraries (${target_name} PRIVATE ${CMAKE_THREAD_LIBS_INIT} )
217
283
endif ()
218
-
219
284
endmacro ()
220
285
221
286
# Common macro for shared and static library
@@ -251,7 +316,11 @@ macro(xeus_cpp_create_target target_name linkage output_name)
251
316
set (XEUS_CPP_XEUS_TARGET xeus-static )
252
317
endif ()
253
318
254
- target_link_libraries (${target_name} PUBLIC ${XEUS_CPP_XEUS_TARGET} clangInterpreter pugixml argparse::argparse xtl)
319
+ target_link_libraries (${target_name} PUBLIC ${XEUS_CPP_XEUS_TARGET} clangCppInterOp pugixml argparse::argparse xtl)
320
+ if (NOT EMSCRIPTEN)
321
+ target_link_libraries (${target_name} PUBLIC Python::Python)
322
+ endif ()
323
+
255
324
if (WIN32 OR CYGWIN )
256
325
#
257
326
elseif (APPLE )
@@ -261,7 +330,7 @@ macro(xeus_cpp_create_target target_name linkage output_name)
261
330
find_package (Threads) # TODO: add Threads as a dependence of xeus-static?
262
331
target_link_libraries (${target_name} PRIVATE ${CMAKE_THREAD_LIBS_INIT} )
263
332
endif ()
264
-
333
+
265
334
endmacro ()
266
335
267
336
# xeus-cpp-headers
@@ -308,6 +377,30 @@ if (XEUS_CPP_BUILD_EXECUTABLE)
308
377
xeus_cpp_set_common_options(xcpp)
309
378
xeus_cpp_set_kernel_options(xcpp)
310
379
target_link_libraries (xcpp PRIVATE xeus-zmq)
380
+ set_target_properties (xcpp PROPERTIES
381
+ ENABLE_EXPORTS 1
382
+ CXX_STANDARD ${CMAKE_CXX_STANDARD} )
383
+ target_link_libraries (xcpp PUBLIC xeus-cpp pthread Python::Python)
384
+
385
+ ##TODO: We may be need sse RPATH
386
+ set_target_properties (xcpp clangCppInterOp PROPERTIES INSTALL_RPATH_USE_LINK_PATH TRUE )
387
+ if (APPLE )
388
+ target_link_libraries (xcpp PUBLIC -Wl,-w -Wl,-bind_at_load -Wl,-undefined,dynamic_lookup)
389
+ elseif (NOT MSVC )
390
+ target_link_libraries (xcpp PUBLIC -Wl,--unresolved-symbols=ignore -in-object-files )
391
+ endif ()
392
+
393
+ target_include_directories (xeus-cpp PUBLIC ${Python_INCLUDE_DIRS} )
394
+ target_link_libraries (xeus-cpp PUBLIC ${PYTHON_LIBRARIES} )
395
+ target_link_libraries (xeus-cpp ${PYTHON_LIBRARIES_Development_Main} )
396
+ set_target_properties (xeus-cpp PROPERTIES
397
+ PUBLIC_HEADER "${XEUS_CPP_HEADERS} "
398
+ COMPILE_DEFINITIONS "XEUS_CPP_EXPORTS"
399
+ PREFIX ""
400
+ VERSION ${${PROJECT_NAME} _VERSION}
401
+ SOVERSION ${XEUS_CPP_VERSION_MAJOR}
402
+ OUTPUT_NAME "libxeus-cpp"
403
+ CXX_STANDARD ${CMAKE_CXX_STANDARD} )
311
404
endif ()
312
405
313
406
if (EMSCRIPTEN)
@@ -337,10 +430,10 @@ set(XEUS_CPP_CMAKECONFIG_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NA
337
430
if (XEUS_CPP_BUILD_SHARED)
338
431
install (TARGETS ${XEUS_CPP_TARGETS}
339
432
EXPORT ${PROJECT_NAME} -targets
340
- ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
341
- LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
342
- RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
343
- PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} /xeus-cpp)
433
+ ARCHIVE DESTINATION ${CMAKE_INSTALL_PREFIX} / ${ CMAKE_INSTALL_LIBDIR}
434
+ LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX} / ${ CMAKE_INSTALL_LIBDIR}
435
+ RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX} / ${ CMAKE_INSTALL_BINDIR}
436
+ PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_PREFIX} / ${ CMAKE_INSTALL_INCLUDEDIR} /xeus-cpp)
344
437
345
438
# Makes the project importable from the build directory
346
439
export (EXPORT ${PROJECT_NAME} -targets
@@ -350,15 +443,15 @@ endif ()
350
443
# Install xcpp
351
444
if (XEUS_CPP_BUILD_EXECUTABLE)
352
445
install (TARGETS xcpp
353
- RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} )
446
+ RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX} / ${ CMAKE_INSTALL_BINDIR} )
354
447
endif ()
355
448
356
449
if (XEUS_CPP_BUILD_EXECUTABLE OR EMSCRIPTEN)
357
450
# Configuration and data directories for jupyter and xeus-cpp
358
451
set (XJUPYTER_DATA_DIR "share/jupyter" CACHE STRING "Jupyter data directory" )
359
452
360
453
# Install xcpp Jupyter kernelspec
361
- set (KERNELSPEC_DIR ${CMAKE_CURRENT_SOURCE_DIR } /share/jupyter/kernels)
454
+ set (KERNELSPEC_DIR ${CMAKE_CURRENT_BINARY_DIR } /share/jupyter/kernels)
362
455
install (DIRECTORY ${KERNELSPEC_DIR}
363
456
DESTINATION ${XJUPYTER_DATA_DIR}
364
457
PATTERN "*.in" EXCLUDE )
@@ -428,3 +521,7 @@ if(EMSCRIPTEN)
428
521
"$<TARGET_FILE_DIR:xcpp>/xcpp.wasm"
429
522
DESTINATION ${CMAKE_INSTALL_BINDIR} )
430
523
endif ()
524
+
525
+ if (XEUS_CPP_INCLUDE_DOCS)
526
+ add_subdirectory (docs)
527
+ endif ()
0 commit comments