forked from NOAA-EMC/NCEPLIBS-bufr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
126 lines (106 loc) · 4.23 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
# This is the main CMake file for NCEPLIBS-bufr.
#
# Mark Potts, Kyle Gerheiser, Rahul Mahajan, Ed Hartnett, Jeff Ator
cmake_minimum_required(VERSION 3.15)
file(STRINGS "VERSION" pVersion)
project(
bufr
VERSION ${pVersion}
LANGUAGES C Fortran)
# Handle user options.
option(ENABLE_DOCS "Enable generation of doxygen-based documentation." OFF)
option(ENABLE_PYTHON "Enable building python module 'ncepbufr'" OFF)
option(BUILD_SHARED_LIBS "Enable building shared libraries" OFF)
option(BUILD_TESTS "Build tests" ON)
set(MASTER_TABLE_DIR "${CMAKE_INSTALL_PREFIX}/tables" CACHE STRING "Installation location of Master BUFR Tables")
string(LENGTH "${MASTER_TABLE_DIR}" _lenmtd)
set(_lenslmax 120) # max number of chars of ${MASTER_TABLE_DIR} to store on a single line of a Fortran90 or C source code file
if(${_lenmtd} LESS_EQUAL ${_lenslmax})
set(MASTER_TABLE_DIR_F "${MASTER_TABLE_DIR}")
set(MASTER_TABLE_DIR_C "${MASTER_TABLE_DIR}")
else() # generate source code lines in chunks of ${_lenslmax} chars each
set(_mtd_f "")
set(_mtd_c "")
set(_len2go ${_lenmtd})
set(_start 0)
while(${_len2go} GREATER ${_lenslmax})
string(SUBSTRING "${MASTER_TABLE_DIR}" ${_start} ${_lenslmax} _chunk)
string(APPEND _mtd_f "${_chunk}" "' // &\n'")
string(APPEND _mtd_c "${_chunk}" "\" \n\t\t\"")
math(EXPR _len2go "${_len2go} - ${_lenslmax}")
math(EXPR _start "${_start} + ${_lenslmax}")
endwhile()
string(SUBSTRING "${MASTER_TABLE_DIR}" ${_start} -1 _chunk)
string(APPEND _mtd_f "${_chunk}")
string(APPEND _mtd_c "${_chunk}")
set(MASTER_TABLE_DIR_F "${_mtd_f}")
set(MASTER_TABLE_DIR_C "${_mtd_c}")
endif()
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()
include(GNUInstallDirs)
enable_testing()
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
if(ENABLE_PYTHON)
if(APPLE)
set(Python3_FIND_FRAMEWORK "LAST")
endif()
find_package(Python3 REQUIRED COMPONENTS Interpreter)
endif()
if(APPLE AND NOT "${CMAKE_RANLIB}" MATCHES "^.*(llvm-ranlib)$")
# The linker on macOS does not include `common symbols` by default
# Passing the -c flag includes them and fixes an error with undefined symbols
set(CMAKE_Fortran_ARCHIVE_FINISH "<CMAKE_RANLIB> -c <TARGET>")
set(CMAKE_C_ARCHIVE_FINISH "<CMAKE_RANLIB> -c <TARGET>")
endif()
# Determine the kinds upfront (both src/ and test/ need them).
list(APPEND kinds "4" "8" "d")
# Set common to the package compiler flags
if(CMAKE_C_COMPILER_ID MATCHES "^(Intel)$")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -traceback")
set(CMAKE_C_FLAGS_DEBUG "-O0")
set(CMAKE_C_FLAGS_RELEASE "-O3")
elseif(CMAKE_C_COMPILER_ID MATCHES "^(GNU)$")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g")
set(CMAKE_C_FLAGS_DEBUG "-ggdb -Wall -O0")
set(CMAKE_C_FLAGS_RELEASE "-O3")
endif()
if(CMAKE_Fortran_COMPILER_ID MATCHES "^(Intel)$")
set(fortran_8_flags "-r8 -i8")
set(fortran_d_flags "-r8")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -g -traceback")
set(CMAKE_Fortran_FLAGS_DEBUG "-O0")
set(CMAKE_Fortran_FLAGS_RELEASE "-O3")
elseif(CMAKE_Fortran_COMPILER_ID MATCHES "^(GNU)$")
set(fortran_8_flags "-fdefault-real-8 -fdefault-integer-8")
set(fortran_d_flags "-fdefault-real-8")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -g -fbacktrace")
set(CMAKE_Fortran_FLAGS_DEBUG "-ggdb -Wall -O0")
set(CMAKE_Fortran_FLAGS_RELEASE "-O3")
endif()
set(underscore_def "UNDERSCORE")
set(c_8_defs "F77_INTSIZE_8")
# For gfortran-10+ backward compatibility
if(${CMAKE_Fortran_COMPILER_ID} MATCHES "^(GNU)$" AND ${CMAKE_Fortran_COMPILER_VERSION} VERSION_GREATER_EQUAL 10)
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -w -fallow-argument-mismatch -fallow-invalid-boz")
endif()
add_subdirectory(src)
add_subdirectory(utils)
if(ENABLE_PYTHON)
add_subdirectory(python)
endif()
add_subdirectory(tables)
if(BUILD_TESTS)
add_subdirectory(test)
endif()
# Generate doxygen documentation if desired.
if(ENABLE_DOCS)
find_package(Doxygen REQUIRED)
add_subdirectory(docs)
endif()