Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion components/omega/OmegaBuild.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,31 @@ macro(update_variables)
# Set the build type
set(CMAKE_BUILD_TYPE ${OMEGA_BUILD_TYPE})

add_definitions(-DOMEGA_BUILD_MODE=${OMEGA_BUILD_MODE})
# Expose the Omega build mode to C/C++ as compile-time macros.
#
# Use the boolean-style macros below in source code:
# #if OMEGA_BUILD_MODE_STANDALONE
# #if OMEGA_BUILD_MODE_E3SM_COUPLED
#
# OMEGA_BUILD_MODE is also kept as a numeric macro for code that needs a
# single build-mode value.
if("${OMEGA_BUILD_MODE}" STREQUAL "STANDALONE")
add_definitions(
-DOMEGA_BUILD_MODE=1
-DOMEGA_BUILD_MODE_STANDALONE=1
-DOMEGA_BUILD_MODE_E3SM_COUPLED=0
)

elseif("${OMEGA_BUILD_MODE}" STREQUAL "E3SM")
add_definitions(
-DOMEGA_BUILD_MODE=2
-DOMEGA_BUILD_MODE_STANDALONE=0
-DOMEGA_BUILD_MODE_E3SM_COUPLED=1
)

else()
message(FATAL_ERROR "OMEGA_BUILD_MODE is neither E3SM nor STANDALONE.")
endif()

if(NOT DEFINED OMEGA_LOG_LEVEL)
set(OMEGA_LOG_LEVEL "INFO")
Expand Down
20 changes: 20 additions & 0 deletions components/omega/doc/devGuide/CMakeBuild.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,26 @@ OMEGA_LOG_TASKS: set the tasks that generate log file. "0" is a default value.
OMEGA_VECTOR_LENGTH: Vector length used for blocking inner loops for vectorization. "1" is a default value.
```

Build-mode compile-time macros

The selected `OMEGA_BUILD_MODE` is exposed to C/C++ source as preprocessor
macros so code can be conditionally compiled for standalone or E3SM-coupled
builds:

```
OMEGA_BUILD_MODE: numeric build-mode id (1 = STANDALONE, 2 = E3SM)
OMEGA_BUILD_MODE_STANDALONE: 1 in standalone builds, 0 otherwise
OMEGA_BUILD_MODE_E3SM_COUPLED: 1 in E3SM-coupled builds, 0 otherwise
```

Prefer the boolean-style macros in source code, e.g.

```c++
#if OMEGA_BUILD_MODE_STANDALONE
// standalone-only code (e.g. the driver's main())
#endif
```

E3SM-specific variables

```
Expand Down
7 changes: 7 additions & 0 deletions components/omega/src/drivers/standalone/OceanDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@

#include <iostream>

// The standalone driver provides Omega's entry point and is only compiled in
// standalone builds. In E3SM-coupled builds the coupler supplies main() and
// drives Omega through the ocnInit/ocnRun/ocnFinalize interface instead.
#if OMEGA_BUILD_MODE_STANDALONE

int main(int argc, char **argv) {

int ErrAll;
Expand Down Expand Up @@ -71,4 +76,6 @@ int main(int argc, char **argv) {
return ErrAll;
}

#endif // OMEGA_BUILD_MODE_STANDALONE

//===----------------------------------------------------------------------===//
Loading