CMakeLists.txt 3.45 KB
Newer Older
1
cmake_minimum_required(VERSION 3.0)
2

3 4 5 6
if(POLICY CMP0048)
  cmake_policy(SET CMP0048 NEW)
endif()

7 8 9 10 11 12
# Use solution folders in IDEs
set_property(GLOBAL PROPERTY USE_FOLDERS ON)

# Create main project.
project(fabm0d Fortran)

13 14
# Find GOTM directory.
# This directory will also be configurable in the CMake GUI or interactive mode.
15
find_path(GOTM_BASE
16 17
          NAMES src/gotm/gotm.F90
          HINTS ENV GOTMDIR
Jorn Bruggeman's avatar
Jorn Bruggeman committed
18 19
          PATHS ${PROJECT_SOURCE_DIR}/../../../../.. ${PROJECT_SOURCE_DIR}/../../..
          PATH_SUFFIXES GOTM/gotm-git gotm-git gotm
20 21
          DOC "Directory with GOTM source code (www.gotm.net)")

22 23
# Make NetCDF usage a configurable option.
option(FABM_USE_NetCDF "Enable NetCDF output" ON)
24

25
# Specify additional compiler flags
26 27 28
if(${CMAKE_Fortran_COMPILER_ID} STREQUAL "GNU")
  set (CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -ffree-line-length-none")
elseif(${CMAKE_Fortran_COMPILER_ID} STREQUAL "Intel")
29 30 31 32 33
  if(WIN32)
    set(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG} /Od")
  endif()
endif()

Jorn Bruggeman's avatar
Jorn Bruggeman committed
34 35 36 37 38 39 40
set(GOTM_USE_NetCDF ${FABM_USE_NetCDF} CACHE BOOL "Enable output in NetCDF format" FORCE)
set(GOTM_USE_FABM OFF CACHE BOOL "use FABM" FORCE)
set(GOTM_USE_SEAGRASS OFF CACHE BOOL "use seagrass" FORCE)
set(GOTM_USE_STIM OFF CACHE BOOL "use STIM" FORCE)
mark_as_advanced(GOTM_USE_FABM GOTM_USE_NetCDF GOTM_USE_SEAGRASS GOTM_USE_STIM)
add_subdirectory(${GOTM_BASE} gotm EXCLUDE_FROM_ALL)

41 42
# Force FABM_HOST to 0d and include FABM CMakeLists.txt.
set(FABM_FORCED_HOST 0d)
43
add_subdirectory(${PROJECT_SOURCE_DIR}/../.. fabm EXCLUDE_FROM_ALL)
44

45
# Build 0d executable.
46 47 48 49 50 51
add_executable (fabm0d
                main.F90
                fabm0d.F90
                shared.F90
                output.F90
                fabm_0d.h
52 53
                )

Jorn Bruggeman's avatar
Jorn Bruggeman committed
54 55
# Link with FABM library, field/output manager and GOTM.
target_link_libraries(fabm0d PRIVATE fabm output_manager field_manager airsea input_manager util)
56

57 58 59
# Set module directory (output of *.mod)
set_property(TARGET fabm0d PROPERTY Fortran_MODULE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/modules)

60 61
# Set include directories with modules (*.mod)
target_include_directories(fabm0d PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/modules")
62 63

# Set include directories with header files (*.h) for GOTM - version.h, cppdefs.h, ode_solver_template.F90.
64 65
target_include_directories(fabm0d PRIVATE "${GOTM_BASE}/include")
target_include_directories(fabm0d PRIVATE "${GOTM_BASE}/src/util")
66 67

# Set include directories with header files (*.h) - our own and FABM's.
68 69 70
target_include_directories(fabm0d PRIVATE "${PROJECT_SOURCE_DIR}")
target_include_directories(fabm0d PRIVATE "${PROJECT_SOURCE_DIR}/../../../include")
target_include_directories(fabm0d PRIVATE $<TARGET_PROPERTY:yaml,INTERFACE_INCLUDE_DIRECTORIES>)
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92

# Set default installation prefix.
if(WIN32)
  if(DEFINED ENV{LOCALAPPDATA})
    set(DEFAULT_PREFIX "$ENV{LOCALAPPDATA}/fabm/0d")
  else()
    set(DEFAULT_PREFIX "$ENV{APPDATA}/fabm/0d")
  endif()
else()
  set(DEFAULT_PREFIX "$ENV{HOME}/local/fabm/0d")
endif()

# Set cache variable with installation prefix.
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
  # None set - set our default prefix.
  set(CMAKE_INSTALL_PREFIX "${DEFAULT_PREFIX}" CACHE PATH "Directory to install FABM's 0d driver in" FORCE)
else()
  # User specified a prefix - just update the variable description.
  set(CMAKE_INSTALL_PREFIX "${DEFAULT_PREFIX}" CACHE PATH "Directory to install FABM's 0d driver in")
endif()
message(STATUS "Installation prefix: ${CMAKE_INSTALL_PREFIX}")

93
install(TARGETS fabm0d
94
  DESTINATION bin)