forked from OSGeo/gdal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
283 lines (258 loc) · 8.83 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
# CMake4GDAL project is distributed under MIT license. See accompanying file LICENSE.txt.
cmake_minimum_required(VERSION 3.9...3.27)
project(gdal LANGUAGES C CXX)
include(CTest)
set(GDAL_LIB_TARGET_NAME GDAL)
#
# setup cmake modules paths
include(cmake/modules/init.cmake)
#
# template files path
set(GDAL_CMAKE_TEMPLATE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/template)
#
# Custom global properties
define_property(
GLOBAL
PROPERTY GDAL_FORMATS
BRIEF_DOCS "Builtin format"
FULL_DOCS "Builtin format")
define_property(
GLOBAL
PROPERTY OGR_FORMATS
BRIEF_DOCS "Builtin ogr drivers"
FULL_DOCS "Builtin ogr drivers")
define_property(
GLOBAL
PROPERTY PLUGIN_MODULES
BRIEF_DOCS "Plugin modules"
FULL_DOCS "Plugin modules")
define_property(
TARGET
PROPERTY PLUGIN_OUTPUT_DIR
BRIEF_DOCS "Plugin modules build directories"
FULL_DOCS "Plugin modules build directories")
#
# check compiler and set preferences.
if (NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
endif()
if (NOT CMAKE_C_STANDARD)
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED ON)
endif()
#
if (MSVC)
add_definitions(-D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE)
add_definitions(-DNOMINMAX)
endif ()
#
include(CheckCompilerMachineOption)
include(CheckCompilerSIMDFeature)
include(Ccache)
#
if ("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "(x86|AMD64)")
check_compiler_machine_option(flag SSE)
if (NOT ${flag} STREQUAL "")
set(HAVE_SSE_AT_COMPILE_TIME 1)
add_definitions(-DHAVE_SSE_AT_COMPILE_TIME)
if (NOT ${flag} STREQUAL " ")
set(GDAL_SSE_FLAG ${flag})
endif ()
endif ()
check_compiler_machine_option(flag SSE2)
if (NOT ${flag} STREQUAL "")
set(HAVE_SSE2_AT_COMPILE_TIME 1)
if (NOT ${flag} STREQUAL " ")
set(GDAL_SSE2_FLAG ${flag})
endif ()
endif ()
check_compiler_machine_option(flag SSSE3)
if (NOT ${flag} STREQUAL "")
set(HAVE_SSSE3_AT_COMPILE_TIME 1)
add_definitions(-DHAVE_SSSE3_AT_COMPILE_TIME)
if (NOT ${flag} STREQUAL " ")
set(GDAL_SSSE3_FLAG ${flag})
endif ()
endif ()
check_compiler_machine_option(flag SSE4_1)
if (NOT ${flag} STREQUAL "")
set(HAVE_SSE41_AT_COMPILE_TIME 1)
if (NOT ${flag} STREQUAL " ")
set(GDAL_SSE41_FLAG ${flag})
endif ()
endif ()
check_compiler_machine_option(flag AVX)
if (NOT ${flag} STREQUAL "")
set(HAVE_AVX_AT_COMPILE_TIME 1)
add_definitions(-DHAVE_AVX_AT_COMPILE_TIME)
if (NOT ${flag} STREQUAL " ")
set(GDAL_AVX_FLAG ${flag})
endif ()
endif ()
check_compiler_machine_option(flag AVX2)
if (NOT ${flag} STREQUAL "")
set(HAVE_AVX2_AT_COMPILE_TIME 1)
if (NOT ${flag} STREQUAL " ")
set(GDAL_AVX2_FLAG ${flag})
endif ()
endif ()
endif ()
#
option(CLANG_TIDY_ENABLED "Run clang-tidy with the compiler." OFF)
set(CLANG_TIDY_CHECKS
"-*,clang-analyzer-alpha.unix.cstring.*"
CACHE STRING "clang-tidy checks")
set(CLANG_TIDY_WARNINGS_AS_ERRORS
"clang-analyzer-alpha.unix.cstring.*"
CACHE STRING "clang-tidy warnings as errors.")
if (RUN_CLANG_TIDY)
if (PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR)
message(FATAL_ERROR "RUN_CLANG_TIDY requires an out-of-source build!")
endif ()
find_program(CLANG_TIDY_COMMAND NAMES clang-tidy)
if (NOT CLANG_TIDY_COMMAND)
message(WARNING "RUN_CLANG_TIDY is ON but clang-tidy is not found!")
set(CMAKE_CXX_CLANG_TIDY)
else ()
set(CMAKE_CXX_CLANG_TIDY
"${CLANG_TIDY_COMMAND}" "-checks='${CLANG_TIDY_CHECKS}'" "-header-filter='${PROJECT_SOURCE_DIR}/*'"
"-warnings-as-errors='${CLANG_TIDY_WARNINGS_AS_ERRORS}'")
endif ()
endif ()
if (APPLE)
# To avoid the issue mentioned at
# https://stackoverflow.com/questions/36523911/osx-homebrew-cmake-libpng-version-mismatch-issue on github action
# MacOSX workers that have the Mono framework installed, whose libpng headers will be used instead of the homebrew
# ones
get_property(
result
CACHE CMAKE_FIND_FRAMEWORK
PROPERTY TYPE)
if (NOT result)
set(CMAKE_FIND_FRAMEWORK LAST)
message(STATUS "Setting CMAKE_FIND_FRAMEWORK=${CMAKE_FIND_FRAMEWORK}")
endif ()
endif ()
#
# Developer may want to specify some variable to find proper version.
# ~~~
# Priority is as same order as follows:
# 1. `Python_LOOKUP_VERSION`: specify major.minor version to find.
# 2. 'Python_FIND_VIRTUALENV': specify 'ONLY' to use virtualenv activated.
# 3. `Python_ROOT`: specify installed location.
# 4. If nothing specified, use default behavior.
#
# for example
# $ cmake -DPython_LOOKUP_VERSION=3.6.0 ..
# $ cmake -DPython_FIND_VIRTUALENV=ONLY ..
# $ cmake -DPython_ROOT=C:\Python36 ..
# ~~~
#
include(FeatureSummary)
find_package(SWIG)
set_package_properties(
SWIG PROPERTIES
DESCRIPTION
"Software development tool that connects programs written in C and C++ with a variety of high-level programming languages."
URL "http://swig.org/"
TYPE RECOMMENDED)
# Workaround Intel MKL library outputting a message in stdout, which cause
# incorrect detection of numpy.get_include() and numpy.__version__
# See https://github.com/numpy/numpy/issues/23775
# Fix also proposed to upstream CMake FindPython per
# https://gitlab.kitware.com/cmake/cmake/-/merge_requests/9359/
if(DEFINED ENV{MKL_ENABLE_INSTRUCTIONS})
set(BACKUP_ENV_VAR_MKL_ENABLE_INSTRUCTIONS ENV{MKL_ENABLE_INSTRUCTIONS})
endif()
set(ENV{MKL_ENABLE_INSTRUCTIONS} "SSE4_2")
if (Python_LOOKUP_VERSION)
set(Python_FIND_STRATEGY VERSION)
find_package(Python ${Python_LOOKUP_VERSION} EXACT COMPONENTS Interpreter Development NumPy)
else ()
set(Python_FIND_STRATEGY LOCATION)
find_package(Python 3.6 COMPONENTS Interpreter Development NumPy)
endif ()
set_package_properties(Python PROPERTIES PURPOSE "SWIG_PYTHON: Python binding")
if (NOT Python_FOUND AND ${CMAKE_VERSION} VERSION_LESS "3.12.0")
# On Ubuntu 18.04 with Python 3.6, the backported FindPython package we have in cmake/modules/3.16 doesn't manage to
# find automatically Python (we can make it work by manually setting -DPython_LOOKUP_VERSION=3.6.9
# -DPython_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython3.6m.so
# -DPython_NumPy_INCLUDE_DIR=/usr/lib/python3/dist-packages/numpy/core/include/numpy ) but this is a bit painful. So
# use the deprecated method (since CMake 3.12), which works out of the box in that situation.
find_package(PythonInterp)
find_package(PythonLibs)
if (PYTHONINTERP_FOUND AND "${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}" VERSION_LESS "3.6")
set(PYTHONINTERP_FOUND FALSE)
set(PYTHONLIBS_FOUND FALSE)
endif()
if (PYTHONINTERP_FOUND)
set(Python_Interpreter_FOUND TRUE)
set(Python_EXECUTABLE ${PYTHON_EXECUTABLE})
set(Python_VERSION_MAJOR ${PYTHON_VERSION_MAJOR})
set(Python_VERSION_MINOR ${PYTHON_VERSION_MINOR})
endif ()
if (PYTHONLIBS_FOUND)
set(Python_Development_FOUND TRUE)
set(Python_LIBRARIES ${PYTHON_LIBRARIES})
set(Python_INCLUDE_DIRS ${PYTHON_INCLUDE_DIRS})
endif ()
endif ()
if (Python_Interpreter_FOUND)
file(
GENERATE
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/python_executable.txt"
CONTENT "${Python_EXECUTABLE}")
if(NOT Python_NumPy_FOUND)
# Detect numpy
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/get_numpy.py
"try:\n import numpy\n print(numpy.get_include())\nexcept:\n pass\n")
execute_process(
COMMAND ${Python_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/get_numpy.py
OUTPUT_VARIABLE _numpy_include
OUTPUT_STRIP_TRAILING_WHITESPACE)
if (NOT _numpy_include STREQUAL "")
set(Python_NumPy_FOUND TRUE)
set(Python_NumPy_INCLUDE_DIRS ${Python_NumPy_INCLUDE_DIRS})
endif ()
endif()
endif()
# Restore previous value of MKL_ENABLE_INSTRUCTIONS
if(DEFINED BACKUP_ENV_VAR_MKL_ENABLE_INSTRUCTIONS)
set(ENV{MKL_ENABLE_INSTRUCTIONS} ${BACKUP_ENV_VAR_MKL_ENABLE_INSTRUCTIONS})
else()
unset(ENV{MKL_ENABLE_INSTRUCTIONS})
endif()
if (SWIG_FOUND AND (Python_Interpreter_FOUND OR Python_FOUND))
option(BUILD_PYTHON_BINDINGS "Build Python bindings" ON)
else()
option(BUILD_PYTHON_BINDINGS "Build Python bindings" OFF)
endif()
if (BUILD_PYTHON_BINDINGS)
if (NOT (Python_Interpreter_FOUND OR Python_FOUND))
message(FATAL_ERROR "Python is a requirement to build the Python bindings")
endif()
if (NOT SWIG_FOUND)
message(FATAL_ERROR "SWIG is a requirement to build the Python bindings")
endif()
endif()
#
include(${CMAKE_CURRENT_SOURCE_DIR}/gdal.cmake)
if (BUILD_TESTING AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/autotest")
# unit tests
add_subdirectory(autotest/cpp)
if(BUILD_PYTHON_BINDINGS)
add_subdirectory(autotest)
endif()
endif ()
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/fuzzers")
# Google OSS-Fuzz project utilities
add_subdirectory(fuzzers)
if (BUILD_TESTING)
add_subdirectory(fuzzers/tests)
endif()
endif()
if (BUILD_TESTING AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/perftests")
add_subdirectory(perftests)
endif ()
# vim: ts=4 sw=4 sts=4 et