Browse Source

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
Kyle Edwards 3 years ago
parent
commit
f779f8c0ad

+ 1 - 1
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

+ 14 - 0
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.

+ 4 - 0
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');

+ 1 - 0
Tests/RunCMake/target_sources/FileSetFramework-result.txt

@@ -0,0 +1 @@
+1

+ 4 - 0
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\)$

+ 7 - 0
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
+  )

+ 3 - 0
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)