-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
101 lines (81 loc) · 4.48 KB
/
Copy pathCMakeLists.txt
File metadata and controls
101 lines (81 loc) · 4.48 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
# Copyright ACCESS-NRI and contributors. See the top-level COPYRIGHT file for details.
# SPDX-License-Identifier: Apache-2.0
# This CMakeLists file has an option to control what to build:
# ACCESS3_LIB_INSTALL:
# If ON, then build libraries for the shared components (CMEPS/CDEPS/Share)
# If OFF, then build ACCESS-OM3 using CMEPS code and linked to model components (built elsewhere).
# Build components are set through the KnownConfigurations CMAKE variable
# This can be extended to included CM3 by linking against the UM libraries built with nuopc/cmeps driver.
cmake_minimum_required(VERSION 3.18)
# CMake version compatibility
#[==============================================================================[
# Basic project definition #
#]==============================================================================]
project(Access3Share
HOMEPAGE_URL https://github.com/access-nri/access3-share
DESCRIPTION "Dependencies for global climate models"
LANGUAGES C Fortran)
#[==============================================================================[
# Options #
#]==============================================================================]
# Build options
option(ACCESS3_LIB_INSTALL "Install ACCESS3 libraries" OFF)
message(STATUS "Build options")
message(STATUS " - ACCESS3_LIB_INSTALL ${ACCESS3_LIB_INSTALL}")
#[==============================================================================[
# Project configuration #
#]==============================================================================]
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
include(GNUInstallDirs)
# Include some custom cmake modules
include(FortranLib)
include(AddPatchedSource)
# Common compiler flags and definitions
if(CMAKE_Fortran_COMPILER_ID MATCHES "GNU")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fbacktrace -fconvert=big-endian -ffree-line-length-none -ffixed-line-length-none -g -grecord-gcc-switches")
if(${CMAKE_Fortran_COMPILER_VERSION} VERSION_GREATER_EQUAL 10)
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fallow-argument-mismatch")
endif()
set(CMAKE_Fortran_FLAGS_RELEASE "-O")
set(CMAKE_Fortran_FLAGS_DEBUG "-g -Wall -Og -ffpe-trap=zero,overflow -fcheck=bounds")
elseif(CMAKE_Fortran_COMPILER_ID MATCHES "Intel")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -qno-opt-dynamic-align -convert big_endian -assume byterecl -ftz -traceback -assume realloc_lhs -fp-model precise -g -grecord-gcc-switches")
set(CMAKE_Fortran_FLAGS_RELEASE "-O2")
set(CMAKE_Fortran_FLAGS_DEBUG "-O0 -check all") #-fpe0 - see https://github.com/ACCESS-NRI/MOM6/issues/39
else()
message(WARNING "Fortran compiler with ID ${CMAKE_Fortran_COMPILER_ID} will be used with CMake default options")
endif()
if(CMAKE_C_COMPILER_ID MATCHES "GNU")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -g -grecord-gcc-switches")
set(CMAKE_C_FLAGS_RELEASE "-O")
set(CMAKE_C_FLAGS_DEBUG "-Wall -Og -fbacktrace -ffpe-trap=invalid,zero,overflow -fcheck=bounds")
elseif(CMAKE_C_COMPILER_ID MATCHES "Intel")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -traceback -qno-opt-dynamic-align -fp-model precise -std=gnu99 -g -grecord-gcc-switches")
set(CMAKE_C_FLAGS_RELEASE "-O2")
set(CMAKE_C_FLAGS_DEBUG "-O0")
else()
message(WARNING "C compiler with ID ${CMAKE_C_COMPILER_ID} will be used with CMake default options")
endif()
add_compile_definitions(
CESMCOUPLED
)
## Fortran modules path; currently this is simply set to be the include dir
set(CMAKE_INSTALL_MODULEDIR ${CMAKE_INSTALL_INCLUDEDIR}
CACHE STRING
"Fortran module installation path (Not a cmake native variable)"
)
#[==============================================================================[
# External packages #
#]==============================================================================]
# Find dependencies
find_package(MPI REQUIRED COMPONENTS Fortran)
find_package(ESMF 8.3.0 MODULE REQUIRED)
#[==============================================================================[
# Build and Install #
#]==============================================================================]
## Use seperate files for building libraries vs final exectuable
if(ACCESS3_LIB_INSTALL)
include(Access3LibInstall)
else()
include(Access3BinInstall)
endif()