-
Notifications
You must be signed in to change notification settings - Fork 24
/
CMakeLists.txt
137 lines (112 loc) · 5.05 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
127
128
129
130
131
132
133
134
135
136
137
cmake_minimum_required(VERSION 3.10)
include(ExternalProject)
include(FetchContent)
option(WERROR "add the -Werror flag to compiler (works with gnu)" OFF)
option(UNITTESTS "build the pfunit based tests (must have PFUNIT_ROOT)" OFF)
enable_language(Fortran)
set(ENABLE_GENF90 ON)
# if (DEFINED CIMEROOT)
# message("Using CIME in ${CIMEROOT} with compiler ${COMPILER}")
# include(${CASEROOT}/Macros.cmake)
# if (${PIO_VERSION} LESS 2)
# message( FATAL_ERROR "Version 2 of the PIO library required")
# endif()
# if (MPILIB STREQUAL mpi-serial)
# set(CMAKE_Fortran_COMPILER ${SFC})
# set(CMAKE_C_COMPILER ${SCC})
# else()
# set(CMAKE_Fortran_COMPILER ${MPIFC})
# set(CMAKE_C_COMPILER ${MPICC})
# endif()
# set(CMAKE_Fortran_FLAGS "${FFLAGS} ${CPPDEFS} -I${LIBROOT}/include -I${LIBROOT}/nuopc/esmf/${NINST_VALUE}/include")
# add_compile_definitions(CESMCOUPLED)
# list(APPEND CMAKE_MODULE_PATH ${SRC_ROOT}/cime/CIME/non_py/src/CMake)
# else()
# set(BLD_STANDALONE TRUE)
project(SHARE LANGUAGES Fortran C VERSION 0.1)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
include(Sourcelist_utils)
include(Compilers)
include(genf90_utils)
#===== genf90 =====
if (DEFINED GENF90_PATH)
add_custom_target(genf90
DEPENDS ${GENF90_PATH}/genf90.pl)
else ()
ExternalProject_Add (genf90
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/genf90
GIT_REPOSITORY https://github.com/PARALLELIO/genf90
GIT_TAG update_cmake_interface
UPDATE_COMMAND ""
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND "")
ExternalProject_Get_Property (genf90 SOURCE_DIR)
set (GENF90_PATH ${SOURCE_DIR})
unset (SOURCE_DIR)
endif ()
set(GENF90 "${GENF90_PATH}/genf90.pl")
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}")
add_subdirectory(src)
if (DEFINED ENV{PIO_ROOT})
message("PIO_ROOT is $ENV{PIO_ROOT}")
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})
endif()
if (NOT DEFINED MPILIB OR NOT ${MPILIB} STREQUAL "mpi-serial")
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$ENV{PIO_ROOT}/lib -L${ESMF_LIBSDIR}")
if("${COMPILER}" STREQUAL "nag")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -D__NAG__")
endif()
set(GENF90SOURCES src/shr_assert_mod.F90 src/shr_frz_mod.F90 src/shr_infnan_mod.F90)
#===== Fortran Source Generation with GenF90 =====
foreach (SRC_FILE IN LISTS GENF90SOURCES)
list(APPEND SHAREGENF90SRC ${SRC_FILE})
add_custom_command (OUTPUT ${SRC_FILE}
COMMAND ${GENF90_PATH}/genf90.pl
${CMAKE_CURRENT_SOURCE_DIR}/${SRC_FILE}.in > ${SRC_FILE}
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${SRC_FILE}.in genf90)
endforeach ()
file(GLOB FSOURCES "src/*.F90" "src/water_isotopes/*.F90" "RandNum/src/*.F90" "RandNum/src/*/*.F90")
file(GLOB CSOURCES "src/*.c" "RandNum/src/*/*.c")
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/src)
add_library(csm_share STATIC ${CSOURCES} ${FSOURCES} ${SHAREGENF90SRC} )
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()
add_dependencies (csm_share genf90)
target_include_directories(csm_share PRIVATE include RandNum/include ${CMAKE_BINARY_DIR})
if(UNITTESTS)
find_package(PFUNIT REQUIRED)
# 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()