Skip to content

Commit

Permalink
Use include target everywhere to get include location
Browse files Browse the repository at this point in the history
  • Loading branch information
aradi committed Aug 9, 2024
1 parent a2d1abf commit 8385cc2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 17 deletions.
17 changes: 1 addition & 16 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ fortuno_setup_build_type("RelWithDebInfo")
# Main definition #
]=================================================================================================]

add_subdirectory(include)
add_subdirectory(src)
if (FORTUNO_BUILD_EXAMPLES)
add_subdirectory(example)
Expand Down Expand Up @@ -143,22 +144,6 @@ if (FORTUNO_INSTALL)
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Fortuno
COMPONENT Fortuno_development
)
install(
FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/fortuno.fypp
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
COMPONENT Fortuno_development
)
# introduce fake target with information about the folder containing the include file
add_library(fortuno_include_dir INTERFACE)
target_include_directories(
fortuno_include_dir INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
install(
TARGETS fortuno_include_dir
EXPORT FortunoTargets
)

endif ()

Expand Down
4 changes: 3 additions & 1 deletion example/fypp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ set(
parametrized_fypp_tests.fypp
simple_fypp_tests.fypp
)

get_target_property(_fortuno_incdir Fortuno::fortuno_include_dir INTERFACE_INCLUDE_DIRECTORIES)
fortuno_preprocess(
${FYPP} "-I${CMAKE_SOURCE_DIR}/include;--file-var-root=${CMAKE_SOURCE_DIR}"
${FYPP} "-I${_fortuno_incdir};--file-var-root=${CMAKE_SOURCE_DIR}"
.fypp .f90
"${fypp-sources}" fypp-f90-sources
)
Expand Down
25 changes: 25 additions & 0 deletions include/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# This file is part of Fortuno.
# Licensed under the BSD-2-Clause Plus Patent license.
# SPDX-License-Identifier: BSD-2-Clause-Patent

# Introduce a fake target associated with the location of the folder containing the include file.
# Query the INTERFACE_INCLUDE_DIRECTORIES of the target to obtain the include folder location.
add_library(fortuno_include_dir INTERFACE)
target_include_directories(
fortuno_include_dir INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
add_library(Fortuno::fortuno_include_dir ALIAS fortuno_include_dir)

if (FORTUNO_INSTALL)
install(
FILES fortuno.fypp
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
COMPONENT Fortuno_development
)
install(
TARGETS fortuno_include_dir
EXPORT FortunoTargets
)
endif ()

0 comments on commit 8385cc2

Please sign in to comment.