Skip to content

Commit e0ecde1

Browse files
committed
Correctly find and compile FABM
1 parent 0010743 commit e0ecde1

5 files changed

Lines changed: 123 additions & 39 deletions

File tree

CMakeLists.txt

Lines changed: 67 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,85 @@
44

55
cmake_minimum_required(VERSION 3.10)
66

7-
# Project Name
8-
project(mossco VERSION 1.2.0
9-
DESCRIPTION "Modular System for Shelves and Coasts"
10-
LANGUAGES Fortran C)
7+
if(NOT PROJECT_NAME STREQUAL mossco)
8+
project(mossco VERSION 1.2.0
9+
DESCRIPTION "Modular System for Shelves and Coasts"
10+
LANGUAGES Fortran C
11+
)
12+
endif()
1113

1214
# Homepage URL
1315
set(PROJECT_HOMEPAGE_URL "http://www.mossco.de")
1416

1517
# Find CMake modules
16-
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
18+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
19+
20+
# Use solution folders in IDEs
21+
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
22+
23+
# Use use position-independent code (-fPIC) everywhere if building shared libraries
24+
if(BUILD_SHARED_LIBS)
25+
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
26+
endif()
27+
28+
# Options for third-party packages that we an link into
29+
option(USE_HAMSOM "Enable HAMSOM-based drivers" OFF)
30+
option(USE_CMAQ "Enable CMAQ-based drivers" OFF)
31+
option(USE_GETM "Enable GETM-based drivers" ON)
32+
option(USE_GOTM "Enable GOTM-based drivers" ON)
33+
option(USE_FABM "Enable FABM-based drivers" ON)
34+
option(USE_EROSED "Enable EROSED-related drivers (biotypes, benthoseffect_class)" OFF)
35+
36+
if(USE_FABM)
37+
mark_as_advanced(FORCE FABM_PREFIX FABM_BASE)
38+
39+
if(FABM_PREFIX)
40+
# Check for pre-built FABM package
41+
find_package(fabm REQUIRED CONFIG HINTS "${FABM_PREFIX}" NO_DEFAULT_PATH)
42+
mark_as_advanced(CLEAR FABM_PREFIX)
43+
else()
44+
# Determine FABM_BASE from -D, env, or fallback to local directory
45+
if(NOT DEFINED FABM_BASE)
46+
if(DEFINED ENV{FABM_BASE})
47+
set(FABM_BASE $ENV{FABM_BASE})
48+
else()
49+
set(FABM_BASE "${CMAKE_CURRENT_LIST_DIR}/external/fabm/code")
50+
endif()
51+
endif()
52+
53+
message(STATUS "Using FABM_BASE=${FABM_BASE}")
54+
55+
# Use a separate variable to locate the FABM source
56+
find_path(FABM_SOURCE_DIR src/fabm.F90
57+
HINTS "${FABM_BASE}"
58+
DOC "Path to FABM source directory."
59+
NO_CMAKE_FIND_ROOT_PATH
60+
)
61+
62+
if(NOT FABM_SOURCE_DIR)
63+
message(FATAL_ERROR "Could not find FABM source at or near ${FABM_BASE}")
64+
endif()
65+
66+
set(FABM_FORCED_HOST mossco)
67+
cmake_policy(PUSH)
68+
cmake_policy(VERSION 3.5)
69+
add_subdirectory("${FABM_SOURCE_DIR}" external/fabm/code)
70+
cmake_policy(POP)
71+
mark_as_advanced(CLEAR FABM_BASE)
72+
endif()
73+
endif()
74+
75+
76+
77+
1778

1879
include(GitVersion)
1980
include(FindESMF)
2081

2182
get_version_from_git()
2283

2384
# Add subdirectories
24-
add_subdirectory(src)
85+
#add_subdirectory(src)
2586
#add_subdirectory(examples)
2687
#add_subdirectory(external)
2788

cmake/FindFABM.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
# if provided in GOTM_PREFIX, use FABM modules used by GOTM
33
find_path(FABM_PREFIX_PATH
44
NAMES include/fabm_driver.h
5-
HINTS "$ENV{FABM_PREFIX}" "${GOTM_PREFIX}" "$ENV{FABM_PREFIX}"
6-
PATHS "$ENV{LOCALAPPDATA}/fabm/gotm" "$ENV{APPDATA}/fabm/gotm" "$ENV{HOME}/local/fabm/gotm"
5+
HINTS "$ENV{FABM_PREFIX}" "$ENV{GOTM_PREFIX}"
6+
PATHS "$ENV{LOCALAPPDATA}/fabm/gotm" "$ENV{APPDATA}/fabm/gotm" "$ENV{HOME}/local/fabm/gotm" "${CURRENT_SOURCE_DIR}/../../external/fabm/install"
77
DOC "Installation prefix for Framework for Aquatic Biogeochemical Models - fabm.net"
88
)
99

src/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
# Placeholder for src CMake definitions
66
# Add subdirectories for components, connectors, drivers, mediators, test, and utilities
7+
add_subdirectory(include)
8+
add_subdirectory(utilities)
9+
add_subdirectory(drivers)
710
add_subdirectory(components)
811
add_subdirectory(connectors)
9-
add_subdirectory(drivers)
10-
add_subdirectory(include)
1112
add_subdirectory(mediators)
1213
add_subdirectory(test)
13-
add_subdirectory(utilities)

src/drivers/CMakeLists.txt

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,51 +13,52 @@ set(DRIVER_SOURCES
1313
#vertical_macrobenthos_driver.F90
1414
)
1515

16-
option(USE_HAMSOM "Enable HAMSOM-based drivers" OFF)
1716
if(USE_HAMSOM)
1817
list(APPEND DRIVER_SOURCES
1918
hamsom_driver.F90
2019
)
2120
endif()
2221

23-
option(USE_CMAQ "Enable CMAQ-based drivers" OFF)
2422
if(USE_CMAQ)
2523
list(APPEND DRIVER_SOURCES
2624
cmaq_driver.F90
2725
)
2826
endif()
2927

30-
option(USE_GETM "Enable GETM-based drivers" OFF)
3128
if(USE_GETM)
3229
list(APPEND DRIVER_SOURCES
3330
getm_driver.F90
3431
)
3532
endif()
3633

37-
include(FindFABM)
38-
39-
# Add FABM include directories if found
40-
if(FABM_INCLUDE_DIRS)
41-
target_include_directories(mossco_drivers PRIVATE ${FABM_INCLUDE_DIRS})
42-
endif()
43-
if(FABM_LIBRARIES)
44-
target_link_libraries(mossco_drivers PRIVATE ${FABM_LIBRARIES})
45-
endif()
46-
47-
option(USE_FABM "Enable FABM-based drivers" ON)
48-
#if(USE_FABM)
49-
# FABM drivers are enabled by default, so we append them to DRIVER_SOURCES
34+
if(USE_FABM)
5035
list(APPEND DRIVER_SOURCES
51-
#fabm0d_driver.F90
52-
#fabm_benthic_driver.F90
53-
#fabm_gotm_driver.F90
54-
fabm_pelagic_driver.F90
55-
fabm_sediment_driver.F90
36+
#fabm0d_driver.F90
37+
#fabm_benthic_driver.F90
38+
#fabm_gotm_driver.F90
39+
fabm_pelagic_driver.F90
40+
fabm_sediment_driver.F90
5641
)
57-
#endif()
42+
43+
set(FABM_HOST mossco)
44+
set(CMAKE_POLICY_VERSION_MINIMUM 3.5)
45+
add_subdirectory(
46+
${CMAKE_CURRENT_SOURCE_DIR}/../../external/fabm/code
47+
${CMAKE_BINARY_DIR}/external/fabm/build
48+
)
49+
50+
#include(FindFABM)
51+
52+
# Add FABM include directories if found
53+
if(FABM_INCLUDE_DIRS)
54+
target_include_directories(mossco_drivers PRIVATE ${FABM_INCLUDE_DIRS})
55+
endif()
56+
if(FABM_LIBRARIES)
57+
target_link_libraries(mossco_drivers PRIVATE ${FABM_LIBRARIES})
58+
endif()
59+
endif()
5860

5961
# Option to enable or disable EROSED-related sources
60-
option(USE_EROSED "Enable EROSED-related drivers (biotypes, benthoseffect_class)" OFF)
6162
if(USE_EROSED)
6263
list(APPEND DRIVER_SOURCES
6364
biotypes.F90

src/include/CMakeLists.txt

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,36 @@
1-
# CMakeLists.txt for src/include
1+
# This CMakeLists.txt is part of MOSSCO
2+
#
3+
# SPDX-FileCopyrightText 2021-2025 Helmholtz-Zentrum hereon GmbH
4+
# SPDX-FileCopyrightText 2014-2021 Helmholtz-Zentrum Geesthacht
5+
# SPDX-License-Identifier: CC0-1.0
6+
# SPDX-FileContributor Carsten Lemmen <carsten.lemmen@hereon.de>
7+
#
8+
# MOSSCO is free software: you can redistribute it and/or modify it under the
9+
# terms of the GNU General Public License v3+. MOSSCO is distributed in the
10+
# hope that it will be useful, but WITHOUT ANY WARRANTY. Consult the file
11+
# LICENSE.GPL or www.gnu.org/licenses/gpl-3.0.txt for the full license terms.
12+
13+
# Set MOSSCO_DIR if not already set
14+
if(NOT DEFINED MOSSCO_DIR)
15+
get_filename_component(MOSSCO_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../.." ABSOLUTE)
16+
endif()
217

318
# Ensure the output directory for headers exists
4-
set(GENERATED_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/include)
19+
set(GENERATED_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR})
520
file(MAKE_DIRECTORY ${GENERATED_INCLUDE_DIR})
621

722
# --- version.h ---
823
# Assuming PROJECT_VERSION_MAJOR, PROJECT_VERSION_MINOR, PROJECT_VERSION_PATCH are set in the root CMakeLists.txt
924
# Example: set(PROJECT_VERSION_MAJOR 1) set(PROJECT_VERSION_MINOR 0) set(PROJECT_VERSION_PATCH 0)
10-
if(NOT DEFINED PROJECT_VERSION_MAJOR) set(PROJECT_VERSION_MAJOR 0) endif()
11-
if(NOT DEFINED PROJECT_VERSION_MINOR) set(PROJECT_VERSION_MINOR 0) endif()
12-
if(NOT DEFINED PROJECT_VERSION_PATCH) set(PROJECT_VERSION_PATCH 0) endif()
25+
if(NOT DEFINED PROJECT_VERSION_MAJOR)
26+
set(PROJECT_VERSION_MAJOR 0)
27+
endif()
28+
if(NOT DEFINED PROJECT_VERSION_MINOR)
29+
set(PROJECT_VERSION_MINOR 0)
30+
endif()
31+
if(NOT DEFINED PROJECT_VERSION_PATCH)
32+
set(PROJECT_VERSION_PATCH 0)
33+
endif()
1334

1435
# Create a version.h.in if it doesn't exist (basic example)
1536
set(VERSION_H_IN_CONTENT "
@@ -43,6 +64,7 @@ message(STATUS "Configured ${VERSION_H_FILE}")
4364
# --- git-sha.h ---
4465
find_package(Git QUIET)
4566
find_package(Subversion QUIET)
67+
find_package(CVS QUIET)
4668

4769
set(GIT_SHA_H_FILE ${GENERATED_INCLUDE_DIR}/git-sha.h)
4870
set(GENERATE_GIT_SHA_SCRIPT ${CMAKE_CURRENT_LIST_DIR}/generate_git_sha.cmake)

0 commit comments

Comments
 (0)