From 58e408dd80a09fb536d55476c9f2222c0c9252b2 Mon Sep 17 00:00:00 2001 From: Martin Stump <martin.stump@mercedes-benz.com> Date: Mon, 19 Dec 2022 09:17:16 +0100 Subject: [PATCH] Add compile_commands.json entries for headers * Add headers to the HEADERS file set * Verify the HEADERS file set * This property will generate a translation unit for each header and check if it can be compiled * This in turn will generate entries for these translation units * Raise minimum CMake version to 3.24.0 for property VERIFY_INTERFACE_HEADER_SETS Signed-off-by: Martin Stump <martin.stump@mercedes-benz.com> --- .cmake-format | 14 ++++++++------ CMakeLists.txt | 25 ++++++++++++++++--------- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/.cmake-format b/.cmake-format index 1fbbb02..ac81022 100644 --- a/.cmake-format +++ b/.cmake-format @@ -47,13 +47,15 @@ additional_commands: PROPERTIES: "*" TEST_LIST: "*" DISCOVERY_TIMEOUT: "*" - setup_target_for_coverage_gcovr_html: + target_sources: + pargs: 1 kwargs: - BASE_DIRECTORY: "*" - EXCLUDE: "*" - EXECUTABLE: "*" - EXECUTABLE_ARGS: "*" - DEPENDENCIES: "*" + INTERFACE: + kwargs: + FILE_SET: 1 + TYPE: 1 + BASE_DIRS: "*" + FILES: "*" always_wrap: [] enable_sort: true autosort: false diff --git a/CMakeLists.txt b/CMakeLists.txt index edc325c..fe89f12 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,7 @@ # SPDX-License-Identifier: EPL-2.0 ################################################################################ -cmake_minimum_required(VERSION 3.15.0 FATAL_ERROR) +cmake_minimum_required(VERSION 3.24.0 FATAL_ERROR) # Add the custom CMake modules to CMake's module path list(PREPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake") @@ -75,12 +75,6 @@ CPMAddPackage( ) # Add library -file( - GLOB_RECURSE HEADERS - RELATIVE ${PROJECT_SOURCE_DIR}/include - CONFIGURE_DEPENDS "*.h" -) - add_library(MantleAPI INTERFACE) add_library(MantleAPI::MantleAPI ALIAS MantleAPI) @@ -95,6 +89,16 @@ target_include_directories( target_compile_features(MantleAPI INTERFACE cxx_std_17) +file(GLOB_RECURSE HEADERS CONFIGURE_DEPENDS "include/**/*.h") +target_sources( + MantleAPI + INTERFACE FILE_SET HEADERS + TYPE HEADERS + BASE_DIRS $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include> + FILES ${HEADERS} +) +set_target_properties(MantleAPI PROPERTIES VERIFY_INTERFACE_HEADER_SETS ON) + # Configure export include(CMakePackageConfigHelpers) configure_package_config_file( @@ -111,8 +115,11 @@ write_basic_package_version_file( # Configure install if(MantleAPI_INSTALL) - install(DIRECTORY include/ TYPE INCLUDE) - install(TARGETS MantleAPI EXPORT MantleAPITargets) + install( + TARGETS MantleAPI + EXPORT MantleAPITargets + FILE_SET HEADERS + ) install( EXPORT MantleAPITargets -- GitLab