-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCMakeLists.txt
285 lines (257 loc) · 11 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
## =============================================================================
##
## CMake projects setttings
##
## =============================================================================
## Minimum required version of CMake to configure the project
cmake_minimum_required(VERSION 2.8.9)
## Name of the project
project (NADC_TOOLS)
file (READ VERSION _version_contents)
string (REGEX REPLACE ".*#define[ \t]+nadc_vers_major[ \t]+([0-9]*).*$"
"\\1" NADC_VERS_MAJOR ${_version_contents})
string (REGEX REPLACE ".*#define[ \t]+nadc_vers_minor[ \t]+([0-9]*).*$"
"\\1" NADC_VERS_MINOR ${_version_contents})
string (REGEX REPLACE ".*#define[ \t]+nadc_vers_release[ \t]+([0-9]*).*$"
"\\1" NADC_VERS_RELEASE ${_version_contents})
string (REGEX REPLACE ".*#define[ \t]+nadc_vers_extra[ \t]+([a-z,0-9]*).*$"
"\\1" NADC_VERS_EXTRA ${_version_contents})
set (PROJECT_VERSION
"${NADC_VERS_MAJOR}.${NADC_VERS_MINOR}.${NADC_VERS_RELEASE}")
## CMake standard modules
include (CheckCCompilerFlag)
include (CheckIncludeFile)
include (CheckFunctionExists)
include (FindPackageHandleStandardArgs)
include (TestBigEndian)
## =============================================================================
##
## Configuration options
##
## =============================================================================
option (ENABLE_TESTING "Enable the CTest test driver?" NO )
option (BUILD_SHARED_LIBS "Enable building shared libraries" YES)
option (CONFIGURE_VERBOSE "Enhanced verbosity during configuration?" NO )
option (CONFIGURE_SUMMARY "Provide summary at the end of configure?" YES)
##__________________________________________________________
## Installation prefix
if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set (CMAKE_INSTALL_PREFIX
"$ENV{HOME}/x86_64" CACHE PATH "Installation location prefix" FORCE
)
endif (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
##__________________________________________________________
## Handle option: building shared libraries
set (LIB_TYPE STATIC)
set (NADC_ENABLE_SHARED_LIB NO)
set (NADC_ENABLE_STATIC_LIB NO)
if (BUILD_SHARED_LIBS)
set (CMAKE_MACOSX_RPATH 1)
set (LIB_TYPE SHARED)
set (NADC_ENABLE_SHARED_LIB YES)
set (CMAKE_INSTALL_SO_NO_EXE "0")
else ()
SET (NADC_ENABLE_STATIC_LIB YES)
endif ()
#-----------------------------------------------------------------------------
# Path to SRON calibration parameters
#-----------------------------------------------------------------------------
find_path (NADC_TOOLS_DATADIR
MEMcorr.h5
PATHS "/SCIA/share/nadc_tools"
"$ENV{HOME}/SCIA/CKD"
"/data/$ENV{USER}/SCIA/CKD"
NO_DEFAULT_PATH
)
## =============================================================================
##
## System inspection
##
## =============================================================================
## Extra location for custom CMake modules
list (INSERT CMAKE_MODULE_PATH 0
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/"
)
foreach (_extraPath
$ENV{NADC_EXTERN}
$ENV{HDF5_DIR}
$ENV{IDL_DIR}
$ENV{PPF_DIR}
)
list (INSERT CMAKE_PREFIX_PATH 0 ${_extraPath} )
list (INSERT CMAKE_INCLUDE_PATH 0 ${_extraPath}/include )
list (INSERT CMAKE_LIBRARY_PATH 0 ${_extraPath}/lib )
list (INSERT CMAKE_PROGRAM_PATH 0 ${_extraPath}/bin )
endforeach (_extraPath)
## Check for required external packages
foreach (_externalPackage
HDF5
PGSQL
NetCDF
IDL
PPF
)
## Convert module name to upper-case
string (TOUPPER ${_externalPackage} _externalPackageVar)
## Verbosity of the script to find the package
if (CONFIGURE_VERBOSE)
set (${_externalPackageVar}_FIND_QUIETLY NO)
else (CONFIGURE_VERBOSE)
set (${_externalPackageVar}_FIND_QUIETLY YES)
endif (CONFIGURE_VERBOSE)
## Find the package
find_package (${_externalPackage} REQUIRED)
endforeach (_externalPackage)
##__________________________________________________________
## Check for system header files
check_include_file ( errno.h HAVE_ERRNO_H )
check_include_file ( float.h HAVE_FLOAT_H )
check_include_file ( limits.h HAVE_LIMITS_H )
check_include_file ( math.h HAVE_MATH_H )
check_include_file ( stdbool.h HAVE_STDBOOL_H )
check_include_file ( stdio.h HAVE_STDIO_H )
check_include_file ( stdlib.h HAVE_STDLIB_H )
check_include_file ( string.h HAVE_STRING_H )
check_include_file ( strings.h HAVE_STRINGS_H )
check_include_file ( time.h HAVE_TIME_H )
#-----------------------------------------------------------------------------
# Set the target names of all the libraries
#-----------------------------------------------------------------------------
set (NADC_LIB_TARGET "nadc")
set (NADC_MERIS_LIB_TARGET "nadc_meris")
set (NADC_SCIA_LIB_TARGET "nadc_scia")
set (NADC_SCIA_CAL_LIB_TARGET "nadc_scia_cal")
set (NADC_IDL_LIB_TARGET "nadc_idl")
#-----------------------------------------------------------------------------
# Set the true names of all the libraries if customized by external project
#-----------------------------------------------------------------------------
set (NADC_LIB_NAME "lib${NADC_LIB_TARGET}")
set (NADC_MERIS_LIB_NAME "lib${NADC_MERIS_LIB_TARGET}")
set (NADC_SCIA_LIB_NAME "lib${NADC_SCIA_LIB_TARGET}")
set (NADC_SCIA_CAL_LIB_NAME "lib${NADC_SCIA_CAL_LIB_TARGET}")
set (NADC_IDL_LIB_NAME "lib${NADC_IDL_LIB_TARGET}")
# uninstall target
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY)
add_custom_target(uninstall
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
## =============================================================================
##
## Global build parameters
##
## =============================================================================
## Default Compiler flags
set (CMAKE_C_FLAGS "-std=c99 -W -Wall -Wstrict-prototypes -Wdeclaration-after-statement")
check_c_compiler_flag (-Wdisabled-optimization HAS_DISABLED_OPTIMIZATION)
if (HAS_DISABLED_OPTIMIZATION)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wdisabled-optimization")
endif ()
## Debug Compiler flags
set (CMAKE_C_FLAGS_DEBUG "-g -pedantic -Wc++-compat -Wcast-align -Wcast-qual -Wwrite-strings -Wno-overlength-strings -Wno-long-long")
check_c_compiler_flag (-fsanitize=undefined HAS_SANITIZE_UNDEF_TRAP)
if (HAS_SANITIZE_UNDEF_TRAP)
set (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -fsanitize=undefined")
endif ()
check_c_compiler_flag (-Wsuggest-attribute=const HAS_SUGGEST_ATTRIBUTE)
if (HAS_SUGGEST_ATTRIBUTE)
set (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Wsuggest-attribute=const -Wsuggest-attribute=pure")
endif ()
## Release Compiler flags
## Optimization Compiler flags
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
set (CMAKE_C_FLAGS_DEBUG "-O0 ${CMAKE_C_FLAGS_DEBUG}")
elseif (CMAKE_BUILD_TYPE STREQUAL "Release")
set (CMAKE_C_FLAGS_RELEASE "-O3 -march=native")
else ()
set (CMAKE_C_FLAGS "-O ${CMAKE_C_FLAGS}")
endif ()
## Include directories for header files
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/include
${HDF5_INCLUDE_DIRS}
${PGSQL_INCLUDE_DIR}
)
## =============================================================================
##
## Project sub-directories
##
## =============================================================================
add_subdirectory (libNADC)
add_subdirectory (libNADC_MERIS)
add_subdirectory (libNADC_SCIA)
add_subdirectory (FRESCO)
add_subdirectory (MERIS)
add_subdirectory (SCIA)
add_subdirectory (include)
add_subdirectory (psql)
## only build when netCDF is available
if (NETCDF_FOUND)
add_subdirectory (IMAP)
add_subdirectory (IMLM)
add_subdirectory (TOSOMI)
endif ()
## check for IDL and shared libraries
if (IDL_FOUND AND BUILD_SHARED_LIBS)
add_subdirectory (libNADC_IDL)
add_subdirectory (idl_progs)
endif ()
## =============================================================================
##
## Configuration summary
##
## =============================================================================
if (CONFIGURE_SUMMARY)
message ( " ========================================================" )
message ( " [nadc_tools] Configuration summary." )
message ( " --------------------------------------------------------" )
message ( " System configuration" )
message ( " .. System name ................ = ${CMAKE_SYSTEM_NAME}" )
message ( " .. System version ............. = ${CMAKE_SYSTEM_VERSION}" )
message ( " .. Processor type ............. = ${CMAKE_SYSTEM_PROCESSOR}" )
message ( " .. CMake executable ........... = ${CMAKE_COMMAND}" )
message ( " .. CMake version .............. = ${CMAKE_VERSION}" )
message ( " .. CMake build type ........... = ${CMAKE_BUILD_TYPE}" )
message ( " .. C compiler ................. = ${CMAKE_C_COMPILER}" )
message ( " .. C compiler flags ........... = ${CMAKE_C_FLAGS}" )
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
message ( " .. C compiler flags Debug...... = ${CMAKE_C_FLAGS_DEBUG}" )
endif()
if (CMAKE_BUILD_TYPE STREQUAL "Release")
message ( " .. C compiler flags Release ... = ${CMAKE_C_FLAGS_RELEASE}" )
endif()
message ( " --------------------------------------------------------" )
message ( " Project configuration" )
message ( " .. Project name ............... = ${PROJECT_NAME}" )
message ( " .. Project version ............ = ${PROJECT_VERSION}" )
message ( " .. Build shared libraries ..... = ${BUILD_SHARED_LIBS}" )
message ( " .. Sciamachy CKD directory .... = ${NADC_TOOLS_DATADIR}" )
message ( " .. Installation prefix ........ = ${CMAKE_INSTALL_PREFIX}" )
message ( " --------------------------------------------------------" )
message ( " Processing tools & libraries" )
message ( " .. HDF5 library ............... = ${HDF5_C_LIBRARIES}" )
message ( " .. HDF5 includes .............. = ${HDF5_INCLUDE_DIRS}" )
message ( " .. HDF5 library version ....... = ${HDF5_VERSION}" )
message ( " .. NETCDF library ............. = ${NETCDF_LIBRARIES}" )
message ( " .. NETCDF library version ..... = ${NETCDF_VERSION}" )
if (PGSQL_FOUND)
message ( " .. PSQL library ............... = ${PGSQL_LIBRARY}" )
message ( " .. PSQL includes .............. = ${PGSQL_INCLUDE_DIR}" )
message ( " .. PSQL library version ....... = ${PGSQL_VERSION}" )
else ()
message ( " .. PSQL library ............... = not installed" )
endif ()
if (IDL_FOUND)
message ( " .. IDL includes ............... = ${IDL_INCLUDE_DIR}" )
else ()
message ( " .. IDL full path .............. = not installed" )
endif ()
if (PPF_FOUND)
message ( " .. PPF libraries .............. = ${PPF_LIBRARIES}" )
message ( " .. PPF includes ............... = ${PPF_INCLUDE_DIR}" )
else ()
message ( " .. PPF libraries .............. = not installed" )
endif ()
message ( " ========================================================" )
endif (CONFIGURE_SUMMARY)