Skip to content

Commit aff7ae5

Browse files
aminyaClausKlein
andcommitted
fix: use absolute path for include_dir due to nested CMakeLists
Co-Authored-By: Claus Klein <1833050+ClausKlein@users.noreply.github.com>
1 parent acd68ab commit aff7ae5

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

my_header_lib/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ add_library(my_header_lib INTERFACE)
22
target_link_libraries(my_header_lib INTERFACE project_options project_warnings) # link project_options/warnings
33

44
# Includes
5-
set(my_header_lib_INCLUDE_DIR "./include" CACHE STRING "") # must be relative paths
5+
set(my_header_lib_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include" CACHE STRING "") # must be relative paths
66
target_include_directories(
7-
my_header_lib INTERFACE "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/${my_header_lib_INCLUDE_DIR}>"
7+
my_header_lib INTERFACE "$<BUILD_INTERFACE:${my_header_lib_INCLUDE_DIR}>"
88
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")
99

1010
# Find dependencies:

my_lib/CMakeLists.txt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@ add_library(my_lib "./src/my_lib/lib.cpp")
22
target_link_libraries(my_lib PRIVATE project_options project_warnings) # link project_options/warnings
33

44
# Includes
5-
set(my_lib_INCLUDE_DIR "include" CACHE STRING "") # must be relative paths
6-
target_include_directories(my_lib PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/${my_lib_INCLUDE_DIR}>"
5+
set(my_lib_INCLUDE_DIR
6+
"${CMAKE_CURRENT_SOURCE_DIR}/include"
7+
CACHE STRING "")
8+
target_include_directories(my_lib PUBLIC "$<BUILD_INTERFACE:${my_lib_INCLUDE_DIR}>"
79
"$<INSTALL_INTERFACE:./${CMAKE_INSTALL_INCLUDEDIR}>")
810

911
# Find dependencies:
10-
set(my_lib_DEPENDENCIES_CONFIGURED fmt CACHE STRING "")
12+
set(my_lib_DEPENDENCIES_CONFIGURED
13+
fmt
14+
CACHE STRING "")
1115

1216
foreach(DEPENDENCY ${my_lib_DEPENDENCIES_CONFIGURED})
1317
find_package(${DEPENDENCY} CONFIG REQUIRED)

0 commit comments

Comments
 (0)