Skip to content

Commit

Permalink
Optionally produce shared libraries
Browse files Browse the repository at this point in the history
From PR #335.
  • Loading branch information
RobertPincus authored Jan 8, 2025
2 parents eb5616a + dd1fd43 commit af6c185
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 4 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ project(
LANGUAGES Fortran
)

option(BUILD_SHARED_LIBS "Build shared libraries" OFF)
option(BUILD_TESTING "Build tests" OFF)

option(RTE_ENABLE_SP "Enable single-precision floating-point model" OFF)
Expand Down
10 changes: 8 additions & 2 deletions rrtmgp-frontend/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
set(gas_optics_source_dir ${PROJECT_SOURCE_DIR}/gas-optics)

add_library(
rrtmgp STATIC # cmake-format: sort
rrtmgp # cmake-format: sort
$<TARGET_OBJECTS:rrtmgpkernels>
${gas_optics_source_dir}/mo_gas_concentrations.F90
${gas_optics_source_dir}/mo_gas_optics.F90
Expand All @@ -14,7 +14,13 @@ add_library(

add_library(rte-rrtmgp::rrtmgp ALIAS rrtmgp)

set_target_properties(rrtmgp PROPERTIES EXPORT_NAME rte-rrtmgp::rrtmgp)
set_target_properties(
rrtmgp
PROPERTIES EXPORT_NAME rte-rrtmgp::rrtmgp
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
INSTALL_RPATH "${CMAKE_INSTALL_FULL_LIBDIR}"
)

target_include_directories(
rrtmgp
Expand Down
4 changes: 4 additions & 0 deletions rrtmgp-kernels/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ else()
endif()
endif()

if(BUILD_SHARED_LIBS)
set_target_properties(rrtmgpkernels PROPERTIES POSITION_INDEPENDENT_CODE ON)
endif()

target_include_directories(
rrtmgpkernels PRIVATE ${CMAKE_Fortran_MODULE_DIRECTORY}
)
Expand Down
9 changes: 7 additions & 2 deletions rte-frontend/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
add_library(
rte STATIC # cmake-format: sort
rte # cmake-format: sort
$<TARGET_OBJECTS:rtekernels>
mo_fluxes.F90
mo_optical_props.F90
Expand All @@ -12,7 +12,12 @@ add_library(

add_library(rte-rrtmgp::rte ALIAS rte)

set_target_properties(rte PROPERTIES EXPORT_NAME rte-rrtmgp::rte)
set_target_properties(
rte
PROPERTIES EXPORT_NAME rte-rrtmgp::rte
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
)

target_include_directories(
rte
Expand Down
4 changes: 4 additions & 0 deletions rte-kernels/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ else()
endif()
endif()

if(BUILD_SHARED_LIBS)
set_target_properties(rtekernels PROPERTIES POSITION_INDEPENDENT_CODE ON)
endif()

target_compile_definitions(
rtekernels PRIVATE $<$<BOOL:${RTE_ENABLE_SP}>:RTE_USE_SP>
)
Expand Down

0 comments on commit af6c185

Please sign in to comment.