Newer
Older
cmake_minimum_required(VERSION 3.19)
option(USE_CONFIG_PARSER "Build config parser" ON)
include(FetchContent)
if(USE_JIKAN_TIMER)
FetchContent_Declare(
jikan_timer
GIT_REPOSITORY http://tesla.parallel.ru/Lizzzka007/Timer.git
GIT_TAG v1.0
)
FetchContent_MakeAvailable(jikan_timer)
FetchContent_GetProperties(jikan_timer)
endif(USE_JIKAN_TIMER)
find_package(Doxygen)
if (DOXYGEN_FOUND)
set(DOXYGEN_IN ../doxygen/config) # doxygen config file
# option ALL allows to build the docs together with the code
add_custom_target( doc_doxygen ALL
COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_IN}
else()
message("Doxygen need to be installed to generate the doxygen documentation")
endif (DOXYGEN_FOUND)
endif(SFX_CHECK_NAN)
if(USE_JIKAN_TIMER)
add_definitions(-DUSE_JIKAN_TIMER)
endif(USE_JIKAN_TIMER)
set(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/modules)
if(USE_CONFIG_PARSER)
add_subdirectory(config-parser/)
endif(USE_CONFIG_PARSER)
if(NOT DEFINED CMAKE_CUDA_ARCHITECTURES)
message(FATAL_ERROR "
CMake will not pass any architecture flags to the compiler
because the CUDA architecture is not set. You should specify
an architecture: set -DCMAKE_CUDA_ARCHITECTURES=<N>.")
endif(NOT DEFINED CMAKE_CUDA_ARCHITECTURES)
include_directories(${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES})
add_definitions(-DINCLUDE_CUDA)
set(USE_CXX ON)
enable_language(C)
enable_language(CXX)
set(CMAKE_CXX_STANDARD 11)
srcF/sfx_config.f90
srcF/sfx_esm.f90
srcF/sfx_esm_param.f90
srcF/sfx_log.f90
srcF/sfx_log_param.f90
srcF/sfx_z0m_all_surface.f90
srcF/sfx_z0t_all_surface.f90
srcF/sfx_most_snow.f90
srcF/sfx_most_snow_param.f90
srcF/sfx_sheba_noniterative.f90
srcF/sfx_sheba_noniterative.f90
srcF/sfx_sheba_noit_param.f90
srcF/sfx_sheba_coare.f90
srcF/sfx_sheba_coare_param.f90
srcF/sfx_api_inmcm.f90
srcF/sfx_api_term.f90
set(DIAG
diag/pbldia_new_sfx.f90
)
set(MAIN_F
srcF/sfx_main.f90)
srcCXX/model-base.cpp
srcCXX/sfx-esm.cpp
srcCXX/sfx-sheba.cpp
srcCXX/cxx-sfx-model-compute-flux.cpp
includeCU/sfx-surface.cuh
includeCU/sfx-math.cuh
includeCU/sfx-model-compute-subfunc.cuh
includeCXX/model-base.h
includeCXX/sfx-esm.h
includeCXX/sfx-sheba.h
includeCXX/cxx-sfx-model-compute-flux.h
list(APPEND HEADERS_DIRS includeCU/)
list(APPEND HEADERS_DIRS includeCXX/)
includeCXX/sfx-memory-processing.h
includeCXX/sfx-template-parameters.h
set(SOURCES
${MEMPROC_HEADERS_CU} ${MEMPROC_SOURCES_CU} ${MEMPROC_HEADERS_CXX} ${MEMPROC_SOURCES_CXX}
${HEADERS_CU} ${SOURCES_CU} ${HEADERS_C} ${HEADERS_CXX} ${SOURCES_CXX} ${SOURCES_C}
${HEADERS_F} ${SOURCES_F} ${DIAG} ${MAIN_F})
set(SOURCES_LIB
${MEMPROC_HEADERS_CU} ${MEMPROC_SOURCES_CU} ${MEMPROC_HEADERS_CXX} ${MEMPROC_SOURCES_CXX}
${HEADERS_CU} ${SOURCES_CU} ${HEADERS_CXX}
${SOURCES_CXX} ${SOURCES_C} ${HEADERS_F} ${SOURCES_F} ${DIAG})
add_library(sfx_lib ${SOURCES_LIB})
set_property(TARGET sfx PROPERTY LINKER_LANGUAGE Fortran)
target_include_directories(sfx PUBLIC ${CMAKE_BINARY_DIR}/modules/)
if(USE_CONFIG_PARSER)
target_link_libraries(sfx config_parser_F config_parser_CXX)
target_link_libraries(sfx_lib config_parser_F config_parser_CXX)
endif(USE_CONFIG_PARSER)
if(USE_JIKAN_TIMER)
target_include_directories(sfx PUBLIC ${jikan_timer_SOURCE_DIR})
target_link_libraries(sfx timerF timerCXX)
target_include_directories(sfx_lib PUBLIC ${jikan_timer_SOURCE_DIR})
target_link_libraries(sfx_lib timerF timerCXX)
endif(USE_JIKAN_TIMER)
set_property(TARGET sfx_lib PROPERTY LINKER_LANGUAGE Fortran)
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
SET(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> Scr <TARGET> <LINK_FLAGS> <OBJECTS>")
SET(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> Scr <TARGET> <LINK_FLAGS> <OBJECTS>")
SET(CMAKE_C_ARCHIVE_FINISH "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>")
SET(CMAKE_CXX_ARCHIVE_FINISH "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>")
SET(CMAKE_Fortran_ARCHIVE_FINISH "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>")
SET(CMAKE_Fortran_ARCHIVE_FINISH "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>")
endif("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
# set(CMAKE_Fortran_ARCHIVE_FINISH "$<CMAKE_RANLIB> -no_warning_for_no_symbols -c $<TARGET>")
target_include_directories(sfx_lib PUBLIC ${CMAKE_BINARY_DIR}/modules/)
if(USE_JIKAN_TIMER)
target_include_directories(sfx PUBLIC ${CMAKE_BINARY_DIR}/jikan_modules/)
target_include_directories(sfx_lib PUBLIC ${CMAKE_BINARY_DIR}/jikan_modules/)
endif(USE_JIKAN_TIMER)
if(VTUNE_FLAGS)
target_compile_options(sfx
PUBLIC $<$<COMPILE_LANGUAGE:C>: -g -O2 -Xsprofile>
PUBLIC $<$<COMPILE_LANGUAGE:CXX>: -g -O2 -Xsprofile>
PUBLIC $<$<COMPILE_LANGUAGE:Fortran>: -g -O2>)
endif(VTUNE_FLAGS)
set(CMAKE_BUILD_TYPE Release)
if ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
target_compile_options(sfx
PUBLIC $<$<COMPILE_LANGUAGE:C>: -g >)
target_compile_options(sfx
PUBLIC $<$<COMPILE_LANGUAGE:CXX>: -g >)
target_compile_options(sfx
PUBLIC $<$<COMPILE_LANGUAGE:CUDA>: -g >)
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
target_compile_options(sfx
PUBLIC $<$<COMPILE_LANGUAGE:Fortran>: -g -traceback -check all -ftrapuv -debug all >)
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
PUBLIC $<$<COMPILE_LANGUAGE:Fortran>: -g -fbacktrace -ffpe-trap=zero,overflow,underflow >)
endif()
if ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
target_compile_options(sfx_lib
PUBLIC $<$<COMPILE_LANGUAGE:C>: -g >)
target_compile_options(sfx_lib
PUBLIC $<$<COMPILE_LANGUAGE:CXX>: -g >)
target_compile_options(sfx_lib
PUBLIC $<$<COMPILE_LANGUAGE:CUDA>: -g >)
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
target_compile_options(sfx_lib
PUBLIC $<$<COMPILE_LANGUAGE:Fortran>: -g -traceback -check all -ftrapuv -debug all >)
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
target_compile_options(sfx_lib
PUBLIC $<$<COMPILE_LANGUAGE:Fortran>: -g -fbacktrace -ffpe-trap=zero,overflow,underflow >)
endif()
endif()
${CMAKE_CURRENT_SOURCE_DIR}/data
${CMAKE_CURRENT_BINARY_DIR}/data)
add_custom_command(
TARGET sfx POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_CURRENT_SOURCE_DIR}/config-ex
${CMAKE_CURRENT_BINARY_DIR}/config-ex)