-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathCMakeLists.txt
184 lines (141 loc) · 5.61 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
############################################################################
# Copyright (c) 2019, Sylvain Corlay, Johan Mabille, Wolf Vollprecht #
# Copyright (c) 2019, QuantStack #
# #
# 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-calc)
set(XEUS_CALC_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)
# Versionning
# ===========
file(STRINGS "${XEUS_CALC_INCLUDE_DIR}/xeus-calc/xeus_calc_config.hpp" xcalc_version_defines
REGEX "#define XCALC_VERSION_(MAJOR|MINOR|PATCH)")
foreach(ver ${xcalc_version_defines})
if(ver MATCHES "#define XCALC_VERSION_(MAJOR|MINOR|PATCH) +([^ ]+)$")
set(XCALC_VERSION_${CMAKE_MATCH_1} "${CMAKE_MATCH_2}" CACHE INTERNAL "")
endif()
endforeach()
set(${PROJECT_NAME}_VERSION
${XCALC_VERSION_MAJOR}.${XPYT_VERSION_MINOR}.${XPYT_VERSION_PATCH})
message(STATUS "Building xeus-calc v${${PROJECT_NAME}_VERSION}")
# Configuration
# =============
include(GNUInstallDirs)
# We generate the kernel.json file, given the installation prefix and the executable name
configure_file (
"${CMAKE_CURRENT_SOURCE_DIR}/share/jupyter/kernels/xcalc/kernel.json.in"
"${CMAKE_CURRENT_SOURCE_DIR}/share/jupyter/kernels/xcalc/kernel.json"
)
# Dependencies
# ============
# Be sure to use recent versions
set(xeus-zmq_REQUIRED_VERSION 3.0.0)
set(cppzmq_REQUIRED_VERSION 4.3.0)
find_package(xeus-zmq ${xeus-zmq_REQUIRED_VERSION} REQUIRED)
find_package(cppzmq ${cppzmq_REQUIRED_VERSION} REQUIRED)
# Flags
# =====
include(CheckCXXCompilerFlag)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
#if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Intel")
# CHECK_CXX_COMPILER_FLAG("-std=c++14" HAS_CPP14_FLAG)
#
# if (HAS_CPP14_FLAG)
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
# else()
# message(FATAL_ERROR "Unsupported compiler -- xeus requires C++14 support!")
# endif()
#endif()
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
# Target and link
# ===============
# xeus-calc source directory
set(XEUS_CALC_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
# xeus-calc source files
set(XEUS_CALC_SRC
${XEUS_CALC_SRC_DIR}/xeus_calc_interpreter.cpp
)
set(XEUS_CALC_HEADERS
include/xeus-calc/xeus_calc_interpreter.hpp
include/xeus-calc/xeus_calc_config.hpp
)
# xeus-calc is the target for the library
add_library(xeus-calc SHARED ${XEUS_CALC_SRC} ${XEUS_CALC_HEADERS})
target_compile_features(xeus-calc PRIVATE cxx_std_17)
# xcalc is the target for the kernel executable
add_executable(xcalc src/main.cpp)
target_compile_features(xcalc PRIVATE cxx_std_17)
set_target_properties(xcalc PROPERTIES ENABLE_EXPORTS 1)
target_link_libraries(xcalc PRIVATE xeus-calc)
target_compile_definitions(xcalc PRIVATE XEUS_CALC_HOME="${XCALC_PREFIX}")
if (APPLE)
set_target_properties(xcalc PROPERTIES
MACOSX_RPATH ON
)
else()
set_target_properties(xcalc PROPERTIES
BUILD_WITH_INSTALL_RPATH 1
SKIP_BUILD_RPATH FALSE
)
endif()
set_target_properties(xcalc xeus-calc PROPERTIES
INSTALL_RPATH_USE_LINK_PATH TRUE
)
OPTION(DOWNLOAD_GTEST "build gtest from downloaded sources" OFF)
#Option for GTest
if(DOWNLOAD_GTEST OR GTEST_SRC_DIR)
set(BUILD_TESTS ON)
endif()
target_link_libraries(xeus-calc PUBLIC xeus-zmq)
set_target_properties(xcalc PROPERTIES
INSTALL_RPATH_USE_LINK_PATH TRUE
)
target_include_directories(xeus-calc
PUBLIC
${XCALC_INCLUDE_DIRS}
$<BUILD_INTERFACE:${XEUS_CALC_INCLUDE_DIR}>
$<INSTALL_INTERFACE:include>)
set_target_properties(xeus-calc PROPERTIES
PUBLIC_HEADER "${XEUS_CALC_HEADERS}"
COMPILE_DEFINITIONS "XEUS_CALC_EXPORTS"
PREFIX ""
VERSION ${${PROJECT_NAME}_VERSION}
SOVERSION ${XCALC_VERSION_MAJOR}
OUTPUT_NAME "libxeus-calc")
## Test ##
# take into account the CMakeList in test
OPTION(BUILD_TESTS "xeus-calc test suite" OFF)
OPTION(DOWNLOAD_GTEST "build gtest from downloaded sources" OFF)
if(DOWNLOAD_GTEST OR GTEST_SRC_DIR)
set(BUILD_TESTS ON)
endif()
if(BUILD_TESTS)
add_subdirectory(test)
endif()
# Installation
# ============
# Install xeus-calc and xcalc
install(TARGETS xeus-calc
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-calc)
install(TARGETS xcalc
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
# Configuration and data directories for jupyter and xeus_calc
set(XJUPYTER_DATA_DIR "share/jupyter" CACHE STRING "Jupyter data directory")
# Install Jupyter kernelspecs
set(XEUS_CALCSPEC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/share/jupyter/kernels)
install(DIRECTORY ${XEUS_CALCSPEC_DIR}
DESTINATION ${XJUPYTER_DATA_DIR}
PATTERN "*.in" EXCLUDE)
# Extra path for installing Jupyter kernelspec
if (XEXTRA_JUPYTER_DATA_DIR)
install(DIRECTORY ${XEUS_CALCSPEC_DIR}
DESTINATION ${XEXTRA_JUPYTER_DATA_DIR}
PATTERN "*.in" EXCLUDE)
endif(XEXTRA_JUPYTER_DATA_DIR)