forked from xtensor-stack/xtensor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
207 lines (177 loc) · 8.26 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
############################################################################
# Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht #
# #
# 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.1)
project(xtensor)
set(XTENSOR_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)
# Versionning
# ===========
file(STRINGS "${XTENSOR_INCLUDE_DIR}/xtensor/xtensor_config.hpp" xtensor_version_defines
REGEX "#define XTENSOR_VERSION_(MAJOR|MINOR|PATCH)")
foreach(ver ${xtensor_version_defines})
if(ver MATCHES "#define XTENSOR_VERSION_(MAJOR|MINOR|PATCH) +([^ ]+)$")
set(XTENSOR_VERSION_${CMAKE_MATCH_1} "${CMAKE_MATCH_2}" CACHE INTERNAL "")
endif()
endforeach()
set(${PROJECT_NAME}_VERSION
${XTENSOR_VERSION_MAJOR}.${XTENSOR_VERSION_MINOR}.${XTENSOR_VERSION_PATCH})
message(STATUS "Building xtensor v${${PROJECT_NAME}_VERSION}")
# Dependencies
# ============
set(xtl_REQUIRED_VERSION 0.4.16)
find_package(xtl ${xtl_REQUIRED_VERSION} REQUIRED)
message(STATUS "Found xtl: ${xtl_INCLUDE_DIRS}/xtl")
find_package(nlohmann_json 3.1.1 QUIET)
# Build
# =====
set(XTENSOR_HEADERS
${XTENSOR_INCLUDE_DIR}/xtensor/xaccumulator.hpp
${XTENSOR_INCLUDE_DIR}/xtensor/xadapt.hpp
${XTENSOR_INCLUDE_DIR}/xtensor/xarray.hpp
${XTENSOR_INCLUDE_DIR}/xtensor/xassign.hpp
${XTENSOR_INCLUDE_DIR}/xtensor/xaxis_iterator.hpp
${XTENSOR_INCLUDE_DIR}/xtensor/xbroadcast.hpp
${XTENSOR_INCLUDE_DIR}/xtensor/xbuffer_adaptor.hpp
${XTENSOR_INCLUDE_DIR}/xtensor/xbuilder.hpp
${XTENSOR_INCLUDE_DIR}/xtensor/xcomplex.hpp
${XTENSOR_INCLUDE_DIR}/xtensor/xconcepts.hpp
${XTENSOR_INCLUDE_DIR}/xtensor/xcontainer.hpp
${XTENSOR_INCLUDE_DIR}/xtensor/xcsv.hpp
${XTENSOR_INCLUDE_DIR}/xtensor/xdynamic_view.hpp
${XTENSOR_INCLUDE_DIR}/xtensor/xeval.hpp
${XTENSOR_INCLUDE_DIR}/xtensor/xexception.hpp
${XTENSOR_INCLUDE_DIR}/xtensor/xexpression.hpp
${XTENSOR_INCLUDE_DIR}/xtensor/xfixed.hpp
${XTENSOR_INCLUDE_DIR}/xtensor/xfunction.hpp
${XTENSOR_INCLUDE_DIR}/xtensor/xfunctor_view.hpp
${XTENSOR_INCLUDE_DIR}/xtensor/xgenerator.hpp
${XTENSOR_INCLUDE_DIR}/xtensor/xhistogram.hpp
${XTENSOR_INCLUDE_DIR}/xtensor/xindex_view.hpp
${XTENSOR_INCLUDE_DIR}/xtensor/xinfo.hpp
${XTENSOR_INCLUDE_DIR}/xtensor/xio.hpp
${XTENSOR_INCLUDE_DIR}/xtensor/xiterable.hpp
${XTENSOR_INCLUDE_DIR}/xtensor/xiterator.hpp
${XTENSOR_INCLUDE_DIR}/xtensor/xjson.hpp
${XTENSOR_INCLUDE_DIR}/xtensor/xlayout.hpp
${XTENSOR_INCLUDE_DIR}/xtensor/xmanipulation.hpp
${XTENSOR_INCLUDE_DIR}/xtensor/xmasked_value.hpp
${XTENSOR_INCLUDE_DIR}/xtensor/xmasked_view.hpp
${XTENSOR_INCLUDE_DIR}/xtensor/xmath.hpp
${XTENSOR_INCLUDE_DIR}/xtensor/xnoalias.hpp
${XTENSOR_INCLUDE_DIR}/xtensor/xnorm.hpp
${XTENSOR_INCLUDE_DIR}/xtensor/xnpy.hpp
${XTENSOR_INCLUDE_DIR}/xtensor/xoffset_view.hpp
${XTENSOR_INCLUDE_DIR}/xtensor/xoperation.hpp
${XTENSOR_INCLUDE_DIR}/xtensor/xoptional.hpp
${XTENSOR_INCLUDE_DIR}/xtensor/xoptional_assembly.hpp
${XTENSOR_INCLUDE_DIR}/xtensor/xoptional_assembly_base.hpp
${XTENSOR_INCLUDE_DIR}/xtensor/xoptional_assembly_storage.hpp
${XTENSOR_INCLUDE_DIR}/xtensor/xrandom.hpp
${XTENSOR_INCLUDE_DIR}/xtensor/xreducer.hpp
${XTENSOR_INCLUDE_DIR}/xtensor/xscalar.hpp
${XTENSOR_INCLUDE_DIR}/xtensor/xsemantic.hpp
${XTENSOR_INCLUDE_DIR}/xtensor/xshape.hpp
${XTENSOR_INCLUDE_DIR}/xtensor/xslice.hpp
${XTENSOR_INCLUDE_DIR}/xtensor/xsort.hpp
${XTENSOR_INCLUDE_DIR}/xtensor/xstorage.hpp
${XTENSOR_INCLUDE_DIR}/xtensor/xstrided_view.hpp
${XTENSOR_INCLUDE_DIR}/xtensor/xstrided_view_base.hpp
${XTENSOR_INCLUDE_DIR}/xtensor/xstrides.hpp
${XTENSOR_INCLUDE_DIR}/xtensor/xtensor.hpp
${XTENSOR_INCLUDE_DIR}/xtensor/xtensor_config.hpp
${XTENSOR_INCLUDE_DIR}/xtensor/xtensor_forward.hpp
${XTENSOR_INCLUDE_DIR}/xtensor/xtensor_simd.hpp
${XTENSOR_INCLUDE_DIR}/xtensor/xutils.hpp
${XTENSOR_INCLUDE_DIR}/xtensor/xvectorize.hpp
${XTENSOR_INCLUDE_DIR}/xtensor/xview.hpp
${XTENSOR_INCLUDE_DIR}/xtensor/xview_utils.hpp
)
add_library(xtensor INTERFACE)
target_include_directories(xtensor INTERFACE $<BUILD_INTERFACE:${XTENSOR_INCLUDE_DIR}>
$<INSTALL_INTERFACE:include>)
target_link_libraries(xtensor INTERFACE xtl)
OPTION(XTENSOR_ENABLE_ASSERT "xtensor bound check" OFF)
OPTION(XTENSOR_CHECK_DIMENSION "xtensor dimension check" OFF)
OPTION(XTENSOR_USE_XSIMD "simd acceleration for xtensor" OFF)
OPTION(XTENSOR_USE_TBB "enable parallelization using intel TBB" OFF)
OPTION(BUILD_TESTS "xtensor test suite" OFF)
OPTION(BUILD_BENCHMARK "xtensor benchmark" OFF)
OPTION(DOWNLOAD_GTEST "build gtest from downloaded sources" OFF)
OPTION(DOWNLOAD_GBENCHMARK "download google benchmark and build from source" ON)
OPTION(DEFAULT_COLUMN_MAJOR "set default layout to column major" OFF)
OPTION(DISABLE_VS2017 "disables the compilation of some test with Visual Studio 2017" OFF)
if(DOWNLOAD_GTEST OR GTEST_SRC_DIR)
set(BUILD_TESTS ON)
endif()
if(XTENSOR_ENABLE_ASSERT OR XTENSOR_CHECK_DIMENSION)
add_definitions(-DXTENSOR_ENABLE_ASSERT)
endif()
if(XTENSOR_CHECK_DIMENSION)
add_definitions(-DXTENSOR_ENABLE_CHECK_DIMENSION)
endif()
if(XTENSOR_USE_XSIMD)
add_definitions(-DXTENSOR_USE_XSIMD)
find_package(xsimd 6.2.0 REQUIRED)
message(STATUS "Found xsimd: ${xsimd_INCLUDE_DIRS}/xsimd")
target_link_libraries(xtensor INTERFACE xsimd)
endif()
if(XTENSOR_USE_TBB)
set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" "${CMAKE_CURRENT_SOURCE_DIR}/cmake/")
add_definitions(-DXTENSOR_USE_TBB)
find_package(TBB REQUIRED)
message(STATUS "Found intel TBB: ${TBB_INCLUDE_DIRS}")
include_directories(${TBB_INCLUDE_DIRS})
target_link_libraries(xtensor INTERFACE ${TBB_LIBRARIES})
endif()
if(DEFAULT_COLUMN_MAJOR)
add_definitions(-DXTENSOR_DEFAULT_LAYOUT=layout_type::column_major)
endif()
if(DISABLE_VS2017)
add_definitions(-DDISABLE_VS2017)
endif()
if(BUILD_TESTS)
add_subdirectory(test)
endif()
if(BUILD_BENCHMARK)
add_subdirectory(benchmark)
endif()
# Installation
# ============
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
install(TARGETS xtensor
EXPORT ${PROJECT_NAME}-targets)
# Makes the project importable from the build directory
export(EXPORT ${PROJECT_NAME}-targets
FILE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Targets.cmake")
install(FILES ${XTENSOR_HEADERS}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/xtensor)
set(XTENSOR_CMAKECONFIG_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" CACHE
STRING "install path for xtensorConfig.cmake")
configure_package_config_file(${PROJECT_NAME}Config.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
INSTALL_DESTINATION ${XTENSOR_CMAKECONFIG_INSTALL_DIR})
# xtensor is header-only and does not depend on the architecture.
# Remove CMAKE_SIZEOF_VOID_P from xtensorConfigVersion.cmake so that an xtensorConfig.cmake
# generated for a 64 bit target can be used for 32 bit targets and vice versa.
set(_XTENSOR_CMAKE_SIZEOF_VOID_P ${CMAKE_SIZEOF_VOID_P})
unset(CMAKE_SIZEOF_VOID_P)
write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
VERSION ${${PROJECT_NAME}_VERSION}
COMPATIBILITY AnyNewerVersion)
set(CMAKE_SIZEOF_VOID_P ${_XTENSOR_CMAKE_SIZEOF_VOID_P})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
DESTINATION ${XTENSOR_CMAKECONFIG_INSTALL_DIR})
install(EXPORT ${PROJECT_NAME}-targets
FILE ${PROJECT_NAME}Targets.cmake
DESTINATION ${XTENSOR_CMAKECONFIG_INSTALL_DIR})
configure_file(${PROJECT_NAME}.pc.in
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc"
@ONLY)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig/")