Skip to content

Commit

Permalink
Merge commit Added SetBuildOptions.cmake (PR ESCOMP#2) 'b61d7108a2f36…
Browse files Browse the repository at this point in the history
…5eb050a094d971c0f0a60a1a6e7' into eclm
  • Loading branch information
AGonzalezNicolas committed Jun 27, 2024
2 parents 9eaa4d4 + b61d710 commit c616438
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 37 deletions.
8 changes: 8 additions & 0 deletions build_tools/build.juwels-centos8
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ ARCH="juwels-centos8"
CLM5_TSMP_ROOT=$(git rev-parse --show-toplevel)
BUILD_FOLDER="$CLM5_TSMP_ROOT/outputs/$ARCH/build"
INSTALL_PATH="$CLM5_TSMP_ROOT/outputs/$ARCH/run"
if [ "$1" = "--debug" ] || [ "$1" = "-d" ]; then
BUILD_TYPE="DEBUG"
else
BUILD_TYPE="RELEASE"
fi
# ---------------------------------------------

module purge
Expand All @@ -29,7 +34,10 @@ GENF90_PATH=$(pwd)
rm -rf $BUILD_FOLDER
cmake -S "$CLM5_TSMP_ROOT/src" \
-B "$BUILD_FOLDER" \
-DCMAKE_INSTALL_PREFIX="$INSTALL_PATH" \
-DCMAKE_MODULE_PATH="$(pwd)/cmake" \
-DCMAKE_BUILD_TYPE=$BUILD_TYPE \
-DCOMPILER="Intel" \
-DCMAKE_C_COMPILER=mpicc \
-DCMAKE_Fortran_COMPILER=mpifort \
-DGENF90_PATH=$GENF90_PATH \
Expand Down
10 changes: 9 additions & 1 deletion build_tools/build.ubuntu-20.04LTS
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ ARCH="ubuntu-20.04LTS"
CLM5_TSMP_ROOT=$(git rev-parse --show-toplevel)
BUILD_FOLDER="$CLM5_TSMP_ROOT/outputs/$ARCH/build"
INSTALL_PATH="$CLM5_TSMP_ROOT/outputs/$ARCH/run"
if [ "$1" = "--debug" ] || [ "$1" = "-d" ]; then
BUILD_TYPE="DEBUG"
else
BUILD_TYPE="RELEASE"
fi
# ---------------------------------------------

NetCDF_ROOT=/opt/custom
Expand All @@ -14,10 +19,13 @@ cmake -S "$CLM5_TSMP_ROOT/src" \
-B "$BUILD_FOLDER" \
-DCMAKE_INSTALL_PREFIX="$INSTALL_PATH" \
-DCMAKE_MODULE_PATH="$(pwd)/cmake" \
-DCMAKE_BUILD_TYPE=$BUILD_TYPE \
-DCOMPILER="GNU" \
-DCMAKE_C_COMPILER=mpicc \
-DCMAKE_Fortran_COMPILER=mpifort \
-DGENF90_PATH=$GENF90_PATH \
-DNetCDF_PATH=$NetCDF_ROOT \
-DPnetCDF_PATH=$NetCDF_ROOT
-DPnetCDF_PATH=$NetCDF_ROOT \

cmake --build "$BUILD_FOLDER" --clean-first
cmake --install "$BUILD_FOLDER"
42 changes: 42 additions & 0 deletions build_tools/cmake/SetBuildOptions.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# This module sets the required compile flags and definitions for all targets.

if(UNIX AND NOT APPLE)
add_compile_definitions(LINUX)
endif()

# Set default build = RELEASE if none was specified.
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_BUILD_TYPE "RELEASE" CACHE STRING "Choose the type of build." FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "DEBUG" "RELEASE")
endif()

# Set default compiler = GNU if none was specified.
if(NOT COMPILER)
set(COMPILER "GNU" CACHE STRING "Choose compiler toolchain." FORCE)
set_property(CACHE COMPILER PROPERTY STRINGS "GNU" "Intel")
endif()

if(COMPILER STREQUAL "GNU")
add_compile_definitions(CPRGNU)
set(CMAKE_C_FLAGS "-std=gnu99")
set(CMAKE_C_FLAGS_DEBUG "-fcheck=bounds")
set(CMAKE_C_FLAGS_RELEASE "-O")
set(CMAKE_Fortran_FLAGS "-fconvert=big-endian -ffree-line-length-none -ffixed-line-length-none -ffree-form")
set(CMAKE_Fortran_FLAGS_DEBUG "-g -Wall -Og -fbacktrace -ffpe-trap=zero,overflow -fcheck=bounds")
set(CMAKE_Fortran_FLAGS_RELEASE "-O")
elseif(COMPILER STREQUAL "Intel")
add_compile_definitions(CPRINTEL)
set(CMAKE_C_FLAGS "-qno-opt-dynamic-align -std=gnu99 -fp-model precise")
set(CMAKE_C_FLAGS_DEBUG "-O0 -g")
set(CMAKE_C_FLAGS_RELEASE "-O2 -debug minimal")
set(CMAKE_Fortran_FLAGS "-free -qno-opt-dynamic-align -ftz -traceback -convert big_endian -assume byterecl -assume realloc_lhs -fp-model source")
set(CMAKE_Fortran_FLAGS_DEBUG "-O0 -g -check uninit -check bounds -check pointers -fpe0 -check noarg_temp_created")
set(CMAKE_Fortran_FLAGS_RELEASE "-O2 -debug minimal")
else()
message(FATAL_ERROR "COMPILER='${COMPILER}' is not supported.")
endif()

message(STATUS " ******* ${CMAKE_PROJECT_NAME} build options ******* ")
message(STATUS " Build type = '${CMAKE_BUILD_TYPE}'")
message(STATUS " Compiler = '${COMPILER}'")
message(STATUS " *************************************** ")
28 changes: 2 additions & 26 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,32 +1,8 @@
cmake_minimum_required (VERSION 3.16.3)

project (clm5-tsmp LANGUAGES C Fortran)
project (CLM5-TSMP LANGUAGES C Fortran)

# Set global compile features and definitions
if(UNIX AND NOT APPLE)
add_compile_definitions(LINUX)
endif()

if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
set(cdefs CPRGNU)
set(cflags -O -std=gnu99)
elseif(CMAKE_C_COMPILER_ID STREQUAL "Intel")
set(cdefs CPRINTEL)
set(cflags -qno-opt-dynamic-align -std=gnu99 -O2 "SHELL:-fp-model precise -debug minimal")
endif()

if(CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
set(fdefs CPRGNU)
set(fflags -ffree-form -ffree-line-length-none -fconvert=big-endian -O)
elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "Intel")
set(fdefs CPRINTEL)
set(fflags -free -qno-opt-dynamic-align -ftz -traceback -O2 "SHELL:-convert big_endian -assume byterecl -assume realloc_lhs -fp-model source -debug minimal")
endif()

add_compile_options("$<$<COMPILE_LANGUAGE:Fortran>:${fflags}>")
add_compile_options("$<$<COMPILE_LANGUAGE:C>:${cflags}>")
add_compile_definitions("$<$<COMPILE_LANGUAGE:Fortran>:${fdefs}>")
add_compile_definitions($<$<COMPILE_LANGUAGE:C>:${cdefs}>)
include(SetBuildOptions)

add_subdirectory(externals)
add_subdirectory(csm_share)
Expand Down
26 changes: 16 additions & 10 deletions src/externals/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
cmake_minimum_required (VERSION 3.16.3)
project(externals)
project(externals LANGUAGES C Fortran)
include(ExternalProject)

# ===========
# GPTL
# ===========
set(GPTL_BLD_DIR ${CMAKE_CURRENT_BINARY_DIR}/gptl)
file(MAKE_DIRECTORY ${GPTL_BLD_DIR}/include ${GPTL_BLD_DIR}/lib)

set(GPTL_MACROS_FILE ${GPTL_BLD_DIR}/Macros.make)
file(WRITE ${GPTL_MACROS_FILE} " MPICC := ${CMAKE_C_COMPILER}\n")
file(APPEND ${GPTL_MACROS_FILE} " MPIFC := ${CMAKE_Fortran_COMPILER}\n")
file(APPEND ${GPTL_MACROS_FILE} " CLAGS := ${CMAKE_C_FLAGS}\n")
file(APPEND ${GPTL_MACROS_FILE} " FFLAGS := ${CMAKE_Fortran_FLAGS}\n")
file(APPEND ${GPTL_MACROS_FILE} "CPPDEFS := -DFORTRANUNDERSCORE\n")

ExternalProject_Add(gptl_external
PREFIX gptl
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/gptl
BUILD_IN_SOURCE FALSE
CONFIGURE_COMMAND echo "CPPDEFS := $(CPPDEFS) -DFORTRANUNDERSCORE" > ${GPTL_BLD_DIR}/Macros.make
CONFIGURE_COMMAND ""
BUILD_COMMAND make install -f ${CMAKE_CURRENT_SOURCE_DIR}/gptl/Makefile
MACFILE=${GPTL_BLD_DIR}/Macros.make
MPICC=${CMAKE_C_COMPILER}
MPIFC=${CMAKE_Fortran_COMPILER}
GPTL_DIR=${CMAKE_CURRENT_SOURCE_DIR}/gptl
SHAREDPATH=${GPTL_BLD_DIR}
INSTALL_COMMAND ""
Expand All @@ -28,8 +34,7 @@ target_include_directories(gptl INTERFACE ${GPTL_BLD_DIR}/include)
target_link_directories(gptl INTERFACE ${GPTL_BLD_DIR}/lib)
target_link_libraries(gptl INTERFACE libgptl.a)
add_dependencies(gptl gptl_external)
install (FILES ${GPTL_BLD_DIR}/lib/libgptl.a
TYPE LIB)
install (FILES ${GPTL_BLD_DIR}/lib/libgptl.a TYPE LIB)

# ===========
# MCT
Expand All @@ -44,7 +49,9 @@ ExternalProject_Add(mct_external
--prefix=${MCT_BLD_DIR}
--exec-prefix=${MCT_BLD_DIR}
CC=${CMAKE_C_COMPILER}
FC=${CMAKE_Fortran_COMPILER}
FC=${CMAKE_Fortran_COMPILER}
CFLAGS=${CMAKE_C_FLAGS}
FCFLAGS=${CMAKE_Fortran_FLAGS}
BUILD_ALWAYS YES
BUILD_BYPRODUCTS ${GPTL_BLD_DIR}/lib/libmct.a ${GPTL_BLD_DIR}/lib/libmpeu.a
)
Expand All @@ -53,10 +60,9 @@ target_include_directories(mct INTERFACE ${MCT_BLD_DIR}/include)
target_link_directories(mct INTERFACE ${MCT_BLD_DIR}/lib)
target_link_libraries(mct INTERFACE libmct.a libmpeu.a)
add_dependencies(mct mct_external)
install (FILES ${MCT_BLD_DIR}/lib/libmct.a ${MCT_BLD_DIR}/lib/libmpeu.a
TYPE LIB)
install (FILES ${MCT_BLD_DIR}/lib/libmct.a ${MCT_BLD_DIR}/lib/libmpeu.a TYPE LIB)

# ===========
# PIO
# ===========
add_subdirectory(pio1)
add_subdirectory(pio1)

0 comments on commit c616438

Please sign in to comment.