cmake_minimum_required(VERSION 3.19) option(INCLUDE_CUDA "GPU build in mode" OFF) option(USE_CXX "CXX build in mode" OFF) option(BUILD_DOC "Build documentation" OFF) option(SFX_CHECK_NAN "Build documentation" OFF) option(USE_JIKAN_TIMER "Jikan timer build in mode" OFF) option(USE_CONFIG_PARSER "Build config parser" ON) option(VTUNE_FLAGS " " OFF) project(INMCM_sfx) enable_language(Fortran) 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) if(BUILD_DOC) 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} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} ) else() message("Doxygen need to be installed to generate the doxygen documentation") endif (DOXYGEN_FOUND) endif(BUILD_DOC) if(SFX_CHECK_NAN) add_definitions(-DSFX_CHECK_NAN) 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/) add_definitions(-DUSE_CONFIG_PARSER) endif(USE_CONFIG_PARSER) if(INCLUDE_CUDA) 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) enable_language(CUDA) include_directories(${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES}) add_definitions(-DINCLUDE_CUDA) set(USE_CXX ON) endif(INCLUDE_CUDA) if(USE_CXX) enable_language(C) enable_language(CXX) set(CMAKE_CXX_STANDARD 11) add_definitions(-DINCLUDE_CXX) endif(USE_CXX) set(SOURCES_F srcF/sfx_data.f90 srcF/sfx_common.f90 srcF/sfx_io.f90 srcF/sfx_config.f90 srcF/sfx_esm.f90 srcF/sfx_esm_param.f90 srcF/sfx_log.f90 srcF/sfx_log_param.f90 srcF/sfx_run.f90 srcF/sfx_phys_const.f90 srcF/sfx_surface.f90 srcF/sfx_thermal_roughness.f90 srcF/sfx_most.f90 srcF/sfx_most_param.f90 srcF/sfx_sheba.f90 srcF/sfx_sheba_noniterative.f90 srcF/sfx_sheba_param.f90 srcF/sfx_sheba_noniterative.f90 srcF/sfx_sheba_noit_param.f90 srcF/sfx_fc_wrapper.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) set(HEADERS_F includeF/sfx_def.fi ) if(USE_CXX) set(SOURCES_C srcC/c-sfx-model-compute-flux.c ) set(HEADERS_C includeC/sfx-data.h ) list(APPEND HEADERS_DIRS includeC/) set(SOURCES_CXX srcCXX/model-base.cpp srcCXX/sfx-esm.cpp srcCXX/sfx-sheba.cpp srcCXX/cxx-sfx-model-compute-flux.cpp ) set(HEADERS_CXX 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/) endif(USE_CXX) if(INCLUDE_CUDA) set(SOURCES_CU srcCU/sfx-esm.cu srcCU/sfx-sheba.cu ) set(HEADERS_CU ) endif(INCLUDE_CUDA) if(USE_CXX OR INCLUDE_CUDA) set(MEMPROC_SOURCES_CXX srcCXX/sfx-memory-processing.cpp ) set(MEMPROC_HEADERS_CXX includeCXX/sfx-memory-processing.h includeCXX/sfx-template-parameters.h ) if(INCLUDE_CUDA) set(MEMPROC_SOURCES_CU srcCU/sfx-memory-processing.cu ) set(MEMPROC_HEADERS_CU includeCU/sfx-memory-processing.cuh ) endif(INCLUDE_CUDA) endif(USE_CXX OR INCLUDE_CUDA) 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}) set(CMAKE_Fortran_FLAGS " -cpp ") add_executable(sfx ${SOURCES}) add_library(sfx_lib ${SOURCES_LIB}) set_property(TARGET sfx PROPERTY LINKER_LANGUAGE Fortran) target_include_directories(sfx PUBLIC ${CMAKE_BINARY_DIR}/modules/) target_include_directories(sfx PUBLIC ${HEADERS_DIRS}) target_include_directories(sfx_lib PUBLIC ${HEADERS_DIRS}) 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") target_compile_options(sfx PUBLIC $<$<COMPILE_LANGUAGE:Fortran>: -g -fbacktrace -ffpe-trap=zero,overflow,underflow >) endif() 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() # copy data & configs on post build add_custom_command( TARGET sfx POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/data ${CMAKE_CURRENT_BINARY_DIR}/data) add_custom_command( TARGET sfx POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/config-ex ${CMAKE_CURRENT_BINARY_DIR}/config-ex)