diff options
author | Kyle Edwards <kyle.edwards@kitware.com> | 2022-08-02 14:48:00 (GMT) |
---|---|---|
committer | Kyle Edwards <kyle.edwards@kitware.com> | 2022-08-03 12:19:08 (GMT) |
commit | 83e44002aeee2e6d147bf5bbd185137c32ff04ce (patch) | |
tree | 510e1d6fed0ccc1cf153a05e878fd46f1b36e88a | |
parent | e18fb0c73edf2c392ab6f86b4bdeebc28a7ec80d (diff) | |
download | CMake-83e44002aeee2e6d147bf5bbd185137c32ff04ce.zip CMake-83e44002aeee2e6d147bf5bbd185137c32ff04ce.tar.gz CMake-83e44002aeee2e6d147bf5bbd185137c32ff04ce.tar.bz2 |
VERIFY_INTERFACE_HEADER_SETS: Add verification target for all
Fixes: #23802
10 files changed, 58 insertions, 0 deletions
diff --git a/Help/prop_tgt/VERIFY_INTERFACE_HEADER_SETS.rst b/Help/prop_tgt/VERIFY_INTERFACE_HEADER_SETS.rst index da461a7..dd415c8 100644 --- a/Help/prop_tgt/VERIFY_INTERFACE_HEADER_SETS.rst +++ b/Help/prop_tgt/VERIFY_INTERFACE_HEADER_SETS.rst @@ -26,6 +26,10 @@ Otherwise, if C++ is enabled globally, the header is compiled as C++. Otherwise, if C is enabled globally, the header is compiled as C. Otherwise, the header file is not compiled. +If any verification targets are created, a top-level target called +``all_verify_interface_header_sets`` is created which depends on all +verification targets. + This property is initialized by the value of the :variable:`CMAKE_VERIFY_INTERFACE_HEADER_SETS` variable if it is set when a target is created. diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 3bb8671..0c351ad 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -8535,6 +8535,9 @@ bool cmGeneratorTarget::AddHeaderSetVerification() } cmTarget* verifyTarget = nullptr; + cmTarget* allVerifyTarget = + this->GlobalGenerator->GetMakefiles().front()->FindTargetToUse( + "all_verify_interface_header_sets", true); auto interfaceFileSetEntries = this->Target->GetInterfaceHeaderSetsEntries(); @@ -8622,6 +8625,15 @@ bool cmGeneratorTarget::AddHeaderSetVerification() verifyTarget->FinalizeTargetCompileInfo( this->Makefile->GetCompileDefinitionsEntries(), perConfigCompileDefinitions); + + if (!allVerifyTarget) { + allVerifyTarget = this->GlobalGenerator->GetMakefiles() + .front() + ->AddNewUtilityTarget( + "all_verify_interface_header_sets", true); + } + + allVerifyTarget->AddUtility(verifyTarget->GetName(), false); } if (fileCgesContextSensitive) { diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index edc4118..4feae6d 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -1758,6 +1758,14 @@ bool cmGlobalGenerator::AddHeaderSetVerification() } } + cmTarget* allVerifyTarget = this->Makefiles.front()->FindTargetToUse( + "all_verify_interface_header_sets", true); + if (allVerifyTarget) { + this->LocalGenerators.front()->AddGeneratorTarget( + cm::make_unique<cmGeneratorTarget>(allVerifyTarget, + this->LocalGenerators.front().get())); + } + return true; } diff --git a/Tests/RunCMake/VerifyHeaderSets/AllVerifyInterfaceHeaderSets-all_verify_interface_header_sets-Debug-build-check.cmake b/Tests/RunCMake/VerifyHeaderSets/AllVerifyInterfaceHeaderSets-all_verify_interface_header_sets-Debug-build-check.cmake new file mode 100644 index 0000000..d5a513a --- /dev/null +++ b/Tests/RunCMake/VerifyHeaderSets/AllVerifyInterfaceHeaderSets-all_verify_interface_header_sets-Debug-build-check.cmake @@ -0,0 +1,10 @@ +# A custom command is used to copy the header file from the source directory to +# the binary directory. If the verification target was built, the custom +# command should have been executed, and the file should be present in the +# binary directory. +if(NOT EXISTS "${RunCMake_TEST_BINARY_DIR}/dir1/lib1.h") + string(APPEND RunCMake_TEST_FAILED "${RunCMake_TEST_BINARY_DIR}/dir1/lib1.h should exist but it does not\n") +endif() +if(NOT EXISTS "${RunCMake_TEST_BINARY_DIR}/dir2/lib2.h") + string(APPEND RunCMake_TEST_FAILED "${RunCMake_TEST_BINARY_DIR}/dir2/lib2.h should exist but it does not\n") +endif() diff --git a/Tests/RunCMake/VerifyHeaderSets/AllVerifyInterfaceHeaderSets.cmake b/Tests/RunCMake/VerifyHeaderSets/AllVerifyInterfaceHeaderSets.cmake new file mode 100644 index 0000000..8948bac --- /dev/null +++ b/Tests/RunCMake/VerifyHeaderSets/AllVerifyInterfaceHeaderSets.cmake @@ -0,0 +1,4 @@ +enable_language(C) + +add_subdirectory(dir1) +add_subdirectory(dir2) diff --git a/Tests/RunCMake/VerifyHeaderSets/RunCMakeTest.cmake b/Tests/RunCMake/VerifyHeaderSets/RunCMakeTest.cmake index 9f9a1e7..b4fe720 100644 --- a/Tests/RunCMake/VerifyHeaderSets/RunCMakeTest.cmake +++ b/Tests/RunCMake/VerifyHeaderSets/RunCMakeTest.cmake @@ -44,5 +44,11 @@ run_cmake_build(VerifyHeaderSets interface_lang_test_cxx_verify_interface_header run_cmake_build(VerifyHeaderSets list_verify_interface_header_sets) set(RunCMake_TEST_OPTIONS -DCMAKE_VERIFY_INTERFACE_HEADER_SETS=ON) +run_cmake(AllVerifyInterfaceHeaderSets) +unset(RunCMake_TEST_OPTIONS) + +run_cmake_build(AllVerifyInterfaceHeaderSets all_verify_interface_header_sets) + +set(RunCMake_TEST_OPTIONS -DCMAKE_VERIFY_INTERFACE_HEADER_SETS=ON) run_cmake(VerifyHeaderSetsNonexistent) unset(RunCMake_TEST_OPTIONS) diff --git a/Tests/RunCMake/VerifyHeaderSets/dir1/CMakeLists.txt b/Tests/RunCMake/VerifyHeaderSets/dir1/CMakeLists.txt new file mode 100644 index 0000000..d26e933 --- /dev/null +++ b/Tests/RunCMake/VerifyHeaderSets/dir1/CMakeLists.txt @@ -0,0 +1,3 @@ +add_library(lib1 STATIC ../lib.c) +add_custom_command(OUTPUT lib1.h COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/lib1.h lib1.h) +target_sources(lib1 PUBLIC FILE_SET HEADERS BASE_DIRS ${CMAKE_CURRENT_BINARY_DIR} FILES ${CMAKE_CURRENT_BINARY_DIR}/lib1.h) diff --git a/Tests/RunCMake/VerifyHeaderSets/dir1/lib1.h b/Tests/RunCMake/VerifyHeaderSets/dir1/lib1.h new file mode 100644 index 0000000..69c37ed --- /dev/null +++ b/Tests/RunCMake/VerifyHeaderSets/dir1/lib1.h @@ -0,0 +1,4 @@ +#ifdef _WIN32 +__declspec(dllimport) +#endif + extern void lib1(void); diff --git a/Tests/RunCMake/VerifyHeaderSets/dir2/CMakeLists.txt b/Tests/RunCMake/VerifyHeaderSets/dir2/CMakeLists.txt new file mode 100644 index 0000000..8c3658c --- /dev/null +++ b/Tests/RunCMake/VerifyHeaderSets/dir2/CMakeLists.txt @@ -0,0 +1,3 @@ +add_library(lib2 STATIC ../lib.c) +add_custom_command(OUTPUT lib2.h COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/lib2.h lib2.h) +target_sources(lib2 PUBLIC FILE_SET HEADERS BASE_DIRS ${CMAKE_CURRENT_BINARY_DIR} FILES ${CMAKE_CURRENT_BINARY_DIR}/lib2.h) diff --git a/Tests/RunCMake/VerifyHeaderSets/dir2/lib2.h b/Tests/RunCMake/VerifyHeaderSets/dir2/lib2.h new file mode 100644 index 0000000..fa24a9a --- /dev/null +++ b/Tests/RunCMake/VerifyHeaderSets/dir2/lib2.h @@ -0,0 +1,4 @@ +#ifdef _WIN32 +__declspec(dllimport) +#endif + extern void lib2(void); |