-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCMakeLists.txt
352 lines (281 loc) · 12.1 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
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
#############################################################################
#Copyright (c) 2021,
#
#Distributed under the terms of the BSD 3-Clause License.
#
#The full license is in the file LICENSE, distributed with this software.
#############################################################################
cmake_minimum_required(VERSION 3.4.3)
project(xeus-wren)
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake;${CMAKE_MODULE_PATH}")
set(XEUS_WREN_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)
# Versionning
# ===========
file(STRINGS "${XEUS_WREN_INCLUDE_DIR}/xeus-wren/xeus_wren_config.hpp" version_defines
REGEX "#define XEUS_WREN_VERSION_(MAJOR|MINOR|PATCH)")
foreach (ver ${version_defines})
if (ver MATCHES "#define XEUS_WREN_VERSION_(MAJOR|MINOR|PATCH) +([^ ]+)$")
set(XEUS_WREN_VERSION_${CMAKE_MATCH_1} "${CMAKE_MATCH_2}" CACHE INTERNAL "")
endif ()
endforeach ()
set(${PROJECT_NAME}_VERSION
${XEUS_WREN_VERSION_MAJOR}.${XEUS_WREN_VERSION_MINOR}.${XEUS_WREN_VERSION_PATCH})
message(STATUS "Building xeus-wren v${${PROJECT_NAME}_VERSION}")
# Configuration
# =============
include(GNUInstallDirs)
if (NOT DEFINED XEUS_WREN_KERNELSPEC_PATH)
set(XEUS_WREN_KERNELSPEC_PATH "${CMAKE_INSTALL_FULL_BINDIR}/")
endif ()
configure_file (
"${CMAKE_CURRENT_SOURCE_DIR}/share/jupyter/kernels/xwren/kernel.json.in"
"${CMAKE_CURRENT_SOURCE_DIR}/share/jupyter/kernels/xwren/kernel.json"
)
# Build options
# =============
# Compilation options
option(XEUS_WREN_BUILD_STATIC "Build xeus-wren static library" OFF)
OPTION(XEUS_WREN_BUILD_SHARED "Split xwren build into executable and library" ON)
OPTION(XEUS_WREN_BUILD_EXECUTABLE "Build the xwren executable" ON)
OPTION(XEUS_WREN_USE_SHARED_XEUS "Link xwren with the xeus shared library (instead of the static library)" ON)
OPTION(XEUS_WREN_USE_SHARED_XEUS_WREN "Link xwren with the xeus shared library (instead of the static library)" ON)
OPTION(XEUS_WREN_EMSCRIPTEN_WASM_BUILD "Build for wasm with emscripten" OFF)
if(XEUS_WREN_EMSCRIPTEN_WASM_BUILD)
add_compile_definitions(XEUS_WREN_EMSCRIPTEN_WASM_BUILD)
message("Build with emscripten")
SET(XEUS_WREN_BUILD_STATIC ON)
SET(XEUS_WREN_BUILD_SHARED OFF)
SET(XEUS_WREN_BUILD_EXECUTABLE OFF)
SET(XEUS_WREN_USE_SHARED_XEUS OFF)
SET(XEUS_WREN_USE_SHARED_XEUS_WREN OFF)
SET(XEUS_WREN_BUILD_TESTS OFF)
endif()
# Dependencies
# ============
set(xeus_REQUIRED_VERSION 5.0.0)
find_package(xeus ${xeus_REQUIRED_VERSION} REQUIRED)
message(STATUS "Before searching for WREN")
find_package(WREN REQUIRED)
message(STATUS "After searching for WREN")
# Flags
# =====
include(CheckCXXCompilerFlag)
if (MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4251 /wd4141")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4018 /wd4267 /wd4715 /wd4146 /wd4129")
endif ()
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Intel")
if(NOT XEUS_WREN_EMSCRIPTEN_WASM_BUILD)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wunused-parameter -Wextra -Wreorder")
endif()
CHECK_CXX_COMPILER_FLAG("-std=c++17" HAS_CPP_17_FLAG)
if (HAS_CPP_17_FLAG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
else ()
message(FATAL_ERROR "Unsupported compiler -- xeus requires C++17 support!")
endif ()
endif ()
if(XEUS_WREN_EMSCRIPTEN_WASM_BUILD)
# ENV (https://github.com/emscripten-core/emscripten/commit/6d9681ad04f60b41ef6345ab06c29bbc9eeb84e0)
set(EMSCRIPTEN_FEATURES "${EMSCRIPTEN_FEATURES} -s \"EXTRA_EXPORTED_RUNTIME_METHODS=[ENV']\"")
endif()
# Source files
# ============
set(XEUS_WREN_HEADERS
include/xeus-wren/xeus_wren_config.hpp
include/xeus-wren/xinterpreter.hpp
)
set(XEUS_WREN_SRC
src/xinterpreter.cpp
src/xio.cpp
src/xcomplete.cpp
src/xerror.cpp
src/xjson.cpp
src/xdisplay.cpp
)
set(XEUS_WREN_MAIN_SRC
src/main.cpp
)
# Targets and link - Macros
# =========================
include(CheckCXXCompilerFlag)
string(TOUPPER "${CMAKE_BUILD_TYPE}" U_CMAKE_BUILD_TYPE)
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib; ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
macro(xeus_wren_set_common_options target_name)
if (MSVC)
target_compile_options(${target_name} PUBLIC /wd4251 /wd4141)
target_compile_options(${target_name} PUBLIC /wd4018 /wd4267 /wd4715 /wd4146 /wd4129)
endif ()
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR
CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR
CMAKE_CXX_COMPILER_ID MATCHES "Intel")
target_compile_options(${target_name} PUBLIC -Wunused-parameter -Wextra -Wreorder)
# C++17 flag
CHECK_CXX_COMPILER_FLAG("-std=c++17" HAS_CPP_17_FLAG)
if (HAS_CPP_17_FLAG)
target_compile_features(${target_name} PRIVATE cxx_std_17)
else ()
message(FATAL_ERROR "Unsupported compiler -- xeus-wren requires C++17 support!")
endif ()
endif ()
if (APPLE)
set_target_properties(${target_name} PROPERTIES
MACOSX_RPATH ON
)
else ()
set_target_properties(${target_name} PROPERTIES
BUILD_WITH_INSTALL_RPATH 1
SKIP_BUILD_RPATH FALSE
)
endif ()
set_target_properties(${target_name} PROPERTIES
INSTALL_RPATH_USE_LINK_PATH TRUE
)
endmacro()
# Common macro kernels (xwren )
macro(xeus_wren_set_kernel_options target_name)
if (XEUS_WREN_USE_SHARED_XEUS_WREN)
target_link_libraries(${target_name} PRIVATE xeus-wren)
if(CMAKE_DL_LIBS)
target_link_libraries(${target_name} PRIVATE ${CMAKE_DL_LIBS} util)
endif()
else ()
target_link_libraries(${target_name} PRIVATE xeus-wren-static)
endif()
if(NOT XEUS_WREN_EMSCRIPTEN_WASM_BUILD)
find_package(Threads)
target_link_libraries(${target_name} PRIVATE ${CMAKE_THREAD_LIBS_INIT} ${WREN_LIBRARIES})
else()
target_link_libraries(${target_name} PRIVATE ${WREN_LIBRARIES})
endif()
endmacro()
# Common macro for shared and static library xeus-wren
macro(xeus_wren_create_target target_name linkage output_name)
string(TOUPPER "${linkage}" linkage_upper)
if (NOT ${linkage_upper} MATCHES "^(SHARED|STATIC)$")
message(FATAL_ERROR "Invalid library linkage: ${linkage}")
endif ()
add_library(${target_name} ${linkage_upper} ${XEUS_WREN_SRC} ${XEUS_WREN_HEADERS})
xeus_wren_set_common_options(${target_name})
set_target_properties(${target_name} PROPERTIES
PUBLIC_HEADER "${XEUS_WREN_HEADERS}"
PREFIX ""
VERSION ${${PROJECT_NAME}_VERSION}
SOVERSION ${XEUS_WREN_VERSION_MAJOR}
OUTPUT_NAME "lib${output_name}")
target_compile_definitions(${target_name} PUBLIC "XEUS_WREN_EXPORTS")
target_compile_features(${target_name} PRIVATE cxx_std_17)
target_include_directories(${target_name}
PUBLIC
${WREN_INCLUDE_DIR}
$<BUILD_INTERFACE:${XEUS_WREN_INCLUDE_DIR}>
$<INSTALL_INTERFACE:include>)
if (XEUS_WREN_USE_SHARED_XEUS)
set(XEUS_WREN_XEUS_TARGET xeus)
else ()
set(XEUS_WREN_XEUS_TARGET xeus-static)
endif ()
target_link_libraries(${target_name} PUBLIC ${XEUS_WREN_XEUS_TARGET} )
if (WIN32 OR CYGWIN)
#
elseif (APPLE)
target_link_libraries(${target_name} PRIVATE "-undefined dynamic_lookup")
endif ()
if(NOT XEUS_WREN_EMSCRIPTEN_WASM_BUILD)
find_package(Threads) # TODO: add Threads as a dependence of xeus-static?
target_link_libraries(${target_name} PRIVATE ${CMAKE_THREAD_LIBS_INIT} ${WREN_LIBRARY})
else()
target_link_libraries(${target_name} PRIVATE ${WREN_LIBRARY})
endif()
endmacro()
# xeus-wren
# ===========
set(XEUS_WREN_TARGETS "")
if (XEUS_WREN_BUILD_SHARED)
# Build libraries
xeus_wren_create_target(xeus-wren SHARED xeus-wren)
list(APPEND XEUS_WREN_TARGETS xeus-wren)
endif ()
if (XEUS_WREN_BUILD_STATIC)
# On Windows, a static library should use a different output name
# to avoid the conflict with the import library of a shared one.
if (CMAKE_HOST_WIN32)
xeus_wren_create_target(xeus-wren-static STATIC xeus-wren-static)
else ()
xeus_wren_create_target(xeus-wren-static STATIC xeus-wren)
endif ()
list(APPEND XEUS_WREN_TARGETS xeus-wren-static)
endif ()
# xeus-wren
# =======
if (XEUS_WREN_BUILD_EXECUTABLE)
find_package(xeus-zmq 1.0.2 REQUIRED)
add_executable(xwren ${XEUS_WREN_MAIN_SRC})
target_compile_features(xwren PRIVATE cxx_std_17)
xeus_wren_set_common_options(xwren)
xeus_wren_set_kernel_options(xwren)
target_link_libraries(xwren PRIVATE xeus-zmq)
endif()
if(XEUS_WREN_EMSCRIPTEN_WASM_BUILD)
find_package(xeus-lite REQUIRED)
add_executable(xeus_kernel src/main_emscripten_kernel.cpp )
target_link_libraries(xeus_kernel PRIVATE xeus-wren-static xeus-static)
target_compile_features(xeus_kernel PRIVATE cxx_std_17)
endif()
# Installation
# ============
include(CMakePackageConfigHelpers)
set(XEUS_WREN_CMAKECONFIG_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" CACHE STRING "install path for xeus-wrenConfig.cmake")
# Install xeus-wren and xeus-wren-static
if (XEUS_WREN_BUILD_SHARED)
install(TARGETS ${XEUS_WREN_TARGETS}
EXPORT ${PROJECT_NAME}-targets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/xeus-wren)
# Makes the project importable from the build directory
export(EXPORT ${PROJECT_NAME}-targets
FILE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Targets.cmake")
endif ()
# Install xwren
if (XEUS_WREN_BUILD_EXECUTABLE)
install(TARGETS xwren
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
# Configuration and data directories for jupyter and xeus-wren
set(XJUPYTER_DATA_DIR "share/jupyter" CACHE STRING "Jupyter data directory")
# Install xwren Jupyter kernelspec
set(KERNELSPEC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/share/jupyter/kernels)
install(DIRECTORY ${KERNELSPEC_DIR}
DESTINATION ${XJUPYTER_DATA_DIR}
PATTERN "*.in" EXCLUDE)
# Extra path for installing Jupyter kernelspec
if (XEXTRA_JUPYTER_DATA_DIR)
install(DIRECTORY ${KERNELSPEC_DIR}
DESTINATION ${XEXTRA_JUPYTER_DATA_DIR}
PATTERN "*.in" EXCLUDE)
endif ()
endif ()
# Configure 'xeus-wrenConfig.cmake' for a build tree
set(XEUS_WREN_CONFIG_CODE "####### Expanded from \@XEUS_WREN_CONFIG_CODE\@ #######\n")
set(XEUS_WREN_CONFIG_CODE "${XEUS_WREN_CONFIG_CODE}set(CMAKE_MODULE_PATH \"${CMAKE_CURRENT_SOURCE_DIR}/cmake;\${CMAKE_MODULE_PATH}\")\n")
set(XEUS_WREN_CONFIG_CODE "${XEUS_WREN_CONFIG_CODE}##################################################")
configure_package_config_file(${PROJECT_NAME}Config.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
INSTALL_DESTINATION ${PROJECT_BINARY_DIR})
# Configure 'xeus-wrenConfig.cmake.in for an install tree
set(XEUS_WREN_CONFIG_CODE "")
configure_package_config_file(${PROJECT_NAME}Config.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${PROJECT_NAME}Config.cmake"
INSTALL_DESTINATION ${XEUS_WREN_CMAKECONFIG_INSTALL_DIR})
write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
VERSION ${${PROJECT_NAME}_VERSION}
COMPATIBILITY AnyNewerVersion)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${PROJECT_NAME}Config.cmake
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
DESTINATION ${XEUS_WREN_CMAKECONFIG_INSTALL_DIR})
if (XEUS_WREN_BUILD_SHARED)
install(EXPORT ${PROJECT_NAME}-targets
FILE ${PROJECT_NAME}Targets.cmake
DESTINATION ${XEUS_WREN_CMAKECONFIG_INSTALL_DIR})
endif ()