This repository has been archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathCMakeLists.txt
122 lines (98 loc) · 4.02 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
# Copyright 2016-2019 Travis Sluka
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#-------------------------------------------------------------------------------
cmake_minimum_required(VERSION 3.2 FATAL_ERROR)
project(letkf Fortran C CXX)
# set the default build type to Release
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING
"Build type, options are: Debug Release RelWithDebInfo" FORCE)
endif()
#------------------------------------------------------------
# determine the repository version
#------------------------------------------------------------
execute_process(COMMAND git describe --dirty --tags --always
OUTPUT_VARIABLE GIT_VERSION
RESULT_VARIABLE RES
OUTPUT_STRIP_TRAILING_WHITESPACE
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
if(NOT ${RES} EQUAL "0")
set(GIT_VERSION "Unknown")
endif()
add_definitions(-DCVERSION=\"${GIT_VERSION}\")
message(STATUS "Git repository version: ${GIT_VERSION}")
#------------------------------------------------------------
# Testing and code coverage
#------------------------------------------------------------
option( LETKF_ENABLE_CODECOVERAGE "enable code coverage testing support")
if(LETKF_ENABLE_CODECOVERAGE)
# TODO, this is only valid for GCC
add_definitions( -fprofile-arcs -ftest-coverage )
set( CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS} --coverage )
endif()
option( LETKF_ENABLE_TESTS "enable testing suite, including downloading of test data")
if(LETKF_ENABLE_TESTS)
enable_testing()
endif()
#------------------------------------------------------------
# dependencies
#------------------------------------------------------------
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
# MPI
find_package(MPI REQUIRED)
# NetCDF
set(NETCDF_F90 "YES")
find_package(NetCDF REQUIRED)
# LAPACK / BLAS
find_package(LAPACK REQUIRED)
# grib2
option( LETKF_ENABLE_GRIB "enable grib2 support for state I/O" OFF)
option( LETKF_BUILD_GRIB "If the wgrib2 api is not found, it is downloaded and built" OFF)
IF(LETKF_ENABLE_GRIB)
# need OpenMP
find_package(OpenMP REQUIRED)
IF(LETKF_BUILD_GRIB)
# If we are going to build grib2 api ourselves in cmake
set(GRIB2_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR}/dep/wgrib2-prefix/src/wgrib2/lib)
set(GRIB2_INC_DIR ${GRIB2_BUILD_DIR})
set(GRIB2_LIBRARY ${GRIB2_BUILD_DIR}/libwgrib2.a)
set(GRIB2_API_LIBRARY ${GRIB2_BUILD_DIR}/libwgrib2_api.a)
ELSE()
# otherwise find the library
find_path(GRIB2_INC_DIR wgrib2api.mod)
find_library(GRIB2_API_LIBRARY libwgrib2_api.a)
find_library(GRIB2_LIBRARY libwgrib2.a)
IF(NOT GRIB2_INC_DIR OR NOT GRIB2_API_LIBRARY OR NOT GRIB2_LIBRARY)
MESSAGE(FATAL_ERROR "cannot find wgrib2 API")
ENDIF()
ENDIF()
mark_as_advanced(GRIB2_API_LIBRARY GRIB2_LIBRARY GRIB2_INC_DIR)
set(GRIB2_LIBRARIES ${GRIB2_API_LIBRARY} ${GRIB2_LIBRARY})
ENDIF()
#------------------------------------------------------------
# Set output directories
#------------------------------------------------------------
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/mod)
#------------------------------------------------------------
# subdirectories
#------------------------------------------------------------
# included source of external dependencies
add_subdirectory(dep)
# main source code for library and default driver
add_subdirectory(src)
# tests
if(LETKF_ENABLE_TESTS)
add_subdirectory(test)
endif()