From 6156206447fbb1ff96c4daa9bcb987478b7a6b0c Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Thu, 25 Aug 2022 21:00:18 +0200 Subject: [PATCH 1/4] add support for FILE_SET HEADERS --- CMakeLists.txt | 6 ++++++ test/CMakeLists.txt | 3 ++- test/dependency/CMakeLists.txt | 2 +- test/namespaced_dependency/CMakeLists.txt | 12 +++++++++++- .../source/namespaced_dependency.cpp | 2 ++ test/transitive_dependency/CMakeLists.txt | 11 ++++++++++- test/transitive_dependency/cmake/CPM.cmake | 2 +- 7 files changed, 33 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f2e27d1..cd2fba6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 @@ -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" diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index f573dbe..586a098 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -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) @@ -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) diff --git a/test/dependency/CMakeLists.txt b/test/dependency/CMakeLists.txt index f321b8f..a441de8 100644 --- a/test/dependency/CMakeLists.txt +++ b/test/dependency/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.14...3.22) +cmake_minimum_required(VERSION 3.14...3.24) project( dependency diff --git a/test/namespaced_dependency/CMakeLists.txt b/test/namespaced_dependency/CMakeLists.txt index cb6cc5b..e8b2a60 100644 --- a/test/namespaced_dependency/CMakeLists.txt +++ b/test/namespaced_dependency/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.14...3.22) +cmake_minimum_required(VERSION 3.14...3.24) project( namespaced_dependency @@ -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() + # the alias ${PROJECT_NAMESPACE}::${PROJECT_NAME} is automatically provided by PackageProject.cmake # if we use the `NAMESPACE` parameter diff --git a/test/namespaced_dependency/source/namespaced_dependency.cpp b/test/namespaced_dependency/source/namespaced_dependency.cpp index 93ae1cb..1b3a397 100644 --- a/test/namespaced_dependency/source/namespaced_dependency.cpp +++ b/test/namespaced_dependency/source/namespaced_dependency.cpp @@ -1,3 +1,5 @@ +#include + #include #include diff --git a/test/transitive_dependency/CMakeLists.txt b/test/transitive_dependency/CMakeLists.txt index 21ab90d..65d9d12 100644 --- a/test/transitive_dependency/CMakeLists.txt +++ b/test/transitive_dependency/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.14...3.22) +cmake_minimum_required(VERSION 3.14...3.24) project( transitive_dependency @@ -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 + ) +endif() + target_include_directories( transitive_dependency PUBLIC $ $ diff --git a/test/transitive_dependency/cmake/CPM.cmake b/test/transitive_dependency/cmake/CPM.cmake index bc06845..b2f22fc 100644 --- a/test/transitive_dependency/cmake/CPM.cmake +++ b/test/transitive_dependency/cmake/CPM.cmake @@ -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 (~) From 9f2861cb9b8c49cd0572819a11f0fce022b1faec Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Thu, 25 Aug 2022 21:09:34 +0200 Subject: [PATCH 2/4] fix clang-format --- test/namespaced_dependency/source/namespaced_dependency.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/test/namespaced_dependency/source/namespaced_dependency.cpp b/test/namespaced_dependency/source/namespaced_dependency.cpp index 1b3a397..d022d90 100644 --- a/test/namespaced_dependency/source/namespaced_dependency.cpp +++ b/test/namespaced_dependency/source/namespaced_dependency.cpp @@ -1,5 +1,4 @@ #include - #include #include From 832d90951dd7b76430f43814287ec50914d0e0ba Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Tue, 20 Sep 2022 23:04:19 +0200 Subject: [PATCH 3/4] show the problem --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cd2fba6..d598aad 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -138,7 +138,7 @@ function(packageProject) PUBLIC_HEADER DESTINATION ${PROJECT_INCLUDE_DESTINATION} COMPONENT "${PROJECT_NAME}_Development" INCLUDES DESTINATION "${PROJECT_INCLUDE_DESTINATION}" - ${FILE_SET_ARGS} + # TODO ${FILE_SET_ARGS} ) set("${PROJECT_NAME}_INSTALL_CMAKEDIR" From 43ff42c85e6979830293d8da7ddfd3eb97357d80 Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Sat, 22 Oct 2022 10:47:27 +0200 Subject: [PATCH 4/4] revert my demo failure --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d598aad..83194fa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -119,7 +119,6 @@ function(packageProject) ) if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.23.0") - # required in CMake 3.23 and more set(FILE_SET_ARGS "FILE_SET" "HEADERS") endif() @@ -138,7 +137,8 @@ function(packageProject) PUBLIC_HEADER DESTINATION ${PROJECT_INCLUDE_DESTINATION} COMPONENT "${PROJECT_NAME}_Development" INCLUDES DESTINATION "${PROJECT_INCLUDE_DESTINATION}" - # TODO ${FILE_SET_ARGS} + # NOTE: this may be only required in CMake 3.23 and more: + ${FILE_SET_ARGS} ) set("${PROJECT_NAME}_INSTALL_CMAKEDIR"