forked from NOAA-EMC/NCEPLIBS-g2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
141 lines (122 loc) · 4.45 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
# This is the main CMake file for NCEPLIBS-g2.
#
# Mark Potts, Kyle Gerheiser, Ed Hartnett
cmake_minimum_required(VERSION 3.15)
# Read the current version number from file VERSION.
file(STRINGS "VERSION" pVersion)
project(g2 VERSION ${pVersion} LANGUAGES C Fortran)
set(lib_name ${PROJECT_NAME})
include(GNUInstallDirs)
# Handle user build options.
option(OPENMP "Use OpenMP threading" OFF)
option(ENABLE_DOCS "Enable generation of doxygen-based documentation." OFF)
option(BUILD_SHARED_LIBS "Build shared libraries" OFF)
option(FTP_TEST_FILES "Fetch and test with files on FTP site." OFF)
option(FTP_LARGE_TEST_FILES "Fetch and test with very large files on FTP site." OFF)
option(FTP_EXTRA_TEST_FILES "Fetch even more large files from FTP and test them." OFF)
option(LOGGING "Turn on internal logging messages. Only useful to g2 developers." OFF)
option(BUILD_4 "Build libg2_4.a" ON)
option(BUILD_D "Build libg2_d.a" ON)
option(BUILD_WITH_W3EMC "Build with NCEPLIBS-w3emc, enabling some GRIB1 functionality" ON)
option(BUILD_UTILS "Build grib utilities" ON)
option(USE_AEC "Build with AEC (CCSDS) compression support" OFF)
option(G2C_COMPARE "Enable copygb2 tests using g2c_compare" OFF)
# Developers can use this option to specify a local directory which
# holds the test files. They will be copied instead of fetching the
# files via FTP.
SET(TEST_FILE_DIR "." CACHE STRING "Check this directory for test files before using FTP.")
message(STATUS "Finding test data files in directory ${TEST_FILE_DIR}.")
# Set pre-processor symbol if logging is desired.
if(LOGGING)
add_definitions(-DLOGGING)
endif()
# Handle build type.
if(NOT CMAKE_BUILD_TYPE MATCHES "^(Debug|Release|RelWithDebInfo|MinSizeRel)$")
message(STATUS "Setting build type to 'Release' as none was specified.")
set(CMAKE_BUILD_TYPE
"Release"
CACHE STRING "Choose the type of build." FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release"
"MinSizeRel" "RelWithDebInfo")
endif()
# Set flags.
if(CMAKE_C_COMPILER_ID MATCHES "^(Intel|IntelLLVM)$")
set(CMAKE_C_FLAGS "-g ${CMAKE_C_FLAGS}")
set(CMAKE_C_FLAGS_RELEASE "-O3")
set(CMAKE_Fortran_FLAGS "-g -assume noold_ldout_format ${CMAKE_Fortran_FLAGS}")
set(fortran_d_flags "-r8")
elseif(CMAKE_C_COMPILER_ID MATCHES "^(GNU|Clang|AppleClang)$")
set(CMAKE_C_FLAGS "-g ${CMAKE_C_FLAGS}")
set(CMAKE_C_FLAGS_DEBUG "-ggdb -Wall")
set(CMAKE_Fortran_FLAGS "-g -funroll-loops ${CMAKE_Fortran_FLAGS}")
set(CMAKE_Fortran_FLAGS_DEBUG "-ggdb -Wall")
set(fortran_d_flags "-fdefault-real-8")
endif()
if(${CMAKE_Fortran_COMPILER_ID} MATCHES "^(GNU)$" AND ${CMAKE_Fortran_COMPILER_VERSION} VERSION_GREATER_EQUAL 10)
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fallow-argument-mismatch")
endif()
# Find openMP if we need it.
if(OPENMP)
find_package(OpenMP REQUIRED COMPONENTS Fortran)
endif()
# There was a bug in jasper for the intel compiler that was fixed in
# 2.0.25.
find_package(Jasper 2.0.25 REQUIRED)
find_package(g2c REQUIRED)
find_package(PNG REQUIRED)
find_package(bacio REQUIRED)
if(bacio_VERSION LESS 2.5.0)
add_library(bacio::bacio ALIAS bacio::bacio_4)
endif()
# NCEPLIBS-w3emc may be required.
if (BUILD_WITH_W3EMC)
if (BUILD_UTILS)
find_package(w3emc 2.10.0 REQUIRED)
else()
find_package(w3emc 2.9.0 REQUIRED)
endif()
endif()
# We need g2c if G2C_COMPARE is chosen.
if (G2C_COMPARE)
find_package(g2c 1.7.0 REQUIRED)
endif()
# Figure whether user wants a _4, a _d, or both libraries.
if(BUILD_4 AND BUILD_D)
set(kinds "4" "d")
elseif(BUILD_4 AND NOT BUILD_D)
set(kinds "4")
elseif(BUILD_D AND NOT BUILD_4)
set(kinds "d")
else()
message(FATAL_ERROR "At least one of BUILD_4 or BUILD_D must be turned on")
endif()
# Build the code in the source directory.
add_subdirectory(src)
if (BUILD_UTILS)
if (BUILD_WITH_W3EMC)
# Check for dependencies
find_package(ZLIB REQUIRED)
find_package(ip 3.3.3 REQUIRED)
if(ip_VERSION LESS 5.0)
find_package(sp 2.3.3 REQUIRED)
endif()
add_subdirectory(utils)
endif()
endif()
# This will cause the memcheck to fail if memory problems are found.
set(MEMORYCHECK_COMMAND_OPTIONS "--leak-check=full --error-exitcode=1 --errors-for-leak-kinds=all")
# Turn on unit testing.
include(CTest)
if(BUILD_TESTING)
add_subdirectory(tests)
if (BUILD_UTILS)
if (BUILD_WITH_W3EMC)
add_subdirectory(test_utils)
endif()
endif()
endif()
# Determine whether or not to generate documentation.
if(ENABLE_DOCS)
find_package(Doxygen REQUIRED)
endif()
add_subdirectory(docs)