|
| 1 | +# |
| 2 | +# This file is part of a C++ interface to the Radiative Transfer for Energetics (RTE) |
| 3 | +# |
| 4 | +cmake_minimum_required (VERSION 3.12) |
| 5 | +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/config) |
| 6 | +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) |
| 7 | + |
| 8 | +# Set the precision of the build. |
| 9 | +if(USESP) |
| 10 | + message(STATUS "Precision: Single (32-bits floats)") |
| 11 | + add_compile_definitions(RTE_USE_SP) |
| 12 | +else() |
| 13 | + message(STATUS "Precision: Double (64-bits floats)") |
| 14 | +endif() |
| 15 | + |
| 16 | +# Load system specific settings if not set, force default.cmake. |
| 17 | +if(NOT SYST) |
| 18 | + set(SYST default) |
| 19 | +endif() |
| 20 | +include(${SYST} OPTIONAL RESULT_VARIABLE SYSTINC) |
| 21 | + |
| 22 | +# Trigger fatal error if illegal module is loaded. |
| 23 | +if(${SYSTINC} STREQUAL "NOTFOUND") |
| 24 | + message(FATAL_ERROR "Config file config/" ${SYST} ".cmake does not exist.") |
| 25 | +endif() |
| 26 | + |
| 27 | +# Set the default build type to RELEASE. |
| 28 | +if(NOT CMAKE_BUILD_TYPE) |
| 29 | + set(CMAKE_BUILD_TYPE RELEASE CACHE STRING |
| 30 | + "Choose the type of build, options are: None Debug Release." FORCE) |
| 31 | +else() |
| 32 | + string(TOUPPER ${CMAKE_BUILD_TYPE} TEMP) |
| 33 | + set(CMAKE_BUILD_TYPE ${TEMP} CACHE STRING |
| 34 | + "Choose the type of build, options are: None Debug Release." FORCE) |
| 35 | +endif() |
| 36 | + |
| 37 | +# Start the project only after the system specific settings are loaded. |
| 38 | +if(USECUDA) |
| 39 | + project(rte-rrtmgp-cpp C CXX Fortran CUDA) |
| 40 | +else() |
| 41 | + project(rte-rrtmgp-cpp C CXX Fortran) |
| 42 | +endif() |
| 43 | + |
| 44 | +# Load the CUDA module in case CUDA is enabled and display status message. |
| 45 | +if(USECUDA) |
| 46 | + message(STATUS "CUDA: Enabled.") |
| 47 | + add_definitions("-DUSECUDA") |
| 48 | +else() |
| 49 | + message(STATUS "CUDA: Disabled.") |
| 50 | +endif() |
| 51 | + |
| 52 | +# Only set the compiler flags when the cache is created |
| 53 | +# to enable editing of the flags in the CMakeCache.txt file. |
| 54 | +if(NOT HASCACHE) |
| 55 | + set(CMAKE_C_FLAGS ${USER_C_FLAGS} CACHE STRING |
| 56 | + "Flags used by the C-compiler during all build types." FORCE) |
| 57 | + set(CMAKE_C_FLAGS_DEBUG ${USER_C_FLAGS_DEBUG} CACHE STRING |
| 58 | + "Flags used by the C-compiler during debug builds." FORCE) |
| 59 | + set(CMAKE_C_FLAGS_RELEASE ${USER_C_FLAGS_RELEASE} CACHE STRING |
| 60 | + "Flags used by the C-compiler during release builds." FORCE) |
| 61 | + |
| 62 | + set(CMAKE_CXX_FLAGS ${USER_CXX_FLAGS} CACHE STRING |
| 63 | + "Flags used by the CXX-compiler during all build types." FORCE) |
| 64 | + set(CMAKE_CXX_FLAGS_DEBUG ${USER_CXX_FLAGS_DEBUG} CACHE STRING |
| 65 | + "Flags used by the CXX-compiler during debug builds." FORCE) |
| 66 | + set(CMAKE_CXX_FLAGS_RELEASE ${USER_CXX_FLAGS_RELEASE} CACHE STRING |
| 67 | + "Flags used by the CXX-compiler during release builds." FORCE) |
| 68 | + |
| 69 | + set(CMAKE_Fortran_FLAGS ${USER_FC_FLAGS} CACHE STRING |
| 70 | + "Flags used by the Fortran-compiler during all build types." FORCE) |
| 71 | + set(CMAKE_Fortran_FLAGS_DEBUG ${USER_FC_FLAGS_DEBUG} CACHE STRING |
| 72 | + "Flags used by the Fortran-compiler during debug builds." FORCE) |
| 73 | + set(CMAKE_Fortran_FLAGS_RELEASE ${USER_FC_FLAGS_RELEASE} CACHE STRING |
| 74 | + "Flags used by the Fortran-compiler during release builds." FORCE) |
| 75 | + |
| 76 | + if(USECUDA) |
| 77 | + set(CMAKE_CUDA_FLAGS ${USER_CUDA_FLAGS} CACHE STRING |
| 78 | + "Flags used by the CXX-compiler during all build types." FORCE) |
| 79 | + set(CMAKE_CUDA_FLAGS_DEBUG ${USER_CUDA_FLAGS_DEBUG} CACHE STRING |
| 80 | + "Flags used by the CXX-compiler during debug builds." FORCE) |
| 81 | + set(CMAKE_CUDA_FLAGS_RELEASE ${USER_CUDA_FLAGS_RELEASE} CACHE STRING |
| 82 | + "Flags used by the CXX-compiler during release builds." FORCE) |
| 83 | + endif() |
| 84 | + |
| 85 | + message(STATUS "Build Type: " ${CMAKE_BUILD_TYPE}) |
| 86 | + set(HASCACHE TRUE CACHE BOOL "CMakeCache.txt created." FORCE) |
| 87 | + |
| 88 | + # Make sure that ccmake only contains build type. |
| 89 | + mark_as_advanced(HASCACHE) |
| 90 | + mark_as_advanced(CMAKE_INSTALL_PREFIX) |
| 91 | +endif() |
| 92 | + |
| 93 | +# Print the C++ and CUDA compiler flags to the screen. |
| 94 | +if(CMAKE_BUILD_TYPE STREQUAL "RELEASE") |
| 95 | + message(STATUS "CXX-compiler flags: " ${CMAKE_CXX_FLAGS} " " ${CMAKE_CXX_FLAGS_RELEASE}) |
| 96 | + message(STATUS "Fortran-compiler flags: " ${CMAKE_CXX_FLAGS} " " ${CMAKE_CXX_FLAGS_RELEASE}) |
| 97 | +else() |
| 98 | + message(STATUS "CXX-compiler flags: " ${CMAKE_CXX_FLAGS} " " ${CMAKE_CXX_FLAGS_DEBUG}) |
| 99 | + message(STATUS "Fortran-compiler flags: " ${CMAKE_CXX_FLAGS} " " ${CMAKE_CXX_FLAGS_DEBUG}) |
| 100 | +endif() |
| 101 | +if(USECUDA) |
| 102 | + if(CMAKE_BUILD_TYPE STREQUAL "RELEASE") |
| 103 | + message(STATUS "NVCC-compiler flags: " ${CMAKE_CUDA_FLAGS} " " ${CMAKE_CUDA_FLAGS_RELEASE}) |
| 104 | + else() |
| 105 | + message(STATUS "NVCC-compiler flags: " ${CMAKE_CUDA_FLAGS} " " ${CMAKE_CUDA_FLAGS_DEBUG}) |
| 106 | + endif() |
| 107 | +endif() |
| 108 | + |
| 109 | +add_subdirectory(src_kernels) |
| 110 | +add_subdirectory(src) |
| 111 | +if(USECUDA) |
| 112 | + add_subdirectory(src_kernels_cuda) |
| 113 | + add_subdirectory(src_cuda) |
| 114 | + add_subdirectory(src_kernels_cuda_rt) |
| 115 | + add_subdirectory(src_cuda_rt) |
| 116 | +endif() |
| 117 | +add_subdirectory(src_test) |
| 118 | + |
0 commit comments