Skip to content
Snippets Groups Projects
CMakeLists.txt 4.71 KiB
Newer Older
Debolskiy Andrey's avatar
Debolskiy Andrey committed
cmake_minimum_required(VERSION 3.23)
option(BUILD_DOC    "Build documentation"    OFF)
option(USE_NETCDF "Enable netcdf library for tests output" OFF)
Debolskiy Andrey's avatar
Debolskiy Andrey committed
option(WITH_RRTMG "with(out) RRTMG radiation transfer" OFF)
option(WITH_TESTS "Generate and compile test cases" OFF)
Debolskiy Andrey's avatar
Debolskiy Andrey committed

#project cmake includes
include(FetchContent)
# Project main definitions
Debolskiy Andrey's avatar
Debolskiy Andrey committed
project(scm_abl)
enable_language(Fortran)
enable_language(C)
Debolskiy Andrey's avatar
Debolskiy Andrey committed
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/modules)
Debolskiy Andrey's avatar
Debolskiy Andrey committed

if(BUILD_DOC)
    find_package(Doxygen)
    if (DOXYGEN_FOUND)
        set(DOXYGEN_IN ${CMAKE_CURRENT_SOURCE_DIR}/doxygen/config)    # doxygen config file

        # option ALL allows to build the docs together with the code
        add_custom_target( pbl_doc ALL
                COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_IN}
                WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) # WORKING_DIRECTORY: Execute the command with the given current working directory. If it is a relative path it will be interpreted relative to the build tree directory corresponding to the current source directory.
    else()
        message("Doxygen need to be installed to generate the doxygen documentation")
    endif (DOXYGEN_FOUND)
endif(BUILD_DOC)


set(lib_files
    src/parkinds.f90
    src/pbl_grid.f90
    src/phys_fluid.f90
    src/state_utils.f90
    src/scm_state_data.f90
    src/pbl_turb_data.f90
        src/pbl_solver.f90
    src/diag_pbl.f90)

add_library(abl_lib ${lib_files})


target_compile_options(abl_lib
        PUBLIC $<$<COMPILE_LANGUAGE:Fortran>: -cpp>)
if ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
    if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
        target_compile_options(abl_lib
                PUBLIC $<$<COMPILE_LANGUAGE:Fortran>: -g -traceback -check all -ftrapuv -debug all >)
    elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
        target_compile_options(abl_lib
                PUBLIC $<$<COMPILE_LANGUAGE:Fortran>: -g -O0 -fbacktrace -ffpe-trap=zero,overflow,underflow >)
    endif()
endif()

if ("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
    if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
        target_compile_options(abl_lib
                PUBLIC $<$<COMPILE_LANGUAGE:Fortran>: -g -traceback -check all -ftrapuv -debug all >)
    elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
        target_compile_options(abl_lib
                PUBLIC $<$<COMPILE_LANGUAGE:Fortran>: -g -fbacktrace -ffpe-trap=zero,overflow,underflow >)
    endif()
endif()

if (WITH_TESTS)
    # RRTMG option
    if (WITH_RRTMG)
        add_definitions(-DUSE_RRTMG)
        add_subdirectory(radiation)
    endif()
    # adding sfx and config-parser stuff
    #fetch sfx model
    FetchContent_Declare(
            inmcm60_sfx
            GIT_REPOSITORY http://tesla.parallel.ru/inmcm-mirror/sfx.git
            GIT_TAG        origin/main)
    FetchContent_MakeAvailable(inmcm60_sfx)
    FetchContent_GetProperties(inmcm60_sfx)

    if(NOT inmcm60_sfx_POPULATED)
        FetchContent_Populate(sfx_lib)
        add_subdirectory(${inmcm60_sfx_SOURCE_DIR} ${inmcm60_sfx_BINARY_DIR}  EXCLUDE_FROM_ALL)
    endif()

    #Config parser from sfx_lib is needed
    if (WITH_RRTMG)
        list(APPEND test_files  src/rrtm_interface.f90)
    endif()
    #gabls1 experiment
    add_executable(gabls1 src/tests/gabls1.f90 src/config-utils.f90 src/scm_io_default.f90 src/scm_sfx_data.f90)
    target_include_directories(gabls1 PUBLIC ${CMAKE_BINARY_DIR}/modules/)
    target_link_libraries( gabls1 PRIVATE abl_lib )
    target_link_libraries(gabls1 PRIVATE sfx_lib)
    target_link_libraries(gabls1 PRIVATE config_parser_F config_parser_CXX)
    if(WITH_RRTMG)
        target_link_libraries(gabls1 PRIVATE rrtm)
    endif()
    target_compile_options(gabls1
            PRIVATE $<$<COMPILE_LANGUAGE:Fortran>: -cpp>)
    if ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
        if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
            target_compile_options(gabls1
                    PUBLIC $<$<COMPILE_LANGUAGE:Fortran>: -g -traceback -check all -ftrapuv -debug all >)
        elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
            target_compile_options(gabls1
                    PUBLIC $<$<COMPILE_LANGUAGE:Fortran>: -g -O0 -fbacktrace -ffpe-trap=zero,overflow,underflow >)
        endif()
    endif()

    if ("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
        if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
            target_compile_options(gabls1
                    PUBLIC $<$<COMPILE_LANGUAGE:Fortran>: -g -traceback -check all -ftrapuv -debug all >)
        elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
            target_compile_options(gabls1
                    PUBLIC $<$<COMPILE_LANGUAGE:Fortran>: -g -fbacktrace -ffpe-trap=zero,overflow,underflow >)
        endif()
    endif()
endif()