-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathCMakeLists.txt
655 lines (543 loc) · 27.2 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
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
################################################################################
# Project: NextGIS QGIS
# Purpose: CMake build scripts
# Author: Dmitry Baryshnikov, dmitry.baryshnikov@nexgis.com
################################################################################
# Copyright (C) 2017-2024, NextGIS <info@nextgis.com>
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
################################################################################
cmake_minimum_required(VERSION 3.12.0)
project(qgis)
if(NOT SKIP_PREFIX)
set(NG_PREFIX ng)
set(PACKAGE_VENDOR "NextGIS")
set(PACKAGE_VENDOR_DOMAIN "nextgis.com")
endif()
# Some init settings
set(CMAKE_COLOR_MAKEFILE ON)
# Set path to additional CMake modules
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
#platform build settings
cmake_host_system_information(RESULT NUMBER_OF_PHYSICAL_CORES QUERY NUMBER_OF_PHYSICAL_CORES)
message(STATUS "CMake ${CMAKE_VERSION} using ${NUMBER_OF_PHYSICAL_CORES} cores")
cmake_host_system_information(RESULT NUMBER_OF_LOGICAL_CORES QUERY NUMBER_OF_LOGICAL_CORES)
message(STATUS "CMake ${CMAKE_VERSION} using ${NUMBER_OF_LOGICAL_CORES} threads")
#set multithread build for MSVC generator
if(CMAKE_GENERATOR MATCHES "Visual Studio")
add_compile_options(/MP${NUMBER_OF_LOGICAL_CORES})
set(MAKE_BUILD_PARALLEL_LEVEL ${NUMBER_OF_LOGICAL_CORES})
endif()
#Configure use CCache if heed
if (USE_CCACHE)
find_program(CCACHE_FOUND ccache)
if(CCACHE_FOUND)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
message("ccache found")
else()
message("ccache not found!")
endif(CCACHE_FOUND)
endif()
if(OSX_FRAMEWORK AND (BUILD_SHARED_LIBS OR BUILD_STATIC_LIBS))
message(FATAL_ERROR "Only OSX_FRAMEWORK key or any or both BUILD_SHARED_LIBS
and BUILD_STATIC_LIBS keys are permitted")
endif()
if(OSX_FRAMEWORK)
set(QGIS_APP_NAME ${PROJECT_NAME}-${NG_PREFIX})
else()
set(QGIS_APP_NAME ${NG_PREFIX}${PROJECT_NAME})
endif()
if(OSX_FRAMEWORK)
set(QGIS_DATA_SUBDIR "Applications/${QGIS_APP_NAME}.app/Contents/Resources")
set(INSTALL_BIN_DIR "Applications" CACHE INTERNAL "Installation directory for executables" FORCE)
set(INSTALL_LIB_DIR "${INSTALL_BIN_DIR}/${QGIS_APP_NAME}.app/Contents/Frameworks" CACHE INTERNAL "Installation directory for libraries" FORCE)
set(_PLUGIN_SUBDIR "Library/Plugins/Qt5")
set(QT5_PLUGINS_DIR Library/Plugins/Qt5)
set(QT5_TRANSLATION_DIR Library/Translations/Qt5)
set(INSTALL_PLUGIN_DIR ${_PLUGIN_SUBDIR}/${NG_PREFIX}${PROJECT_NAME} CACHE INTERNAL "Installation directory for plugins" FORCE)
set(INSTALL_SHARE_DIR ${QGIS_DATA_SUBDIR} CACHE INTERNAL "Installation directory for share data" FORCE)
set(INSTALL_MAN_DIR ${INSTALL_SHARE_DIR}/man CACHE INTERNAL "Installation directory for manual pages" FORCE)
set(INSTALL_DOC_DIR ${INSTALL_SHARE_DIR}/doc CACHE INTERNAL "Installation directory for doc pages" FORCE)
set(QT_PLUGIN_SUBDIR ${_PLUGIN_SUBDIR})
set(QGIS_PLUGIN_SUBDIR ${_PLUGIN_SUBDIR}/${NG_PREFIX}${PROJECT_NAME})
set(QGIS_LIB_SUBDIR "Applications/${QGIS_APP_NAME}.app/Contents/Frameworks")
set(INSTALL_LIB_DIR2 Library/Frameworks CACHE INTERNAL "Installation directory for symlinks" FORCE)
set(QGIS_MACAPP_BUNDLE 1)
set(SKIP_INSTALL_HEADERS ON)
set(SKIP_INSTALL_EXECUTABLES OFF)
set(SKIP_INSTALL_FILES OFF)
set(SKIP_INSTALL_EXPORT ON)
set(CMAKE_MACOSX_RPATH ON)
else()
include(GNUInstallDirs)
set(QGIS_DATA_SUBDIR "${CMAKE_INSTALL_DATADIR}/${NG_PREFIX}${PROJECT_NAME}")
set(INSTALL_BIN_DIR ${CMAKE_INSTALL_BINDIR} CACHE INTERNAL "Installation directory for executables" FORCE)
set(INSTALL_LIB_DIR ${CMAKE_INSTALL_LIBDIR} CACHE INTERNAL "Installation directory for libraries" FORCE)
set(INSTALL_INC_DIR ${CMAKE_INSTALL_INCLUDEDIR}/${NG_PREFIX}${PROJECT_NAME} CACHE INTERNAL "Installation directory for headers" FORCE)
set(INSTALL_SHARE_DIR ${CMAKE_INSTALL_DATADIR}/${NG_PREFIX}${PROJECT_NAME} CACHE INTERNAL "Installation directory for share data" FORCE)
set(INSTALL_PKGCONFIG_DIR ${INSTALL_LIB_DIR}/pkgconfig CACHE INTERNAL "Installation directory for pkgconfig (.pc) files" FORCE)
set(INSTALL_MAN_DIR ${CMAKE_INSTALL_MANDIR} CACHE INTERNAL "Installation directory for manual pages" FORCE)
set(INSTALL_DOC_DIR ${INSTALL_SHARE_DIR}/doc CACHE INTERNAL "Installation directory for doc pages" FORCE)
# TODO: solve the qt and qgis plugins paths
set(INSTALL_PLUGIN_DIR ${INSTALL_LIB_DIR}/${NG_PREFIX}${PROJECT_NAME}/plugins CACHE INTERNAL "Installation directory for plugins" FORCE)
set(QT_PLUGIN_SUBDIR "${INSTALL_LIB_DIR}/qt5/plugins" )
set(QGIS_PLUGIN_SUBDIR "${INSTALL_LIB_DIR}/${NG_PREFIX}${PROJECT_NAME}/plugins")
set(QGIS_LIB_SUBDIR ${INSTALL_LIB_DIR})
set(QGIS_MACAPP_BUNDLE 0)
endif()
set(QT_PREFIX ${CMAKE_INSTALL_PREFIX})
# set(CMAKE_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
# set the default locations where the targets (executables, libraries) will land when compiled
# this is to allow running qgis from the source tree without having to actually do a "make install"
set (QGIS_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/output)
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${QGIS_OUTPUT_DIRECTORY}/bin)
set (CMAKE_LIBRARY_OUTPUT_DIRECTORY ${QGIS_OUTPUT_DIRECTORY}/lib)
get_property(IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if (IS_MULTI_CONFIG)
set (BINARY_DIR ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${CMAKE_BUILD_TYPE})
else()
set (BINARY_DIR ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
endif()
include(util)
check_version(NGQGIS_MAJOR_VERSION NGQGIS_MINOR_VERSION NGQGIS_PATCH_VERSION CPACK_PACKAGE_VERSION_MAJOR CPACK_PACKAGE_VERSION_MINOR CPACK_PACKAGE_VERSION_PATCH RELEASE_NAME)
set(VERSION ${NGQGIS_MAJOR_VERSION}.${NGQGIS_MINOR_VERSION}.${NGQGIS_PATCH_VERSION})
set(QGIS_VERSION ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH})
if(OSX_FRAMEWORK)
set(FRAMEWORK_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}")
endif()
# For configure
include(GenerateExportHeader)
include(configure)
include_directories ( ${CMAKE_CURRENT_SOURCE_DIR} )
include_directories ( ${CMAKE_CURRENT_BINARY_DIR} )
report_version("${NG_PREFIX}${PROJECT_NAME}" ${VERSION})
option(PREPARE_ONLY "Only generate flex and bison files" OFF)
include(FindAnyProject)
# POLICIES
set_policy(CMP0048 NEW)
set_policy(CMP0053 NEW)
set_policy(CMP0058 NEW)
set_policy(CMP0063 NEW)
set_policy(CMP0071 NEW)
set_policy(CMP0075 NEW)
set_policy(CMP0077 NEW)
set_policy(CMP0094 NEW)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOUIC_SEARCH_PATHS ${CMAKE_AUTOUIC_SEARCH_PATHS}
${CMAKE_CURRENT_SOURCE_DIR}/src/ui
${CMAKE_CURRENT_SOURCE_DIR}/src/ui/symbollayer
${CMAKE_CURRENT_SOURCE_DIR}/src/ui/editorwidgets
${CMAKE_CURRENT_SOURCE_DIR}/src/ui/effects
${CMAKE_CURRENT_SOURCE_DIR}/src/ui/labeling
${CMAKE_CURRENT_SOURCE_DIR}/src/ui/layout
${CMAKE_CURRENT_SOURCE_DIR}/src/ui/processing
${CMAKE_CURRENT_SOURCE_DIR}/src/ui/auth
${CMAKE_CURRENT_SOURCE_DIR}/src/ui/raster
${CMAKE_CURRENT_SOURCE_DIR}/src/ui/styledock
${CMAKE_CURRENT_SOURCE_DIR}/src/ui/mesh
${CMAKE_CURRENT_SOURCE_DIR}/src/ui/pointcloud
${CMAKE_CURRENT_SOURCE_DIR}/src/ui/3d
${CMAKE_CURRENT_SOURCE_DIR}/src/ui/callouts
${CMAKE_CURRENT_SOURCE_DIR}/src/ui/numericformats
${CMAKE_CURRENT_SOURCE_DIR}/src/ui/attributeformconfig
${CMAKE_CURRENT_SOURCE_DIR}/src/ui/georeferencer
${CMAKE_CURRENT_SOURCE_DIR}/src/ui/annotations
${CMAKE_CURRENT_SOURCE_DIR}/src/ui/sensor
)
set(CMAKE_AUTOMOC ON)
file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/symlinks)
################################################################################
# Find Qt5 packages
set(QT_REQUIRED_COMPONENTS Core Gui Widgets Network Xml Svg Concurrent Test UiTools Sql PrintSupport)
# For gui.multimedia
set(QT_REQUIRED_COMPONENTS ${QT_REQUIRED_COMPONENTS} Multimedia MultimediaWidgets)
if (MSVC)
set(QT_REQUIRED_COMPONENTS ${QT_REQUIRED_COMPONENTS} WinExtras)
endif()
if (APPLE)
set(QT_REQUIRED_COMPONENTS ${QT_REQUIRED_COMPONENTS} MacExtras)
endif()
if (UNIX AND NOT APPLE)
set(QT_REQUIRED_COMPONENTS ${QT_REQUIRED_COMPONENTS} DBus)
endif()
option(WITH_QTWEBKIT "Build support QT Webkit" OFF)
if(WITH_QTWEBKIT)
set(QT_REQUIRED_COMPONENTS ${QT_REQUIRED_COMPONENTS} WebKit WebKitWidgets)
add_definitions(-DWITH_QTWEBKIT)
endif()
set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS $<$<NOT:$<CONFIG:Debug>>:QT_NO_DEBUG>)
# Need for synccrsdb
find_anyproject(PROJ REQUIRED)
if (PROJ_FOUND)
string(REPLACE "." ";" VERSION_LIST ${PROJ_VERSION})
list(GET VERSION_LIST 0 PROJ_VERSION_MAJOR)
list(GET VERSION_LIST 1 PROJ_VERSION_MINOR)
list(GET VERSION_LIST 2 PROJ_VERSION_PATCH)
endif()
find_anyproject(GDAL REQUIRED)
find_anyproject(GEOS REQUIRED)
find_anyproject(Qca REQUIRED)
find_anyproject(QtKeychain REQUIRED)
find_anyproject(SpatialIndex REQUIRED)
find_anyproject(SQLite3 REQUIRED)
find_anyproject(LIBZIP REQUIRED)
# find_anyproject(EXIV REQUIRED)
find_anyproject(EXPAT REQUIRED)
find_anyproject(ZLIB REQUIRED)
find_anyproject(NGSTD DEFAULT ON COMPONENTS core framework)
if(NGSTD_FOUND)
add_definitions(-DNGSTD_USING)
endif()
# if (APPLE)
# # Libtasn1 is for DER-encoded PKI ASN.1 parsing/extracting workarounds
# find_anyproject(Libtasn1 REQUIRED)
# endif()
# try` to configure and build POLY2TRI support
set (WITH_INTERNAL_POLY2TRI TRUE CACHE BOOL "Determines whether POLY2TRI should be built from internal copy")
if (NOT WITH_INTERNAL_POLY2TRI)
find_anyproject(Poly2Tri REQUIRED)
endif()
if(PREPARE_ONLY)
set(SKIP_INSTALL_LIBRARIES ON)
set(SKIP_INSTALL_ALL ON)
set(WITH_GUI OFF)
set(WITH_AUTH OFF)
set(WITH_ANALYSIS ON)
set(WITH_DESKTOP OFF)
set(WITH_3D OFF)
set(WITH_QGIS_PROCESS OFF)
set(WITH_BINDINGS OFF)
set(ENABLE_TESTS OFF)
set(WITH_THREAD_LOCAL OFF)
set(WITH_DOCS OFF)
else()
option(WITH_GUI "Determines whether QGIS GUI library (and everything built on top of it) should be built" ON)
option(WITH_AUTH "Determines whether QGIS authentication methods should be built" ON)
option(WITH_ANALYSIS "Determines whether QGIS analysis library should be built" ON)
option(WITH_DESKTOP "Determines whether QGIS desktop should be built" ON)
option(WITH_3D "Determines whether QGIS 3D library should be built" ON)
option(WITH_QGIS_PROCESS "Determines whether the standalone \"qgis_process\" tool should be built" OFF) # TODO: Set ON
option(WITH_BINDINGS "Determines whether python bindings should be built" ON)
option(WITH_DOCS "Determines whether documents should be built" ON)
option(ENABLE_TESTS "Build unit tests?" OFF)
option(WITH_OAUTH2_PLUGIN "Build OAuth2 authentication method plugin" OFF) # TODO: Set ON
if(WITH_OAUTH2_PLUGIN)
set(HAVE_OAUTH2_PLUGIN TRUE)
endif()
option(WITH_THREAD_LOCAL "Determines whether std::thread_local should be used" ON)
if (WITH_THREAD_LOCAL)
set (USE_THREAD_LOCAL TRUE) # used in qgsconfig.h
endif()
# find_anyproject(ZLIB REQUIRED)
if (WITH_GUI)
find_anyproject(Qwt REQUIRED)
find_anyproject(QScintilla REQUIRED)
set(QT_REQUIRED_COMPONENTS ${QT_REQUIRED_COMPONENTS} Qml QuickWidgets)
add_definitions(-DWITH_QML)
set(HAVE_GUI TRUE)
endif()
set(QT_REQUIRED_COMPONENTS ${QT_REQUIRED_COMPONENTS} LinguistTools)
find_package(OpenCL)
if(${OpenCL_FOUND})
set(USE_OPENCL TRUE)
set(HAVE_OPENCL TRUE)
# Fixup for standard FindOpenCL module not assigning proper framework headers directory
if (APPLE AND "${OpenCL_INCLUDE_DIR}" MATCHES "OpenCL\\.framework/?$")
set(OpenCL_INCLUDE_DIR "${OpenCL_INCLUDE_DIR}/Headers" CACHE PATH "" FORCE)
set(OpenCL_INCLUDE_DIRS ${OpenCL_INCLUDE_DIR})
endif()
find_package(OpenCLhpp)
if(NOT OPENCL_HPP_FOUND)
# Use internal headers copied from OpenCL-CLHPP project
set(OPENCL_HPP_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/external/opencl-clhpp/include CACHE PATH "" FORCE)
message(STATUS "Couldn't find OpenCL C++ headers, using internal: ${OPENCL_HPP_INCLUDE_DIR}")
endif()
set(OpenCL_INCLUDE_DIRS ${OpenCL_INCLUDE_DIRS} ${OPENCL_HPP_INCLUDE_DIR})
else()
message(STATUS "Couldn't find OpenCL: support DISABLED")
endif()
endif()
if(WITH_DESKTOP)
if((WIN32 AND NOT MINGW) OR (UNIX AND NOT APPLE AND NOT ANDROID AND NOT IOS))
set(HAVE_CRASH_HANDLER TRUE)
endif()
endif()
# set(QT5_3DEXTRA_LIBRARY "/usr/lib/x86_64-linux-gnu/libQt53DExtras.so")
# set(QT5_3DEXTRA_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/external/qt3dextra-headers")
# set(Qt53DExtras_DIR "${CMAKE_CURRENT_SOURCE_DIR}/external/qt3dextra-headers/cmake/Qt53DExtras")
# set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/external/qt3dextra-headers")
if (WITH_3D)
set(QT_REQUIRED_COMPONENTS ${QT_REQUIRED_COMPONENTS} 3DCore 3DRender 3DInput 3DLogic 3DExtras)
set(HAVE_3D TRUE) # used in qgsconfig.h
endif()
find_anyproject(Qt5 REQUIRED COMPONENTS ${QT_REQUIRED_COMPONENTS})
# if (BUILD_WITH_QT6)
set(QT_VERSION_BASE Qt5)
set(QT_VERSION_BASE_LOWER qt5)
get_target_property(QMAKE_EXECUTABLE ${QT_VERSION_BASE}::qmake LOCATION)
if(WIN32)
get_target_property(LR_PATH Qt5::lrelease IMPORTED_LOCATION)
get_filename_component(QT_BIN_DIR ${LR_PATH} PATH)
set(QT5_PLUGINS_DIR "${QT_BIN_DIR}/../plugins")
set(QT5_TRANSLATION_DIR "${QT_BIN_DIR}/../translation")
# Copy zlib1.dll to make moc.exe, rcc.exe, etc. working
if(${ZLIB_FOUND})
get_target_property(ZLIB_IMPORTED_LOCATION ${ZLIB_LIBRARIES} IMPORTED_LOCATION_RELEASE)
if(EXISTS ${ZLIB_IMPORTED_LOCATION})
file(COPY ${ZLIB_IMPORTED_LOCATION} DESTINATION ${QT_BIN_DIR})
endif()
endif()
endif()
configure_file(${CMAKE_SOURCE_DIR}/cmake/qt.conf.cmake.in ${CMAKE_BINARY_DIR}/qt.conf IMMEDIATE @ONLY)
############################################
# Add binaries and libraries
set(CMAKE_CXX_STANDARD 17)
if(MSVC)
set(_warnings "")
if (NOT USING_NMAKE AND NOT USING_NINJA)
set(_warnings "${_warnings} /W4" )
endif()
# disable warnings
set(_warnings "${_warnings} /wd4091 ") # 'typedef': ignored on left of '' when no variable is declared (occurs in MS DbgHelp.h header)
set(_warnings "${_warnings} /wd4100 ") # unused formal parameters
set(_warnings "${_warnings} /wd4127 ") # constant conditional expressions (used in Qt template classes)
set(_warnings "${_warnings} /wd4190 ") # 'identifier' has C-linkage specified, but returns UDT 'identifier2' which is incompatible with C
set(_warnings "${_warnings} /wd4231 ") # nonstandard extension used : 'identifier' before template explicit instantiation (used in Qt template classes)
set(_warnings "${_warnings} /wd4244 ") # conversion from '...' to '...' possible loss of data
set(_warnings "${_warnings} /wd4251 ") # needs to have dll-interface to be used by clients of class (occurs in Qt template classes)
set(_warnings "${_warnings} /wd4267 ") # 'argument': conversion from 'size_t' to 'int', possible loss of data
set(_warnings "${_warnings} /wd4275 ") # non dll-interface class '...' used as base for dll-interface class '...'
set(_warnings "${_warnings} /wd4290 ") # c++ exception specification ignored except to indicate a function is not __declspec(nothrow) (occurs in sip generated bindings)
set(_warnings "${_warnings} /wd4456 ") # declaration of '...' hides previous local declaration
set(_warnings "${_warnings} /wd4457 ") # declaration of '...' hides a function parameter
set(_warnings "${_warnings} /wd4458 ") # declaration of '...' hides class member
set(_warnings "${_warnings} /wd4505 ") # unreferenced local function has been removed (QgsRasterDataProvider::extent)
set(_warnings "${_warnings} /wd4510 ") # default constructor could not be generated (sqlite3_index_info, QMap)
set(_warnings "${_warnings} /wd4512 ") # assignment operator could not be generated (sqlite3_index_info)
set(_warnings "${_warnings} /wd4610 ") # user defined constructor required (sqlite3_index_info)
set(_warnings "${_warnings} /wd4706 ") # assignment within conditional expression (pal)
set(_warnings "${_warnings} /wd4714 ") # function '...' marked as __forceinline not inlined (QString::toLower/toUpper/trimmed)
set(_warnings "${_warnings} /wd4800 ") # 'int' : forcing value to bool 'true' or 'false' (performance warning)
set(_warnings "${_warnings} /wd4996 ") # '...': was declared deprecated (unfortunately triggered when implementing deprecated interfaces even when it is deprecated too)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_warnings} /utf-8")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_warnings} /utf-8")
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /utf-8 /std:c++17")
# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /utf-8 /std:c++17")
# set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
# set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
# disable macros that offend std::numeric_limits<T>::min()/max()
add_definitions(-DNOMINMAX)
else()
# add warnings via flags (not as definitions as on Mac -Wall can not be overridden per language )
set(_warnings "-Wall -Wextra -Wno-long-long -Wformat-security -Wno-strict-aliasing")
# c++ only warnings
set(_warnings "${_warnings} -Wnon-virtual-dtor")
# unavoidable - we can't avoid these, as older, supported compilers do not support removing the redundant move
set(_warnings "${_warnings} -Wno-redundant-move")
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 7.9.999)
# heaps of these thrown by Qt headers at the moment (sep 2019)
set(_warnings "${_warnings} -Wno-deprecated-copy")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_warnings}")
# Qt produces lots of warnings with strict aliasing (as of Qt 4.4.0 & GCC 4.3)
# There are redundant declarations in Qt and GDAL
# add_definitions( -fstrict-aliasing -Wstrict-aliasing=1 -Wredundant-decls )
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wreturn-type-c-linkage -Woverloaded-virtual -Wimplicit-fallthrough")
endif()
# add any extra CXXFLAGS flags set by user. can be -D CXX_EXTRA_FLAGS or environment variable
# command line -D option overrides environment variable
# e.g. useful for suppressing transient upstream warnings in dependencies, like Qt
set(CXX_EXTRA_FLAGS "" CACHE STRING "Additional appended CXXFLAGS")
if ("${CXX_EXTRA_FLAGS}" STREQUAL "" AND DEFINED $ENV{CXX_EXTRA_FLAGS})
set(CXX_EXTRA_FLAGS "$ENV{CXX_EXTRA_FLAGS}")
endif()
if (NOT "${CXX_EXTRA_FLAGS}" STREQUAL "")
message (STATUS "Appending CXX_EXTRA_FLAGS")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX_EXTRA_FLAGS}")
endif()
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Qunused-arguments")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Qunused-arguments")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Qunused-arguments")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Qunused-arguments")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Qunused-arguments")
endif()
endif()
if (CMAKE_BUILD_TYPE MATCHES Debug)
message (STATUS "Debug output enabled")
set(QGISDEBUG TRUE)
else()
set(QGISDEBUG FALSE)
endif()
set (AGGRESSIVE_SAFE_MODE FALSE CACHE BOOL "Forces a aggressive safe mode where issues like unsafe thread access will resort in fatal exceptions")
if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /utf-8 /std:c++17")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /utf-8 /std:c++17")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
# disable macros that offend std::numeric_limits<T>::min()/max()
add_definitions(-DNOMINMAX)
endif()
# Prevent build when Qt api deprecated before this Qt version is used:
add_definitions(-DQT_DEPRECATED_WARNINGS)
# Unfortunately Qwt uses deprecated QString::null in headers, preventing this being raised above 5.8
add_definitions(-DQT_DISABLE_DEPRECATED_BEFORE=0x050800)
# For fast string concatenation
add_definitions(-DQT_USE_QSTRINGBUILDER)
if (WITH_ANALYSIS AND NOT PREPARE_ONLY)
find_anyproject(GSL REQUIRED)
set(HAVE_GSL TRUE)
set(HAVE_GEOREFERENCER TRUE)
endif()
find_anyproject(Spatialite DEFAULT ON)
if(SPATIALITE_FOUND)
set(HAVE_SPATIALITE TRUE)
endif()
find_anyproject(PostgreSQL DEFAULT ON NAMES PQ pq libpq)
if(POSTGRESQL_FOUND)
set(HAVE_POSTGRESQL TRUE)
add_definitions(-DHAVE_PGCONFIG=1) #-DHAVE_POSTGRESQL
endif()
find_anyproject(OCI DEFAULT ON)
if(OCI_FOUND)
include_directories(${OCI_INCLUDE_DIRS}/oci)
set(HAVE_ORACLE TRUE)
endif()
if(QWT_FOUND)
add_definitions(-DQWT_VERSION_STR="${QWT_VERSION}")
endif()
math(EXPR QGIS_VERSION_INT "${CPACK_PACKAGE_VERSION_MAJOR}*10000+${CPACK_PACKAGE_VERSION_MINOR}*100+${CPACK_PACKAGE_VERSION_PATCH}")
#############################################################
if(MSVC)
# Turn on defines for non standard maths stuff
add_definitions(-D_USE_MATH_DEFINES)
# Turn off deprecation warnings
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
add_definitions(-D_CRT_NONSTDC_NO_WARNINGS)
endif()
if("${CMAKE_SYSTEM_NAME}" MATCHES "Linux")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--no-undefined")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--no-undefined")
endif() #"${CMAKE_SYSTEM_NAME}" MATCHES "Linux")
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
if (WITH_BINDINGS)
find_package(Python3 REQUIRED COMPONENTS Interpreter Development)
if(${Python3_FOUND})
set(PYTHON_EXECUTABLE ${Python3_EXECUTABLE})
set(PYTHON_LIBRARIES ${Python3_LIBRARIES})
set(PYTHON_SITEARCH ${Python3_SITEARCH})
set(PYTHON_INCLUDE_DIRS ${Python3_INCLUDE_DIRS})
set(PYTHON_VERSION_MAJOR ${Python3_VERSION_MAJOR})
set(PYTHON_VERSION_MINOR ${Python3_VERSION_MINOR})
set(PYTHON_VERSION_STRING ${Python3_VERSION_MAJOR}.${Python3_VERSION_MINOR}.${Python3_VERSION_PATCH})
endif()
if(OSX_FRAMEWORK)
set(QGIS_PYTHON_DIR "Library/Python/${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/site-packages/${PROJECT_NAME}")
elseif(WIN32)
set(QGIS_PYTHON_DIR "${INSTALL_LIB_DIR}/Python${PYTHON_VERSION_MAJOR}${PYTHON_VERSION_MINOR}/site-packages/${PROJECT_NAME}")
else()
set(QGIS_PYTHON_DIR "lib/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/dist-packages/${PROJECT_NAME}")
endif()
find_package(SIP REQUIRED)
find_package(PyQt5 REQUIRED)
set(PYQT_SIP_FLAGS ${PYQT5_SIP_FLAGS})
# separate_arguments(PYQT_SIP_FLAGS) # convert space separated values to a list
find_anyproject(Qsci REQUIRED)
include(PythonMacros)
include(PyQtMacros)
include(SIPMacros)
add_subdirectory(python)
if(NOT SUPPRESS_VERBOSE_OUTPUT)
message("i Found Python executable: ${PYTHON_EXECUTABLE} (version ${PYTHON_VERSION_STRING})")
message("i Python library: ${PYTHON_LIBRARIES}")
message("i Python site-packages: ${PYTHON_SITEARCH}")
endif()
else()
find_package(PythonInterp 3 REQUIRED)
# find_anyproject(Python3 REQUIRED COMPONENTS Interpreter)
message("i Found python executable: ${PYTHON_EXECUTABLE} (version ${PYTHON_VERSION_STRING})")
endif()
get_property(IS_MULTI_CONFIG_GENERATOR GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
#############################################################
# create qgsconfig.h
# installed with app target
configure_file(${CMAKE_SOURCE_DIR}/cmake_templates/qgsconfig.h.in ${CMAKE_BINARY_DIR}/qgsconfig.h)
include_directories(${CMAKE_BINARY_DIR})
#############################################################
# create qgsversion.h
include(CreateQgsVersion)
CREATE_QGSVERSION()
#############################################################
set(PACKAGE_NAME ${PROJECT_NAME})
string(TOUPPER ${PACKAGE_NAME} PACKAGE_UPPER_NAME)
set(TEST_DATA_DIR "${CMAKE_CURRENT_SOURCE_DIR}/tests/testdata")
add_subdirectory(src)
if(WITH_DOCS)
add_subdirectory(doc)
endif()
if (ENABLE_TESTS)
set(QT_USE_QTTEST TRUE)
set(GET_DEPENDENCIES ON)
enable_testing()
#create a variable to specify where our test data is
#so that unit tests can use TEST_DATA_DIR to locate
#the test data. See CMakeLists in test dirs for more info
#TEST_DATA_DIR is also used by QgsRenderChecker currently in core
add_subdirectory(tests)
set (CTEST_BINARY_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/output/bin" )
message (STATUS "Ctest Binary Directory set to: ${CTEST_BINARY_DIRECTORY}")
endif()
if (NOT PREPARE_ONLY)
add_subdirectory(images)
add_subdirectory(resources)
add_subdirectory(i18n)
endif()
if (PREPARE_ONLY)
add_custom_target(prepare_parser DEPENDS ${PREPARE_PARSER_TARGETS})
else()
add_custom_target(uninstall COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
# Export package ===============================================================
# Add all targets to the build-tree export set
# export(TARGETS ${TARGETS} FILE ${PROJECT_BINARY_DIR}/${PACKAGE_UPPER_NAME}Targets.cmake)
# if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL)
# # Install the export set for use with the install-tree
# install(EXPORT ${PACKAGE_UPPER_NAME}Targets DESTINATION ${INSTALL_CMAKECONF_DIR} COMPONENT dev)
# endif()
# Create the Config.cmake file
# configure_file(${CMAKE_SOURCE_DIR}/cmake/PackageConfig.cmake.in ${PROJECT_BINARY_DIR}/${PACKAGE_UPPER_NAME}Config.cmake @ONLY)
# Archiving ====================================================================
set(CPACK_PACKAGE_NAME "${PACKAGE_NAME}")
set(CPACK_PACKAGE_VENDOR "${PACKAGE_VENDOR}")
set(CPACK_PACKAGE_VERSION "${VERSION}")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "${PACKAGE_NAME} Installation")
set(CPACK_PACKAGE_RELOCATABLE TRUE)
set(CPACK_ARCHIVE_COMPONENT_INSTALL ON)
set(CPACK_GENERATOR "ZIP")
set(CPACK_MONOLITHIC_INSTALL ON)
set(CPACK_STRIP_FILES TRUE)
# Get cpack zip archive name
get_cpack_filename(${VERSION} PROJECT_CPACK_FILENAME)
set(CPACK_PACKAGE_FILE_NAME ${PROJECT_CPACK_FILENAME})
include(CPack)
endif()