-
Notifications
You must be signed in to change notification settings - Fork 16
/
CMakeLists.txt
277 lines (235 loc) · 11.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
############################################################################
# Copyright (c) 2017, Sylvain Corlay, Johan Mabille 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.8)
project(xleaflet)
message(STATUS "Forcing tests build type to Release")
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
set(XLEAFLET_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)
set(XLEAFLET_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
set(XLEAFLET_SHARE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/share)
# Configuration
# =============
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
set(XLEAFLET_INSTALL_LIBRARY_DIR "\"${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}\"")
configure_file (
"${XLEAFLET_INCLUDE_DIR}/xleaflet/xleaflet_config_cling.hpp.in"
"${XLEAFLET_INCLUDE_DIR}/xleaflet/xleaflet_config_cling.hpp"
)
set(XLEAFLET_BASEMAPS_PATH "\"${CMAKE_INSTALL_PREFIX}/share/xleaflet/basemaps.json\"")
configure_file (
"${XLEAFLET_INCLUDE_DIR}/xleaflet/xget_basemaps_path.hpp.in"
"${XLEAFLET_INCLUDE_DIR}/xleaflet/xget_basemaps_path.hpp"
)
# Versionning
# ===========
file(STRINGS "${XLEAFLET_INCLUDE_DIR}/xleaflet/xleaflet_config.hpp" xleaflet_version_defines
REGEX "#define XLEAFLET_VERSION_(MAJOR|MINOR|PATCH)")
foreach(ver ${xleaflet_version_defines})
if(ver MATCHES "#define XLEAFLET_VERSION_(MAJOR|MINOR|PATCH) +([^ ]+)$")
set(XLEAFLET_VERSION_${CMAKE_MATCH_1} "${CMAKE_MATCH_2}" CACHE INTERNAL "")
endif()
endforeach()
set(XLEAFLET_VERSION
${XLEAFLET_VERSION_MAJOR}.${XLEAFLET_VERSION_MINOR}.${XLEAFLET_VERSION_PATCH})
message(STATUS "xleaflet version: v${XLEAFLET_VERSION}")
# Binary version
# See the following URL for explanations about the binary versionning
# https://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html#Updating-version-info
file(STRINGS "${XLEAFLET_INCLUDE_DIR}/xleaflet/xleaflet_config.hpp" xleaflet_version_defines
REGEX "#define XLEAFLET_BINARY_(CURRENT|REVISION|AGE)")
foreach(ver ${xleaflet_version_defines})
if(ver MATCHES "#define XLEAFLET_BINARY_(CURRENT|REVISION|AGE) +([^ ]+)$")
set(XLEAFLET_BINARY_${CMAKE_MATCH_1} "${CMAKE_MATCH_2}" CACHE INTERNAL "")
endif()
endforeach()
set(XLEAFLET_BINARY_VERSION
${XLEAFLET_BINARY_CURRENT}.${XLEAFLET_BINARY_REVISION}.${XLEAFLET_BINARY_AGE})
message(STATUS "xleaflet binary version: v${XLEAFLET_BINARY_VERSION}")
# Build options
# =============
option(XLEAFLET_BUILD_TESTS "xleaflet test suite" OFF)
# Dependencies
# ============
set(xproperty_REQUIRED_VERSION 0.12.0)
set(xwidgets_REQUIRED_VERSION 0.29.0)
if (NOT TARGET xproperty)
find_package(xproperty ${xproperty_REQUIRED_VERSION} REQUIRED)
endif ()
if (NOT TARGET xwidgets)
find_package(xwidgets ${xwidgets_REQUIRED_VERSION} REQUIRED)
endif ()
# Source files
# ============
set(XLEAFLET_HEADERS
${XLEAFLET_INCLUDE_DIR}/xleaflet/xbasemaps.hpp
${XLEAFLET_INCLUDE_DIR}/xleaflet/xget_basemaps_path.hpp
${XLEAFLET_INCLUDE_DIR}/xleaflet/xcircle_marker.hpp
${XLEAFLET_INCLUDE_DIR}/xleaflet/xcircle.hpp
${XLEAFLET_INCLUDE_DIR}/xleaflet/xcontrol.hpp
${XLEAFLET_INCLUDE_DIR}/xleaflet/xdraw_control.hpp
${XLEAFLET_INCLUDE_DIR}/xleaflet/xfeature_group.hpp
${XLEAFLET_INCLUDE_DIR}/xleaflet/xgeo_json.hpp
${XLEAFLET_INCLUDE_DIR}/xleaflet/xheatmap.hpp
${XLEAFLET_INCLUDE_DIR}/xleaflet/xicon.hpp
${XLEAFLET_INCLUDE_DIR}/xleaflet/ximage_overlay.hpp
${XLEAFLET_INCLUDE_DIR}/xleaflet/xlayer_group.hpp
${XLEAFLET_INCLUDE_DIR}/xleaflet/xlayer.hpp
${XLEAFLET_INCLUDE_DIR}/xleaflet/xfullscreen_control.hpp
${XLEAFLET_INCLUDE_DIR}/xleaflet/xlayers_control.hpp
${XLEAFLET_INCLUDE_DIR}/xleaflet/xleaflet_config_cling.hpp
${XLEAFLET_INCLUDE_DIR}/xleaflet/xleaflet_config.hpp
${XLEAFLET_INCLUDE_DIR}/xleaflet/xmap.hpp
${XLEAFLET_INCLUDE_DIR}/xleaflet/xmarker_cluster.hpp
${XLEAFLET_INCLUDE_DIR}/xleaflet/xmarker.hpp
${XLEAFLET_INCLUDE_DIR}/xleaflet/xmeasure_control.hpp
${XLEAFLET_INCLUDE_DIR}/xleaflet/xpath.hpp
${XLEAFLET_INCLUDE_DIR}/xleaflet/xpolygon.hpp
${XLEAFLET_INCLUDE_DIR}/xleaflet/xpolyline.hpp
${XLEAFLET_INCLUDE_DIR}/xleaflet/xpopup.hpp
${XLEAFLET_INCLUDE_DIR}/xleaflet/xraster_layer.hpp
${XLEAFLET_INCLUDE_DIR}/xleaflet/xrectangle.hpp
${XLEAFLET_INCLUDE_DIR}/xleaflet/xsplit_map_control.hpp
${XLEAFLET_INCLUDE_DIR}/xleaflet/xtile_layer.hpp
${XLEAFLET_INCLUDE_DIR}/xleaflet/xui_layer.hpp
${XLEAFLET_INCLUDE_DIR}/xleaflet/xvector_layer.hpp
${XLEAFLET_INCLUDE_DIR}/xleaflet/xvelocity.hpp
${XLEAFLET_INCLUDE_DIR}/xleaflet/xvideo_overlay.hpp
${XLEAFLET_INCLUDE_DIR}/xleaflet/xwms_layer.hpp
${XLEAFLET_INCLUDE_DIR}/xleaflet/xwidget_control.hpp
${XLEAFLET_INCLUDE_DIR}/xleaflet/xzoom_control.hpp
)
set(XLEAFLET_SOURCES
${XLEAFLET_SOURCE_DIR}/xcircle_marker.cpp
${XLEAFLET_SOURCE_DIR}/xcircle.cpp
${XLEAFLET_SOURCE_DIR}/xcontrol.cpp
${XLEAFLET_SOURCE_DIR}/xdraw_control.cpp
${XLEAFLET_SOURCE_DIR}/xfeature_group.cpp
${XLEAFLET_SOURCE_DIR}/xgeo_json.cpp
${XLEAFLET_SOURCE_DIR}/xheatmap.cpp
${XLEAFLET_SOURCE_DIR}/xicon.cpp
${XLEAFLET_SOURCE_DIR}/ximage_overlay.cpp
${XLEAFLET_SOURCE_DIR}/xlayer_group.cpp
${XLEAFLET_SOURCE_DIR}/xlayer.cpp
${XLEAFLET_SOURCE_DIR}/xlayers_control.cpp
${XLEAFLET_SOURCE_DIR}/xfullscreen_control.cpp
${XLEAFLET_SOURCE_DIR}/xmap.cpp
${XLEAFLET_SOURCE_DIR}/xmarker_cluster.cpp
${XLEAFLET_SOURCE_DIR}/xmarker.cpp
${XLEAFLET_SOURCE_DIR}/xmeasure_control.cpp
${XLEAFLET_SOURCE_DIR}/xpath.cpp
${XLEAFLET_SOURCE_DIR}/xpolygon.cpp
${XLEAFLET_SOURCE_DIR}/xpolyline.cpp
${XLEAFLET_SOURCE_DIR}/xpopup.cpp
${XLEAFLET_SOURCE_DIR}/xraster_layer.cpp
${XLEAFLET_SOURCE_DIR}/xrectangle.cpp
${XLEAFLET_SOURCE_DIR}/xsplit_map_control.cpp
${XLEAFLET_SOURCE_DIR}/xtile_layer.cpp
${XLEAFLET_SOURCE_DIR}/xui_layer.cpp
${XLEAFLET_SOURCE_DIR}/xvector_layer.cpp
${XLEAFLET_SOURCE_DIR}/xvelocity.cpp
${XLEAFLET_SOURCE_DIR}/xvideo_overlay.cpp
${XLEAFLET_SOURCE_DIR}/xwms_layer.cpp
${XLEAFLET_SOURCE_DIR}/xwidget_control.cpp
${XLEAFLET_SOURCE_DIR}/xzoom_control.cpp
)
# Output
# ======
add_library(xleaflet SHARED ${XLEAFLET_SOURCES} ${XLEAFLET_HEADERS})
target_include_directories(xleaflet PUBLIC $<BUILD_INTERFACE:${XLEAFLET_INCLUDE_DIR}>
$<INSTALL_INTERFACE:include>)
target_link_libraries(xleaflet
PUBLIC xproperty
PUBLIC xwidgets)
set_target_properties(xleaflet PROPERTIES
PUBLIC_HEADER "${XLEAFLET_HEADERS}"
COMPILE_DEFINITIONS "XLEAFLET_EXPORTS"
PREFIX ""
VERSION ${XLEAFLET_BINARY_VERSION}
SOVERSION ${XLEAFLET_BINARY_CURRENT}
OUTPUT_NAME "libxleaflet")
# Compilation flags
# =================
include(CheckCXXCompilerFlag)
string(TOUPPER "${CMAKE_BUILD_TYPE}" U_CMAKE_BUILD_TYPE)
set_target_properties(xleaflet PROPERTIES
CXX_EXTENSIONS OFF
CXX_STANDARD_REQUIRED 14)
target_compile_features(xleaflet PRIVATE cxx_std_17)
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Intel")
target_compile_options(xleaflet PUBLIC -Wunused-parameter -Wextra -Wreorder)
# Enable link time optimization and set the default symbol
# visibility to hidden (very important to obtain small binaries)
if (NOT ${U_CMAKE_BUILD_TYPE} MATCHES DEBUG)
# Check for Link Time Optimization support
# (GCC/Clang)
CHECK_CXX_COMPILER_FLAG("-flto" HAS_LTO_FLAG)
if (HAS_LTO_FLAG)
target_compile_options(xleaflet PUBLIC -flto)
endif()
# Intel equivalent to LTO is called IPO
if (CMAKE_CXX_COMPILER_ID MATCHES "Intel")
CHECK_CXX_COMPILER_FLAG("-ipo" HAS_IPO_FLAG)
if (HAS_IPO_FLAG)
target_compile_options(xleaflet PUBLIC -ipo)
endif()
endif()
endif()
message(STATUS "CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
endif()
# if(MSVC)
# target_compile_definitions(xleaflet PUBLIC -DNOMINMAX)
# target_compile_options(xleaflet PUBLIC /DGUID_WINDOWS /MP /bigobj)
# target_compile_options(xleaflet PUBLIC /wd4251 /wd 4996)
# # Allows to compile in debug without requiring each dependencies to
# # be compiled in debug
# if(${U_CMAKE_BUILD_TYPE} MATCHES DEBUG)
# set(CMAKE_CXX_FLAGS_DEBUG "/DNDEBUG /MD /Zi /Ob0 /Od /RTC1")
# message(STATUS "Overriding CMAKE_CXX_FLAGS_DEBUG: ${CMAKE_CXX_FLAGS_DEBUG}")
# endif()
# endif()
# Tests
# =====
if(XLEAFLET_BUILD_TESTS)
add_subdirectory(test)
endif()
# Installation
# ============
install(DIRECTORY "${XLEAFLET_SHARE_DIR}/xleaflet"
DESTINATION "share")
set(XLEAFLET_CMAKECONFIG_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" CACHE STRING "install path for xleafletConfig.cmake")
install(TARGETS xleaflet
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}/xleaflet)
# Makes the project importable from the build directory
export(EXPORT ${PROJECT_NAME}-targets
FILE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Targets.cmake")
# Configure 'xleafletConfig.cmake' for a build tree
set(XLEAFLET_CONFIG_CODE "####### Expanded from \@XLEAFLET_CONFIG_CODE\@ #######\n")
set(XLEAFLET_CONFIG_CODE "${XLEAFLET_CONFIG_CODE}set(CMAKE_MODULE_PATH \"${CMAKE_CURRENT_SOURCE_DIR}/cmake;\${CMAKE_MODULE_PATH}\")\n")
set(XLEAFLET_CONFIG_CODE "${XLEAFLET_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 'xleafletConfig.cmake' for an install tree
set(XLEAFLET_CONFIG_CODE "")
configure_package_config_file(${PROJECT_NAME}Config.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
INSTALL_DESTINATION ${XLEAFLET_CMAKECONFIG_INSTALL_DIR})
write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
VERSION ${XLEAFLET_VERSION}
COMPATIBILITY AnyNewerVersion)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
DESTINATION ${XLEAFLET_CMAKECONFIG_INSTALL_DIR})
install(EXPORT ${PROJECT_NAME}-targets
FILE ${PROJECT_NAME}Targets.cmake
DESTINATION ${XLEAFLET_CMAKECONFIG_INSTALL_DIR})