Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CMake config to support building shared libraries #1559

Merged
merged 2 commits into from
Jul 29, 2024
Merged
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
11 changes: 6 additions & 5 deletions CMAKE_INSTRUCTIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,18 @@ make install
```

### User configurable options:
By default, FMS is built without `OpenMP` and in `single precision (r4)`
By default, FMS is built without `OpenMP`, in `single precision (r4)` and delivered in static library files.

The 64BIT and 32BIT precision options will build distinct libraries when enabled with the given default
real size, libfms_r4 or libfms_r8.

The following build options are available:
```
-DOPENMP "Build FMS with OpenMP support" DEFAULT: OFF
-D32BIT "Build 32-bit (r4) FMS library" DEFAULT: ON
-D64BIT "Build 64-bit (r8) FMS library" DEFAULT: OFF
-DFPIC "Build with position independent code" DEFAULT: OFF
-DOPENMP "Build FMS with OpenMP support" DEFAULT: OFF
-D32BIT "Build 32-bit (r4) FMS library" DEFAULT: ON
-D64BIT "Build 64-bit (r8) FMS library" DEFAULT: OFF
-DFPIC "Build with position independent code" DEFAULT: OFF
-DSHARED_LIBS "Build shared/dynamic libraries" DEFAULT: OFF

-DCONSTANTS "Build with <X> constants parameter definitions" DEFAULT:GFDL OPTIONS:GFS|GEOS|GFDL
-DINTERNAL_FILE_NML "Enable compiler definition -DINTERNAL_FILE_NML" DEFAULT: ON
Expand Down
23 changes: 16 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,11 @@ endif()
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)

# Build options
option(OPENMP "Build FMS with OpenMP support" OFF)
option(32BIT "Build 32-bit (r4) FMS library" ON)
option(64BIT "Build 64-bit (r8) FMS library" OFF)
option(FPIC "Build with position independent code" OFF)
option(OPENMP "Build FMS with OpenMP support" OFF)
option(32BIT "Build 32-bit (r4) FMS library" ON)
option(64BIT "Build 64-bit (r8) FMS library" OFF)
option(FPIC "Build with position independent code" OFF)
option(SHARED_LIBS "Build shared/dynamic libraries" OFF)

# Options for compiler definitions
option(INTERNAL_FILE_NML "Enable compiler definition -DINTERNAL_FILE_NML" ON)
Expand Down Expand Up @@ -360,8 +361,15 @@ foreach(kind ${kinds})
endif()

# FMS (C + Fortran)
add_library(${libTgt} STATIC $<TARGET_OBJECTS:${libTgt}_c>
$<TARGET_OBJECTS:${libTgt}_f>)
if (SHARED_LIBS)
message(STATUS "Shared library target: ${libTgt}")
add_library(${libTgt} SHARED $<TARGET_OBJECTS:${libTgt}_c>
$<TARGET_OBJECTS:${libTgt}_f>)
else ()
message(STATUS "Static library target: ${libTgt}")
add_library(${libTgt} STATIC $<TARGET_OBJECTS:${libTgt}_c>
$<TARGET_OBJECTS:${libTgt}_f>)
endif ()

target_include_directories(${libTgt} PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
Expand Down Expand Up @@ -397,7 +405,8 @@ foreach(kind ${kinds})
target_compile_definitions(${libTgt} PRIVATE "${fms_defs}")
target_compile_definitions(${libTgt} PRIVATE "${${kind}_defs}")

target_link_libraries(${libTgt} PUBLIC NetCDF::NetCDF_Fortran
target_link_libraries(${libTgt} PUBLIC NetCDF::NetCDF_C
NetCDF::NetCDF_Fortran
MPI::MPI_Fortran)

if(OpenMP_Fortran_FOUND)
Expand Down
Loading