-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
258 lines (237 loc) · 8 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
cmake_minimum_required (VERSION 3.1.0)
project (Weathergrib)
set(VERSION_MAJOR 2)
set(VERSION_MINOR 3)
set(VERSION_PATCH 0)
set(WEATHERGRIB_VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
set(WEATHERGRIB_VERSION_DATE "2021-01-28")
set(CMAKE_VERBOSE_MAKEFILE ON)
# Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Unfotunately cmake <3.9 is not able to handle the coding style of Weathergrib and AUTOMOC misses many classes. Once the code is fixed or we can expect newer cmake everywhere, we can enable this and get rid of the QT5_WRAP_CPP() macros
## Instruct CMake to run moc automatically when needed
#set(CMAKE_AUTOMOC ON)
#set(CMAKE_AUTOMOC_RELAXED_MODE TRUE)
# Unfotunately AUTOUIC_SEARCH_PATHS is not available before cmake 3.9 so we can't use this on all the current platforms
# At some future moment, turn this on and simplify src/GUI/CMakeLists.txt
## Create code from a list of Qt designer ui files
#set(CMAKE_AUTOUIC ON)
#set(CMAKE_AUTOUIC_SEARCH_PATHS "${CMAKE_CURRENT_SOURCE_DIR}/src/GUI")
set(CMAKE_CXX_STANDARD 11)
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
if(UNIX AND NOT APPLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -fPIC")
endif()
# Add support for address etc sanitizers, part 1/2 (other half after ADD_EXECUTABLE)
if ( CMAKE_VERSION VERSION_GREATER 3.4 )
set(ENABLE_SANITIZER "none" CACHE STRING "Add clang sanitizer to the build")
set_property(CACHE ENABLE_SANITIZER PROPERTY STRINGS none address memory thread undefined)
if (NOT "${ENABLE_SANITIZER}" MATCHES "none")
add_compile_options(-fsanitize=${ENABLE_SANITIZER})
endif()
endif()
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_PREFIX}/cmake")
set(CMAKE_FIND_FRAMEWORK LAST)
# Find the QtWidgets library
find_package(Qt5Widgets CONFIG REQUIRED)
include_directories(${Qt5Widgets_INCLUDE_DIRS})
find_package(Qt5Core CONFIG REQUIRED)
find_package(Qt5Gui CONFIG REQUIRED)
find_package(Qt5Network CONFIG REQUIRED)
include_directories(${Qt5Network_INCLUDE_DIRS})
find_package(Qt5PrintSupport CONFIG REQUIRED)
include_directories(${Qt5PrintSupport_INCLUDE_DIRS})
find_package(Qt5Xml CONFIG REQUIRED)
include_directories(${Qt5Xml_INCLUDE_DIRS})
set(BZIP2_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include")
set(BZIP2_LIBRARIES "${CMAKE_CURRENT_SOURCE_DIR}/lib/libbz2.a")
set(LIBNOVA_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include")
set(LIBNOVA_LIBRARY "${CMAKE_CURRENT_SOURCE_DIR}/lib/libnova.a")
set(OPENJPEG_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include")
set(OPENJPEG_LIBRARIES "${CMAKE_CURRENT_SOURCE_DIR}/lib/libopenjp2.dll")
set(PNG_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include")
set(PNG_LIBRARIES "${CMAKE_CURRENT_SOURCE_DIR}/lib/libpng.a")
set(PROJ4_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include")
set(PROJ4_LIBRARIES "${CMAKE_CURRENT_SOURCE_DIR}/lib/libproj.a")
set(ZLIB_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include")
set(ZLIB_LIBRARIES "${CMAKE_CURRENT_SOURCE_DIR}/lib/libz.a")
#message(FATAL_ERROR "STOP")
find_library(LIBNOVA_LIBRARY
NAMES "libnova.a" "libnova.so"
PATHS
$ENV{EXTERNLIBS}/lib
~/Library/Frameworks
/Library/Frameworks
/usr/local
/usr
/sw
/opt/local
/opt/csw
/opt
PATH_SUFFIXES lib lib64 lib/x86_64-linux-gnu lib/i386-linux-gnu lib/armhf-linux-gnu lib/arm64-linux-gnu
REQUIRED
)
find_path(LIBNOVA_INCLUDE_DIR
NAMES "libnova/libnova.h" "libnova.h"
PATHS
$ENV{EXTERNLIBS}/include
~/Library/Frameworks/include
/Library/Frameworks/include
/usr/local/include
/usr/include
/sw/include # Fink
/opt/local/include # DarwinPorts
/opt/csw/include # Blastwave
/opt/include
REQUIRED
)
include_directories(${LIBNOVA_INCLUDE_DIR})
#find_package(OpenJPEG REQUIRED)
find_library(OPENJPEG_LIBRARIES
# NAMES "libopenjp2.a" "libopenjp2.so" "libopenjpeg.so.2" "libopenjp2.dll.a"
NAMES "libopenjp2.so.7" "libopenjp2.so" "libopenjp2.a" "libopenjpeg.so.2" "libopenjp2.dll.a"
PATHS
$ENV{EXTERNLIBS}/lib
~/Library/Frameworks
/Library/Frameworks
/usr/local
/usr
/sw
/opt/local
/opt/csw
/opt
PATH_SUFFIXES lib lib64
REQUIRED
)
find_path(OPENJPEG_INCLUDE_DIR
NAMES "openjpeg.h"
PATHS
$ENV{EXTERNLIBS}/include
~/Library/Frameworks/include
/Library/Frameworks/include
/usr/local/include
/usr/local/include/openjpeg-2.3
/usr/include/openjpeg-2.3
/usr/local/include/openjpeg-2.1
/usr/include/openjpeg-2.1
/usr/local/include/openjpeg-2.2
/usr/include/openjpeg-2.2
/usr/include
/sw/include # Fink
/opt/local/include # DarwinPorts
/opt/csw/include # Blastwave
/opt/include
REQUIRED
)
include_directories(${OPENJPEG_INCLUDE_DIR})
if(NOT WIN32)
include(cmake/FindPROJ4.cmake)
if(NOT PROJ4_FOUND)
message(FATAL_ERROR "PROJ.4 library not found!")
endif()
include_directories(${PROJ4_INCLUDE_DIR})
endif()
if(WIN32)
find_library(PROJ4_LIBRARIES
NAME "libproj.a"
PATHS
$ENV{EXTERNLIBS}/lib
/opt/lib
REQUIRED
)
find_path(PROJ4_INCLUDE_DIR
NAMES "proj_api.h"
PATHS
$ENV{EXTERNLIBS}/include
/opt/include
REQUIRED
)
endif()
if(WIN32)
message(STATUS "Search WIN32 BZIP2")
find_library(BZIP2_LIBRARIES
NAME "libbz2.a"
PATHS
$ENV{EXTERNLIBS}/lib
/opt/lib
REQUIRED
)
find_path(BZIP2_INCLUDE_DIR
NAMES "bzlib.h"
PATHS
$ENV{EXTERNLIBS}/include
/opt/include
REQUIRED
)
else()
find_package(BZip2 REQUIRED)
endif()
include_directories(${BZIP2_INCLUDE_DIR})
if(WIN32)
find_library(ZLIB_LIBRARIES
NAME "libz.a"
PATHS
$ENV{EXTERNLIBS}/lib
/opt/lib
REQUIRED
)
find_path(ZLIB_INCLUDE_DIR
NAMES "zlib.h"
PATHS
$ENV{EXTERNLIBS}/include
/opt/include
REQUIRED
)
else()
find_package(ZLIB REQUIRED)
endif()
include_directories(${ZLIB_INCLUDE_DIR})
if(WIN32)
find_library(PNG_LIBRARIES
NAME "libpng.a"
PATHS
$ENV{EXTERNLIBS}/lib
/opt/lib
REQUIRED
)
find_path(PNG_INCLUDE_DIR
NAMES "png.h"
PATHS
$ENV{EXTERNLIBS}/include
/opt/include
REQUIRED
)
else()
find_package(PNG REQUIRED)
endif()
include_directories(${PNG_INCLUDE_DIR})
configure_file(cmake/Version.h.in ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/include/Version.h)
include_directories(${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/include)
if(APPLE)
set(PREFIX_BIN ${PROJECT_NAME})
set(PREFIX_PKGDATA ${PROJECT_NAME})
endif()
if(WIN32)
set(PREFIX_BIN ".")
set(PREFIX_PKGDATA ".")
endif()
if(UNIX AND NOT APPLE)
# This is not exactly a good idea on linux - the code should be changed so that the executable would go to /usr/local/bin and the data to /usr/local/share/Weathergrib
set(PREFIX_BIN ${PROJECT_NAME})
set(PREFIX_PKGDATA ${PROJECT_NAME})
endif()
add_subdirectory(src)
add_subdirectory(data/tr)
# Installation
# macOS bundle parameters
set_target_properties(${PROJECT_NAME} PROPERTIES MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/cmake/MacOSXBundleInfo.plist.in")
set_target_properties(${PROJECT_NAME} PROPERTIES MACOSX_BUNDLE_INFO_STRING "${PROJECT_NAME}")
set_target_properties(${PROJECT_NAME} PROPERTIES MACOSX_BUNDLE_ICON_FILE "Weathergrib.icns")
set_target_properties(${PROJECT_NAME} PROPERTIES MACOSX_BUNDLE_GUI_IDENTIFIER "${PROJECT_NAME}")
set_target_properties(${PROJECT_NAME} PROPERTIES MACOSX_BUNDLE_LONG_VERSION_STRING "${WEATHERGRIB_VERSION}")
set_target_properties(${PROJECT_NAME} PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "${PROJECT_NAME}")
set_target_properties(${PROJECT_NAME} PROPERTIES MACOSX_BUNDLE_SHORT_VERSION_STRING "${WEATHERGRIB_VERSION}")
set_target_properties(${PROJECT_NAME} PROPERTIES MACOSX_BUNDLE_BUNDLE_VERSION "${WEATHERGRIB_VERSION}")
set_target_properties(${PROJECT_NAME} PROPERTIES MACOSX_BUNDLE_COPYRIGHT "${PROJECT_NAME} Authors")
# Install data
install(DIRECTORY data DESTINATION ${PREFIX_PKGDATA})