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

Update src/CMakeLists.txt: use modern cmake features to install Fortran modules in the correct place #653

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
33 changes: 8 additions & 25 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,29 +1,12 @@
include(GNUInstallDirs)

#------------------------------------------------------------------------------
# Set the sources
set(SOURCES_F90
ccpp_types.F90
)

# Generate list of Fortran modules from defined sources
foreach(source_f90 ${SOURCES_F90})
string(REGEX REPLACE ".F90" ".mod" module_f90 ${source_f90})
list(APPEND MODULES_F90 ${CMAKE_CURRENT_BINARY_DIR}/${module_f90})
endforeach()

#------------------------------------------------------------------------------
# Add the toplevel source directory to our include directoies (for .h)
include_directories(${CMAKE_CURRENT_SOURCE_DIR})

# Add the toplevel binary directory to our include directoies (for .mod)
include_directories(${CMAKE_CURRENT_BINARY_DIR})

# Set a cached variable containing the includes, so schemes can use them
set(${PACKAGE}_INCLUDE_DIRS
"${CMAKE_CURRENT_SOURCE_DIR}$<SEMICOLON>${CMAKE_CURRENT_BINARY_DIR}"
CACHE FILEPATH "${PACKAGE} include directories")
set(${PACKAGE}_LIB_DIRS
"${CMAKE_CURRENT_BINARY_DIR}"
CACHE FILEPATH "${PACKAGE} library directories")
set(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_INCLUDEDIR})

#------------------------------------------------------------------------------
# Define the executable and what to link
@@ -37,16 +20,17 @@ set_target_properties(ccpp_framework PROPERTIES VERSION ${PROJECT_VERSION}
# Installation
#
target_include_directories(ccpp_framework PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
$<INSTALL_INTERFACE:include>
INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_INCLUDEDIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)


# Define where to install the library
install(TARGETS ccpp_framework
EXPORT ccpp_framework-targets
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION lib
RUNTIME DESTINATION bin
)

# Export our configuration
@@ -55,5 +39,4 @@ install(EXPORT ccpp_framework-targets
DESTINATION lib/cmake
)

# Define where to install the Fortran modules
install(FILES ${MODULES_F90} DESTINATION include)
install(DIRECTORY ${CMAKE_Fortran_MODULE_DIRECTORY}/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})