summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKyle Edwards <kyle.edwards@kitware.com>2022-04-13 14:12:35 (GMT)
committerBrad King <brad.king@kitware.com>2022-04-14 13:17:54 (GMT)
commitd0d09aa29fa354bc13a925655c0d191bbadd4c6a (patch)
tree7edfc176da81146fd401e52a66675323559bea09
parentefe08e289466683b0945a5396f6848064dec5ae0 (diff)
downloadCMake-d0d09aa29fa354bc13a925655c0d191bbadd4c6a.zip
CMake-d0d09aa29fa354bc13a925655c0d191bbadd4c6a.tar.gz
CMake-d0d09aa29fa354bc13a925655c0d191bbadd4c6a.tar.bz2
FILE_SET: Make INTERFACE libraries with HEADER_SETS participate in buildsystem
If an INTERFACE library has HEADER_SETS, and its header sets contain files generated by a custom command, the library needs to participate in the buildsystem so that the files will be generated. Fixes: #23422
-rw-r--r--Help/command/add_library.rst1
-rw-r--r--Source/cmGeneratorTarget.cxx6
-rw-r--r--Tests/RunCMake/target_sources/FileSetGeneratedDependency.cmake12
-rw-r--r--Tests/RunCMake/target_sources/FileSetGeneratedDependency.h.in1
-rw-r--r--Tests/RunCMake/target_sources/RunCMakeTest.cmake9
-rw-r--r--Tests/RunCMake/target_sources/dependency.c6
6 files changed, 33 insertions, 2 deletions
diff --git a/Help/command/add_library.rst b/Help/command/add_library.rst
index 1235155..7dc4365 100644
--- a/Help/command/add_library.rst
+++ b/Help/command/add_library.rst
@@ -151,6 +151,7 @@ itself and is not included as a target in the generated buildsystem.
``PUBLIC`` keywords.
If an interface library has source files (i.e. the :prop_tgt:`SOURCES`
+ target property is set), or header sets (i.e. the :prop_tgt:`HEADER_SETS`
target property is set), it will appear in the generated buildsystem
as a build target much like a target defined by the
:command:`add_custom_target` command. It does not compile any sources,
diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx
index a8bc91c..fec4679 100644
--- a/Source/cmGeneratorTarget.cxx
+++ b/Source/cmGeneratorTarget.cxx
@@ -1208,8 +1208,10 @@ bool cmGeneratorTarget::IsInBuildSystem() const
case cmStateEnums::GLOBAL_TARGET:
return true;
case cmStateEnums::INTERFACE_LIBRARY:
- // An INTERFACE library is in the build system if it has SOURCES.
- if (!this->SourceEntries.empty()) {
+ // An INTERFACE library is in the build system if it has SOURCES or
+ // HEADER_SETS.
+ if (!this->SourceEntries.empty() ||
+ !this->Target->GetHeaderSetsEntries().empty()) {
return true;
}
break;
diff --git a/Tests/RunCMake/target_sources/FileSetGeneratedDependency.cmake b/Tests/RunCMake/target_sources/FileSetGeneratedDependency.cmake
new file mode 100644
index 0000000..9e91929
--- /dev/null
+++ b/Tests/RunCMake/target_sources/FileSetGeneratedDependency.cmake
@@ -0,0 +1,12 @@
+enable_language(C)
+
+add_library(lib INTERFACE)
+add_custom_command(
+ OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/dependency.h
+ COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/FileSetGeneratedDependency.h.in ${CMAKE_CURRENT_BINARY_DIR}/dependency.h
+ VERBATIM
+ )
+target_sources(lib PUBLIC FILE_SET HEADERS BASE_DIRS ${CMAKE_CURRENT_BINARY_DIR} FILES ${CMAKE_CURRENT_BINARY_DIR}/dependency.h)
+
+add_executable(exe dependency.c)
+target_link_libraries(exe PRIVATE lib)
diff --git a/Tests/RunCMake/target_sources/FileSetGeneratedDependency.h.in b/Tests/RunCMake/target_sources/FileSetGeneratedDependency.h.in
new file mode 100644
index 0000000..40a8c17
--- /dev/null
+++ b/Tests/RunCMake/target_sources/FileSetGeneratedDependency.h.in
@@ -0,0 +1 @@
+/* empty */
diff --git a/Tests/RunCMake/target_sources/RunCMakeTest.cmake b/Tests/RunCMake/target_sources/RunCMakeTest.cmake
index 8429c96..e78ee9d 100644
--- a/Tests/RunCMake/target_sources/RunCMakeTest.cmake
+++ b/Tests/RunCMake/target_sources/RunCMakeTest.cmake
@@ -43,6 +43,15 @@ if(APPLE)
run_cmake(FileSetFramework)
endif()
+set(RunCMake_TEST_NO_CLEAN 1)
+set(RunCMake_TEST_BINARY_DIR "${RunCMake_BINARY_DIR}/FileSetGeneratedDependency-build")
+file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
+file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
+run_cmake(FileSetGeneratedDependency)
+run_cmake_command(FileSetGeneratedDependency-build ${CMAKE_COMMAND} --build . --config Debug)
+unset(RunCMake_TEST_BINARY_DIR)
+unset(RunCMake_TEST_NO_CLEAN)
+
set(RunCMake_TEST_OPTIONS -DCMAKE_POLICY_DEFAULT_CMP0115=NEW)
run_cmake(FileSetFileNoExist)
unset(RunCMake_TEST_OPTIONS)
diff --git a/Tests/RunCMake/target_sources/dependency.c b/Tests/RunCMake/target_sources/dependency.c
new file mode 100644
index 0000000..2f2dd25
--- /dev/null
+++ b/Tests/RunCMake/target_sources/dependency.c
@@ -0,0 +1,6 @@
+#include <dependency.h>
+
+int main(void)
+{
+ return 0;
+}