-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
183 lines (156 loc) · 6.49 KB
/
CMakeLists.txt
File metadata and controls
183 lines (156 loc) · 6.49 KB
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
cmake_minimum_required(VERSION 3.6)
project(f90gio Fortran C)
#set(CMAKE_VERBOSE_MAKEFILE on)
# for message display
if(NOT WIN32)
string(ASCII 27 Esc)
set(MsgStart "${Esc}[32m=================>")
set(MsgEnd "<=================${Esc}[m")
endif()
option(BUILD_NC "build f90gionc" ON)
option(BUILD_H4 "build f90gioh4" OFF)
option(BUILD_H5 "build f90gioh5" ON)
option(BUILD_FAST_IO "build fast io libs" ON)
option(USE_NC_C "use netcdf-c lib in fast IO libs" ON)
option(H5_VERSION_1_8 "H5LIB <=1.8" OFF)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "release")
endif()
set(BUILD_SHARED_LIBS OFF) # build static libraries
set(CMAKE_Fortran_MODULE_DIRECTORY ${PROJECT_BINARY_DIR}/include)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
if (CMAKE_Fortran_COMPILER_ID MATCHES GNU)
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -cpp")
set(CMAKE_Fortran_FLAGS_DEBUG "-fbacktrace -O0 -g -fcheck=bounds")
set(CMAKE_Fortran_FLAGS_RELEASE "-O2 -fbacktrace")
if (CMAKE_Fortran_COMPILER_VERSION VERSION_GREATER_EQUAL 10)
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fallow-argument-mismatch")
endif()
elseif (CMAKE_Fortran_COMPILER_ID MATCHES Intel)
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fpp") # only apply to Fortran code, not C code
set(CMAKE_Fortran_FLAGS_DEBUG "-traceback -check bounds -O0")
set(CMAKE_Fortran_FLAGS_RELEASE "-O2 -fp-model precise -traceback")
else()
message(FATAL_ERROR "unsupported compiler, Add compiling flags in CMakeLists.txt first")
endif()
# check if netcdf vars is set
if (BUILD_NC)
if (DEFINED ENV{NC_INCLUDE} AND DEFINED ENV{NC_LIBS} )
set(HAS_NC TRUE)
set(FPPS_FLAGS ${FPPS_FLAGS} HAS_NC)
set(F90GIO_LIBS ${F90GIO_LIBS} $ENV{NC_LIBS})
set(F90GIO_INCLUDE $ENV{NC_INCLUDE} ${F90GIO_INCLUDE})
message("${MsgStart} will build f90gionc ${MsgEnd}")
message("NC_INCLUDE= $ENV{NC_INCLUDE}")
message("NC_LIBS= $ENV{NC_LIBS}")
if (BUILD_FAST_IO AND USE_NC_C)
if (DEFINED ENV{NC_C_INCLUDE} AND DEFINED ENV{NC_C_LIBS})
set(HAS_NC_C TRUE)
set(FPPS_FLAGS ${FPPS_FLAGS} HAS_NC_C)
set(F90GIO_LIBS ${F90GIO_LIBS} $ENV{NC_C_LIBS})
set(F90GIO_INCLUDE $ENV{NC_C_INCLUDE} ${F90GIO_INCLUDE})
message("${MsgStart} will use netcdf-c library for building m_ncio ${MsgEnd}")
message("NC_C_INCLUDE= $ENV{NC_C_INCLUDE}")
message("NC_C_LIBS= $ENV{NC_C_LIBS}")
else()
set(HAS_NC_C FALSE)
message("${MsgStart} USE_NC_C=ON & BUILD_FAST_IO but NC_C_INCLUDE, NC_C_LIBS not set ${MsgEnd}")
message("will not use netcdf-c library for m_ncio")
endif()
endif()
else()
set(HAS_NC FALSE)
message("${MsgStart} BUILD_NC=ON but NC_INCLUDE, NC_LIBS not set ${MsgEnd}")
message("will not build f90gionc")
endif()
endif()
# check if hdf4 var is set
if (BUILD_H4)
if (DEFINED ENV{H4_INCLUDE} AND DEFINED ENV{H4_LIBS} )
set(HAS_H4 TRUE)
set(FPPS_FLAGS ${FPPS_FLAGS} HAS_H4)
set(F90GIO_LIBS ${F90GIO_LIBS} $ENV{H4_LIBS})
set(F90GIO_INCLUDE $ENV{H4_INCLUDE} ${F90GIO_INCLUDE})
message("${MsgStart} will build f90gioh4 ${MsgEnd}")
message("H4_INCLUDE= $ENV{H4_INCLUDE}")
message("H4_LIBS= $ENV{H4_LIBS}")
else()
set(HAS_H4 FALSE)
message("${MsgStart} BUILD_H4=ON but H4_INCLUDE, H4_LIBS not set ${MsgEnd}")
message("will not build f90gioh4")
endif()
endif()
# check if hdf5 var is set
if (BUILD_H5)
if (DEFINED ENV{H5_INCLUDE} AND DEFINED ENV{H5_LIBS} )
set(HAS_H5 TRUE)
set(FPPS_FLAGS ${FPPS_FLAGS} HAS_H5)
if (H5_VERSION_1_8)
set(FPPS_FLAGS ${FPPS_FLAGS} H5_VERSION_1_8)
message("H5_VERSION_1_8=${H5_VERSION_1_8}, update FPPS_FLAGS=${H5_VERSION_1_8}")
else()
message(WARNING "H5_VERSION_1_8=${H5_VERSION_1_8}, make sure your hdf5 lib has version >=1.10")
endif()
set(F90GIO_LIBS ${F90GIO_LIBS} $ENV{H5_LIBS})
set(F90GIO_INCLUDE $ENV{H5_INCLUDE} ${F90GIO_INCLUDE})
message("${MsgStart} will build f90gioh5 ${MsgEnd}")
message("H5_INCLUDE= $ENV{H5_INCLUDE}")
message("H5_LIBS= $ENV{H5_LIBS}")
else()
set(HAS_H5 FALSE)
message("${MsgStart} BUILD_H5=ON but H5_INCLUDE, H5_LIBS not set ${MsgEnd}")
message("will not build f90gioh5")
endif()
endif()
message("${MsgStart} will build f90gio ${MsgEnd}")
message("F90GIO_INCLUDE=${F90GIO_INCLUDE}")
message("F90GIO_LIBS=${F90GIO_LIBS}")
# F90GIO lib
add_subdirectory(libsrc)
# F90GIO fast I/O lib
add_subdirectory(libsrc/fast/nc)
add_subdirectory(libsrc/fast/h5)
# tests for F90GIO lib
add_subdirectory(test)
# tests for F90GIO fast I/O lib
add_subdirectory(test-fast)
# testing
enable_testing()
macro(cda_add_test TARGET CMD WORK_DIR PASS_RESULT)
add_test(
NAME ${TARGET}
COMMAND ${CMD}
WORKING_DIRECTORY ${WORK_DIR})
set_tests_properties(${TARGET}
PROPERTIES PASS_REGULAR_EXPRESSION ${PASS_RESULT})
endmacro(cda_add_test)
# test netcdf libs
if (HAS_NC)
cda_add_test(test_nc test_nc ${CMAKE_SOURCE_DIR}/test "Test passed")
cda_add_test(test_nc_g test_nc_g ${CMAKE_SOURCE_DIR}/test "Test passed")
cda_add_test(test_nc_write test_nc_write ${CMAKE_SOURCE_DIR}/test "Test passed")
cda_add_test(test_nc_nolib test_nc_nolib ${CMAKE_SOURCE_DIR}/test "Test passed")
endif()
# test h4 libs
if (HAS_H4)
cda_add_test(test_h4 test_h4 ${CMAKE_SOURCE_DIR}/test "Test passed")
cda_add_test(test_h4_g test_h4_g ${CMAKE_SOURCE_DIR}/test "Test passed")
cda_add_test(test_h4_nolib test_h4_nolib ${CMAKE_SOURCE_DIR}/test "Test passed")
endif()
# test h5 libs
if (HAS_H5)
cda_add_test(test_h5 test_h5 ${CMAKE_SOURCE_DIR}/test "Test passed")
cda_add_test(test_h5_g test_h5_g ${CMAKE_SOURCE_DIR}/test "Test passed")
cda_add_test(test_h5_nolib test_h5_nolib ${CMAKE_SOURCE_DIR}/test "Test passed")
endif()
# test nc Fast I/O lib
if (BUILD_FAST_IO AND HAS_NC)
cda_add_test(test_ncio test_ncio ${CMAKE_SOURCE_DIR}/test-fast "Test passed")
cda_add_test(test_ncio_group test_ncio_group ${CMAKE_SOURCE_DIR}/test-fast "Test passed")
endif()
# test hdf5 Fast I/O lib
if (BUILD_FAST_IO AND HAS_H5)
cda_add_test(test_h5io test_h5io ${CMAKE_SOURCE_DIR}/test-fast "Test passed")
endif()