File: CMakeLists.txt

package info (click to toggle)
metview 5.10.2-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 242,296 kB
  • sloc: cpp: 437,117; ansic: 41,433; xml: 19,944; f90: 13,059; sh: 6,562; python: 3,953; yacc: 1,774; lex: 1,121; perl: 701; makefile: 92
file content (929 lines) | stat: -rw-r--r-- 32,151 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
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
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
############################################################################################
# cmake options:
#
#       -DCMAKE_BUILD_TYPE=Debug|RelWithDebInfo|Release|Production
#
#       -DCMAKE_MODULE_PATH=/path/to/ecbuild/cmake
#
#       -DCMAKE_C_COMPILER=gcc
#       -DCMAKE_C_COMPILER=g++
#
#       -DCMAKE_PREFIX_PATH=/path/to/jasper:/path/to/any/package/out/of/place
#       -DBUILD_SHARED_LIBS=OFF
#
#  Metview-specific:
#  -DMETVIEW_SITE=ecmwf | other
#  -DMETVIEW_SCRIPT=name-of-generated-startup-script
#  -DMARS_HOME=/path/to/MARS/home  (requires WITH_MARS=ON)
#  -DMAGICS_PATH=/path/to/magics   (requires WITH_PLOTTING=ON)
#  -DEXTRA_TITLE=extra-title-string
#  -DLOG_DIR=/path/to/dir/for/module/log/files
#  -DODB1_USE_SCRIPT_PATH=/path/to/odb1/use/script

cmake_minimum_required( VERSION 3.12 FATAL_ERROR )

find_package( ecbuild 3.4 REQUIRED HINTS ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_CURRENT_SOURCE_DIR}/../ecbuild)

 
if(POLICY CMP0025)
  cmake_policy(SET CMP0025 NEW)
endif()

project(metview VERSION 5.10.2 LANGUAGES C CXX)


# All executables and scripts apart from the startup script should go into MV_BIN_DIR.
# Users can override by setting METVIEW_INSTALL_EXE_BIN_DIR.
# It should be relative to the root of the install directory.
if(DEFINED METVIEW_INSTALL_EXE_BIN_DIR)
    set(MV_BIN_DIR ${METVIEW_INSTALL_EXE_BIN_DIR})
else()
    set(MV_BIN_DIR bin/metview_bin)
endif()


set(CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE OFF)

set(ORIGINAL_INSTALL_BIN_DIR ${INSTALL_BIN_DIR}) # will restore at the end
set(INSTALL_BIN_DIR "${MV_BIN_DIR}" CACHE PATH "Metview installation directory for executable files")

include( ecbuild_system NO_POLICY_SCOPE )

IF(APPLE)
  SET(MACOSX_RPATH 1)
  SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
  #SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
ENDIF(APPLE)

ecbuild_requires_macro_version( 1.9 )

#ecbuild_add_cxx11_flags()  # Magics 3 requires C++11/14
set (CMAKE_CXX_STANDARD 14)
set (CMAKE_C_STANDARD 99)

###############################################################################
# some options of this project

option( ENABLE_UI             "enable the user interface"                          ON )
option( ENABLE_PLOTTING       "enable the plotting module"                         ON )
option( ENABLE_MARS           "enable MARS access"                                 OFF )
option( ENABLE_ODB            "enable ODB"                                         OFF )
option( ENABLE_USAGE_LOG      "enable usage logging (only at ECMWF)"               OFF )
option( ENABLE_QT_DEBUG       "enable Qt debugging messages"                       OFF )
option( ENABLE_INPE           "enable INPE modules"                                OFF )
option( ENABLE_URL_DOWNLOAD   "enable downloading of files from URLs"              ON )
option( ENABLE_WEATHER_ROOM   "enable Weather Room plot export (only at ECMWF)"    OFF )
option( ENABLE_SHARE_PLOT     "enable sharing of plots (only at ECMWF)"            OFF )
option( ENABLE_SHARE_TO_GLOBE "enable Globe plot export (only at ECMWF)"           OFF )
option( ENABLE_NETWORK_PROXY  "enable network proxy settings for WMS"              OFF )
option( ENABLE_EXPERIMENTAL   "enable experimental modules"                        OFF )
option( ENABLE_CONTRIB        "enable externally contributed modules"              OFF )
option( ENABLE_METVIEW_FORTRAN "enable modules which use Fortran code"             OFF )
option( ENABLE_METVIEW_DOCS   "enable building of documentation"                   OFF )
option( ENABLE_CODES_UI       "enable building of CodesUI"                         OFF )
#option( ENABLE_CODE_WEBHELP   "enable inline web help in code editor"              OFF )




###############################################################################


if( ENABLE_METVIEW_FORTRAN )
    ecbuild_enable_fortran( REQUIRED )
    set(HAVE_METVIEW_FORTRAN 1)
endif()


# ensure we can add non-existent dependencies - required for generating icon files
if( ${CMAKE_VERSION} VERSION_GREATER "2.9.9" )
    cmake_policy(SET CMP0046 OLD)
endif()



# if we don't explicitly state that we're at ECMWF, then assume we're not, and use the generic config
if(NOT METVIEW_SITE STREQUAL ecmwf)
    set( SITE_WMO_CODE "255")    # DO WE NEED AN OPTION TO ALLOW INSTALLERS TO SPECIFY THIS?
    set( MV_ENVIRON    "common")
    set( AT_ECMWF "FALSE" )
    ecbuild_info("Building outside ECMWF")
else()
    set( SITE_WMO_CODE "098")
    set( MV_ENVIRON    "ecm_lnx64")
    set( AT_ECMWF "TRUE" )
    add_definitions( -DECMWF )
    ecbuild_info("Building inside ECMWF")
endif()


if(DEFINED EXTRA_CONFIG_PATH)
    ecbuild_info("Will search ${EXTRA_CONFIG_PATH} for additional config files")
endif()



# default startup script name
if(NOT DEFINED METVIEW_SCRIPT )
    set( METVIEW_SCRIPT "metview" )
endif()

set(FULL_STARTUP_SCRIPT_PATH ${CMAKE_BINARY_DIR}/bin/${METVIEW_SCRIPT})

# ensure we don't build shared libraries
set(BUILD_SHARED_LIBS OFF)


# Weather Room plot export (ECMWF only)
if(ENABLE_WEATHER_ROOM)
    if(AT_ECMWF)
        find_package( Boost 1.49.0 )            # Weather Room export needs Boost
        set(MV_WEATHER_ROOM_BUILT true)
    else()
        ecbuild_error("ENABLE_WEATHER_ROOM only available when building at ECMWF")
    endif()
else()
    set(MV_WEATHER_ROOM_BUILT false)
endif()

# Globe plot export (ECMWF only)
if(ENABLE_SHARE_TO_GLOBE)
    if(NOT AT_ECMWF)
        ecbuild_error("ENABLE_SHARE_TO_GLOBE only available when building at ECMWF")
    endif()
    if(NOT ENABLE_SHARE_PLOT)
        ecbuild_error("ENABLE_SHARE_TO_GLOBE only available when ENABLE_SHARE_PLOT is enabled")
    endif()
endif()

if(ENABLE_INPE)
    set(METVIEW_INPE true)
endif()





# ----------------
# look for eccodes 
# ----------------

ecbuild_find_package(NAME eccodes VERSION 2.19.0 REQUIRED)

set( GRIB_API_INCLUDE_DIRS  ${eccodes_INCLUDE_DIRS} )
set( GRIB_API_LIBRARIES     ${eccodes_LIBRARIES} )
set( GRIB_API_DEFINITIONS   ${eccodes_DEFINITIONS} )
set( GRIB_API_TPL_LIBRARIES ${eccodes_TPL_LIBRARIES} )
set( grib_api_BASE_DIR      ${eccodes_BASE_DIR} )
add_definitions(-DGRIB_HANDLING_PACKAGE=ecCodes)



# --------------------
# look for MARS client 
# --------------------

ecbuild_find_package(NAME mars_client VERSION 6.28.6 REQUIRED)
ecbuild_find_package(NAME mir VERSION 1.6.1 REQUIRED)

set(MARSCLIENT_LIBS "marsclient")


# check which post-processing libraries it found
list(FIND mars_client_FEATURES "PPROC_MIR"  HAVE_PPROC_MIR)
list(FIND mars_client_FEATURES "PPROC_EMOS" HAVE_PPROC_EMOS)
if (HAVE_PPROC_MIR EQUAL -1)
    set(HAVE_PPROC_MIR 0)
else()
    set(HAVE_PPROC_MIR 1)
    list(APPEND MARSCLIENT_LIBS "mir")
endif()
if (HAVE_PPROC_EMOS EQUAL -1)
    set(HAVE_PPROC_EMOS 0)
else()
    set(HAVE_PPROC_EMOS 1)
    ecbuild_find_package(NAME libemos REQUIRED)
    list(APPEND MARSCLIENT_LIBS "emos")
endif()


if( NOT HAVE_PPROC_MIR AND NOT HAVE_PPROC_EMOS  )
    message( FATAL_ERROR "MARS client requires PPROC (for which MIR or EMOSLIB is required)" )
endif()


if(HAVE_PPROC_MIR)
    ecbuild_find_package(NAME eckit VERSION 1.0 REQUIRED)  # for DivRot, which uses eckit directly
endif()

# decide which interpolation library to use by default
if(HAVE_PPROC_MIR)
    set(DEFAULT_INTERP_PACKAGE "MIR")
else()
    set(DEFAULT_INTERP_PACKAGE "EMOS")
endif()




# look for curl because it is needed for the Mars Web API client
find_package(CURL)
if(CURL_FOUND)
    list(APPEND MARSCLIENT_LIBS ${CURL_LIBRARIES})
endif()



# local MARS access
if(ENABLE_MARS)
    set( MARS_ACCESS MARS_local )
    set( METVIEW_MARS 1 )
    if(DEFINED MARS_LOCAL_HOME)
        ecbuild_info("MARS_LOCAL_HOME=${MARS_LOCAL_HOME}")
        if(NOT EXISTS ${MARS_LOCAL_HOME})
            ecbuild_critical("MARS_LOCAL_HOME (${MARS_LOCAL_HOME}) does not exist")
        else()
            set(MARS_HOME ${MARS_LOCAL_HOME})
        endif()
    else()
        ecbuild_critical("If setting local MARS access, -DMARS_LOCAL_HOME=/path/to/mars/home must be provided.")
    endif()

    list(FIND mars_client_FEATURES "ODB" HAVE_MARS_ODB)
    if (HAVE_MARS_ODB EQUAL -1)
        set(ENABLE_MARS_ODB "OFF")
    else()
        set(ENABLE_MARS_ODB "ON")
    endif()
    

    if(ENABLE_MARS_ODB)
        set(ENABLE_ODB 1)
        set(METVIEW_MARS_ODB 1)
    endif()

    #find_library( FDB  REQUIRED )
    #ecbuild_debug("FDB: ${FDB_LIBRARIES}" )

else()
    if(${CURL_FOUND})
        set( MARS_ACCESS MARS_webapi )
    else()
        set( MARS_ACCESS MARS_none )
        add_definitions(-DNOCURL)
        ecbuild_warn("Could not find the Curl library - disabling Web API Mars")
    endif()
endif()


# Network access (download via URLs)
if(ENABLE_URL_DOWNLOAD)
    if(NOT CURL_FOUND)
        ecbuild_critical("URL_DOWNLOAD was enabled, but the 'curl' development package was not found.")
    endif()
endif()



###############################################################################
# local project requirements

# ecbuild_use_package( PROJECT eckit VERSION 0.3 REQUIRED )




#message(FATAL_ERROR "ECCODES_INCLUDE_DIRS ${ECCODES_INCLUDE_DIRS}")


if(ENABLE_ODB)
    ecbuild_find_package(NAME odc    VERSION 1.1.0 REQUIRED)
    if( odc_FOUND )
        set(METVIEW_ODB_API_LIBRARIES odccore)
        set(METVIEW_ODB 1)

        add_definitions(-DMETVIEW_ODB_NEW -DMETVIEW_ODB)
    else()
        if(ENABLE_MARS_ODB)
            ecbuild_critical("ENABLE_ODB was set, but ODB not found")
            set(ENABLE_MARS_ODB 0)
            set(METVIEW_MARS_ODB 0)
        endif()
    endif()

    # ODB-1

    #ecbuild_use_package( PROJECT ODB )
    ecbuild_find_package(NAME odb)

    if(odb_FOUND)
        if(EXISTS ${ODB_PATH}/bin)
            if(EXISTS ${ODB_PATH}/bin/odbsql)
                add_definitions(-DMETVIEW_ODB_OLD)
                set(ENABLE_ODB1 "ON")

                if(ODB1_USE_SCRIPT) # was an ODB-1 use script name passed?
                    set(ODB1_LOAD_ENV "MV_ODB1_USE_SCRIPT=${ODB1_USE_SCRIPT}")
                endif()

                if(ODB1_MODULE) # was an ODB-1 module name passed?
                    set(ODB1_LOAD_ENV "MV_ODB1_MODULE=${ODB1_MODULE}")
                endif()

                if(ODB1_VERSION) # was an ODB-1 module name passed?
                    set(MV_ODB1_VERSION ${ODB1_VERSION})
                else()
                    set(MV_ODB1_VERSION "ANY")
                endif()

            else()
                ecbuild_warn("ODB-1 support is DISABLED - No odbsql script found in ${ODB_PATH}/bin")
            endif()
        else()
            ecbuild_warn("ODB-1 found, but no bin directory in ${ODB_PATH}")
        endif()
    else()
        ecbuild_warn("ODB-1 not found!")
    endif()
endif()


if(ENABLE_PLOTTING)
    #ecbuild_use_package( PROJECT magics VERSION 4.1.0)
    ecbuild_find_package(NAME magics VERSION 4.1.0 REQUIRED)

    if( magics_FOUND )

        set(MAGICS_LIB_DIR "${magics_BASE_DIR}/lib")

        if(ENABLE_UI AND (NOT magics_HAVE_METVIEW))
            ecbuild_critical("Magics must be built with Metview and Qt support!")
        endif()

        if((NOT ENABLE_UI) AND (NOT magics_HAVE_METVIEW_NO_QT))
            ecbuild_critical("No UI: Magics must be built with Metview but no Qt support!")
        endif()

        if(NOT magics_HAVE_NETCDF)
            ecbuild_critical("Magics must be built with netCDF support!")
        endif()

        if(magics_HAVE_ODB)
            add_definitions(-DMETVIEW_ODB_PLOT)
        else()
            if(ENABLE_ODB)
                ecbuild_warn("ODB plotting is disabled, because Magics was built without ODB support! Please, rebuild Magics with ODB support to enable ODB plotting!")  #xxx should be at end
            endif()
        endif()

        if(NOT magics_HAVE_CAIRO)
            ecbuild_warn("NO PNG and PDF plotting support (disabled in Magics)")  #xxx should be at end
        endif()

    else()
        ecbuild_critical("Magics was not found, and it is required if ENABLE_PLOTTING=ON. Please supply MAGICS_PATH if necessary.")
    endif()
endif()


ecbuild_declare_project()
ecbuild_debug("VERSION: ${METVIEW_VERSION_STR}")

###############################################################################
# Find external dependencies

#set( CMAKE_THREAD_PREFER_PTHREAD 1 )
#find_package( Threads )

#ecbuild_add_extra_search_paths( boost )
#find_package( Boost 1.49.0 )


# some systems require libquadmath, so we add it if it exists on the system
# NOTE that it should not really be necessary - it is a MISTAKE to require
# to link quadmath, but it can easily happen...

if(CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
    find_library(QUADMATH_LIB quadmath)
    if(QUADMATH_LIB)
        ecbuild_debug("quadmath found: ${QUADMATH_LIB}")
        list( APPEND METVIEW_EXTRA_LIBRARIES ${QUADMATH_LIB} )
    else()
        # sometimes CMake does not properly detect libquadmath

        if (EXISTS /usr/lib64/libquadmath.so.0)
            list( APPEND METVIEW_EXTRA_LIBRARIES /usr/lib64/libquadmath.so.0 )
        endif()
    endif()
endif()


find_library(PTHREAD_LIB pthread)
if(PTHREAD_LIB)
    ecbuild_debug("pthread found: ${PTHREAD_LIB}")
else()
    ecbuild_critical("library pthread not found")
endif()



# FLEXTRA

if(DEFINED FLEXTRA_PATH)
    if(EXISTS ${FLEXTRA_PATH})
        set(MV_FLEXTRA_PATH_SET "MV_FLEXTRA_EXE=${FLEXTRA_PATH}")
    else()
        ecbuild_critical("FLEXTRA_PATH: (${FLEXTRA_PATH}) does not exist")
    endif()
endif()

# FLEXPART

if(DEFINED FLEXPART_EXE_PATH)
    if(EXISTS ${FLEXPART_EXE_PATH})
        set(MV_FLEXPART_EXE_PATH_SET "MV_FLEXPART_EXE=${FLEXPART_EXE_PATH}")
    else()
        ecbuild_critical("FLEXPART_EXE_PATH: (${FLEXPART_EXE_PATH}) does not exist")
    endif()
endif()

if(DEFINED FLEXPART_RESOURCES_PATH)
    if(EXISTS ${FLEXPART_RESOURCES_PATH})
        set(MV_FLEXPART_RESOURCES_PATH_SET "MV_FLEXPART_RESOURCES=${FLEXPART_RESOURCES_PATH}")
    else()
        ecbuild_critical("FLEXPART_RESOURCES_PATH: (${FLEXPART_RESOURCES_PATH}) does not exist")
    endif()
endif()

if(DEFINED FLEXPART_SPECIES_PATH)
    if(EXISTS ${FLEXPART_SPECIES_PATH})
        set(MV_FLEXPART_SPECIES_PATH_SET "MV_FLEXPART_SPECIES=${FLEXPART_SPECIES_PATH}")
    else()
        ecbuild_critical("FLEXPART_SPECIES_PATH: (${FLEXPART_SPECIES_PATH}) does not exist")
    endif()
endif()

# Network proxy

if(ENABLE_NETWORK_PROXY)
    if(NOT DEFINED PROXY_URL)
        ecbuild_critical("ENABLE_NETWORK_PROXY is ON but PROXY_URL is not defined")
    endif()

    if(NOT DEFINED PROXY_PORT)
        ecbuild_critical("ENABLE_NETWORK_PROXY is ON but PROXY_PORT is not defined")
    endif()

    if(NOT DEFINED NO_PROXY_FOR)
        ecbuild_critical("ENABLE_NETWORK_PROXY is ON but NO_PROXY_FOR is not defined")
    endif()

    set(USE_NETWORK_PROXY YES)
else()
    set(USE_NETWORK_PROXY NO)
    set(PROXY_URL proxy.url)  # does not matter what it is in this case
    set(PROXY_PORT 1234)      # does not matter what it is in this case
    set(NO_PROXY_FOR none)    # does not matter what it is in this case
endif()



# find_package( EXPAT  )

find_package(FLEX  REQUIRED)
find_package(BISON REQUIRED)


# netCDF
find_package( NetCDF 4)
if( NETCDF_FOUND )
    list( APPEND METVIEW_TPLS  NetCDF )
else()
    ecbuild_critical("NetCDF was not found")
endif()

set(NETCDF_LIBRARIES NetCDF::NetCDF_C) 


find_library(GDBM_LIB gdbm )
find_path( GDBM_INCLUDE gdbm.h )
if(GDBM_LIB AND GDBM_INCLUDE)
    ecbuild_debug("gdbm found")
    ecbuild_debug("  library: ${GDBM_LIB}")
    ecbuild_debug("  include: ${GDBM_INCLUDE}")
else()
    ecbuild_critical("library gdbm not found")
endif()


if( ENABLE_UI )

    find_package(Qt5Widgets      REQUIRED)
    find_package(Qt5Gui          REQUIRED)
    find_package(Qt5Network      REQUIRED)
    find_package(Qt5Xml          REQUIRED)
    find_package(Qt5XmlPatterns  REQUIRED)
    find_package(Qt5PrintSupport REQUIRED)
    find_package(Qt5Svg          REQUIRED)

    if( Qt5Widgets_FOUND )
        ecbuild_debug("Qt5 version ${Qt5Widgets_VERSION_STRING} was found")
        include_directories(${Qt5Widgets_INCLUDE_DIRS} ${Qt5Gui_INCLUDE_DIRS} ${Qt5Xml_INCLUDE_DIRS} ${Qt5XmlPatterns_INCLUDE_DIRS} ${Qt5Network_INCLUDE_DIRS} ${Qt5PrintSupport_INCLUDE_DIRS} ${Qt5Svg_INCLUDE_DIRS})
        set( METVIEW_QT 1)
        set( METVIEW_QT5 true)
        add_definitions( -DMETVIEW_QT5 )

        if(ENABLE_CODE_WEBHELP)
            find_package(Qt5WebEngineWidgets 5.5.0)
            if (Qt5WebEngineWidgets_FOUND)
                ecbuild_info("Qt5WebEngineWidgets was found - Code Editor web document browser will be built")
                set(METVIEW_QT_WEBENGINE 1)
            else()
                ecbuild_info("Qt5WebEngineWidgets was not found - Code Editor web document browser will not be built")
            endif()
        endif()

    else()
        ecbuild_critical("Qt5 was NOT found ...")
    endif()

    set( METVIEW_GUI_BUILT true )

else()
    set( METVIEW_GUI_BUILT false )
endif()



if( NOT ENABLE_QT_DEBUG )
    add_definitions( -DQT_NO_DEBUG_OUTPUT )
endif()



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

######set( METVIEW_TPLS grib_api odb_api EXPAT NetCDF PangoCairo Proj4 libemos)

set( METVIEW_STANDARD_INCLUDE_DIRS
        ${MARS_CLIENT_INCLUDE_DIRS}
        ${CMAKE_CURRENT_SOURCE_DIR}/src/libMetview
        ${MARS_SOURCE}
        ${CMAKE_CURRENT_SOURCE_DIR}/src/libMars
        ${CMAKE_CURRENT_BINARY_DIR}/src/libMars        # for generated header files
        ${CMAKE_CURRENT_SOURCE_DIR}/src
        ${CMAKE_CURRENT_SOURCE_DIR}/src/libFTimeUtil
        ${Boost_INCLUDE_DIRS} )

#message(FATAL_ERROR "METVIEW_STANDARD_INCLUDE_DIRS: ${METVIEW_STANDARD_INCLUDE_DIRS}")
if( METVIEW_ODB )
    list( APPEND METVIEW_STANDARD_INCLUDE_DIRS
        ${CMAKE_CURRENT_SOURCE_DIR}/src/Odb
        ${ODB_API_INCLUDE_DIRS}/../eclib
    )
endif()

if(CURL_FOUND)
    list(APPEND METVIEW_STANDARD_INCLUDE_DIRS ${CURL_INCLUDE_DIRS})
endif()


set(STANDARD_METVIEW_LIBS Metview MvFTimeUtil) ### ${METVIEW_3RDPARTY_LIBS}"
set(METVIEW_MACRO_API_C_LIB   macro_api_c)
set(METVIEW_MACRO_API_F90_LIB macro_api_f90)


unset( LIBEMOS_DEFINITIONS ) # no need to use exported libemos definitions

# only want certain third-party libraries linked with all modules - the rest
# are on a per-module basis
set(METVIEW_TPLS grib_api NetCDF)
foreach( _tpl ${METVIEW_TPLS} )
    string( TOUPPER ${_tpl} TPL )
    list( APPEND METVIEW_EXTRA_DEFINITIONS   ${${TPL}_DEFINITIONS}  )
    list( APPEND METVIEW_EXTRA_INCLUDE_DIRS  ${${TPL}_INCLUDE_DIRS} )
    list( APPEND METVIEW_EXTRA_LIBRARIES     ${${TPL}_LIBRARIES} )
    ecbuild_debug("xTPL_LIBRARIES: ${TPL}_LIBRARIES")
endforeach()
list( APPEND METVIEW_EXTRA_LIBRARIES     ${LIBEMOS_LIBRARIES} )


###list( APPEND METVIEW_EXTRA_DEFINITIONS   fortfloat=double fortint=int boolean=bool )

if( ENABLE_UI )
  list( APPEND METVIEW_QT_INCLUDE_DIRS ${Qt5Widgets_INCLUDE_DIR} ${Qt5Gui_INCLUDE_DIR} ${Qt5Xml_INCLUDE_DIR} ${Qt5XmlPatterns_INCLUDE_DIR} ${Qt5Network_INCLUDE_DIR} ${Qt5PrintSupport_INCLUDE_DIR} ${Qt5Svg_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/src/libMvQtUtil ${CMAKE_CURRENT_SOURCE_DIR}/src/libMvQtGui )
  list( APPEND METVIEW_QT_LIBRARIES  MvQtGui MvQtUtil ${Qt5Widgets_LIBRARIES} ${Qt5Gui_LIBRARIES} ${Qt5Xml_LIBRARIES} ${Qt5XmlPatterns_LIBRARIES} ${Qt5Network_LIBRARIES} ${Qt5PrintSupport_LIBRARIES} ${Qt5Svg_LIBRARIES})
endif()


set(STANDARD_METVIEW_LIBS_ODB ${STANDARD_METVIEW_LIBS})

ecbuild_info("METVIEW_EXTRA_DEFINITIONS  => ${METVIEW_EXTRA_DEFINITIONS}")
ecbuild_info("METVIEW_EXTRA_INCLUDE_DIRS => ${METVIEW_EXTRA_INCLUDE_DIRS}")
ecbuild_info("METVIEW_EXTRA_LIBRARIES    => ${METVIEW_EXTRA_LIBRARIES}")
ecbuild_info("STANDARD_METVIEW_LIBS      => ${STANDARD_METVIEW_LIBS}")
ecbuild_info("LIBEMOS_LIBRARIES          => ${LIBEMOS_LIBRARIES}")


###get_directory_property( MAGICS_DEFINITIONS COMPILE_DEFINITIONS )

# we need to make sure that
#set(CMAKE_INCLUDE_DIRECTORIES_BEFORE "ON")

###include_directories( ${METVIEW_INCLUDE_DIRS} ${METVIEW_EXTRA_INCLUDE_DIRS} )

set(METVIEW_STANDARD_INCLUDES ${METVIEW_STANDARD_INCLUDE_DIRS} ${METVIEW_EXTRA_INCLUDE_DIRS} )
list(REMOVE_ITEM METVIEW_STANDARD_INCLUDES "/usr/include") # no need to have /usr/include, and could cause wrong grib_api.mod to be found
ecbuild_info("METVIEW_STANDARD_INCLUDE_DIRS  => ${METVIEW_STANDARD_INCLUDES}")


set(  __metview_inc_tmp ${METVIEW_EXTRA_INCLUDE_DIRS} )
set(METVIEW_EXTRA_INCLUDES "")

foreach( inc ${__metview_inc_tmp} )
  set(METVIEW_EXTRA_INCLUDES "${METVIEW_EXTRA_INCLUDES} -I${inc}" )
endforeach()

### from MARS add_definitions( -DECMWF -DR64 -DODB_SUPPORT )

add_definitions( -DR64 -DMETVIEW -DMETVIEW_BUFR -DH_INCLUDES_CC -DUSE_NEW_IO )

# ecbuild automatically test endiness and sets variable EC_BIG_ENDIAN or EC_LITTLE_ENDIAN
if( EC_LITTLE_ENDIAN )
	add_definitions(-DLITTLE_END) # needed for libMars/bufr.h
endif()

# -------------------------
# compiler-specific options
# -------------------------

ecbuild_add_cxx_flags("${FPIC}")
ecbuild_add_c_flags("${FPIC}")
ecbuild_add_fortran_flags("${FPIC}")

if     (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" )
    ecbuild_add_cxx_flags("-fpermissive -Wno-write-strings -Wno-deprecated -Werror=return-type")
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" )
    ecbuild_add_cxx_flags("-fpermissive -Wno-deprecated -undefined dynamic_lookup")
endif()

if     (CMAKE_C_COMPILER_ID STREQUAL "Clang" )
    ecbuild_add_c_flags("-undefined dynamic_lookup")     #  "-fno-common  -mmacosx-version-min=10.8")
endif()


# Fortran flags

# ensure double-precision REALs

if(CMAKE_Fortran_COMPILER_ID STREQUAL "PGI")
    ecbuild_add_fortran_flags("-r8")
elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "Intel")
    ecbuild_add_fortran_flags("-r8")
elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
    # NOTE that if we add -fdefault-real-8 then we NEED -fdefault-double-8 to avoid quadmath
    ecbuild_add_fortran_flags("-fdefault-real-8 -fdefault-double-8")
endif()


if (HAVE_METVIEW_FORTRAN)
    # for grib_api.mod
    if(GRIB_API_INCLUDE_DIR)
        ecbuild_add_fortran_flags("-I${GRIB_API_INCLUDE_DIR}")
    endif()
endif()


# we have to create the share directories now, because otherwise module-specific
# etc/xpm files will be copied to etc before it is created and etc will become a
# file rather than a directory
make_directory(${CMAKE_BINARY_DIR}/share/metview/etc/)
make_directory(${CMAKE_BINARY_DIR}/share/metview/icons/)
make_directory(${CMAKE_BINARY_DIR}/share/metview/eccharts/style_previews/)

set(ModuleObjectSpecFiles) # empty to start with
set(ModuleXpmFiles)        # empty to start with
set(ModuleSvgFiles)        # empty to start with


# ------------------------------------------------------------------------
# MACRO metview_module_files
# Ensures the files listed in ETC_FILES are copied to the build directory
# and that they will be installed at install time. Same with icon files,
# but they will additionally be added to a list of files to convert.
# ------------------------------------------------------------------------

macro(metview_module_files)
    set(options )
    set(single_value_args )
    set(multi_value_args ETC_FILES XPM_FILES SVG_FILES)
    cmake_parse_arguments( PAR "${options}" "${single_value_args}" "${multi_value_args}" ${_FIRST_ARG} ${ARGN} )

    foreach( etc ${PAR_ETC_FILES} )
        # copy to the build 'etc' directory
        configure_file(${etc} ${CMAKE_BINARY_DIR}/share/metview/etc/ COPYONLY)


        # ensure file is installed at install time
        install( FILES ${CMAKE_CURRENT_SOURCE_DIR}/${etc}
                 DESTINATION share/metview/etc
                 PERMISSIONS OWNER_WRITE OWNER_READ GROUP_READ WORLD_READ)


        # pick out the ObjectSpec files and add them to a list which we propagate to
        # the parent scope so that it is shared between all directories
        if(${etc} MATCHES ObjectSpec*)
            set(ModuleObjectSpecFiles ${ModuleObjectSpecFiles} ${CMAKE_BINARY_DIR}/share/metview/etc/${etc})
            set(ModuleObjectSpecFiles ${ModuleObjectSpecFiles} PARENT_SCOPE) # make it visible outside
        endif()

    endforeach()

    foreach( xpm ${PAR_XPM_FILES} )
        # copy to the build 'etc' directory
        set(ModuleXpmFiles ${ModuleXpmFiles} ${CMAKE_CURRENT_SOURCE_DIR}/${xpm})
        set(ModuleXpmFiles ${ModuleXpmFiles}  PARENT_SCOPE)

        #configure_file(${xpm} ${CMAKE_BINARY_DIR}/share/metview/icons/ COPYONLY)


        # ensure file is installed at install time
        #install( FILES ${CMAKE_CURRENT_SOURCE_DIR}/${xpm}
        #         DESTINATION share/metview/xpm
        #         PERMISSIONS OWNER_WRITE OWNER_READ GROUP_READ WORLD_READ)

    endforeach()

    foreach( svg ${PAR_SVG_FILES} )

        # copy to the build 'etc' directory
        set(ModuleSvgFiles ${ModuleSvgFiles} ${CMAKE_CURRENT_SOURCE_DIR}/${svg})
        set(ModuleSvgFiles ${ModuleSvgFiles}  PARENT_SCOPE)

    endforeach()

endmacro()


# ------------------------------------------------------------------------
# MACRO metview_script_files
# Ensures the files listed in SCRIPT_FILES are copied to the build
# directory and that they will be installed at install time.
#
# Searches in the current source directory, EXTRA_CONFIG_PATH if given and
# metview-ecmwf-configs inside and parallel to the metview source root.
# ------------------------------------------------------------------------

macro(metview_script_files)
    set(options )
    set(single_value_args )
    set(multi_value_args SCRIPT_FILES)
    cmake_parse_arguments( PAR "${options}" "${single_value_args}" "${multi_value_args}" ${_FIRST_ARG} ${ARGN} )

    foreach( script ${PAR_SCRIPT_FILES} )

        find_file( SCRIPT_${script} ${script}
                   PATHS ${CMAKE_CURRENT_SOURCE_DIR}
                         ${EXTRA_CONFIG_PATH}
                         ${CMAKE_SOURCE_DIR}/metview-ecmwf-configs
                         ${CMAKE_SOURCE_DIR}/../metview-ecmwf-configs )

        if( NOT SCRIPT_${script} )
          ecbuild_critical( "Could not find script ${script}. Specify the path to the script with -DEXTRA_CONFIG_PATH=...")
        else()
          ecbuild_debug("metview_script_files: found ${script} at ${SCRIPT_${script}}")
        endif()

        # we need this line to ensure that the target/dependency relationship is correct
        configure_file( ${SCRIPT_${script}} ${CMAKE_BINARY_DIR}/bin COPYONLY)


        # copy to the build 'bin' directory, setting exe permissions
        file(COPY ${SCRIPT_${script}}
             DESTINATION ${CMAKE_BINARY_DIR}/bin
             FILE_PERMISSIONS OWNER_WRITE OWNER_READ GROUP_READ OWNER_EXECUTE GROUP_EXECUTE
             )


        # ensure file is installed at install time
        install( FILES ${CMAKE_BINARY_DIR}/bin/${script}
                 DESTINATION ${MV_BIN_DIR}
                 PERMISSIONS OWNER_WRITE OWNER_READ GROUP_READ WORLD_READ OWNER_EXECUTE GROUP_EXECUTE WORLD_EXECUTE)

    endforeach()

endmacro()

# ---------------------------
# traverse the subdirectories
# ---------------------------

# source files
add_subdirectory( src )

if(ENABLE_CONTRIB)
    add_subdirectory( contrib )
endif()

add_subdirectory( scripts )
add_subdirectory( share )
add_subdirectory( test )


if(ENABLE_METVIEW_DOCS)
    add_subdirectory( docs/confluence )
endif()


# install the metview.desktop file
install( FILES ${CMAKE_CURRENT_SOURCE_DIR}/metview.desktop
         DESTINATION share/applications/
         PERMISSIONS OWNER_WRITE OWNER_READ GROUP_READ WORLD_READ )



### not for Metview?? configure_file( metview-config.in  metview-config @ONLY )

#ecbuild_dont_pack(REGEX "~*")
ecbuild_dont_pack(REGEX "src/*.xd")
ecbuild_dont_pack(REGEX "*.mdbg")
ecbuild_dont_pack(REGEX "share/metview/icons/*.svg")
ecbuild_dont_pack(REGEX "configure*.sh")
ecbuild_dont_pack(REGEX "Makefile.am")
ecbuild_dont_pack(REGEX "Makefile.in")
#ecbuild_dont_pack(DIRS  "rpms;metview-ecmwf-configs" )
#ecbuild_dont_pack(REGEX "metview-ecmwf-configs/*")
ecbuild_dont_pack(FILES "rpms;metview-ecmwf-configs;bamboo" )

ecbuild_dont_pack(DIRS  "m4/;src/libMars-Odb;src/libMars-old;src/MvApp/MARS")
ecbuild_dont_pack(DIRS  "src/DataAccess;src/ForwardApp;src/OperaRadar")
ecbuild_dont_pack(DIRS  "share/metview/etc/MSMARS")
#ecbuild_add_resources(TARGET all SOURCES_PACK src/libMars/MARS/mars.h)
#ecbuild_pack(FILES src/libMars/MARS/mars.h)
ecbuild_dont_pack(FILES "README.ECMWF.Obsoletes;" )
ecbuild_dont_pack(FILES "README.developers" )
ecbuild_dont_pack(FILES "license.pl;LICENSE_for_source_files.txt" )
ecbuild_dont_pack(FILES "license_dir.sh;license_log.txt;prepare_new_p4_view" )
ecbuild_dont_pack(FILES "bootstrap;version.sh;ecmwf_setup.sh;configure.ecmwf;src/generateNewModule.sh" )

ecbuild_dont_pack(FILES "share/metview/etc_mv3;share/metview/icons_mv3;src/xd" )
ecbuild_dont_pack(FILES "lib;bin;config" )
ecbuild_dont_pack(FILES "metview.sublime-workspace;metview.sublime-project;autom4te.cache;aux_build;docs" )
ecbuild_dont_pack(FILES "metview-edit.config;metview-edit.creator;metview-edit.creator.user;metview-edit.files;metview-edit.includes" )
ecbuild_dont_pack(FILES "MetviewFixLog" )
ecbuild_dont_pack(FILES "src/Traj" )
ecbuild_dont_pack(FILES "src/Budget" )
ecbuild_dont_pack(FILES "src/TropCycTrack" )
ecbuild_dont_pack(FILES "share/metview/grib_seed" )

#file(GLOB_RECURSE IGNORE_FILES_XD  "${CMAKE_SOURCE_DIR}/src/*.xd")
#file(GLOB IGNORE_FILES_SVG "${CMAKE_SOURCE_DIR}/share/metview/icons/*.svg")
#file(GLOB IGNORE_FILES_CONFIGURE "${CMAKE_SOURCE_DIR}/configure.*")
#file(GLOB IGNORE_FILES_MAKEFILES_AM "${CMAKE_SOURCE_DIR}/*/*/Makefile.am")
#file(GLOB IGNORE_FILES_MAKEFILES_IN "${CMAKE_SOURCE_DIR}/*/*/Makefile.in")
#file(GLOB IGNORE_FILES_LOCAL_ECM    "${CMAKE_SOURCE_DIR}/scripts/metview_local*.ecm_*")

#SET(ECBUILD_DONT_PACK_FILES "${CMAKE_BINARY_DIR}/;${CMAKE_SOURCE_DIR}/m4/;${CMAKE_SOURCE_DIR}/src/libMars-Odb/MARS/")
#list( APPEND ECBUILD_DONT_PACK_FILES "${CMAKE_SOURCE_DIR}/LICENSE_for_source_files.txt;" )
#list( APPEND ECBUILD_DONT_PACK_FILES "${CMAKE_SOURCE_DIR}/README.ECMWF.Obsoletes;" )
#list( APPEND ECBUILD_DONT_PACK_FILES "${CMAKE_SOURCE_DIR}/README.developers" )
#list( APPEND ECBUILD_DONT_PACK_FILES "${CMAKE_SOURCE_DIR}/license.pl;${CMAKE_SOURCE_DIR}/LICENSE_for_source_files.txt" )
#list( APPEND ECBUILD_DONT_PACK_FILES "${CMAKE_SOURCE_DIR}/license_dir.sh;${CMAKE_SOURCE_DIR}/license_log.txt;${CMAKE_SOURCE_DIR}/prepare_new_p4_view" )
#list( APPEND ECBUILD_DONT_PACK_FILES "${CMAKE_SOURCE_DIR}/ecmwf_setup.sh;${IGNORE_FILES_CONFIGURE}" )
#list( APPEND ECBUILD_DONT_PACK_FILES "${IGNORE_FILES_MAKEFILES_AM};${IGNORE_FILES_MAKEFILES_IN};${IGNORE_FILES_LOCAL_ECM}" )
#list( APPEND ECBUILD_DONT_PACK_FILES "${CMAKE_SOURCE_DIR}/scripts/mv_cp" )


#list( APPEND ECBUILD_DONT_PACK_FILES "${CMAKE_SOURCE_DIR}/share/metview/etc_mv3;${CMAKE_SOURCE_DIR}/share/metview/icons_mv3;${CMAKE_SOURCE_DIR}/src/xd" )
#list( APPEND ECBUILD_DONT_PACK_FILES "${CMAKE_SOURCE_DIR}/lib;${CMAKE_SOURCE_DIR}/bin;${CMAKE_SOURCE_DIR}/config" )
#list( APPEND ECBUILD_DONT_PACK_FILES "${CMAKE_SOURCE_DIR}/autom4te.cache;${CMAKE_SOURCE_DIR}/aux_build;${CMAKE_SOURCE_DIR}/docs" )
#list( APPEND ECBUILD_DONT_PACK_FILES "${CMAKE_SOURCE_DIR}/rpms;${CMAKE_SOURCE_DIR}/tools" )
#list( APPEND ECBUILD_DONT_PACK_FILES "${IGNORE_FILES_XD};${IGNORE_FILES_SVG}" )
#list( APPEND ECBUILD_DONT_PACK_FILES "${CMAKE_SOURCE_DIR}/src/Traj" )
#list( APPEND ECBUILD_DONT_PACK_FILES "${CMAKE_SOURCE_DIR}/share/metview/grib_seed" )

#ecbuild_debug("NOPACK: ${ECBUILD_DONT_PACK_FILES}")

#CPACK_SOURCE_IGNORE_FILES

#ecbuild_add_resources(TARGET package_source SOURCES_PACK ${CMAKE_CURRENT_SOURCE_DIR}/../ecbuild/cmake/ecbuild_find_python.cmake)

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


# print all variables
#get_cmake_property(_variableNames VARIABLES)
#foreach (_variableName ${_variableNames})
#    ecbuild_info("${_variableName}=${${_variableName}}")
#endforeach()


ecbuild_install_project( NAME Metview )

ecbuild_print_summary()

 # restore this for the case where we're in a larger bundle that may be
 # rebuilt multiple times within the same build directory
set(INSTALL_BIN_DIR ${ORIGINAL_INSTALL_BIN_DIR})