Merge topic 'all-verify-interface-header-sets'

83e44002ae VERIFY_INTERFACE_HEADER_SETS: Add verification target for all

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !7536
This commit is contained in:
Kyle Edwards 2022-08-03 13:58:34 +00:00 committed by Kitware Robot
commit e7bfd0ac7a
10 changed files with 58 additions and 0 deletions

View File

@ -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.

View File

@ -8579,6 +8579,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();
@ -8666,6 +8669,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) {

View File

@ -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;
}

View File

@ -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()

View File

@ -0,0 +1,4 @@
enable_language(C)
add_subdirectory(dir1)
add_subdirectory(dir2)

View File

@ -43,6 +43,12 @@ run_cmake_build(VerifyHeaderSets lang_test_cxx_verify_interface_header_sets)
run_cmake_build(VerifyHeaderSets interface_lang_test_cxx_verify_interface_header_sets)
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)

View File

@ -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)

View File

@ -0,0 +1,4 @@
#ifdef _WIN32
__declspec(dllimport)
#endif
extern void lib1(void);

View File

@ -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)

View File

@ -0,0 +1,4 @@
#ifdef _WIN32
__declspec(dllimport)
#endif
extern void lib2(void);