File: CMakeLists.txt

package info (click to toggle)
grib-api 1.19.0-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 217,848 kB
  • ctags: 16,929
  • sloc: ansic: 111,244; sh: 14,785; makefile: 5,307; f90: 3,583; perl: 3,160; python: 2,830; yacc: 712; fortran: 468; lex: 330; cpp: 305; awk: 66
file content (365 lines) | stat: -rw-r--r-- 12,077 bytes parent folder | download
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
############################################################################################
# cmake options:
#
#       -DCMAKE_BUILD_TYPE=Debug|RelWithDebInfo|Release|Production
#       -DCMAKE_INSTALL_PREFIX=/path/to/install
#
#       -DCMAKE_MODULE_PATH=/path/to/ecbuild/cmake

cmake_minimum_required( VERSION 2.8.11 FATAL_ERROR )

project( grib_api C )

set( CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/../ecbuild/cmake")

include( ecbuild_system NO_POLICY_SCOPE )

ecbuild_requires_macro_version( 1.9 )

###############################################################################
# local project

ecbuild_declare_project()

###############################################################################
# some variables/options of this project

ecbuild_add_option( FEATURE EXAMPLES
    DESCRIPTION "Build the examples"
    DEFAULT ON
)

ecbuild_add_option( FEATURE JPG
    DESCRIPTION "support for JPG decoding/encoding"
    DEFAULT ON
)

ecbuild_add_option( FEATURE PNG
    DESCRIPTION "support for PNG decoding/encoding"
    DEFAULT OFF
    REQUIRED_PACKAGES PNG
)

if( HAVE_PNG )
    set( HAVE_LIBPNG 1 ) # compatibility with autotools
    add_definitions( ${PNG_DEFINITIONS} )
else()
    set( HAVE_LIBPNG 0 )
endif()

ecbuild_add_option( FEATURE NETCDF
    DESCRIPTION "support for GRIB to NetCDF conversion"
    DEFAULT ON
    REQUIRED_PACKAGES NetCDF
)

ecbuild_add_option( FEATURE AEC
    DESCRIPTION "support for Adaptive Entropy Coding"
    DEFAULT OFF
    REQUIRED_PACKAGES AEC
)

ecbuild_add_option( FEATURE PYTHON
    DESCRIPTION "build the GRIB_API Python interface"
    DEFAULT ON
    REQUIRED_PACKAGES "Python VERSION 2.5"
)

ecbuild_add_option( FEATURE FORTRAN
    DESCRIPTION "build the GRIB_API Fortran interface"
    DEFAULT ON
    # REQUIRED_LANGUAGES Fortran # TODO
)

ecbuild_add_option( FEATURE BIT_REPRODUCIBLE
    DESCRIPTION "build bit-reproducible package"
    DEFAULT ON
    # Required for Debian, soon the world ...
)

# TODO Remove this after REQUIRED_LANGUAGES
if( ENABLE_FORTRAN )
    # will set EC_HAVE_FORTRAN with the result
    ecbuild_enable_fortran( MODULE_DIRECTORY ${PROJECT_BINARY_DIR}/fortran/modules )
    set( HAVE_FORTRAN ${EC_HAVE_FORTRAN} )
else()
    set( HAVE_FORTRAN 0 )
endif()

# advanced options (not visible in cmake-gui )

ecbuild_add_option( FEATURE MEMORY_MANAGEMENT DESCRIPTION "enable memory management" DEFAULT OFF ADVANCED )
ecbuild_add_option( FEATURE ALIGN_MEMORY      DESCRIPTION "enable memory alignment"  DEFAULT OFF ADVANCED )
ecbuild_add_option( FEATURE GRIB_TIMER       DESCRIPTION "enable timer"         DEFAULT OFF ADVANCED )
ecbuild_add_option( FEATURE GRIB_THREADS     DESCRIPTION "enable POSIX threads" DEFAULT OFF ADVANCED )
ecbuild_add_option( FEATURE GRIB_OMP_THREADS DESCRIPTION "enable OMP threads"   DEFAULT OFF ADVANCED )

###############################################################################
# macro processing

set( GRIB_API_EXTRA_LIBRARIES    "" )
set( GRIB_API_EXTRA_INCLUDE_DIRS "" )
set( GRIB_API_EXTRA_DEFINITIONS  "" )

find_package( CMath )
list( APPEND GRIB_API_TPLS CMath )

### JPG support

set( HAVE_JPEG 0 )
set( HAVE_LIBJASPER 0 )
set( HAVE_LIBOPENJPEG 0 )

if( ENABLE_JPG )

    # Note: This is a deprecated feature but we need it to find Jasper at ECMWF.
    #       ecbuild_add_extra_search_paths modifies CMAKE_PREFIX_PATH
    #       which can affect future package discovery if not undone by the caller.
    #       The current CMAKE_PREFIX_PATH is backed up as _CMAKE_PREFIX_PATH
    #
    set(CMAKE_WARN_DEPRECATED OFF) # Suppress deprecation message
    ecbuild_add_extra_search_paths( jasper )
    find_package( Jasper )
    set(CMAKE_PREFIX_PATH ${_CMAKE_PREFIX_PATH})    # Restore CMAKE_PREFIX_PATH
    set(CMAKE_WARN_DEPRECATED ON)  # Remove suppression

    find_package( OpenJPEG )

    if( JASPER_FOUND )
        list( APPEND GRIB_API_TPLS Jasper )
        set( HAVE_JPEG 1 )
        set( HAVE_LIBJASPER 1 )
    endif()

    if( OPENJPEG_FOUND )
        list( APPEND GRIB_API_TPLS OpenJPEG )
        set( HAVE_JPEG 1 )
        set( HAVE_LIBOPENJPEG 1 )
    endif()

endif()


###############################################################################
# other options

if( GRIB_TIMER )
    set( GRIB_TIMER 1 )
else()
    set( GRIB_TIMER 0 )
endif()

set( IS_BIG_ENDIAN 0 )
if( EC_BIG_ENDIAN )
    set( IS_BIG_ENDIAN 1 )
endif()

set( MANAGE_MEM 0 )
if( ENABLE_MEMORY_MANAGEMENT )
    set( MANAGE_MEM 1 )
endif()

set( CMAKE_THREAD_PREFER_PTHREAD 1 ) # find thread library, but prefer pthreads
find_package(Threads REQUIRED)

# debug
ecbuild_info(" CMAKE_THREAD_LIBS_INIT=${CMAKE_THREAD_LIBS_INIT}")
ecbuild_info(" CMAKE_USE_PTHREADS_INIT=${CMAKE_USE_PTHREADS_INIT}")
ecbuild_info(" GRIB_THREADS=${GRIB_THREADS}, HAVE_GRIB_THREADS=${HAVE_GRIB_THREADS}")


set( GRIB_PTHREADS 0 )
set( GRIB_OMP_THREADS 0 )
set( GRIB_LINUX_PTHREADS 0 )
#if( HAVE_GRIB_THREADS AND CMAKE_THREAD_LIBS_INIT )
if( HAVE_GRIB_THREADS )
    if( NOT ${CMAKE_USE_PTHREADS_INIT} )
        ecbuild_critical("Only pthreads supported - thread library found is [${CMAKE_THREAD_LIBS_INIT}]" )
    endif()
    set( GRIB_PTHREADS 1 )
    if( ${CMAKE_SYSTEM_NAME} MATCHES "Linux" )
        set( GRIB_LINUX_PTHREADS 1 )
    endif()
elseif(HAVE_GRIB_OMP_THREADS)
    ecbuild_enable_omp()
    set( GRIB_OMP_THREADS 1 )
endif()

# Cannot have both options
if( HAVE_GRIB_THREADS AND HAVE_GRIB_OMP_THREADS )
    ecbuild_critical( "Cannot enable both POSIX threads and OMP! Please specify just one option" )
endif()

ecbuild_info(" GRIB_PTHREADS=${GRIB_PTHREADS}")
ecbuild_info(" GRIB_OMP_THREADS=${GRIB_OMP_THREADS}")

set( GRIB_MEM_ALIGN 0 )
if( ENABLE_ALIGN_MEMORY )
  set( GRIB_MEM_ALIGN 1 )
endif()

# fix for #if IEEE_LE or IEE_BE instead of #ifdef

if( IEEE_BE )
    set( IEEE_LE 0 )
endif()

if( IEEE_LE )
    set( IEEE_BE 0 )
endif()

###############################################################################
# contents

if( NOT ${DEVELOPER_MODE} )
    set( the_default_data_prefix ${CMAKE_INSTALL_PREFIX} )
else()
    set( the_default_data_prefix ${CMAKE_BINARY_DIR} )
endif()

if( NOT DEFINED GRIB_API_DEFINITION_SUFF )
  set( GRIB_API_DEFINITION_SUFF  share/grib_api/definitions )
endif()
if( NOT DEFINED GRIB_API_SAMPLES_SUFF )
  set( GRIB_API_SAMPLES_SUFF     share/grib_api/samples )
endif()
if( NOT DEFINED GRIB_API_IFS_SAMPLES_SUFF )
  set( GRIB_API_IFS_SAMPLES_SUFF share/grib_api/ifs_samples )
endif()

set( GRIB_API_DEFINITION_PATH  ${the_default_data_prefix}/${GRIB_API_DEFINITION_SUFF} )
set( GRIB_API_SAMPLES_PATH     ${the_default_data_prefix}/${GRIB_API_SAMPLES_SUFF} )
set( GRIB_API_IFS_SAMPLES_PATH ${the_default_data_prefix}/${GRIB_API_IFS_SAMPLES_SUFF} )

### config header

ecbuild_generate_config_headers()

configure_file( grib_api_config.h.in grib_api_config.h )

add_definitions( -DHAVE_GRIB_API_CONFIG_H )

install( FILES ${CMAKE_CURRENT_BINARY_DIR}/grib_api_config.h DESTINATION ${INSTALL_INCLUDE_DIR} )

if( CMAKE_COMPILER_IS_GNUCC )
    ecbuild_add_c_flags("-pedantic")
endif()

############################################################################################
# contents

### export package to other ecbuild packages

set( GRIB_API_INCLUDE_DIRS    ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_BINARY_DIR}/src )
set( GRIB_API_LIBRARIES       grib_api )

get_directory_property( COMPILE_DEFINITIONS GRIB_API_DEFINITIONS )

foreach( _tpl ${GRIB_API_TPLS} )
    string( TOUPPER ${_tpl} TPL )
    if( ${TPL}_FOUND )
        list( APPEND GRIB_API_EXTRA_DEFINITIONS   ${${TPL}_DEFINITIONS} )
        list( APPEND GRIB_API_EXTRA_INCLUDE_DIRS  ${${TPL}_INCLUDE_DIRS} ${${TPL}_INCLUDE_DIR} )
        list( APPEND GRIB_API_EXTRA_LIBRARIES     ${${TPL}_LIBRARIES} )
    endif()
endforeach()

### include directories

include_directories( ${GRIB_API_INCLUDE_DIRS}  ${GRIB_API_EXTRA_INCLUDE_DIRS} )

add_subdirectory( src )
add_subdirectory( tools )
add_subdirectory( fortran )
add_subdirectory( python )
add_subdirectory( definitions )
add_subdirectory( tests )
add_subdirectory( tigge )
add_subdirectory( examples )
add_subdirectory( data )
add_subdirectory( samples )
add_subdirectory( ifs_samples ) # must come after samples

# ecbuild_dont_pack( DIRS samples DONT_PACK_REGEX "*.grib" )
ecbuild_dont_pack( DIRS
     concepts tests.ecmwf doxygen examples.dev templates sms parameters java
     gaussian_experimental gribex examples/F77
     examples/extra bamboo definitions/bufr use fortran/fortranCtypes tigge/tools share/grib_api
     src/.deps tests/.deps tools/.deps tigge/.deps examples/C/.deps examples/python/.deps
     python/.deps fortran/.deps
)

add_custom_target(dist COMMAND ${CMAKE_MAKE_PROGRAM} package_source)

############################################################################################
# export to other projects

# temporary -- add support for ecbuild 1.0.x sub-project inclusion
# to remove once mars server & client use eckit & ecbuild >= 1.1

if( EC_HAVE_FORTRAN )
    list( APPEND GRIB_API_INCLUDE_DIRS  ${CMAKE_Fortran_MODULE_DIRECTORY} )
    list( APPEND GRIB_API_LIBRARIES grib_api_f77 grib_api_f90 )
endif()

# Bundle
if( NOT PROJECT_NAME STREQUAL CMAKE_PROJECT_NAME )
  set( GRIB_API_FOUND            TRUE PARENT_SCOPE )
  set( GRIB_API_DEFINITIONS      ${GRIB_API_DEFINITIONS}  PARENT_SCOPE ) # includes already TPL definitions
  set( GRIB_API_INCLUDE_DIRS     ${GRIB_API_INCLUDE_DIRS} ${GRIB_API_EXTRA_INCLUDE_DIRS} PARENT_SCOPE )
  set( GRIB_API_LIBRARIES        ${GRIB_API_LIBRARIES}    ${GRIB_API_EXTRA_LIBRARIES} ${CMATH_LIBRARIES} PARENT_SCOPE )
  set( GRIB_API_INSTALL_EXTRA_TOOLS ${GRIB_API_INSTALL_EXTRA_TOOLS} PARENT_SCOPE )
  set( GRIB_API_DEFINITION_PATH  ${CMAKE_BINARY_DIR}/${GRIB_API_DEFINITION_SUFF}  PARENT_SCOPE )
  set( GRIB_API_SAMPLES_PATH     ${CMAKE_BINARY_DIR}/${GRIB_API_SAMPLES_SUFF}     PARENT_SCOPE )
  set( GRIB_API_IFS_SAMPLES_PATH ${CMAKE_BINARY_DIR}/${GRIB_API_IFS_SAMPLES_SUFF} PARENT_SCOPE )
endif()

# pkg-config
ecbuild_pkgconfig(
  NAME                grib_api
  URL                 "https://software.ecmwf.int/wiki/display/GRIB/"
  DESCRIPTION         "The GRIB API library"
  LIBRARIES           grib_api
  VARIABLES           HAVE_JPG HAVE_LIBJASPER HAVE_LIBOPENJPEG
                      HAVE_GRIB_THREADS HAVE_GRIB_OMP_THREADS
                      HAVE_NETCDF HAVE_PYTHON HAVE_FORTRAN HAVE_PNG HAVE_AEC
)
if( EC_HAVE_FORTRAN )
 ecbuild_pkgconfig(
   NAME                grib_api_f90
   URL                 "https://software.ecmwf.int/wiki/display/GRIB/"
   LIBRARIES           grib_api_f90 grib_api
   DESCRIPTION         "The GRIB API library for Fortran 90"
   IGNORE_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/fortran ${PROJECT_BINARY_DIR}/fortran
   VARIABLES           HAVE_JPG HAVE_LIBJASPER HAVE_LIBOPENJPEG
                       HAVE_GRIB_THREADS HAVE_GRIB_OMP_THREADS
                       HAVE_NETCDF HAVE_PYTHON HAVE_PNG HAVE_AEC
 )
  ecbuild_pkgconfig(
   NAME                grib_api_f77
   URL                 "https://software.ecmwf.int/wiki/display/GRIB/"
   LIBRARIES           grib_api_f77 grib_api
   DESCRIPTION         "The GRIB API library for Fortran 77"
   IGNORE_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/fortran ${PROJECT_BINARY_DIR}/fortran
   VARIABLES           HAVE_JPG HAVE_LIBJASPER HAVE_LIBOPENJPEG
                       HAVE_GRIB_THREADS HAVE_GRIB_OMP_THREADS
                       HAVE_NETCDF HAVE_PYTHON HAVE_PNG HAVE_AEC
 )
endif()

############################################################################################
# finalize

ecbuild_install_project( NAME ${CMAKE_PROJECT_NAME} )

ecbuild_print_summary()

ecbuild_info("")
ecbuild_info("   +---------------------------+")
ecbuild_info("   |  GRIB API version ${GRIB_API_VERSION}  |")
ecbuild_info("   |  Configuration completed  |")
ecbuild_info("   +---------------------------+")
ecbuild_info("")
ecbuild_info("   You can now do 'make' to compile the package, 'ctest' to test it and 'make install' to install it afterwards.")
ecbuild_info("")
ecbuild_info("")