forked from OSGeo/gdal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gdal.cmake
867 lines (764 loc) · 36 KB
/
gdal.cmake
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
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
# CMake4GDAL project is distributed under MIT license. See accompanying file LICENSE.txt.
# Increment the below number each time an ABI incompatible change is done,
# e.g removing a public function/method, changing its prototype (including
# adding a default value to a parameter of a C++ method), adding
# a new member or virtual function in a public C++ class, etc.
# This will typically happen for each GDAL feature release (change of X or Y in
# a X.Y.Z numbering scheme), but should not happen for a bugfix release (change of Z)
# Previous value: 34 for GDAL 3.8
set(GDAL_SOVERSION 34)
# Switches to control build targets(cached)
option(ENABLE_GNM "Build GNM (Geography Network Model) component" ON)
option(ENABLE_PAM "Set ON to enable Persistent Auxiliary Metadata (.aux.xml)" ON)
option(BUILD_APPS "Build command line utilities" ON)
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/doc" AND NOT "${CMAKE_BINARY_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}")
# In-tree builds do not support Doc building because Sphinx requires (at least
# at first sight) a Makefile file which conflicts with the CMake generated one
option(BUILD_DOCS "Build documentation" ON)
endif()
# This option is to build drivers as plugins, for drivers that have external dependencies, that are not parf of GDAL
# core dependencies Examples are netCDF, HDF4, Oracle, PDF, etc. This global setting can be overridden at the driver
# level with GDAL_ENABLE_FRMT_{foo}_PLUGIN or OGR_ENABLE_{foo}_PLUGIN variables.
option(GDAL_ENABLE_PLUGINS "Set ON to build drivers that have non-core external dependencies as plugin" OFF)
# This option is to build drivers as plugins, for drivers that have no external dependencies or dependencies that are
# part of GDAL core dependencies Examples are BMP, FlatGeobuf, etc.
option(GDAL_ENABLE_PLUGINS_NO_DEPS "Set ON to build drivers that have no non-core external dependencies as plugin" OFF)
mark_as_advanced(GDAL_ENABLE_PLUGINS_NO_DEPS)
option(ENABLE_IPO "Enable Inter-Procedural Optimization if possible" OFF)
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
option(GDAL_ENABLE_MACOSX_FRAMEWORK "Enable Framework on Mac OS X" OFF)
endif ()
option(GDAL_BUILD_OPTIONAL_DRIVERS "Whether to build GDAL optional drivers by default" ON)
option(OGR_BUILD_OPTIONAL_DRIVERS "Whether to build OGR optional drivers by default" ON)
# libgdal shared/satic library generation
option(BUILD_SHARED_LIBS "Set ON to build shared library" ON)
# produce position independent code, default is on when building a shared library
option(GDAL_OBJECT_LIBRARIES_POSITION_INDEPENDENT_CODE "Set ON to produce -fPIC code" ${BUILD_SHARED_LIBS})
# Option to set preferred C# compiler
option(CSHARP_MONO "Whether to force the C# compiler to be Mono" OFF)
# This line must be kept early in the CMake instructions. At time of writing,
# this file is populated only be scripts/install_bash_completions.cmake.in
install(CODE "file(REMOVE \"${PROJECT_BINARY_DIR}/install_manifest_extra.txt\")")
# ######################################################################################################################
# Detect available warning flags
# Do that check now, since we need the result of HAVE_GCC_WARNING_ZERO_AS_NULL_POINTER_CONSTANT for cpl_config.h
set(GDAL_C_WARNING_FLAGS)
set(GDAL_CXX_WARNING_FLAGS)
if (MSVC)
# 1. conditional expression is constant
# 2. 'identifier' : class 'type' needs to have dll-interface to be used by clients of class 'type2'
# 3. non DLL-interface classkey 'identifier' used as base for DLL-interface classkey 'identifier'
# 4. ??????????
# 5. 'identifier' : unreferenced formal parameter
# 6. 'conversion' : conversion from 'type1' to 'type2', signed/unsigned mismatch
# 7. nonstandard extension used : translation unit is empty (only applies to C source code)
# 8. new behavior: elements of array 'array' will be default initialized (needed for
# https://trac.osgeo.org/gdal/changeset/35593)
# 9. interaction between '_setjmp' and C++ object destruction is non-portable
#
set(GDAL_C_WARNING_FLAGS
/W4
/wd4127
/wd4251
/wd4275
/wd4786
/wd4100
/wd4245
/wd4206
/wd4351
/wd4611)
set(GDAL_CXX_WARNING_FLAGS ${GDAL_C_WARNING_FLAGS})
add_compile_options(/EHsc)
# The following are extra disables that can be applied to external source not under our control that we wish to use
# less stringent warnings with.
set(GDAL_SOFTWARNFLAGS
/wd4244
/wd4702
/wd4701
/wd4013
/wd4706
/wd4057
/wd4210
/wd4305)
else ()
set(GDAL_SOFTWARNFLAGS "")
macro (detect_and_set_c_warning_flag flag_name)
string(TOUPPER ${flag_name} flag_name_upper)
string(REPLACE "-" "_" flag_name_upper "${flag_name_upper}")
string(REPLACE "=" "_" flag_name_upper "${flag_name_upper}")
check_c_compiler_flag(-W${flag_name} "HAVE_WFLAG_${flag_name_upper}")
if (HAVE_WFLAG_${flag_name_upper})
set(GDAL_C_WARNING_FLAGS ${GDAL_C_WARNING_FLAGS} -W${flag_name})
endif ()
endmacro ()
macro (detect_and_set_cxx_warning_flag flag_name)
string(TOUPPER ${flag_name} flag_name_upper)
string(REPLACE "-" "_" flag_name_upper "${flag_name_upper}")
string(REPLACE "=" "_" flag_name_upper "${flag_name_upper}")
check_cxx_compiler_flag(-W${flag_name} "HAVE_WFLAG_${flag_name_upper}")
if (HAVE_WFLAG_${flag_name_upper})
set(GDAL_CXX_WARNING_FLAGS ${GDAL_CXX_WARNING_FLAGS} -W${flag_name})
endif ()
endmacro ()
macro (detect_and_set_c_and_cxx_warning_flag flag_name)
string(TOUPPER ${flag_name} flag_name_upper)
string(REPLACE "-" "_" flag_name_upper "${flag_name_upper}")
string(REPLACE "=" "_" flag_name_upper "${flag_name_upper}")
check_c_compiler_flag(-W${flag_name} "HAVE_WFLAG_${flag_name_upper}")
if (HAVE_WFLAG_${flag_name_upper})
set(GDAL_C_WARNING_FLAGS ${GDAL_C_WARNING_FLAGS} -W${flag_name})
set(GDAL_CXX_WARNING_FLAGS ${GDAL_CXX_WARNING_FLAGS} -W${flag_name})
endif ()
endmacro ()
detect_and_set_c_and_cxx_warning_flag(all)
detect_and_set_c_and_cxx_warning_flag(extra)
detect_and_set_c_and_cxx_warning_flag(init-self)
detect_and_set_c_and_cxx_warning_flag(unused-parameter)
detect_and_set_c_warning_flag(missing-prototypes)
detect_and_set_c_and_cxx_warning_flag(missing-declarations)
detect_and_set_c_and_cxx_warning_flag(shorten-64-to-32)
detect_and_set_c_and_cxx_warning_flag(logical-op)
detect_and_set_c_and_cxx_warning_flag(shadow)
detect_and_set_cxx_warning_flag(shadow-field) # CLang only for now
detect_and_set_c_and_cxx_warning_flag(missing-include-dirs)
check_c_compiler_flag("-Wformat -Werror=format-security -Wno-format-nonliteral" HAVE_WFLAG_FORMAT_SECURITY)
if (HAVE_WFLAG_FORMAT_SECURITY)
set(GDAL_C_WARNING_FLAGS ${GDAL_C_WARNING_FLAGS} -Wformat -Werror=format-security -Wno-format-nonliteral)
set(GDAL_CXX_WARNING_FLAGS ${GDAL_CXX_WARNING_FLAGS} -Wformat -Werror=format-security -Wno-format-nonliteral)
else ()
detect_and_set_c_and_cxx_warning_flag(format)
endif ()
detect_and_set_c_and_cxx_warning_flag(error=vla)
detect_and_set_c_and_cxx_warning_flag(no-clobbered)
detect_and_set_c_and_cxx_warning_flag(date-time)
detect_and_set_c_and_cxx_warning_flag(null-dereference)
detect_and_set_c_and_cxx_warning_flag(duplicate-cond)
detect_and_set_cxx_warning_flag(extra-semi)
detect_and_set_c_and_cxx_warning_flag(comma)
detect_and_set_c_and_cxx_warning_flag(float-conversion)
check_c_compiler_flag("-Wdocumentation -Wno-documentation-deprecated-sync" HAVE_WFLAG_DOCUMENTATION_AND_NO_DEPRECATED)
if (HAVE_WFLAG_DOCUMENTATION_AND_NO_DEPRECATED)
set(GDAL_C_WARNING_FLAGS ${GDAL_C_WARNING_FLAGS} -Wdocumentation -Wno-documentation-deprecated-sync)
set(GDAL_CXX_WARNING_FLAGS ${GDAL_CXX_WARNING_FLAGS} -Wdocumentation -Wno-documentation-deprecated-sync)
endif ()
detect_and_set_cxx_warning_flag(unused-private-field)
detect_and_set_cxx_warning_flag(non-virtual-dtor)
detect_and_set_cxx_warning_flag(overloaded-virtual)
detect_and_set_cxx_warning_flag(suggest-override)
check_cxx_compiler_flag(-fno-operator-names HAVE_FLAG_NO_OPERATOR_NAMES)
if (HAVE_FLAG_NO_OPERATOR_NAMES)
set(GDAL_CXX_WARNING_FLAGS ${GDAL_CXX_WARNING_FLAGS} -fno-operator-names)
endif ()
check_cxx_compiler_flag(-Wzero-as-null-pointer-constant HAVE_GCC_WARNING_ZERO_AS_NULL_POINTER_CONSTANT)
if (HAVE_GCC_WARNING_ZERO_AS_NULL_POINTER_CONSTANT)
set(GDAL_CXX_WARNING_FLAGS ${GDAL_CXX_WARNING_FLAGS} -Wzero-as-null-pointer-constant)
endif ()
# Detect -Wold-style-cast but do not add it by default, as not all targets support it
check_cxx_compiler_flag(-Wold-style-cast HAVE_WFLAG_OLD_STYLE_CAST)
if (HAVE_WFLAG_OLD_STYLE_CAST)
set(WFLAG_OLD_STYLE_CAST -Wold-style-cast)
endif ()
# Detect Weffc++ but do not add it by default, as not all targets support it
check_cxx_compiler_flag(-Weffc++ HAVE_WFLAG_EFFCXX)
if (HAVE_WFLAG_EFFCXX)
set(WFLAG_EFFCXX -Weffc++)
endif ()
if (CMAKE_BUILD_TYPE MATCHES Debug)
check_c_compiler_flag(-ftrapv HAVE_FTRAPV)
if (HAVE_FTRAPV)
set(GDAL_C_WARNING_FLAGS ${GDAL_C_WARNING_FLAGS} -ftrapv)
set(GDAL_CXX_WARNING_FLAGS ${GDAL_CXX_WARNING_FLAGS} -ftrapv)
endif ()
endif ()
endif ()
add_compile_definitions($<$<CONFIG:DEBUG>:DEBUG>)
# message(STATUS "GDAL_C_WARNING_FLAGS: ${GDAL_C_WARNING_FLAGS}") message(STATUS "GDAL_CXX_WARNING_FLAGS: ${GDAL_CXX_WARNING_FLAGS}")
if (CMAKE_CXX_COMPILER_ID STREQUAL "IntelLLVM" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
check_cxx_compiler_flag(-fno-finite-math-only HAVE_FLAG_NO_FINITE_MATH_ONLY)
if (HAVE_FLAG_NO_FINITE_MATH_ONLY)
# Intel CXX compiler based on clang defaults to -ffinite-math-only, which breaks std::isinf(), std::isnan(), etc.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-finite-math-only")
endif ()
set(TEST_LINK_STDCPP_SOURCE_CODE
"#include <string>
int main(){
std::string s;
s += \"x\";
return 0;
}")
check_cxx_source_compiles("${TEST_LINK_STDCPP_SOURCE_CODE}" _TEST_LINK_STDCPP)
if( NOT _TEST_LINK_STDCPP )
message(WARNING "Cannot link code using standard C++ library. Automatically adding -lstdc++ to CMAKE_EXE_LINKER_FLAGS, CMAKE_SHARED_LINKER_FLAGS and CMAKE_MODULE_LINKER_FLAGS")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lstdc++")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -lstdc++")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -lstdc++")
check_cxx_source_compiles("${TEST_LINK_STDCPP_SOURCE_CODE}" _TEST_LINK_STDCPP_AGAIN)
if( NOT _TEST_LINK_STDCPP_AGAIN )
message(FATAL_ERROR "Cannot link C++ program")
endif()
endif()
check_c_compiler_flag(-wd188 HAVE_WD188) # enumerated type mixed with another type
if( HAVE_WD188 )
set(GDAL_C_WARNING_FLAGS ${GDAL_C_WARNING_FLAGS} -wd188)
endif()
check_c_compiler_flag(-wd2259 HAVE_WD2259) # non-pointer conversion from ... may lose significant bits
if( HAVE_WD2259 )
set(GDAL_C_WARNING_FLAGS ${GDAL_C_WARNING_FLAGS} -wd2259)
endif()
check_c_compiler_flag(-wd2312 HAVE_WD2312) # pointer cast involving 64-bit pointed-to type
if( HAVE_WD2259 )
set(GDAL_C_WARNING_FLAGS ${GDAL_C_WARNING_FLAGS} -wd2312)
endif()
endif ()
# ######################################################################################################################
# generate ${CMAKE_CURRENT_BINARY_DIR}/port/cpl_config.h
set(_CMAKE_C_FLAGS_backup ${CMAKE_C_FLAGS})
set(_CMAKE_CXX_FLAGS_backup ${CMAKE_CXX_FLAGS})
if (CMAKE_C_FLAGS)
string(REPLACE "-Werror " " " CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ")
string(REPLACE "/WX " " " CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ")
endif ()
if (CMAKE_CXX_FLAGS)
string(REPLACE "-Werror " " " CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ")
string(REPLACE "/WX " " " CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ")
endif ()
include(configure)
# generate ${CMAKE_CURRENT_BINARY_DIR}/gcore/gdal_version.h and set GDAL_VERSION variable
include(GdalVersion)
# find 3rd party libraries
include(CheckDependentLibraries)
# Generates now port/cpl_config.h (it depends on at least iconv detection in CheckDependentLibraries)
configure_file(${GDAL_CMAKE_TEMPLATE_PATH}/cpl_config.h.in ${PROJECT_BINARY_DIR}/port/cpl_config.h @ONLY)
set(CMAKE_C_FLAGS ${_CMAKE_C_FLAGS_backup})
set(CMAKE_CXX_FLAGS ${_CMAKE_CXX_FLAGS_backup})
if (GDAL_HIDE_INTERNAL_SYMBOLS)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
endif ()
# Check that all symbols we need are present in our dependencies This is in particular useful to check that drivers
# built as plugins can access all symbols they need.
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
include(CheckLinkerFlag)
check_linker_flag(C "-Wl,--no-undefined" HAS_NO_UNDEFINED)
if (HAS_NO_UNDEFINED AND (NOT "${CMAKE_CXX_FLAGS}" MATCHES "-fsanitize") AND NOT CMAKE_SYSTEM_NAME MATCHES "OpenBSD")
string(APPEND CMAKE_SHARED_LINKER_FLAGS " -Wl,--no-undefined")
string(APPEND CMAKE_MODULE_LINKER_FLAGS " -Wl,--no-undefined")
endif ()
endif ()
macro(set_alternate_linker linker)
if( NOT "${USE_ALTERNATE_LINKER}" STREQUAL "${USE_ALTERNATE_LINKER_OLD_CACHED}" )
unset(LINKER_EXECUTABLE CACHE)
endif()
find_program(LINKER_EXECUTABLE ld.${USE_ALTERNATE_LINKER} ${USE_ALTERNATE_LINKER})
if(LINKER_EXECUTABLE)
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
if( "${CMAKE_CXX_COMPILER_VERSION}" VERSION_GREATER_EQUAL 12.0.0)
add_link_options("--ld-path=${LINKER_EXECUTABLE}")
else()
add_link_options("-fuse-ld=${LINKER_EXECUTABLE}")
endif()
elseif( "${linker}" STREQUAL "mold" AND
"${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" AND
"${CMAKE_CXX_COMPILER_VERSION}" VERSION_LESS 12.1.0)
# GCC before 12.1.0: -fuse-ld does not accept mold as a valid argument,
# so you need to use -B option instead.
get_filename_component(_dir ${LINKER_EXECUTABLE} DIRECTORY)
get_filename_component(_dir ${_dir} DIRECTORY)
if( EXISTS "${_dir}/libexec/mold/ld" )
add_link_options(-B "${_dir}/libexec/mold")
else()
message(FATAL_ERROR "Cannot find ${_dir}/libexec/mold/ld")
endif()
else()
add_link_options("-fuse-ld=${USE_ALTERNATE_LINKER}")
endif()
message(STATUS "Using alternative linker: ${LINKER_EXECUTABLE}")
else()
message(FATAL_ERROR "Cannot find alternative linker ${USE_ALTERNATE_LINKER}")
endif()
endmacro()
# CMake >= 3.13 needed for add_link_options()
if( (CMAKE_VERSION VERSION_GREATER_EQUAL 3.13) AND ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") )
set(USE_ALTERNATE_LINKER "" CACHE STRING "Use alternate linker. Leave empty for system default; potential alternatives are 'gold', 'lld', 'bfd', 'mold'")
if(NOT "${USE_ALTERNATE_LINKER}" STREQUAL "")
set_alternate_linker(${USE_ALTERNATE_LINKER})
endif()
set(USE_ALTERNATE_LINKER_OLD_CACHED
${USE_ALTERNATE_LINKER}
CACHE INTERNAL "Previous value of USE_ALTERNATE_LINKER")
endif()
# Default definitions during build
add_definitions(-DGDAL_COMPILATION)
if (ENABLE_IPO)
if (POLICY CMP0069)
include(CheckIPOSupported)
check_ipo_supported(RESULT result)
if (result)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION True)
endif ()
endif ()
endif ()
# ######################################################################################################################
set_property(GLOBAL PROPERTY gdal_private_link_libraries)
function (gdal_add_private_link_libraries)
get_property(tmp GLOBAL PROPERTY gdal_private_link_libraries)
foreach (arg ${ARGV})
set(tmp ${tmp} ${arg})
endforeach ()
set_property(GLOBAL PROPERTY gdal_private_link_libraries ${tmp})
endfunction (gdal_add_private_link_libraries)
add_library(${GDAL_LIB_TARGET_NAME} gcore/gdal.h)
set(GDAL_LIB_OUTPUT_NAME
"gdal"
CACHE STRING "Name of the GDAL library")
# If a shared lib renaming has been set in ConfigUser.cmake
set_target_properties(${GDAL_LIB_TARGET_NAME} PROPERTIES OUTPUT_NAME ${GDAL_LIB_OUTPUT_NAME})
add_library(GDAL::GDAL ALIAS ${GDAL_LIB_TARGET_NAME})
add_dependencies(${GDAL_LIB_TARGET_NAME} generate_gdal_version_h)
if (M_LIB)
gdal_add_private_link_libraries(-lm)
endif ()
# Set project and C++ Standard properties
set_target_properties(
${GDAL_LIB_TARGET_NAME}
PROPERTIES PROJECT_LABEL ${PROJECT_NAME}
VERSION ${GDAL_ABI_FULL_VERSION}
SOVERSION "${GDAL_SOVERSION}"
ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
CXX_STANDARD 11
CXX_STANDARD_REQUIRED YES)
set_property(TARGET ${GDAL_LIB_TARGET_NAME} PROPERTY PLUGIN_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/gdalplugins")
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/gdalplugins")
if (MSVC)
set(GDAL_DEBUG_POSTFIX
"d"
CACHE STRING "Postfix to add to the GDAL dll name for debug builds")
set_target_properties(${GDAL_LIB_TARGET_NAME} PROPERTIES DEBUG_POSTFIX "${GDAL_DEBUG_POSTFIX}")
endif ()
if (MINGW AND BUILD_SHARED_LIBS)
set_target_properties(${GDAL_LIB_TARGET_NAME} PROPERTIES SUFFIX "-${GDAL_SOVERSION}${CMAKE_SHARED_LIBRARY_SUFFIX}")
endif ()
if (MINGW)
if (TARGET_CPU MATCHES "x86_64")
add_definitions(-m64)
endif ()
# Workaround for export too large error - force problematic large file to be optimized to prevent string table
# overflow error Used -Os instead of -O2 as previous issues had mentioned, since -Os is roughly speaking -O2,
# excluding any optimizations that take up extra space. Given that the issue is a string table overflowing, -Os seemed
# appropriate. Solves issue of https://github.com/OSGeo/gdal/issues/4706 with for example x86_64-w64-mingw32-gcc-posix
# (GCC) 9.3-posix 20200320
if (CMAKE_BUILD_TYPE MATCHES Debug OR CMAKE_BUILD_TYPE STREQUAL "")
add_compile_options(-Os)
endif ()
endif ()
# Install properties
if (GDAL_ENABLE_MACOSX_FRAMEWORK)
set(FRAMEWORK_VERSION ${GDAL_VERSION_MAJOR}.${GDAL_VERSION_MINOR})
set(FRAMEWORK_DESTINATION
"Library/Frameworks"
CACHE STRING "Framework destination sub-directory")
set(FRAMEWORK_SUBDIR "${FRAMEWORK_DESTINATION}/gdal.framework/Versions/${FRAMEWORK_VERSION}")
set(INSTALL_PLUGIN_DIR
"${FRAMEWORK_SUBDIR}/PlugIns"
CACHE PATH "Installation sub-directory for plugins")
set(CMAKE_INSTALL_BINDIR
"bin"
CACHE STRING "Installation sub-directory for executables")
set(CMAKE_INSTALL_LIBDIR
"${FRAMEWORK_SUBDIR}"
CACHE INTERNAL "Installation sub-directory for libraries" FORCE)
# CMAKE_INSTALL_INCLUDEDIR should normally not be used
set(CMAKE_INSTALL_INCLUDEDIR
"${FRAMEWORK_SUBDIR}/Headers"
CACHE INTERNAL "Installation sub-directory for headers" FORCE)
set(CMAKE_INSTALL_DATADIR
"${FRAMEWORK_SUBDIR}/Resources"
CACHE INTERNAL "Installation sub-directory for resources" FORCE)
set(GDAL_RESOURCE_PATH ${CMAKE_INSTALL_DATADIR})
set_target_properties(
${GDAL_LIB_TARGET_NAME}
PROPERTIES FRAMEWORK TRUE
FRAMEWORK_VERSION ${GDAL_VERSION_MAJOR}.${GDAL_VERSION_MINOR}
MACOSX_FRAMEWORK_SHORT_VERSION_STRING ${GDAL_VERSION_MAJOR}.${GDAL_VERSION_MINOR}
MACOSX_FRAMEWORK_BUNDLE_VERSION "GDAL ${GDAL_VERSION_MAJOR}.${GDAL_VERSION_MINOR}"
MACOSX_FRAMEWORK_IDENTIFIER org.osgeo.libgdal
XCODE_ATTRIBUTE_INSTALL_PATH "@rpath"
INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/${FRAMEWORK_DESTINATION}"
BUILD_WITH_INSTALL_RPATH TRUE
# MACOSX_FRAMEWORK_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/info.plist.in"
)
else ()
include(GNUInstallDirs)
set(INSTALL_PLUGIN_DIR
"${CMAKE_INSTALL_LIBDIR}/gdalplugins"
CACHE PATH "Installation sub-directory for plugins")
set(GDAL_RESOURCE_PATH ${CMAKE_INSTALL_DATADIR}/gdal)
option(GDAL_SET_INSTALL_RELATIVE_RPATH "Whether the rpath of installed binaries should be written as a relative path to the library" OFF)
if(GDAL_SET_INSTALL_RELATIVE_RPATH)
if(APPLE)
set(base @loader_path)
else()
set(base $ORIGIN)
endif()
file(RELATIVE_PATH relDir
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}
)
if( NOT "${CMAKE_INSTALL_RPATH}" STREQUAL "" )
message(WARNING "CMAKE_INSTALL_RPATH=${CMAKE_INSTALL_RPATH} will be ignored and replaced with ${base};${base}/${relDir} due to GDAL_SET_INSTALL_RELATIVE_RPATH being set")
endif()
set(CMAKE_INSTALL_RPATH ${base} ${base}/${relDir})
endif()
endif ()
set(INSTALL_PLUGIN_FULL_DIR "${CMAKE_INSTALL_PREFIX}/${INSTALL_PLUGIN_DIR}")
# Configure internal libraries
if (GDAL_USE_ZLIB_INTERNAL)
option(RENAME_INTERNAL_ZLIB_SYMBOLS "Rename internal zlib symbols" ON)
mark_as_advanced(RENAME_INTERNAL_ZLIB_SYMBOLS)
add_subdirectory(frmts/zlib)
endif ()
if (GDAL_USE_JSONC_INTERNAL)
# Internal libjson symbols are renamed by default
add_subdirectory(ogr/ogrsf_frmts/geojson/libjson)
endif ()
option(ENABLE_DEFLATE64 "Enable Deflate64 decompression" ON)
mark_as_advanced(ENABLE_DEFLATE64)
if(ENABLE_DEFLATE64)
add_subdirectory(frmts/zlib/contrib/infback9)
endif()
# Internal zlib and jsonc must be declared before
add_subdirectory(port)
# JPEG options need to be defined before internal libtiff
if (GDAL_USE_JPEG_INTERNAL)
option(RENAME_INTERNAL_JPEG_SYMBOLS "Rename internal libjpeg symbols" ON)
mark_as_advanced(RENAME_INTERNAL_JPEG_SYMBOLS)
add_subdirectory(frmts/jpeg/libjpeg)
endif ()
if (NOT HAVE_JPEGTURBO_DUAL_MODE_8_12)
option(GDAL_USE_JPEG12_INTERNAL "Set ON to use internal libjpeg12 support" ON)
else()
option(GDAL_USE_JPEG12_INTERNAL "Set ON to use internal libjpeg12 support" OFF)
endif()
if (GDAL_USE_JPEG12_INTERNAL)
add_subdirectory(frmts/jpeg/libjpeg12)
endif ()
# Lerc options need to be defined before internal libtiff
if (GDAL_USE_LERC_INTERNAL)
# Internal liblerc uses a dedicated namespace
add_subdirectory(third_party/LercLib)
endif ()
if (GDAL_USE_TIFF_INTERNAL)
option(RENAME_INTERNAL_TIFF_SYMBOLS "Rename internal libtiff symbols" ON)
mark_as_advanced(RENAME_INTERNAL_TIFF_SYMBOLS)
add_subdirectory(frmts/gtiff/libtiff)
endif ()
if (GDAL_USE_GEOTIFF_INTERNAL)
option(RENAME_INTERNAL_GEOTIFF_SYMBOLS "Rename internal libgeotiff symbols" ON)
mark_as_advanced(RENAME_INTERNAL_GEOTIFF_SYMBOLS)
add_subdirectory(frmts/gtiff/libgeotiff)
endif ()
if (GDAL_USE_PNG_INTERNAL)
option(RENAME_INTERNAL_PNG_SYMBOLS "Rename internal libpng symbols" ON)
mark_as_advanced(RENAME_INTERNAL_PNG_SYMBOLS)
add_subdirectory(frmts/png/libpng)
endif ()
if (GDAL_USE_SHAPELIB_INTERNAL)
option(RENAME_INTERNAL_SHAPELIB_SYMBOLS "Rename internal Shapelib symbols" ON)
mark_as_advanced(RENAME_INTERNAL_SHAPELIB_SYMBOLS)
endif ()
# Core components
add_subdirectory(alg)
add_subdirectory(ogr)
if (ENABLE_GNM)
add_subdirectory(gnm)
endif ()
# Raster/Vector drivers (built-in and plugins)
set(GDAL_RASTER_FORMAT_SOURCE_DIR "${PROJECT_SOURCE_DIR}/frmts")
set(GDAL_VECTOR_FORMAT_SOURCE_DIR "${PROJECT_SOURCE_DIR}/ogr/ogrsf_frmts")
if(OGR_ENABLE_DRIVER_GPKG AND
NOT DEFINED OGR_ENABLE_DRIVER_SQLITE AND
DEFINED OGR_BUILD_OPTIONAL_DRIVERS AND
NOT OGR_BUILD_OPTIONAL_DRIVERS)
message(STATUS "Automatically enabling SQLite driver")
set(OGR_ENABLE_DRIVER_SQLITE ON CACHE BOOL "Set ON to build OGR SQLite driver")
endif()
# We need to forward declare a few OGR drivers because raster formats need them
option(OGR_ENABLE_DRIVER_AVC "Set ON to build OGR AVC driver" ${OGR_BUILD_OPTIONAL_DRIVERS})
option(OGR_ENABLE_DRIVER_GML "Set ON to build OGR GML driver" ${OGR_BUILD_OPTIONAL_DRIVERS})
cmake_dependent_option(OGR_ENABLE_DRIVER_SQLITE "Set ON to build OGR SQLite driver" ${OGR_BUILD_OPTIONAL_DRIVERS}
"GDAL_USE_SQLITE3" OFF)
cmake_dependent_option(OGR_ENABLE_DRIVER_GPKG "Set ON to build OGR GPKG driver" ${OGR_BUILD_OPTIONAL_DRIVERS}
"GDAL_USE_SQLITE3;OGR_ENABLE_DRIVER_SQLITE" OFF)
cmake_dependent_option(OGR_ENABLE_DRIVER_MVT "Set ON to build OGR MVT driver" ${OGR_BUILD_OPTIONAL_DRIVERS}
"GDAL_USE_SQLITE3" OFF)
# Build frmts/iso8211 conditionally to drivers requiring it
if ((GDAL_BUILD_OPTIONAL_DRIVERS AND NOT DEFINED GDAL_ENABLE_DRIVER_ADRG AND NOT DEFINED GDAL_ENABLE_DRIVER_SDTS) OR
GDAL_ENABLE_DRIVER_ADRG OR
GDAL_ENABLE_DRIVER_SDTS OR
(OGR_BUILD_OPTIONAL_DRIVERS AND NOT DEFINED OGR_ENABLE_DRIVER_S57 AND NOT DEFINED OGR_ENABLE_DRIVER_SDTS) OR
OGR_ENABLE_DRIVER_S57 OR
OGR_ENABLE_DRIVER_SDTS)
add_subdirectory(frmts/iso8211)
endif()
add_subdirectory(frmts)
add_subdirectory(ogr/ogrsf_frmts)
# It needs to be after ogr/ogrsf_frmts so it can use OGR_ENABLE_SQLITE
add_subdirectory(gcore)
# Bindings
if (BUILD_SHARED_LIBS)
add_subdirectory(swig)
endif ()
# Utilities
add_subdirectory(apps)
add_subdirectory(scripts)
# Add all library dependencies of target gdal
get_property(GDAL_PRIVATE_LINK_LIBRARIES GLOBAL PROPERTY gdal_private_link_libraries)
# GDAL_EXTRA_LINK_LIBRARIES may be set by the user if the various FindXXXX modules
# didn't capture all required dependencies (used for example by OSGeo4W)
target_link_libraries(${GDAL_LIB_TARGET_NAME} PRIVATE ${GDAL_PRIVATE_LINK_LIBRARIES} ${GDAL_EXTRA_LINK_LIBRARIES})
# Document/Manuals
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/doc" AND BUILD_DOCS)
add_subdirectory(doc)
endif ()
add_subdirectory(man)
# So that GDAL can be used as a add_subdirectory() of another project
target_include_directories(
${GDAL_LIB_TARGET_NAME}
PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/apps>
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/alg>
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/gcore>
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/gcore/gdal_version_full>
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/port>
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/port>
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/ogr>
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/ogr/ogrsf_frmts>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
# MSVC specific resource preparation
if (MSVC)
target_sources(${GDAL_LIB_TARGET_NAME} PRIVATE gcore/Version.rc)
source_group("Resource Files" FILES gcore/Version.rc)
if (CMAKE_CL_64)
set_target_properties(${GDAL_LIB_TARGET_NAME} PROPERTIES STATIC_LIBRARY_FLAGS "/machine:x64")
endif ()
endif ()
get_property(_plugins GLOBAL PROPERTY PLUGIN_MODULES)
add_custom_target(gdal_plugins DEPENDS ${_plugins})
# Install drivers.ini along with plugins
# We request the TARGET_FILE_DIR of one of the plugins, since the PLUGIN_OUTPUT_DIR will not contain the \Release suffix
# with MSVC generator
list(LENGTH _plugins PLUGIN_MODULES_LENGTH)
if (PLUGIN_MODULES_LENGTH GREATER_EQUAL 1)
list(GET _plugins 0 FIRST_TARGET)
set(PLUGIN_OUTPUT_DIR "$<TARGET_FILE_DIR:${FIRST_TARGET}>")
file(READ ${CMAKE_CURRENT_SOURCE_DIR}/frmts/drivers.ini DRIVERS_INI_CONTENT)
file(
GENERATE
OUTPUT ${PLUGIN_OUTPUT_DIR}/drivers.ini
CONTENT ${DRIVERS_INI_CONTENT})
endif ()
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/frmts/drivers.ini DESTINATION ${INSTALL_PLUGIN_DIR})
# ######################################################################################################################
# Note: this file is generated but not used.
configure_file(${GDAL_CMAKE_TEMPLATE_PATH}/gdal_def.h.in ${CMAKE_CURRENT_BINARY_DIR}/gcore/gdal_def.h @ONLY)
# ######################################################################################################################
set_property(
TARGET ${GDAL_LIB_TARGET_NAME}
APPEND
PROPERTY PUBLIC_HEADER ${CMAKE_CURRENT_BINARY_DIR}/port/cpl_config.h)
set(GDAL_DATA_FILES
LICENSE.TXT
data/GDALLogoBW.svg
data/GDALLogoColor.svg
data/GDALLogoGS.svg
data/gdalicon.png
)
set_property(
TARGET ${GDAL_LIB_TARGET_NAME}
APPEND
PROPERTY RESOURCE "${GDAL_DATA_FILES}")
# Copy all resource files from their source location to ${CMAKE_CURRENT_BINARY_DIR}/data
# Note that this is not only the small list of files set a few lines above,
# but also resource files attached to ${GDAL_LIB_TARGET_NAME} in other directories (drivers, etc.)
get_property(
_data_files
TARGET ${GDAL_LIB_TARGET_NAME}
PROPERTY RESOURCE)
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/data")
foreach(_file IN LISTS _data_files)
configure_file("${_file}" "${CMAKE_CURRENT_BINARY_DIR}/data" COPYONLY)
endforeach()
if (GDAL_ENABLE_MACOSX_FRAMEWORK)
# We need to add data files and public headers as sources of the library os they get installed through the framework
# installation mechanisms
target_sources(${GDAL_LIB_TARGET_NAME} PRIVATE "${GDAL_DATA_FILES}")
get_property(
_public_headers
TARGET ${GDAL_LIB_TARGET_NAME}
PROPERTY PUBLIC_HEADER)
target_sources(${GDAL_LIB_TARGET_NAME} PRIVATE "${_public_headers}")
endif ()
install(
TARGETS ${GDAL_LIB_TARGET_NAME}
EXPORT gdal-export
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RESOURCE DESTINATION ${GDAL_RESOURCE_PATH}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FRAMEWORK DESTINATION "${FRAMEWORK_DESTINATION}")
if (NOT GDAL_ENABLE_MACOSX_FRAMEWORK)
# Generate GdalConfig.cmake and GdalConfigVersion.cmake
install(
EXPORT gdal-export
FILE GDAL-targets.cmake
NAMESPACE GDAL::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/gdal/
EXPORT_LINK_INTERFACE_LIBRARIES)
if (NOT BUILD_SHARED_LIBS)
install(
FILES
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/GdalFindModulePath.cmake"
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/DefineFindPackage2.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/gdal/")
include(GdalFindModulePath)
foreach(dir IN LISTS GDAL_VENDORED_FIND_MODULES_CMAKE_VERSIONS ITEMS packages thirdparty)
install(
DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/${dir}"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/gdal")
endforeach()
endif ()
include(CMakePackageConfigHelpers)
if(CMAKE_VERSION VERSION_LESS 3.11)
set(comptatibility_check ExactVersion)
else()
# SameMinorVersion compatibility are supported CMake >= 3.11
# Our C++ ABI remains stable only among major.minor.XXX patch releases
set(comptatibility_check SameMinorVersion)
endif()
write_basic_package_version_file(
GDALConfigVersion.cmake
VERSION ${GDAL_VERSION}
COMPATIBILITY ${comptatibility_check})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/GDALConfigVersion.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/gdal/)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/template/GDALConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/GDALConfig.cmake @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/GDALConfig.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/gdal/)
# Generate gdal-config utility command and pkg-config module gdal.pc
include(GdalGenerateConfig)
gdal_generate_config(
TARGET
"${GDAL_LIB_TARGET_NAME}"
GLOBAL_PROPERTY
"gdal_private_link_libraries"
GDAL_CONFIG
"${PROJECT_BINARY_DIR}/apps/gdal-config"
PKG_CONFIG
"${CMAKE_CURRENT_BINARY_DIR}/gdal.pc")
install(
PROGRAMS ${PROJECT_BINARY_DIR}/apps/gdal-config
DESTINATION ${CMAKE_INSTALL_BINDIR}
COMPONENT applications)
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/gdal.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
COMPONENT libraries)
endif ()
configure_file(${GDAL_CMAKE_TEMPLATE_PATH}/uninstall.cmake.in ${PROJECT_BINARY_DIR}/cmake_uninstall.cmake @ONLY)
add_custom_target(uninstall COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
################################################################
# Final reports and warnings
################################################################
if($ENV{GDAL_CMAKE_QUIET})
set(GDAL_CMAKE_QUIET ON)
endif()
# Print summary
include(SystemSummary)
if(NOT GDAL_CMAKE_QUIET)
system_summary(DESCRIPTION "GDAL is now configured on;")
endif()
# Do not warn about Shapelib being an optional package not found, as we don't recommend using it.
# Mono/DotNetFrameworkSdk is also an internal detail of CSharp that we don't want to report
get_property(_packages_not_found GLOBAL PROPERTY PACKAGES_NOT_FOUND)
set(_new_packages_not_found)
foreach (_package IN LISTS _packages_not_found)
if (NOT ${_package} STREQUAL "Shapelib"
AND NOT ${_package} STREQUAL "Podofo"
AND NOT ${_package} STREQUAL "Mono"
AND NOT ${_package} STREQUAL "DotNetFrameworkSdk")
set(_new_packages_not_found ${_new_packages_not_found} "${_package}")
endif ()
endforeach ()
include(FeatureSummary)
set_property(GLOBAL PROPERTY PACKAGES_NOT_FOUND ${_new_packages_not_found})
if(NOT GDAL_CMAKE_QUIET)
feature_summary(DESCRIPTION "Enabled drivers and features and found dependency packages" WHAT ALL)
endif()
set_property(GLOBAL PROPERTY PACKAGES_NOT_FOUND ${_packages_not_found})
set(disabled_packages "")
get_property(_packages_found GLOBAL PROPERTY PACKAGES_FOUND)
foreach (_package IN LISTS _packages_found)
string(TOUPPER ${_package} key)
if (DEFINED GDAL_USE_${key} AND NOT GDAL_USE_${key})
if (DEFINED GDAL_USE_${key}_INTERNAL)
if (NOT GDAL_USE_${key}_INTERNAL)
string(APPEND disabled_packages " * ${key} component has been detected, but is disabled with GDAL_USE_${key}=${GDAL_USE_${key}}, and the internal library is also disabled with GDAL_USE_${key}_INTERNAL=${GDAL_USE_${key}_INTERNAL}\n")
endif()
else ()
string(APPEND disabled_packages " * ${key} component has been detected, but is disabled with GDAL_USE_${key}=${GDAL_USE_${key}}\n")
endif()
endif ()
endforeach ()
if (NOT GDAL_CMAKE_QUIET AND disabled_packages)
message(STATUS "Disabled components:\n\n${disabled_packages}\n")
endif ()
set(internal_libs_used "")
foreach (_package IN LISTS _packages_found _new_packages_not_found)
string(TOUPPER ${_package} key)
if( GDAL_USE_${key}_INTERNAL )
string(APPEND internal_libs_used " * ${key} internal library enabled\n")
endif()
endforeach()
if (NOT GDAL_CMAKE_QUIET AND internal_libs_used)
message(STATUS "Internal libraries enabled:\n\n${internal_libs_used}\n")
endif ()
if (NOT GDAL_CMAKE_QUIET AND
DEFINED GDAL_USE_EXTERNAL_LIBS_OLD_CACHED)
if (GDAL_USE_EXTERNAL_LIBS_OLD_CACHED AND NOT GDAL_USE_EXTERNAL_LIBS)
message(
WARNING
"Setting GDAL_USE_EXTERNAL_LIBS=OFF after an initial invocation to ON may require to invoke CMake with \"-UGDAL_USE_*\""
)
endif ()
endif ()
set(GDAL_USE_EXTERNAL_LIBS_OLD_CACHED
${GDAL_USE_EXTERNAL_LIBS}
CACHE INTERNAL "Previous value of GDAL_USE_EXTERNAL_LIBS")
# Emit a warning if users do not define the build type for non-multi config and that we can't find -O in CMAKE_CXX_FLAGS
# This is not super idiomatic to warn this way, but this will help users transitionning from autoconf where the default
# settings result in a -O2 build.
get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if (NOT GDAL_CMAKE_QUIET
AND NOT _isMultiConfig
AND ("${CMAKE_BUILD_TYPE}" STREQUAL "")
AND (((CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
AND (NOT ("${CMAKE_C_FLAGS}" MATCHES "-O") OR NOT ("${CMAKE_CXX_FLAGS}" MATCHES "-O"))) OR
((CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
AND (("${CMAKE_C_FLAGS}" MATCHES "/Od") OR NOT ("${CMAKE_C_FLAGS}" MATCHES "/O")))))
message(
WARNING
"CMAKE_BUILD_TYPE is not defined and CMAKE_C_FLAGS='${CMAKE_C_FLAGS}' and/or CMAKE_CXX_FLAGS='${CMAKE_CXX_FLAGS}' do not contain optimizing flags. Do not use in production! Using -DCMAKE_BUILD_TYPE=Release is suggested."
)
endif ()
if (NOT GDAL_CMAKE_QUIET AND
"${CMAKE_BINARY_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}")
message(WARNING "In-tree builds, that is running cmake from the top of the source tree are not recommended. You are advised instead to 'mkdir build; cd build; cmake ..'.")
endif()
if (NOT GDAL_CMAKE_QUIET
AND UNIX # On Windows, Conda seems to be automatically used
AND DEFINED ENV{CONDA_PREFIX}
AND NOT "${CMAKE_PREFIX_PATH}" MATCHES "$ENV{CONDA_PREFIX}")
message(WARNING "Environment variable CONDA_PREFIX=$ENV{CONDA_PREFIX} found, its value is not included in the content of the CMake variable CMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}. You likely want to run \"${CMAKE_COMMAND} ${PROJECT_SOURCE_DIR} -DCMAKE_PREFIX_PATH=$ENV{CONDA_PREFIX}\"")
endif()
# vim: ts=4 sw=4 sts=4 et