-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
115 lines (95 loc) · 4.66 KB
/
CMakeLists.txt
File metadata and controls
115 lines (95 loc) · 4.66 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
cmake_minimum_required(VERSION 3.10)
set(CIME_CMAKE_MODULE_DIRECTORY "" CACHE PATH "Path to CIME's CMake modules")
if (NOT DEFINED CIME_CMAKE_MODULE_DIRECTORY OR CIME_CMAKE_MODULE_DIRECTORY STREQUAL "")
message(FATAL_ERROR "You must set CIME_CMAKE_MODULE_DIRECTORY when invoking cmake, e.g. -DCIME_CMAKE_MODULE_DIRECTORY=/path/to/cime/CIME/non_py/src/CMake")
endif()
option(USE_CIME_MACROS "include a CIME-generated Macros.cmake file from CMAKE_BINARY_DIR" OFF)
option(UNITTESTS "build the pfunit based tests (must have PFUNIT_ROOT)" OFF)
option(WERROR "add the -Werror flag to compiler (works with gnu)" OFF)
if (USE_CIME_MACROS)
set(CIME_SKIP_MACROS OFF)
else()
set(CIME_SKIP_MACROS ON)
endif()
if (UNITTESTS)
set(CIME_SKIP_UNITTESTS OFF)
else()
set(CIME_SKIP_UNITTESTS ON)
endif()
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
list(APPEND CMAKE_MODULE_PATH ${CIME_CMAKE_MODULE_DIRECTORY})
include(CIME_initial_setup)
project(SHARE LANGUAGES Fortran C VERSION 0.1)
# CIME_utils defines an ENABLE_GENF90 option, which is OFF by default. However, we need
# GENF90 in order to generate some of the files from *.in files in this library, so here
# we set the default to ON.
set(ENABLE_GENF90 ON CACHE BOOL "Use genf90.pl to regenerate out-of-date Fortran files from .in files.")
include(CIME_utils)
string (TOUPPER "${CMAKE_Fortran_COMPILER_ID}" CMAKE_Fortran_COMPILER_NAME)
if (CMAKE_Fortran_COMPILER_NAME STREQUAL "XL")
set (CMAKE_Fortran_COMPILER_NAME "IBM")
endif ()
if (CMAKE_Fortran_COMPILER_NAME STREQUAL "INTELLLVM")
set (CMAKE_Fortran_COMPILER_NAME "INTEL")
endif ()
set (CMAKE_Fortran_COMPILER_DIRECTIVE "-DCPR${CMAKE_Fortran_COMPILER_NAME}"
CACHE STRING "Fortran compiler name preprocessor directive")
message("CMAKE_Fortran_COMPILER_DIRECTIVE is ${CMAKE_Fortran_COMPILER_DIRECTIVE}")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${CMAKE_Fortran_COMPILER_DIRECTIVE} -I${CMAKE_SOURCE_DIR}/include -I${CMAKE_BINARY_DIR}")
if (DEFINED ENV{PIO_ROOT})
message("PIO_ROOT is $ENV{PIO_ROOT}")
link_directories("$ENV{PIO_ROOT}/lib")
else()
if (DEFINED PIO)
set(PIO_PATH ${PIO})
else()
set(PIO_PATH $ENV{PIO})
endif()
find_package(PIO REQUIRED COMPONENT C Fortran PATH ${PIO_PATH})
link_directories(${PIO_LIBDIR})
endif()
if (DEFINED MPILIB)
if (${MPILIB} STREQUAL "mpi-serial")
find_package(MPISERIAL COMPONENTS C Fortran REQUIRED)
# We need this for the sake of includes of mpif.h
include_directories(${MPISERIAL_Fortran_INCLUDE_DIR})
else()
find_package(MPI REQUIRED)
endif()
else()
find_package(MPI REQUIRED)
endif()
if (DEFINED ENV{ESMF_ROOT})
list(APPEND CMAKE_MODULE_PATH $ENV{ESMF_ROOT}/cmake)
endif()
find_package(ESMF REQUIRED)
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${ESMF_F90COMPILEPATHS} ")
link_libraries("-L${ESMF_LIBSDIR}")
if("${COMPILER}" STREQUAL "nag")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -D__NAG__")
endif()
if(WERROR)
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -Werror --warn-no-unused-dummy-argument --warn-no-missing-include-dirs -ffree-line-length-none")
set_source_files_properties(src/shr_mpi_mod.F90 src/shr_reprosum_mod.F90 PROPERTIES COMPILE_OPTIONS "-Wno-error;-fallow-argument-mismatch")
# This flag seems to be needed for temp variables generated by the compiler version in jammy
set_source_files_properties(src/shr_assert_mod.F90 PROPERTIES COMPILE_OPTIONS "-Wno-error=maybe-uninitialized")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -Wno-error=cpp")
set_source_files_properties(src/shr_cal_mod.F90 PROPERTIES COMPILE_OPTIONS "-Wno-error=conversion")
endif()
# Among other things, this handles the genf90 generation
add_subdirectory(src)
file(GLOB FSOURCES "src/*.F90" "src/water_isotopes/*.F90" "RandNum/src/*.F90" "RandNum/src/*/*.F90")
file(GLOB CSOURCES "src/*.c" "RandNum/src/*/*.c")
add_library(csm_share STATIC ${CSOURCES} ${FSOURCES} ${share_genf90_sources} )
declare_generated_dependencies(csm_share "${share_genf90_sources}")
# Add these include directories to all targets, including unit tests:
include_directories(include RandNum/include)
# But just add this to csm_share (adding this to all targets causes a failure in the
# shr_cal tests for some reason, and is probably unnecessary):
target_include_directories(csm_share PRIVATE ${CMAKE_BINARY_DIR})
if(UNITTESTS)
# need to turn the warning check off for pfunit
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -Wno-error ${CMAKE_Fortran_COMPILER_DIRECTIVE} -I${CMAKE_BINARY_DIR}/unittests/shr_assert_test/mod/assert/ ")
add_subdirectory(${CMAKE_SOURCE_DIR}/unit_test_stubs/util csm_share_stubs)
add_subdirectory(${CMAKE_SOURCE_DIR}/test/unit ${CMAKE_BINARY_DIR}/unittests)
endif()