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

CMake: add install target #323

Merged
merged 7 commits into from
Jan 6, 2025
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
2 changes: 1 addition & 1 deletion .github/workflows/style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
workflow_dispatch:

env:
FIND_CMAKE_FILES_CMD: "find '${{ github.workspace }}' -name 'CMakeLists.txt' -o -name '*.cmake'"
FIND_CMAKE_FILES_CMD: "find '${{ github.workspace }}' -name 'CMakeLists.txt' -o -name '*.cmake' -o -name '*.cmake.in'"

jobs:
Format:
Expand Down
39 changes: 39 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ set_property(CACHE KERNEL_MODE PROPERTY STRINGS ${PREFERRED_KERNEL_MODES})

list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)

# GNUInstallDirs issues a warning if CMAKE_SIZEOF_VOID_P is not defined, which
# is the case with NAG. One way to circumvent that is to enable C language for
# the project:
if(CMAKE_Fortran_COMPILER_ID STREQUAL NAG)
enable_language(C)
endif()
include(GNUInstallDirs)

add_compile_options(
$<$<COMPILE_LANG_AND_ID:Fortran,GNU>:-ffree-line-length-none>
)
Expand Down Expand Up @@ -97,3 +105,34 @@ else()
# Allow for 'make test' even if the tests are disabled:
enable_testing()
endif()

export(
EXPORT rte-rrtmgp-targets FILE ${PROJECT_BINARY_DIR}/rte-rrtmgp-targets.cmake
)

include(CMakePackageConfigHelpers)
configure_package_config_file(
${PROJECT_SOURCE_DIR}/cmake/config.cmake.in
${PROJECT_BINARY_DIR}/rte-rrtmgp-config.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/rte-rrtmgp/cmake
NO_SET_AND_CHECK_MACRO NO_CHECK_REQUIRED_COMPONENTS_MACRO
)

write_basic_package_version_file(
${PROJECT_BINARY_DIR}/rte-rrtmgp-config-version.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMinorVersion
)

install(DIRECTORY ${CMAKE_Fortran_MODULE_DIRECTORY}/ TYPE INCLUDE)

install(
EXPORT rte-rrtmgp-targets
DESTINATION ${CMAKE_INSTALL_LIBDIR}/rte-rrtmgp/cmake
)

install(
FILES ${PROJECT_BINARY_DIR}/rte-rrtmgp-config.cmake
${PROJECT_BINARY_DIR}/rte-rrtmgp-config-version.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/rte-rrtmgp/cmake
)
6 changes: 6 additions & 0 deletions cmake/config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@PACKAGE_INIT@

include(${CMAKE_CURRENT_LIST_DIR}/rte-rrtmgp-targets.cmake)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(rte-rrtmgp REQUIRED_VARS rte-rrtmgp_DIR)
3 changes: 2 additions & 1 deletion examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ target_include_directories(
)

target_link_libraries(
examples_utils PUBLIC rrtmgp rte ${NetCDF_Fortran_LIBRARY}
examples_utils
PUBLIC rte-rrtmgp::rrtmgp rte-rrtmgp::rte ${NetCDF_Fortran_LIBRARY}
)

add_subdirectory(all-sky)
Expand Down
13 changes: 8 additions & 5 deletions rrtmgp-frontend/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ set(gas_optics_source_dir ${PROJECT_SOURCE_DIR}/gas-optics)

add_library(
rrtmgp STATIC # cmake-format: sort
$<TARGET_OBJECTS:rrtmgpkernels>
${gas_optics_source_dir}/mo_gas_concentrations.F90
${gas_optics_source_dir}/mo_gas_optics.F90
${gas_optics_source_dir}/mo_gas_optics_constants.F90
Expand All @@ -11,14 +12,16 @@ add_library(
mo_gas_optics_rrtmgp.F90
)

add_library(rte-rrtmgp::rrtmgp ALIAS rrtmgp)

set_target_properties(rrtmgp PROPERTIES EXPORT_NAME rte-rrtmgp::rrtmgp)

target_include_directories(
rrtmgp
PUBLIC
$<BUILD_INTERFACE:$<$<COMPILE_LANGUAGE:Fortran>:${CMAKE_Fortran_MODULE_DIRECTORY}>>
)

target_link_libraries(
rrtmgp
PUBLIC rrtmgpkernels
PRIVATE rte
)
target_link_libraries(rrtmgp PRIVATE rte)

install(TARGETS rrtmgp EXPORT rte-rrtmgp-targets)
4 changes: 1 addition & 3 deletions rrtmgp-kernels/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ else()
endif()

target_include_directories(
rrtmgpkernels
PUBLIC
$<BUILD_INTERFACE:$<$<COMPILE_LANGUAGE:Fortran>:${CMAKE_Fortran_MODULE_DIRECTORY}>>
rrtmgpkernels PRIVATE ${CMAKE_Fortran_MODULE_DIRECTORY}
)

target_link_libraries(rrtmgpkernels PRIVATE rte)
7 changes: 6 additions & 1 deletion rte-frontend/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
add_library(
rte STATIC # cmake-format: sort
$<TARGET_OBJECTS:rtekernels>
mo_fluxes.F90
mo_optical_props.F90
mo_rte_config.F90
Expand All @@ -9,10 +10,14 @@ add_library(
mo_source_functions.F90
)

add_library(rte-rrtmgp::rte ALIAS rte)

set_target_properties(rte PROPERTIES EXPORT_NAME rte-rrtmgp::rte)

target_include_directories(
rte
PUBLIC
$<BUILD_INTERFACE:$<$<COMPILE_LANGUAGE:Fortran>:${CMAKE_Fortran_MODULE_DIRECTORY}>>
)

target_link_libraries(rte PUBLIC rtekernels)
install(TARGETS rte EXPORT rte-rrtmgp-targets)
6 changes: 1 addition & 5 deletions rte-kernels/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,4 @@ target_compile_definitions(
$<$<BOOL:${RTE_USE_C_BOOL}>:RTE_USE_CBOOL>
)

target_include_directories(
rtekernels
PUBLIC
$<BUILD_INTERFACE:$<$<COMPILE_LANGUAGE:Fortran>:${CMAKE_Fortran_MODULE_DIRECTORY}>>
)
target_include_directories(rtekernels PRIVATE ${CMAKE_Fortran_MODULE_DIRECTORY})
Loading