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

add support for FILE_SET HEADERS #31

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ function(packageProject)
COMPATIBILITY ${PROJECT_COMPATIBILITY} ${wbpvf_extra_args}
)

if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.23.0")
# required in CMake 3.23 and more
set(FILE_SET_ARGS "FILE_SET" "HEADERS")
endif()

install(
TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}Targets
Expand All @@ -133,6 +138,7 @@ function(packageProject)
PUBLIC_HEADER DESTINATION ${PROJECT_INCLUDE_DESTINATION} COMPONENT "${PROJECT_NAME}_Development"
INCLUDES
DESTINATION "${PROJECT_INCLUDE_DESTINATION}"
${FILE_SET_ARGS}
)

set("${PROJECT_NAME}_INSTALL_CMAKEDIR"
Expand Down
3 changes: 2 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.14...3.22)
cmake_minimum_required(VERSION 3.14...3.24)

option(TEST_INSTALLED_VERSION "Test the version found by find_package" OFF)

Expand All @@ -13,6 +13,7 @@ if(TEST_INSTALLED_VERSION)
find_package(namespaced_dependency 4.5.6 REQUIRED)
find_package(transitive_dependency 7.8.9 REQUIRED)
else()
set(CMAKE_VERIFY_INTERFACE_HEADER_SETS ON)
add_subdirectory(dependency)
add_subdirectory(namespaced_dependency)
add_subdirectory(transitive_dependency)
Expand Down
2 changes: 1 addition & 1 deletion test/dependency/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.14...3.22)
cmake_minimum_required(VERSION 3.14...3.24)

project(
dependency
Expand Down
12 changes: 11 additions & 1 deletion test/namespaced_dependency/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.14...3.22)
cmake_minimum_required(VERSION 3.14...3.24)

project(
namespaced_dependency
Expand All @@ -8,6 +8,16 @@ project(

set(PROJECT_NAMESPACE "ns")
add_library(${PROJECT_NAME} STATIC source/namespaced_dependency.cpp)

if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.23.0")
# required in CMake 3.23 and more
set(CMAKE_VERIFY_INTERFACE_HEADER_SETS ON)
target_sources(
${PROJECT_NAME} PUBLIC FILE_SET HEADERS BASE_DIRS include FILES
include/namespaced_dependency/namespaced_dependency.h
)
endif()
ClausKlein marked this conversation as resolved.
Show resolved Hide resolved

# the alias ${PROJECT_NAMESPACE}::${PROJECT_NAME} is automatically provided by PackageProject.cmake
# if we use the `NAMESPACE` parameter

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <namespaced_dependency/namespaced_dependency.h>
ClausKlein marked this conversation as resolved.
Show resolved Hide resolved
#include <namespaced_dependency/version.h>

#include <iostream>
Expand Down
11 changes: 10 additions & 1 deletion test/transitive_dependency/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.14...3.22)
cmake_minimum_required(VERSION 3.14...3.24)

project(
transitive_dependency
Expand Down Expand Up @@ -30,6 +30,15 @@ add_library(${PROJECT_NAME} SHARED source/transitive_dependency.cpp)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)
target_link_libraries(${PROJECT_NAME} PUBLIC fmt::fmt-header-only cxxopts)

if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.23.0")
# required in CMake 3.23 and more
set(CMAKE_VERIFY_INTERFACE_HEADER_SETS ON)
target_sources(
${PROJECT_NAME} PUBLIC FILE_SET HEADERS BASE_DIRS include FILES
include/transitive_dependency/transitive_dependency.h
ClausKlein marked this conversation as resolved.
Show resolved Hide resolved
)
endif()

target_include_directories(
transitive_dependency PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include/${PROJECT_NAME}-${PROJECT_VERSION}>
Expand Down
2 changes: 1 addition & 1 deletion test/transitive_dependency/cmake/CPM.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
set(CPM_DOWNLOAD_VERSION 0.35.0)
set(CPM_DOWNLOAD_VERSION 0.35.5)

if(CPM_SOURCE_CACHE)
# Expand relative path. This is important if the provided path contains a tilde (~)
Expand Down