From f779f8c0ad4c16cda5a166d440915a01e986d396 Mon Sep 17 00:00:00 2001 From: Kyle Edwards Date: Wed, 6 Apr 2022 16:40:34 -0400 Subject: FILE_SET: Forbid adding header sets to Apple FRAMEWORK libraries The feature needs a specialized implementation to place headers in the right place inside frameworks. To avoid silently doing the wrong thing, make this case an error for the 3.23 series. Issue: #23386 --- Help/command/target_sources.rst | 2 +- Help/release/3.23.rst | 14 ++++++++++++++ Source/cmTargetSourcesCommand.cxx | 4 ++++ Tests/RunCMake/target_sources/FileSetFramework-result.txt | 1 + Tests/RunCMake/target_sources/FileSetFramework-stderr.txt | 4 ++++ Tests/RunCMake/target_sources/FileSetFramework.cmake | 7 +++++++ Tests/RunCMake/target_sources/RunCMakeTest.cmake | 3 +++ 7 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 Tests/RunCMake/target_sources/FileSetFramework-result.txt create mode 100644 Tests/RunCMake/target_sources/FileSetFramework-stderr.txt create mode 100644 Tests/RunCMake/target_sources/FileSetFramework.cmake diff --git a/Help/command/target_sources.rst b/Help/command/target_sources.rst index 6ad86e3..1ad6c37 100644 --- a/Help/command/target_sources.rst +++ b/Help/command/target_sources.rst @@ -77,7 +77,7 @@ have zero or more named file sets. Each file set has a name, a type, a scope of ``INTERFACE``, ``PUBLIC``, or ``PRIVATE``, one or more base directories, and files within those directories. The only acceptable type is ``HEADERS``. The optional default file sets are named after their type. The target may not be a -custom target. +custom target or :prop_tgt:`FRAMEWORK` target. Files in a ``PRIVATE`` or ``PUBLIC`` file set are marked as source files for the purposes of IDE integration. Additionally, files in ``HEADERS`` file sets diff --git a/Help/release/3.23.rst b/Help/release/3.23.rst index 1a3f53e..257c3d5 100644 --- a/Help/release/3.23.rst +++ b/Help/release/3.23.rst @@ -264,3 +264,17 @@ Other Changes * :manual:`ccmake(1)` may now be enabled on Windows when building CMake from source. This is experimental, and so is not included in official distributions. + +Updates +======= + +Changes made since CMake 3.23.0 include the following. + +3.23.1 +------ + +* The :command:`target_sources` ``FILE_SET`` feature added in CMake 3.23.0 + does not yet place header files properly in Apple :prop_tgt:`FRAMEWORK` + targets. Pending further work in a future version of CMake, it is now + an error to add a ``FILE_SET`` of type ``HEADERS`` to such targets on + Apple platforms. diff --git a/Source/cmTargetSourcesCommand.cxx b/Source/cmTargetSourcesCommand.cxx index 43a9b3a..9173a34 100644 --- a/Source/cmTargetSourcesCommand.cxx +++ b/Source/cmTargetSourcesCommand.cxx @@ -230,6 +230,10 @@ bool TargetSourcesImpl::HandleOneFileSet( this->SetError("FILE_SETs may not be added to custom targets"); return false; } + if (this->Target->IsFrameworkOnApple()) { + this->SetError("FILE_SETs may not be added to FRAMEWORK targets"); + return false; + } bool const isDefault = args.Type == args.FileSet || (args.Type.empty() && args.FileSet[0] >= 'A' && args.FileSet[0] <= 'Z'); diff --git a/Tests/RunCMake/target_sources/FileSetFramework-result.txt b/Tests/RunCMake/target_sources/FileSetFramework-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/target_sources/FileSetFramework-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/target_sources/FileSetFramework-stderr.txt b/Tests/RunCMake/target_sources/FileSetFramework-stderr.txt new file mode 100644 index 0000000..ae7026a --- /dev/null +++ b/Tests/RunCMake/target_sources/FileSetFramework-stderr.txt @@ -0,0 +1,4 @@ +^CMake Error at FileSetFramework\.cmake:[0-9]+ \(target_sources\): + target_sources FILE_SETs may not be added to FRAMEWORK targets +Call Stack \(most recent call first\): + CMakeLists\.txt:[0-9]+ \(include\)$ diff --git a/Tests/RunCMake/target_sources/FileSetFramework.cmake b/Tests/RunCMake/target_sources/FileSetFramework.cmake new file mode 100644 index 0000000..d8a924f --- /dev/null +++ b/Tests/RunCMake/target_sources/FileSetFramework.cmake @@ -0,0 +1,7 @@ +enable_language(C) + +add_library(lib1 SHARED lib1.c) +set_property(TARGET lib1 PROPERTY FRAMEWORK ON) +target_sources(lib1 + PUBLIC FILE_SET HEADERS BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR} FILES h1.h + ) diff --git a/Tests/RunCMake/target_sources/RunCMakeTest.cmake b/Tests/RunCMake/target_sources/RunCMakeTest.cmake index d23bce1..743879e 100644 --- a/Tests/RunCMake/target_sources/RunCMakeTest.cmake +++ b/Tests/RunCMake/target_sources/RunCMakeTest.cmake @@ -40,6 +40,9 @@ run_cmake(FileSetNoExistInstall) run_cmake(FileSetDirectories) run_cmake(FileSetCustomTarget) run_cmake(FileSetBadName) +if(APPLE) + run_cmake(FileSetFramework) +endif() set(RunCMake_TEST_OPTIONS -DCMAKE_POLICY_DEFAULT_CMP0115=NEW) run_cmake(FileSetFileNoExist) -- cgit v0.12