summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2021-10-28 13:57:53 (GMT)
committerKitware Robot <kwrobot@kitware.com>2021-10-28 13:58:13 (GMT)
commit51e9d93c9c8f45aeebb5566cace2e0d3d7da2fda (patch)
tree3587b246f886cb40a65a6b413e064c01c1bbd2f4
parenta3791b24c9a84788ae426697c768f5126fab8c75 (diff)
parenta7c71b9f035175def9a3e53ed12112c6bb4862e5 (diff)
downloadCMake-51e9d93c9c8f45aeebb5566cace2e0d3d7da2fda.zip
CMake-51e9d93c9c8f45aeebb5566cace2e0d3d7da2fda.tar.gz
CMake-51e9d93c9c8f45aeebb5566cace2e0d3d7da2fda.tar.bz2
Merge topic 'target-sources-file-set'
a7c71b9f03 Tests: Add tests for target_sources(FILE_SET) and associated functionality 4b0ee4e338 Help: Add documentation for target_sources(FILE_SET) and associated properties 3c3698b0e4 FileAPI: Add information on file set installers 8a09723bff cmGeneratorTarget: Integrate file sets into calculated sources 2a78d47b16 install(EXPORT): Install file sets 9b479124cc install(TARGETS): Add FILE_SET mode d8af2d954f target_sources(): Add FILE_SET mode f2bd022468 cmTargetSources: Refactor to add enum class parameters ... Acked-by: Kitware Robot <kwrobot@kitware.com> Tested-by: buildbot <buildbot@kitware.com> Merge-request: !6653
-rw-r--r--Help/command/install.rst33
-rw-r--r--Help/command/target_sources.rst102
-rw-r--r--Help/manual/cmake-file-api.7.rst46
-rw-r--r--Help/manual/cmake-properties.7.rst6
-rw-r--r--Help/prop_tgt/HEADER_DIRS.rst6
-rw-r--r--Help/prop_tgt/HEADER_DIRS_NAME.rst6
-rw-r--r--Help/prop_tgt/HEADER_SET.rst8
-rw-r--r--Help/prop_tgt/HEADER_SETS.rst6
-rw-r--r--Help/prop_tgt/HEADER_SET_NAME.rst8
-rw-r--r--Help/prop_tgt/INTERFACE_HEADER_SETS.rst7
-rw-r--r--Help/release/dev/target-sources-file-set.rst18
-rw-r--r--Source/CMakeLists.txt4
-rw-r--r--Source/cmExportBuildFileGenerator.cxx19
-rw-r--r--Source/cmExportBuildFileGenerator.h7
-rw-r--r--Source/cmExportFileGenerator.cxx37
-rw-r--r--Source/cmExportFileGenerator.h12
-rw-r--r--Source/cmExportInstallFileGenerator.cxx105
-rw-r--r--Source/cmExportInstallFileGenerator.h6
-rw-r--r--Source/cmExportTryCompileFileGenerator.cxx19
-rw-r--r--Source/cmExportTryCompileFileGenerator.h9
-rw-r--r--Source/cmFileAPI.cxx3
-rw-r--r--Source/cmFileAPICodemodel.cxx49
-rw-r--r--Source/cmFileSet.cxx151
-rw-r--r--Source/cmFileSet.h64
-rw-r--r--Source/cmGeneratorTarget.cxx145
-rw-r--r--Source/cmInstallCommand.cxx156
-rw-r--r--Source/cmInstallCommandArguments.cxx19
-rw-r--r--Source/cmInstallCommandArguments.h16
-rw-r--r--Source/cmInstallFileSetGenerator.cxx88
-rw-r--r--Source/cmInstallFileSetGenerator.h52
-rw-r--r--Source/cmOutputConverter.cxx9
-rw-r--r--Source/cmOutputConverter.h8
-rw-r--r--Source/cmTarget.cxx321
-rw-r--r--Source/cmTarget.h15
-rw-r--r--Source/cmTargetExport.h3
-rw-r--r--Source/cmTargetPropCommandBase.cxx4
-rw-r--r--Source/cmTargetPropCommandBase.h6
-rw-r--r--Source/cmTargetSourcesCommand.cxx238
-rw-r--r--Tests/RunCMake/CommandLine/E_capabilities-stdout.txt2
-rw-r--r--Tests/RunCMake/FileAPI/codemodel-v2-check.py31
-rw-r--r--Tests/RunCMake/FileAPI/codemodel-v2-data/directories/fileset.json203
-rw-r--r--Tests/RunCMake/FileAPI/codemodel-v2-data/directories/top.json29
-rw-r--r--Tests/RunCMake/FileAPI/codemodel-v2-data/projects/codemodel-v2.json7
-rw-r--r--Tests/RunCMake/FileAPI/codemodel-v2-data/targets/all_build_top.json8
-rw-r--r--Tests/RunCMake/FileAPI/codemodel-v2-data/targets/c_headers_1.json231
-rw-r--r--Tests/RunCMake/FileAPI/codemodel-v2-data/targets/c_headers_2.json105
-rw-r--r--Tests/RunCMake/FileAPI/codemodel-v2-data/targets/c_shared_lib.json6
-rw-r--r--Tests/RunCMake/FileAPI/codemodel-v2-data/targets/cxx_exe.json2
-rw-r--r--Tests/RunCMake/FileAPI/codemodel-v2-data/targets/cxx_shared_lib.json6
-rw-r--r--Tests/RunCMake/FileAPI/codemodel-v2.cmake1
-rw-r--r--Tests/RunCMake/FileAPI/fileset/CMakeLists.txt25
-rw-r--r--Tests/RunCMake/FileAPI/fileset/dir/h2.h0
-rw-r--r--Tests/RunCMake/FileAPI/fileset/empty.c0
-rw-r--r--Tests/RunCMake/FileAPI/fileset/error.c1
-rw-r--r--Tests/RunCMake/FileAPI/fileset/h1.h0
-rw-r--r--Tests/RunCMake/FileAPI/fileset/h3.h0
-rw-r--r--Tests/RunCMake/FileAPI/fileset/other.c0
-rw-r--r--Tests/RunCMake/target_sources/FileSetChangeScope-result.txt1
-rw-r--r--Tests/RunCMake/target_sources/FileSetChangeScope-stderr.txt5
-rw-r--r--Tests/RunCMake/target_sources/FileSetChangeScope.cmake5
-rw-r--r--Tests/RunCMake/target_sources/FileSetChangeType-result.txt1
-rw-r--r--Tests/RunCMake/target_sources/FileSetChangeType-stderr.txt5
-rw-r--r--Tests/RunCMake/target_sources/FileSetChangeType.cmake5
-rw-r--r--Tests/RunCMake/target_sources/FileSetDefaultWrongType-result.txt1
-rw-r--r--Tests/RunCMake/target_sources/FileSetDefaultWrongType-stderr.txt4
-rw-r--r--Tests/RunCMake/target_sources/FileSetDefaultWrongType.cmake4
-rw-r--r--Tests/RunCMake/target_sources/FileSetDirectories.cmake4
-rw-r--r--Tests/RunCMake/target_sources/FileSetExport.cmake21
-rw-r--r--Tests/RunCMake/target_sources/FileSetFileNoExist-result.txt1
-rw-r--r--Tests/RunCMake/target_sources/FileSetFileNoExist-stderr.txt10
-rw-r--r--Tests/RunCMake/target_sources/FileSetFileNoExist.cmake4
-rw-r--r--Tests/RunCMake/target_sources/FileSetImport.cmake97
-rw-r--r--Tests/RunCMake/target_sources/FileSetInstallMissingSetsInterface-result.txt1
-rw-r--r--Tests/RunCMake/target_sources/FileSetInstallMissingSetsInterface-stderr.txt5
-rw-r--r--Tests/RunCMake/target_sources/FileSetInstallMissingSetsInterface.cmake5
-rw-r--r--Tests/RunCMake/target_sources/FileSetInstallMissingSetsPrivate.cmake9
-rw-r--r--Tests/RunCMake/target_sources/FileSetNoExistInterface-result.txt1
-rw-r--r--Tests/RunCMake/target_sources/FileSetNoExistInterface-stderr.txt4
-rw-r--r--Tests/RunCMake/target_sources/FileSetNoExistInterface.cmake7
-rw-r--r--Tests/RunCMake/target_sources/FileSetNoExistPrivate-result.txt1
-rw-r--r--Tests/RunCMake/target_sources/FileSetNoExistPrivate-stderr.txt4
-rw-r--r--Tests/RunCMake/target_sources/FileSetNoExistPrivate.cmake7
-rw-r--r--Tests/RunCMake/target_sources/FileSetNoScope-result.txt1
-rw-r--r--Tests/RunCMake/target_sources/FileSetNoScope-stderr.txt4
-rw-r--r--Tests/RunCMake/target_sources/FileSetNoScope.cmake6
-rw-r--r--Tests/RunCMake/target_sources/FileSetNoType-result.txt1
-rw-r--r--Tests/RunCMake/target_sources/FileSetNoType-stderr.txt4
-rw-r--r--Tests/RunCMake/target_sources/FileSetNoType.cmake4
-rw-r--r--Tests/RunCMake/target_sources/FileSetOverlappingBaseDirs-result.txt1
-rw-r--r--Tests/RunCMake/target_sources/FileSetOverlappingBaseDirs-stderr.txt9
-rw-r--r--Tests/RunCMake/target_sources/FileSetOverlappingBaseDirs.cmake4
-rw-r--r--Tests/RunCMake/target_sources/FileSetProperties.cmake67
-rw-r--r--Tests/RunCMake/target_sources/FileSetWrongBaseDirs-result.txt1
-rw-r--r--Tests/RunCMake/target_sources/FileSetWrongBaseDirs-stderr.txt12
-rw-r--r--Tests/RunCMake/target_sources/FileSetWrongBaseDirs.cmake4
-rw-r--r--Tests/RunCMake/target_sources/FileSetWrongBaseDirsRelative-result.txt1
-rw-r--r--Tests/RunCMake/target_sources/FileSetWrongBaseDirsRelative-stderr.txt10
-rw-r--r--Tests/RunCMake/target_sources/FileSetWrongBaseDirsRelative.cmake3
-rw-r--r--Tests/RunCMake/target_sources/FileSetWrongType-result.txt1
-rw-r--r--Tests/RunCMake/target_sources/FileSetWrongType-stderr.txt4
-rw-r--r--Tests/RunCMake/target_sources/FileSetWrongType.cmake4
-rw-r--r--Tests/RunCMake/target_sources/RunCMakeTest.cmake57
-rw-r--r--Tests/RunCMake/target_sources/debug/empty.h0
-rw-r--r--Tests/RunCMake/target_sources/debug/empty2.h0
-rw-r--r--Tests/RunCMake/target_sources/dir/dir.h0
-rw-r--r--Tests/RunCMake/target_sources/dir1/file1.h0
-rw-r--r--Tests/RunCMake/target_sources/dir2/file2.h0
-rw-r--r--Tests/RunCMake/target_sources/dir3/CMakeLists.txt1
-rw-r--r--Tests/RunCMake/target_sources/dir3/dir3.h4
-rw-r--r--Tests/RunCMake/target_sources/dir4/CMakeLists.txt4
-rw-r--r--Tests/RunCMake/target_sources/dir4/dir4.h0
-rw-r--r--Tests/RunCMake/target_sources/empty.c0
-rw-r--r--Tests/RunCMake/target_sources/empty3.h0
-rw-r--r--Tests/RunCMake/target_sources/error.c1
-rw-r--r--Tests/RunCMake/target_sources/h1.h0
-rw-r--r--Tests/RunCMake/target_sources/h2.h0
-rw-r--r--Tests/RunCMake/target_sources/h3.h0
-rw-r--r--Tests/RunCMake/target_sources/lib1.c6
-rw-r--r--Tests/RunCMake/target_sources/lib2.c8
-rw-r--r--Tests/RunCMake/target_sources/reldir/CMakeLists.txt2
-rw-r--r--Tests/RunCMake/target_sources/release/empty.h0
-rw-r--r--Tests/RunCMake/target_sources/release/empty2.h0
-rwxr-xr-xbootstrap2
123 files changed, 2818 insertions, 88 deletions
diff --git a/Help/command/install.rst b/Help/command/install.rst
index 1236f1d..abde6e0 100644
--- a/Help/command/install.rst
+++ b/Help/command/install.rst
@@ -132,7 +132,7 @@ Installing Targets
install(TARGETS targets... [EXPORT <export-name>]
[RUNTIME_DEPENDENCIES args...|RUNTIME_DEPENDENCY_SET <set-name>]
[[ARCHIVE|LIBRARY|RUNTIME|OBJECTS|FRAMEWORK|BUNDLE|
- PRIVATE_HEADER|PUBLIC_HEADER|RESOURCE]
+ PRIVATE_HEADER|PUBLIC_HEADER|RESOURCE|FILE_SET <set-name>]
[DESTINATION <dir>]
[PERMISSIONS permissions...]
[CONFIGURATIONS [Debug|Release|...]]
@@ -204,6 +204,13 @@ that may be installed:
Similar to ``PUBLIC_HEADER`` and ``PRIVATE_HEADER``, but for
``RESOURCE`` files. See :prop_tgt:`RESOURCE` for details.
+``FILE_SET <set>``
+ If the file set ``<set>`` exists and is ``PUBLIC`` or ``INTERFACE``, any
+ files added to the file set ``<set>`` created by
+ :command:`target_sources(FILE_SET)` are installed in the specified
+ destination, preserving their directory structure relative to the file set's
+ base directories.
+
For each of these arguments given, the arguments following them only apply
to the target or file type specified in the argument. If none is given, the
installation properties apply to all target types. If only one is given then
@@ -225,15 +232,16 @@ end of this section).
The following table shows the target types with their associated variables and
built-in defaults that apply when no destination is given:
-================== =============================== ======================
- Target Type GNUInstallDirs Variable Built-In Default
-================== =============================== ======================
-``RUNTIME`` ``${CMAKE_INSTALL_BINDIR}`` ``bin``
-``LIBRARY`` ``${CMAKE_INSTALL_LIBDIR}`` ``lib``
-``ARCHIVE`` ``${CMAKE_INSTALL_LIBDIR}`` ``lib``
-``PRIVATE_HEADER`` ``${CMAKE_INSTALL_INCLUDEDIR}`` ``include``
-``PUBLIC_HEADER`` ``${CMAKE_INSTALL_INCLUDEDIR}`` ``include``
-================== =============================== ======================
+=============================== =============================== ======================
+ Target Type GNUInstallDirs Variable Built-In Default
+=============================== =============================== ======================
+``RUNTIME`` ``${CMAKE_INSTALL_BINDIR}`` ``bin``
+``LIBRARY`` ``${CMAKE_INSTALL_LIBDIR}`` ``lib``
+``ARCHIVE`` ``${CMAKE_INSTALL_LIBDIR}`` ``lib``
+``PRIVATE_HEADER`` ``${CMAKE_INSTALL_INCLUDEDIR}`` ``include``
+``PUBLIC_HEADER`` ``${CMAKE_INSTALL_INCLUDEDIR}`` ``include``
+``FILE_SET`` (type ``HEADERS``) ``${CMAKE_INSTALL_INCLUDEDIR}`` ``include``
+=============================== =============================== ======================
Projects wishing to follow the common practice of installing headers into a
project-specific subdirectory will need to provide a destination rather than
@@ -338,6 +346,11 @@ top level:
See documentation of the :prop_tgt:`EXPORT_NAME` target property to change
the name of the exported target.
+ If ``EXPORT`` is used and the targets include ``PUBLIC`` or ``INTERFACE``
+ file sets, all of them must be specified with ``FILE_SET`` arguments. All
+ ``PUBLIC`` or ``INTERFACE`` file sets associated with a target are included
+ in the export.
+
``INCLUDES DESTINATION``
This option specifies a list of directories which will be added to the
:prop_tgt:`INTERFACE_INCLUDE_DIRECTORIES` target property of the
diff --git a/Help/command/target_sources.rst b/Help/command/target_sources.rst
index 520614a..2fded5e 100644
--- a/Help/command/target_sources.rst
+++ b/Help/command/target_sources.rst
@@ -46,3 +46,105 @@ Arguments to ``target_sources`` may use "generator expressions"
with the syntax ``$<...>``. See the :manual:`cmake-generator-expressions(7)`
manual for available expressions. See the :manual:`cmake-buildsystem(7)`
manual for more on defining buildsystem properties.
+
+.. code-block:: cmake
+
+ target_sources(<target>
+ <INTERFACE|PUBLIC|PRIVATE> [FILE_SET set1] [TYPE type1] [BASE_DIRS dirs1...] [FILES files1...]
+ [<INTERFACE|PUBLIC|PRIVATE> [FILE_SET set2] [TYPE type2] [BASE_DIRS dirs2...] [FILES files2...])
+
+Adds a file set to a target, or adds files to an existing file set. Targets
+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.
+
+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
+have their :prop_sf:`HEADER_FILE_ONLY` property set to ``TRUE``. Files in an
+``INTERFACE`` or ``PUBLIC`` file set can be installed with the
+:command:`install(TARGETS)` command, and exported with the
+:command:`install(EXPORT)` and :command:`export` commands.
+
+Each ``target_sources(FILE_SET)`` entry starts with ``INTERFACE``, ``PUBLIC``, or
+``PRIVATE`` and accepts the following arguments:
+
+``FILE_SET <set>``
+
+ A string representing the name of the file set to create or add to. This must
+ not start with a capital letter, unless its name is ``HEADERS``.
+
+``TYPE <type>``
+
+ A string representing the type of the file set. The only acceptable value is
+ ``HEADERS``. This may be omitted if the name of the file set is ``HEADERS``.
+
+``BASE_DIRS <dirs>``
+
+ An optional list of strings representing the base directories of the file
+ set. This argument supports
+ :manual:`generator expressions <cmake-generator-expressions(7)>`. No two
+ ``BASE_DIRS`` may be sub-directories of each other. If no ``BASE_DIRS`` are
+ specified when the file set is first created, the value of
+ :variable:`CMAKE_CURRENT_SOURCE_DIR` is added.
+
+``FILES <files>``
+
+ An optional list of strings representing files in the file set. Each file
+ must be in one of the ``BASE_DIRS``. This argument supports
+ :manual:`generator expressions <cmake-generator-expressions(7)>`. If relative
+ paths are specified, they are considered relative to
+ :variable:`CMAKE_CURRENT_SOURCE_DIR` at the time ``target_sources()`` is
+ called, unless they start with ``$<``, in which case they are computed
+ relative to the target's source directory after genex evaluation.
+
+The following target properties are set by ``target_sources(FILE_SET)``:
+
+:prop_tgt:`HEADER_SETS`
+
+ List of ``PRIVATE`` and ``PUBLIC`` header sets associated with a target.
+ Headers listed in these header sets are treated as source files for the
+ purposes of IDE integration, and have their :prop_sf:`HEADER_FILE_ONLY`
+ property set to ``TRUE``.
+
+:prop_tgt:`INTERFACE_HEADER_SETS`
+
+ List of ``INTERFACE`` and ``PUBLIC`` header sets associated with a target.
+ Headers listed in these header sets can be installed with
+ :command:`install(TARGETS)` and exported with :command:`install(EXPORT)` and
+ :command:`export`.
+
+:prop_tgt:`HEADER_SET`
+
+ Headers in the default header set associated with a target. This property
+ supports :manual:`generator expressions <cmake-generator-expressions(7)>`.
+
+:prop_tgt:`HEADER_SET_<NAME>`
+
+ Headers in the named header set ``<NAME>`` associated with a target. This
+ property supports
+ :manual:`generator expressions <cmake-generator-expressions(7)>`.
+
+:prop_tgt:`HEADER_DIRS`
+
+ Base directories of the default header set associated with a target. This
+ property supports
+ :manual:`generator expressions <cmake-generator-expressions(7)>`.
+
+:prop_tgt:`HEADER_DIRS_<NAME>`
+
+ Base directories of the header set ``<NAME>`` associated with a target. This
+ property supports
+ :manual:`generator expressions <cmake-generator-expressions(7)>`.
+
+:prop_tgt:`INCLUDE_DIRECTORIES`
+
+ If the ``TYPE`` is ``HEADERS``, and the scope of the file set is ``PRIVATE``
+ or ``PUBLIC``, all of the ``BASE_DIRS`` of the file set are wrapped in
+ :genex:`$<BUILD_INTERFACE>` and appended to this property.
+
+:prop_tgt:`INTERFACE_INCLUDE_DIRECTORIES`
+
+ If the ``TYPE`` is ``HEADERS``, and the scope of the file set is
+ ``INTERFACE`` or ``PUBLIC``, all of the ``BASE_DIRS`` of the file set are
+ wrapped in :genex:`$<BUILD_INTERFACE>` and appended to this property.
diff --git a/Help/manual/cmake-file-api.7.rst b/Help/manual/cmake-file-api.7.rst
index 5e22ea9..4b8ac65 100644
--- a/Help/manual/cmake-file-api.7.rst
+++ b/Help/manual/cmake-file-api.7.rst
@@ -425,7 +425,7 @@ Version 1 does not exist to avoid confusion with that from
{
"kind": "codemodel",
- "version": { "major": 2, "minor": 2 },
+ "version": { "major": 2, "minor": 4 },
"paths": {
"source": "/path/to/top-level-source-dir",
"build": "/path/to/top-level-build-dir"
@@ -758,6 +758,15 @@ with members:
``destination`` member is populated. This type has additional members
``runtimeDependencySetName`` and ``runtimeDependencySetType``.
+ ``fileSet``
+ An :command:`install(TARGETS)` call with ``FILE_SET``.
+ The ``destination`` and ``paths`` members are populated.
+ The ``isOptional`` member may exist.
+ This type has additional members ``fileSetName``, ``fileSetType``,
+ ``fileSetDirectories``, and ``fileSetTarget``.
+
+ This type was added in codemodel version 2.4.
+
``isExcludeFromAll``
Optional member that is present with boolean value ``true`` when
:command:`install` is called with the ``EXCLUDE_FROM_ALL`` option.
@@ -835,6 +844,41 @@ with members:
Indicates that this installer installs dependencies that are macOS
frameworks.
+ ``fileSetName``
+ Optional member that is present when ``type`` is ``fileSet``. The value is
+ a string with the name of the file set.
+
+ This field was added in codemodel version 2.4.
+
+ ``fileSetType``
+ Optional member that is present when ``type`` is ``fileSet``. The value is
+ a string with the type of the file set.
+
+ This field was added in codemodel version 2.4.
+
+ ``fileSetDirectories``
+ Optional member that is present when ``type`` is ``fileSet``. The value
+ is a list of strings with the file set's base directories (determined by
+ genex-evaluation of :prop_tgt:`HEADER_DIRS` or
+ :prop_tgt:`HEADER_DIRS_<NAME>`).
+
+ This field was added in codemodel version 2.4.
+
+ ``fileSetTarget``
+ Optional member that is present when ``type`` is ``fileSet``. The value
+ is a JSON object with members:
+
+ ``id``
+ A string uniquely identifying the target. This matches
+ the ``id`` member of the target in the main "codemodel"
+ object's ``targets`` array.
+
+ ``index``
+ An unsigned integer 0-based index into the main "codemodel"
+ object's ``targets`` array for the target.
+
+ This field was added in codemodel version 2.4.
+
``scriptFile``
Optional member that is present when ``type`` is ``script``.
The value is a string specifying the path to the script file on disk,
diff --git a/Help/manual/cmake-properties.7.rst b/Help/manual/cmake-properties.7.rst
index 435b2c6..3d74a11 100644
--- a/Help/manual/cmake-properties.7.rst
+++ b/Help/manual/cmake-properties.7.rst
@@ -214,6 +214,11 @@ Properties on Targets
/prop_tgt/GHS_NO_SOURCE_GROUP_FILE
/prop_tgt/GNUtoMS
/prop_tgt/HAS_CXX
+ /prop_tgt/HEADER_DIRS
+ /prop_tgt/HEADER_DIRS_NAME
+ /prop_tgt/HEADER_SET
+ /prop_tgt/HEADER_SET_NAME
+ /prop_tgt/HEADER_SETS
/prop_tgt/HIP_ARCHITECTURES
/prop_tgt/HIP_EXTENSIONS
/prop_tgt/HIP_STANDARD
@@ -255,6 +260,7 @@ Properties on Targets
/prop_tgt/INTERFACE_COMPILE_DEFINITIONS
/prop_tgt/INTERFACE_COMPILE_FEATURES
/prop_tgt/INTERFACE_COMPILE_OPTIONS
+ /prop_tgt/INTERFACE_HEADER_SETS
/prop_tgt/INTERFACE_INCLUDE_DIRECTORIES
/prop_tgt/INTERFACE_LINK_DEPENDS
/prop_tgt/INTERFACE_LINK_DIRECTORIES
diff --git a/Help/prop_tgt/HEADER_DIRS.rst b/Help/prop_tgt/HEADER_DIRS.rst
new file mode 100644
index 0000000..3495545
--- /dev/null
+++ b/Help/prop_tgt/HEADER_DIRS.rst
@@ -0,0 +1,6 @@
+HEADER_DIRS
+-----------
+
+Semicolon-separated list of base directories of the default header set created
+by :command:`target_sources(FILE_SET)`. This property supports
+:manual:`generator expressions <cmake-generator-expressions(7)>`.
diff --git a/Help/prop_tgt/HEADER_DIRS_NAME.rst b/Help/prop_tgt/HEADER_DIRS_NAME.rst
new file mode 100644
index 0000000..c2bbd0a
--- /dev/null
+++ b/Help/prop_tgt/HEADER_DIRS_NAME.rst
@@ -0,0 +1,6 @@
+HEADER_DIRS_<NAME>
+------------------
+
+Semicolon-separated list of base directories of the header set with name
+``<NAME>`` created by :command:`target_sources(FILE_SET)`. This property
+supports :manual:`generator expressions <cmake-generator-expressions(7)>`.
diff --git a/Help/prop_tgt/HEADER_SET.rst b/Help/prop_tgt/HEADER_SET.rst
new file mode 100644
index 0000000..2b8b0d4
--- /dev/null
+++ b/Help/prop_tgt/HEADER_SET.rst
@@ -0,0 +1,8 @@
+HEADER_SET
+----------
+
+Semicolon-separated list of headers in the default header set created by
+:command:`target_sources(FILE_SET)`. This property supports
+:manual:`generator expressions <cmake-generator-expressions(7)>`. If any of the
+headers are relative paths, they are computed relative to the target's source
+directory.
diff --git a/Help/prop_tgt/HEADER_SETS.rst b/Help/prop_tgt/HEADER_SETS.rst
new file mode 100644
index 0000000..ed7c528
--- /dev/null
+++ b/Help/prop_tgt/HEADER_SETS.rst
@@ -0,0 +1,6 @@
+HEADER_SETS
+-----------
+
+List of ``PRIVATE`` and ``PUBLIC`` header sets added by
+:command:`target_sources(FILE_SET)`. Headers listed in these header sets are
+treated as source files for the purposes of IDE integration.
diff --git a/Help/prop_tgt/HEADER_SET_NAME.rst b/Help/prop_tgt/HEADER_SET_NAME.rst
new file mode 100644
index 0000000..25a5573
--- /dev/null
+++ b/Help/prop_tgt/HEADER_SET_NAME.rst
@@ -0,0 +1,8 @@
+HEADER_SET_<NAME>
+-----------------
+
+Semicolon-separated list of headers in the named header set ``<NAME>`` created
+by :command:`target_sources(FILE_SET)`. This property supports
+:manual:`generator expressions <cmake-generator-expressions(7)>`. If any of the
+headers are relative paths, they are computed relative to the target's source
+directory.
diff --git a/Help/prop_tgt/INTERFACE_HEADER_SETS.rst b/Help/prop_tgt/INTERFACE_HEADER_SETS.rst
new file mode 100644
index 0000000..93ea9c5
--- /dev/null
+++ b/Help/prop_tgt/INTERFACE_HEADER_SETS.rst
@@ -0,0 +1,7 @@
+INTERFACE_HEADER_SETS
+---------------------
+
+List of ``INTERFACE`` and ``PUBLIC`` header sets added by
+:command:`target_sources(FILE_SET)`. Headers listed in these header sets can be
+installed with :command:`install(TARGETS)` and exported with
+:command:`install(EXPORT)` and :command:`export`.
diff --git a/Help/release/dev/target-sources-file-set.rst b/Help/release/dev/target-sources-file-set.rst
new file mode 100644
index 0000000..bd28efa
--- /dev/null
+++ b/Help/release/dev/target-sources-file-set.rst
@@ -0,0 +1,18 @@
+target-headers
+--------------
+
+* The :command:`target_sources` command gained a new ``FILE_SET`` mode, which
+ can be used to add headers as header-only source files of a target.
+* New :prop_tgt:`HEADER_SETS` and :prop_tgt:`INTERFACE_HEADER_SETS` properties
+ were added, which list the header file sets associated with a target.
+* New :prop_tgt:`HEADER_SET` and :prop_tgt:`HEADER_SET_<NAME>` properties were
+ added, which list the files in the associated header file set.
+* New :prop_tgt:`HEADER_DIRS` and :prop_tgt:`HEADER_DIRS_<NAME>` properties
+ were added, which specify the base directories of the associated header file
+ set.
+* The :command:`install(TARGETS)` command gained a new ``FILE_SET`` argument,
+ which can be used to install header file sets associated with a target.
+* The :manual:`File API <cmake-file-api(7)>` ``codemodel-v2`` minor version has
+ been bumped to ``4``.
+* The :manual:`File API <cmake-file-api(7)>` ``codemodel-v2`` ``directory``
+ object gained a new installer type of ``fileSet``.
diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt
index c8498a9..c125378 100644
--- a/Source/CMakeLists.txt
+++ b/Source/CMakeLists.txt
@@ -261,6 +261,8 @@ set(SRCS
cmFileLockResult.h
cmFilePathChecksum.cxx
cmFilePathChecksum.h
+ cmFileSet.cxx
+ cmFileSet.h
cmFileTime.cxx
cmFileTime.h
cmFileTimeCache.cxx
@@ -316,6 +318,8 @@ set(SRCS
cmInstallExportGenerator.cxx
cmInstalledFile.h
cmInstalledFile.cxx
+ cmInstallFileSetGenerator.h
+ cmInstallFileSetGenerator.cxx
cmInstallFilesGenerator.h
cmInstallFilesGenerator.cxx
cmInstallImportedRuntimeArtifactsGenerator.h
diff --git a/Source/cmExportBuildFileGenerator.cxx b/Source/cmExportBuildFileGenerator.cxx
index aa968dc..a47f1e5 100644
--- a/Source/cmExportBuildFileGenerator.cxx
+++ b/Source/cmExportBuildFileGenerator.cxx
@@ -11,12 +11,15 @@
#include <cmext/algorithm>
#include "cmExportSet.h"
+#include "cmFileSet.h"
#include "cmGeneratorExpression.h"
#include "cmGeneratorTarget.h"
#include "cmGlobalGenerator.h"
+#include "cmListFileCache.h"
#include "cmLocalGenerator.h"
#include "cmMakefile.h"
#include "cmMessageType.h"
+#include "cmOutputConverter.h"
#include "cmPolicies.h"
#include "cmStateTypes.h"
#include "cmStringAlgorithms.h"
@@ -135,6 +138,8 @@ bool cmExportBuildFileGenerator::GenerateMainFile(std::ostream& os)
this->PopulateCompatibleInterfaceProperties(gte, properties);
this->GenerateInterfaceProperties(gte, os, properties);
+
+ this->GenerateTargetFileSets(gte, os);
}
// Generate import file content for each configuration.
@@ -356,3 +361,17 @@ std::string cmExportBuildFileGenerator::InstallNameDir(
return install_name_dir;
}
+
+std::string cmExportBuildFileGenerator::GetFileSetDirectories(
+ cmGeneratorTarget* /*gte*/, cmFileSet* fileSet, cmTargetExport* /*te*/)
+{
+ return cmOutputConverter::EscapeForCMake(
+ cmJoin(fileSet->GetDirectoryEntries(), ";"));
+}
+
+std::string cmExportBuildFileGenerator::GetFileSetFiles(
+ cmGeneratorTarget* /*gte*/, cmFileSet* fileSet, cmTargetExport* /*te*/)
+{
+ return cmOutputConverter::EscapeForCMake(
+ cmJoin(fileSet->GetFileEntries(), ";"));
+}
diff --git a/Source/cmExportBuildFileGenerator.h b/Source/cmExportBuildFileGenerator.h
index 244f526..a7985c7 100644
--- a/Source/cmExportBuildFileGenerator.h
+++ b/Source/cmExportBuildFileGenerator.h
@@ -15,9 +15,11 @@
#include "cmStateTypes.h"
class cmExportSet;
+class cmFileSet;
class cmGeneratorTarget;
class cmGlobalGenerator;
class cmLocalGenerator;
+class cmTargetExport;
/** \class cmExportBuildFileGenerator
* \brief Generate a file exporting targets from a build tree.
@@ -76,6 +78,11 @@ protected:
std::string InstallNameDir(cmGeneratorTarget const* target,
const std::string& config) override;
+ std::string GetFileSetDirectories(cmGeneratorTarget* gte, cmFileSet* fileSet,
+ cmTargetExport* te) override;
+ std::string GetFileSetFiles(cmGeneratorTarget* gte, cmFileSet* fileSet,
+ cmTargetExport* te) override;
+
std::pair<std::vector<std::string>, std::string> FindBuildExportInfo(
cmGlobalGenerator* gg, const std::string& name);
diff --git a/Source/cmExportFileGenerator.cxx b/Source/cmExportFileGenerator.cxx
index 9f38c12..896240c 100644
--- a/Source/cmExportFileGenerator.cxx
+++ b/Source/cmExportFileGenerator.cxx
@@ -12,6 +12,7 @@
#include "cmsys/FStream.hxx"
#include "cmComputeLinkInformation.h"
+#include "cmFileSet.h"
#include "cmGeneratedFileStream.h"
#include "cmGeneratorTarget.h"
#include "cmGlobalGenerator.h"
@@ -1256,3 +1257,39 @@ bool cmExportFileGenerator::PopulateExportProperties(
}
return true;
}
+
+void cmExportFileGenerator::GenerateTargetFileSets(cmGeneratorTarget* gte,
+ std::ostream& os,
+ cmTargetExport* te)
+{
+ auto interfaceFileSets = gte->Target->GetAllInterfaceFileSets();
+ if (!interfaceFileSets.empty()) {
+ std::string targetName = cmStrCat(this->Namespace, gte->GetExportName());
+ os << "if(NOT CMAKE_VERSION VERSION_LESS \"" << DEVEL_CMAKE_VERSION(3, 23)
+ << "\")\n"
+ " target_sources("
+ << targetName << "\n";
+
+ for (auto const& name : interfaceFileSets) {
+ auto* fileSet = gte->Target->GetFileSet(name);
+ if (!fileSet) {
+ gte->Makefile->IssueMessage(
+ MessageType::FATAL_ERROR,
+ cmStrCat("File set \"", name,
+ "\" is listed in interface file sets of ", gte->GetName(),
+ " but has not been created"));
+ return;
+ }
+
+ os << " INTERFACE"
+ << "\n FILE_SET " << cmOutputConverter::EscapeForCMake(name)
+ << "\n TYPE "
+ << cmOutputConverter::EscapeForCMake(fileSet->GetType())
+ << "\n BASE_DIRS "
+ << this->GetFileSetDirectories(gte, fileSet, te) << "\n FILES "
+ << this->GetFileSetFiles(gte, fileSet, te) << "\n";
+ }
+
+ os << " )\nendif()\n\n";
+ }
+}
diff --git a/Source/cmExportFileGenerator.h b/Source/cmExportFileGenerator.h
index 24e048b..5875247 100644
--- a/Source/cmExportFileGenerator.h
+++ b/Source/cmExportFileGenerator.h
@@ -15,7 +15,9 @@
#include "cmVersion.h"
#include "cmVersionConfig.h"
+class cmFileSet;
class cmGeneratorTarget;
+class cmTargetExport;
#define STRINGIFY_HELPER(X) #X
#define STRINGIFY(X) STRINGIFY_HELPER(X)
@@ -184,6 +186,16 @@ protected:
ImportPropertyMap& properties,
std::string& errorMessage);
+ void GenerateTargetFileSets(cmGeneratorTarget* gte, std::ostream& os,
+ cmTargetExport* te = nullptr);
+
+ virtual std::string GetFileSetDirectories(cmGeneratorTarget* gte,
+ cmFileSet* fileSet,
+ cmTargetExport* te) = 0;
+ virtual std::string GetFileSetFiles(cmGeneratorTarget* gte,
+ cmFileSet* fileSet,
+ cmTargetExport* te) = 0;
+
// The namespace in which the exports are placed in the generated file.
std::string Namespace;
diff --git a/Source/cmExportInstallFileGenerator.cxx b/Source/cmExportInstallFileGenerator.cxx
index e9ac875..2dd8b8f 100644
--- a/Source/cmExportInstallFileGenerator.cxx
+++ b/Source/cmExportInstallFileGenerator.cxx
@@ -2,19 +2,23 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmExportInstallFileGenerator.h"
+#include <algorithm>
#include <memory>
#include <sstream>
#include <utility>
#include "cmExportSet.h"
+#include "cmFileSet.h"
#include "cmGeneratedFileStream.h"
#include "cmGeneratorExpression.h"
#include "cmGeneratorTarget.h"
#include "cmGlobalGenerator.h"
#include "cmInstallExportGenerator.h"
+#include "cmInstallFileSetGenerator.h"
#include "cmInstallTargetGenerator.h"
#include "cmLocalGenerator.h"
#include "cmMakefile.h"
+#include "cmOutputConverter.h"
#include "cmPolicies.h"
#include "cmStateTypes.h"
#include "cmStringAlgorithms.h"
@@ -147,6 +151,8 @@ bool cmExportInstallFileGenerator::GenerateMainFile(std::ostream& os)
this->PopulateCompatibleInterfaceProperties(gt, properties);
this->GenerateInterfaceProperties(gt, os, properties);
+
+ this->GenerateTargetFileSets(gt, os, te);
}
if (require3_1_0) {
@@ -534,3 +540,102 @@ std::string cmExportInstallFileGenerator::InstallNameDir(
return install_name_dir;
}
+
+namespace {
+bool EntryIsContextSensitive(
+ const std::unique_ptr<cmCompiledGeneratorExpression>& cge)
+{
+ return cge->GetHadContextSensitiveCondition();
+}
+}
+
+std::string cmExportInstallFileGenerator::GetFileSetDirectories(
+ cmGeneratorTarget* gte, cmFileSet* fileSet, cmTargetExport* te)
+{
+ std::vector<std::string> resultVector;
+
+ auto configs =
+ gte->Makefile->GetGeneratorConfigs(cmMakefile::IncludeEmptyConfig);
+
+ cmGeneratorExpression ge;
+ auto cge = ge.Parse(te->FileSetGenerators.at(fileSet)->GetDestination());
+
+ for (auto const& config : configs) {
+ auto dest = cmStrCat("${_IMPORT_PREFIX}/",
+ cmOutputConverter::EscapeForCMake(
+ cge->Evaluate(gte->LocalGenerator, config, gte),
+ cmOutputConverter::WrapQuotes::NoWrap));
+
+ if (cge->GetHadContextSensitiveCondition() && configs.size() != 1) {
+ resultVector.push_back(
+ cmStrCat("\"$<$<CONFIG:", config, ">:", dest, ">\""));
+ } else {
+ resultVector.push_back(cmStrCat('"', dest, '"'));
+ break;
+ }
+ }
+
+ return cmJoin(resultVector, " ");
+}
+
+std::string cmExportInstallFileGenerator::GetFileSetFiles(
+ cmGeneratorTarget* gte, cmFileSet* fileSet, cmTargetExport* te)
+{
+ std::vector<std::string> resultVector;
+
+ auto configs =
+ gte->Makefile->GetGeneratorConfigs(cmMakefile::IncludeEmptyConfig);
+
+ auto fileEntries = fileSet->CompileFileEntries();
+ auto directoryEntries = fileSet->CompileDirectoryEntries();
+
+ cmGeneratorExpression destGe;
+ auto destCge =
+ destGe.Parse(te->FileSetGenerators.at(fileSet)->GetDestination());
+
+ for (auto const& config : configs) {
+ auto directories = fileSet->EvaluateDirectoryEntries(
+ directoryEntries, gte->LocalGenerator, config, gte);
+
+ std::map<std::string, std::vector<std::string>> files;
+ for (auto const& entry : fileEntries) {
+ fileSet->EvaluateFileEntry(directories, files, entry,
+ gte->LocalGenerator, config, gte);
+ }
+ auto dest = cmStrCat("${_IMPORT_PREFIX}/",
+ cmOutputConverter::EscapeForCMake(
+ destCge->Evaluate(gte->LocalGenerator, config, gte),
+ cmOutputConverter::WrapQuotes::NoWrap),
+ '/');
+
+ bool const contextSensitive = destCge->GetHadContextSensitiveCondition() ||
+ std::any_of(directoryEntries.begin(), directoryEntries.end(),
+ EntryIsContextSensitive) ||
+ std::any_of(fileEntries.begin(), fileEntries.end(),
+ EntryIsContextSensitive);
+
+ for (auto const& it : files) {
+ auto prefix = it.first.empty() ? "" : cmStrCat(it.first, '/');
+ for (auto const& filename : it.second) {
+ auto relFile =
+ cmStrCat(prefix, cmSystemTools::GetFilenameName(filename));
+ auto escapedFile =
+ cmStrCat(dest,
+ cmOutputConverter::EscapeForCMake(
+ relFile, cmOutputConverter::WrapQuotes::NoWrap));
+ if (contextSensitive && configs.size() != 1) {
+ resultVector.push_back(
+ cmStrCat("\"$<$<CONFIG:", config, ">:", escapedFile, ">\""));
+ } else {
+ resultVector.push_back(cmStrCat('"', escapedFile, '"'));
+ }
+ }
+ }
+
+ if (!(contextSensitive && configs.size() != 1)) {
+ break;
+ }
+ }
+
+ return cmJoin(resultVector, " ");
+}
diff --git a/Source/cmExportInstallFileGenerator.h b/Source/cmExportInstallFileGenerator.h
index 5cec2e0..9374c6b 100644
--- a/Source/cmExportInstallFileGenerator.h
+++ b/Source/cmExportInstallFileGenerator.h
@@ -14,6 +14,7 @@
#include "cmExportFileGenerator.h"
#include "cmStateTypes.h"
+class cmFileSet;
class cmGeneratorTarget;
class cmGlobalGenerator;
class cmInstallExportGenerator;
@@ -97,6 +98,11 @@ protected:
std::string InstallNameDir(cmGeneratorTarget const* target,
const std::string& config) override;
+ std::string GetFileSetDirectories(cmGeneratorTarget* gte, cmFileSet* fileSet,
+ cmTargetExport* te) override;
+ std::string GetFileSetFiles(cmGeneratorTarget* gte, cmFileSet* fileSet,
+ cmTargetExport* te) override;
+
cmInstallExportGenerator* IEGen;
// The import file generated for each configuration.
diff --git a/Source/cmExportTryCompileFileGenerator.cxx b/Source/cmExportTryCompileFileGenerator.cxx
index cbe3c4d..4fe92c6 100644
--- a/Source/cmExportTryCompileFileGenerator.cxx
+++ b/Source/cmExportTryCompileFileGenerator.cxx
@@ -7,17 +7,22 @@
#include <cm/memory>
+#include "cmFileSet.h"
#include "cmGeneratorExpression.h"
#include "cmGeneratorExpressionDAGChecker.h"
#include "cmGeneratorTarget.h"
#include "cmGlobalGenerator.h"
+#include "cmListFileCache.h"
#include "cmLocalGenerator.h"
#include "cmMakefile.h"
+#include "cmOutputConverter.h"
#include "cmStateTypes.h"
#include "cmStringAlgorithms.h"
#include "cmTarget.h"
#include "cmValue.h"
+class cmTargetExport;
+
cmExportTryCompileFileGenerator::cmExportTryCompileFileGenerator(
cmGlobalGenerator* gg, const std::vector<std::string>& targets,
cmMakefile* mf, std::set<std::string> const& langs)
@@ -137,3 +142,17 @@ std::string cmExportTryCompileFileGenerator::InstallNameDir(
return install_name_dir;
}
+
+std::string cmExportTryCompileFileGenerator::GetFileSetDirectories(
+ cmGeneratorTarget* /*gte*/, cmFileSet* fileSet, cmTargetExport* /*te*/)
+{
+ return cmOutputConverter::EscapeForCMake(
+ cmJoin(fileSet->GetDirectoryEntries(), ";"));
+}
+
+std::string cmExportTryCompileFileGenerator::GetFileSetFiles(
+ cmGeneratorTarget* /*gte*/, cmFileSet* fileSet, cmTargetExport* /*te*/)
+{
+ return cmOutputConverter::EscapeForCMake(
+ cmJoin(fileSet->GetFileEntries(), ";"));
+}
diff --git a/Source/cmExportTryCompileFileGenerator.h b/Source/cmExportTryCompileFileGenerator.h
index 127b8df..8a1fd7e 100644
--- a/Source/cmExportTryCompileFileGenerator.h
+++ b/Source/cmExportTryCompileFileGenerator.h
@@ -11,9 +11,11 @@
#include "cmExportFileGenerator.h"
+class cmFileSet;
class cmGeneratorTarget;
class cmGlobalGenerator;
class cmMakefile;
+class cmTargetExport;
class cmExportTryCompileFileGenerator : public cmExportFileGenerator
{
@@ -48,6 +50,13 @@ protected:
std::string InstallNameDir(cmGeneratorTarget const* target,
const std::string& config) override;
+ std::string GetFileSetDirectories(cmGeneratorTarget* target,
+ cmFileSet* fileSet,
+ cmTargetExport* te) override;
+
+ std::string GetFileSetFiles(cmGeneratorTarget* target, cmFileSet* fileSet,
+ cmTargetExport* te) override;
+
private:
std::string FindTargets(const std::string& prop,
const cmGeneratorTarget* tgt,
diff --git a/Source/cmFileAPI.cxx b/Source/cmFileAPI.cxx
index d529f52..c1df992 100644
--- a/Source/cmFileAPI.cxx
+++ b/Source/cmFileAPI.cxx
@@ -686,7 +686,8 @@ std::string cmFileAPI::NoSupportedVersion(
// The "codemodel" object kind.
-static unsigned int const CodeModelV2Minor = 3;
+// Update Help/manual/cmake-file-api.7.rst when updating this constant.
+static unsigned int const CodeModelV2Minor = 4;
void cmFileAPI::BuildClientRequestCodeModel(
ClientRequest& r, std::vector<RequestVersion> const& versions)
diff --git a/Source/cmFileAPICodemodel.cxx b/Source/cmFileAPICodemodel.cxx
index 147181e..40e1d2e 100644
--- a/Source/cmFileAPICodemodel.cxx
+++ b/Source/cmFileAPICodemodel.cxx
@@ -23,11 +23,13 @@
#include "cmCryptoHash.h"
#include "cmExportSet.h"
#include "cmFileAPI.h"
+#include "cmFileSet.h"
#include "cmGeneratorExpression.h"
#include "cmGeneratorTarget.h"
#include "cmGlobalGenerator.h"
#include "cmInstallDirectoryGenerator.h"
#include "cmInstallExportGenerator.h"
+#include "cmInstallFileSetGenerator.h"
#include "cmInstallFilesGenerator.h"
#include "cmInstallGenerator.h"
#include "cmInstallGetRuntimeDependenciesGenerator.h"
@@ -1043,6 +1045,53 @@ Json::Value DirectoryObject::DumpInstaller(cmInstallGenerator* gen)
installer["runtimeDependencySetType"] = "library";
break;
}
+ } else if (auto* installFileSet =
+ dynamic_cast<cmInstallFileSetGenerator*>(gen)) {
+ installer["type"] = "fileSet";
+ installer["destination"] = installFileSet->GetDestination(this->Config);
+
+ auto* fileSet = installFileSet->GetFileSet();
+ auto* target = installFileSet->GetTarget();
+
+ auto dirCges = fileSet->CompileDirectoryEntries();
+ auto dirs = fileSet->EvaluateDirectoryEntries(
+ dirCges, target->GetLocalGenerator(), this->Config, target);
+
+ auto entryCges = fileSet->CompileFileEntries();
+ std::map<std::string, std::vector<std::string>> entries;
+ for (auto const& entryCge : entryCges) {
+ fileSet->EvaluateFileEntry(dirs, entries, entryCge,
+ target->GetLocalGenerator(), this->Config,
+ target);
+ }
+
+ Json::Value files = Json::arrayValue;
+ for (auto const& it : entries) {
+ auto dir = it.first;
+ if (!dir.empty()) {
+ dir += '/';
+ }
+ for (auto const& file : it.second) {
+ files.append(this->DumpInstallerPath(
+ this->TopSource, file,
+ cmStrCat(dir, cmSystemTools::GetFilenameName(file))));
+ }
+ }
+ installer["paths"] = std::move(files);
+ installer["fileSetName"] = fileSet->GetName();
+ installer["fileSetType"] = fileSet->GetType();
+ installer["fileSetDirectories"] = Json::arrayValue;
+ for (auto const& dir : dirs) {
+ installer["fileSetDirectories"].append(
+ RelativeIfUnder(this->TopSource, dir));
+ }
+ installer["fileSetTarget"] = Json::objectValue;
+ installer["fileSetTarget"]["id"] = TargetId(target, this->TopBuild);
+ installer["fileSetTarget"]["index"] = this->TargetIndexMap[target];
+
+ if (installFileSet->GetOptional()) {
+ installer["isOptional"] = true;
+ }
}
// Add fields common to all install generators.
diff --git a/Source/cmFileSet.cxx b/Source/cmFileSet.cxx
new file mode 100644
index 0000000..08d56ba
--- /dev/null
+++ b/Source/cmFileSet.cxx
@@ -0,0 +1,151 @@
+/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
+ file Copyright.txt or https://cmake.org/licensing for details. */
+#include "cmFileSet.h"
+
+#include <sstream>
+#include <string>
+#include <utility>
+#include <vector>
+
+#include "cmGeneratorExpression.h"
+#include "cmListFileCache.h"
+#include "cmLocalGenerator.h"
+#include "cmMessageType.h"
+#include "cmStringAlgorithms.h"
+#include "cmSystemTools.h"
+#include "cmake.h"
+
+cmFileSet::cmFileSet(std::string name, std::string type)
+ : Name(std::move(name))
+ , Type(std::move(type))
+{
+}
+
+void cmFileSet::ClearDirectoryEntries()
+{
+ this->DirectoryEntries.clear();
+}
+
+void cmFileSet::AddDirectoryEntry(BT<std::string> directories)
+{
+ this->DirectoryEntries.push_back(std::move(directories));
+}
+
+void cmFileSet::ClearFileEntries()
+{
+ this->FileEntries.clear();
+}
+
+void cmFileSet::AddFileEntry(BT<std::string> files)
+{
+ this->FileEntries.push_back(std::move(files));
+}
+
+std::vector<std::unique_ptr<cmCompiledGeneratorExpression>>
+cmFileSet::CompileFileEntries() const
+{
+ std::vector<std::unique_ptr<cmCompiledGeneratorExpression>> result;
+
+ for (auto const& entry : this->FileEntries) {
+ for (auto const& ex : cmExpandedList(entry.Value)) {
+ cmGeneratorExpression ge(entry.Backtrace);
+ auto cge = ge.Parse(ex);
+ result.push_back(std::move(cge));
+ }
+ }
+
+ return result;
+}
+
+std::vector<std::unique_ptr<cmCompiledGeneratorExpression>>
+cmFileSet::CompileDirectoryEntries() const
+{
+ std::vector<std::unique_ptr<cmCompiledGeneratorExpression>> result;
+
+ for (auto const& entry : this->DirectoryEntries) {
+ for (auto const& ex : cmExpandedList(entry.Value)) {
+ cmGeneratorExpression ge(entry.Backtrace);
+ auto cge = ge.Parse(ex);
+ result.push_back(std::move(cge));
+ }
+ }
+
+ return result;
+}
+
+std::vector<std::string> cmFileSet::EvaluateDirectoryEntries(
+ const std::vector<std::unique_ptr<cmCompiledGeneratorExpression>>& cges,
+ cmLocalGenerator* lg, const std::string& config,
+ const cmGeneratorTarget* target,
+ cmGeneratorExpressionDAGChecker* dagChecker) const
+{
+ std::vector<std::string> result;
+ for (auto const& cge : cges) {
+ auto entry = cge->Evaluate(lg, config, target, dagChecker);
+ auto dirs = cmExpandedList(entry);
+ for (std::string dir : dirs) {
+ if (!cmSystemTools::FileIsFullPath(dir)) {
+ dir = cmStrCat(lg->GetCurrentSourceDirectory(), '/', dir);
+ }
+ auto collapsedDir = cmSystemTools::CollapseFullPath(dir);
+ for (auto const& priorDir : result) {
+ auto collapsedPriorDir = cmSystemTools::CollapseFullPath(priorDir);
+ if (!cmSystemTools::SameFile(collapsedDir, collapsedPriorDir) &&
+ (cmSystemTools::IsSubDirectory(collapsedDir, collapsedPriorDir) ||
+ cmSystemTools::IsSubDirectory(collapsedPriorDir, collapsedDir))) {
+ lg->GetCMakeInstance()->IssueMessage(
+ MessageType::FATAL_ERROR,
+ cmStrCat(
+ "Base directories in file set cannot be subdirectories of each "
+ "other:\n ",
+ priorDir, "\n ", dir),
+ cge->GetBacktrace());
+ return {};
+ }
+ }
+ result.push_back(dir);
+ }
+ }
+ return result;
+}
+
+void cmFileSet::EvaluateFileEntry(
+ const std::vector<std::string>& dirs,
+ std::map<std::string, std::vector<std::string>>& filesPerDir,
+ const std::unique_ptr<cmCompiledGeneratorExpression>& cge,
+ cmLocalGenerator* lg, const std::string& config,
+ const cmGeneratorTarget* target,
+ cmGeneratorExpressionDAGChecker* dagChecker) const
+{
+ auto files = cge->Evaluate(lg, config, target, dagChecker);
+ for (std::string file : cmExpandedList(files)) {
+ if (!cmSystemTools::FileIsFullPath(file)) {
+ file = cmStrCat(lg->GetCurrentSourceDirectory(), '/', file);
+ }
+ auto collapsedFile = cmSystemTools::CollapseFullPath(file);
+ bool found = false;
+ std::string relDir;
+ for (auto const& dir : dirs) {
+ auto collapsedDir = cmSystemTools::CollapseFullPath(dir);
+ if (cmSystemTools::IsSubDirectory(collapsedFile, collapsedDir)) {
+ found = true;
+ relDir = cmSystemTools::GetParentDirectory(
+ cmSystemTools::RelativePath(collapsedDir, collapsedFile));
+ break;
+ }
+ }
+ if (!found) {
+ std::ostringstream e;
+ e << "File:\n " << file
+ << "\nmust be in one of the file set's base directories:";
+ for (auto const& dir : dirs) {
+ e << "\n " << dir;
+ }
+ lg->GetCMakeInstance()->IssueMessage(MessageType::FATAL_ERROR, e.str(),
+ cge->GetBacktrace());
+ return;
+ }
+
+ filesPerDir[relDir].push_back(file);
+ }
+}
diff --git a/Source/cmFileSet.h b/Source/cmFileSet.h
new file mode 100644
index 0000000..5ee4a98
--- /dev/null
+++ b/Source/cmFileSet.h
@@ -0,0 +1,64 @@
+/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
+ file Copyright.txt or https://cmake.org/licensing for details. */
+#pragma once
+
+#include <map>
+#include <memory>
+#include <string>
+#include <vector>
+
+#include "cmListFileCache.h"
+
+class cmCompiledGeneratorExpression;
+struct cmGeneratorExpressionDAGChecker;
+class cmGeneratorTarget;
+class cmLocalGenerator;
+
+class cmFileSet
+{
+public:
+ cmFileSet(std::string name, std::string type);
+
+ const std::string& GetName() const { return this->Name; }
+ const std::string& GetType() const { return this->Type; }
+
+ void ClearDirectoryEntries();
+ void AddDirectoryEntry(BT<std::string> directories);
+ const std::vector<BT<std::string>>& GetDirectoryEntries() const
+ {
+ return this->DirectoryEntries;
+ }
+
+ void ClearFileEntries();
+ void AddFileEntry(BT<std::string> files);
+ const std::vector<BT<std::string>>& GetFileEntries() const
+ {
+ return this->FileEntries;
+ }
+
+ std::vector<std::unique_ptr<cmCompiledGeneratorExpression>>
+ CompileFileEntries() const;
+
+ std::vector<std::unique_ptr<cmCompiledGeneratorExpression>>
+ CompileDirectoryEntries() const;
+
+ std::vector<std::string> EvaluateDirectoryEntries(
+ const std::vector<std::unique_ptr<cmCompiledGeneratorExpression>>& cges,
+ cmLocalGenerator* lg, const std::string& config,
+ const cmGeneratorTarget* target,
+ cmGeneratorExpressionDAGChecker* dagChecker = nullptr) const;
+
+ void EvaluateFileEntry(
+ const std::vector<std::string>& dirs,
+ std::map<std::string, std::vector<std::string>>& filesPerDir,
+ const std::unique_ptr<cmCompiledGeneratorExpression>& cge,
+ cmLocalGenerator* lg, const std::string& config,
+ const cmGeneratorTarget* target,
+ cmGeneratorExpressionDAGChecker* dagChecker = nullptr) const;
+
+private:
+ std::string Name;
+ std::string Type;
+ std::vector<BT<std::string>> DirectoryEntries;
+ std::vector<BT<std::string>> FileEntries;
+};
diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx
index f5ea8c3..59c3e7a 100644
--- a/Source/cmGeneratorTarget.cxx
+++ b/Source/cmGeneratorTarget.cxx
@@ -25,6 +25,7 @@
#include "cmAlgorithms.h"
#include "cmComputeLinkInformation.h"
#include "cmCustomCommandGenerator.h"
+#include "cmFileSet.h"
#include "cmFileTimes.h"
#include "cmGeneratedFileStream.h"
#include "cmGeneratorExpression.h"
@@ -41,6 +42,7 @@
#include "cmSourceFile.h"
#include "cmSourceFileLocation.h"
#include "cmSourceFileLocationKind.h"
+#include "cmSourceGroup.h"
#include "cmStandardLevelResolver.h"
#include "cmState.h"
#include "cmStringAlgorithms.h"
@@ -173,6 +175,65 @@ private:
BT<std::string> PropertyValue;
};
+class TargetPropertyEntryFileSet
+ : public cmGeneratorTarget::TargetPropertyEntry
+{
+public:
+ TargetPropertyEntryFileSet(
+ std::vector<std::string> dirs, bool contextSensitiveDirs,
+ std::unique_ptr<cmCompiledGeneratorExpression> entryCge,
+ const cmFileSet* fileSet, cmLinkImplItem const& item = NoLinkImplItem)
+ : cmGeneratorTarget::TargetPropertyEntry(item)
+ , BaseDirs(std::move(dirs))
+ , ContextSensitiveDirs(contextSensitiveDirs)
+ , EntryCge(std::move(entryCge))
+ , FileSet(fileSet)
+ {
+ }
+
+ const std::string& Evaluate(cmLocalGenerator* lg, const std::string& config,
+ cmGeneratorTarget const* headTarget,
+ cmGeneratorExpressionDAGChecker* dagChecker,
+ std::string const& /*lang*/) const override
+ {
+ std::map<std::string, std::vector<std::string>> filesPerDir;
+ this->FileSet->EvaluateFileEntry(this->BaseDirs, filesPerDir,
+ this->EntryCge, lg, config, headTarget,
+ dagChecker);
+
+ std::vector<std::string> files;
+ for (auto const& it : filesPerDir) {
+ files.insert(files.end(), it.second.begin(), it.second.end());
+ }
+
+ static std::string filesStr;
+ filesStr = cmJoin(files, ";");
+ return filesStr;
+ }
+
+ cmListFileBacktrace GetBacktrace() const override
+ {
+ return this->EntryCge->GetBacktrace();
+ }
+
+ std::string const& GetInput() const override
+ {
+ return this->EntryCge->GetInput();
+ }
+
+ bool GetHadContextSensitiveCondition() const override
+ {
+ return this->ContextSensitiveDirs ||
+ this->EntryCge->GetHadContextSensitiveCondition();
+ }
+
+private:
+ const std::vector<std::string> BaseDirs;
+ const bool ContextSensitiveDirs;
+ const std::unique_ptr<cmCompiledGeneratorExpression> EntryCge;
+ const cmFileSet* FileSet;
+};
+
std::unique_ptr<
cmGeneratorTarget::
TargetPropertyEntry> static CreateTargetPropertyEntry(const BT<std::
@@ -1594,6 +1655,80 @@ void AddObjectEntries(cmGeneratorTarget const* headTarget,
}
}
+void addFileSetEntry(cmGeneratorTarget const* headTarget,
+ std::string const& config,
+ cmGeneratorExpressionDAGChecker* dagChecker,
+ cmFileSet const* fileSet,
+ EvaluatedTargetPropertyEntries& entries)
+{
+ auto dirCges = fileSet->CompileDirectoryEntries();
+ auto dirs = fileSet->EvaluateDirectoryEntries(
+ dirCges, headTarget->GetLocalGenerator(), config, headTarget, dagChecker);
+ bool contextSensitiveDirs = false;
+ for (auto const& dirCge : dirCges) {
+ if (dirCge->GetHadContextSensitiveCondition()) {
+ contextSensitiveDirs = true;
+ break;
+ }
+ }
+ cmake* cm = headTarget->GetLocalGenerator()->GetCMakeInstance();
+ for (auto& entryCge : fileSet->CompileFileEntries()) {
+ TargetPropertyEntryFileSet tpe(dirs, contextSensitiveDirs,
+ std::move(entryCge), fileSet);
+ entries.Entries.emplace_back(
+ EvaluateTargetPropertyEntry(headTarget, config, "", dagChecker, tpe));
+ for (auto const& file : entries.Entries.back().Values) {
+ auto* sf = headTarget->Makefile->GetOrCreateSource(file);
+ if (fileSet->GetType() == "HEADERS"_s) {
+ sf->SetProperty("HEADER_FILE_ONLY", "TRUE");
+ }
+
+#ifndef CMAKE_BOOTSTRAP
+ std::string e;
+ std::string w;
+ auto path = sf->ResolveFullPath(&e, &w);
+ if (!w.empty()) {
+ cm->IssueMessage(MessageType::AUTHOR_WARNING, w,
+ headTarget->GetBacktrace());
+ }
+ if (path.empty()) {
+ if (!e.empty()) {
+ cm->IssueMessage(MessageType::FATAL_ERROR, e,
+ headTarget->GetBacktrace());
+ }
+ return;
+ }
+ bool found = false;
+ for (auto const& sg : headTarget->Makefile->GetSourceGroups()) {
+ if (sg.MatchesFiles(path)) {
+ found = true;
+ break;
+ }
+ }
+ if (!found) {
+ if (fileSet->GetType() == "HEADERS"_s) {
+ headTarget->Makefile->GetOrCreateSourceGroup("Header Files")
+ ->AddGroupFile(path);
+ }
+ }
+#endif
+ }
+ }
+}
+
+void AddFileSetEntries(cmGeneratorTarget const* headTarget,
+ std::string const& config,
+ cmGeneratorExpressionDAGChecker* dagChecker,
+ EvaluatedTargetPropertyEntries& entries)
+{
+ for (auto const& entry : headTarget->Target->GetHeaderSetsEntries()) {
+ for (auto const& name : cmExpandedList(entry.Value)) {
+ auto const* headerSet = headTarget->Target->GetFileSet(name);
+ addFileSetEntry(headTarget, config, dagChecker, headerSet, entries);
+ }
+ }
+}
+
bool processSources(cmGeneratorTarget const* tgt,
EvaluatedTargetPropertyEntries& entries,
std::vector<BT<std::string>>& srcs,
@@ -1731,10 +1866,18 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetSourceFilePaths(
uniqueSrcs, debugSources);
}
+ // Collect this target's file sets.
+ std::vector<std::string>::size_type numFilesBefore3 = files.size();
+ EvaluatedTargetPropertyEntries fileSetEntries;
+ AddFileSetEntries(this, config, &dagChecker, fileSetEntries);
+ bool contextDependentFileSets =
+ processSources(this, fileSetEntries, files, uniqueSrcs, debugSources);
+
// Determine if sources are context-dependent or not.
if (!contextDependentDirectSources &&
!(contextDependentInterfaceSources && numFilesBefore < files.size()) &&
- !(contextDependentObjects && numFilesBefore2 < files.size())) {
+ !(contextDependentObjects && numFilesBefore2 < files.size()) &&
+ !(contextDependentFileSets && numFilesBefore3 < files.size())) {
this->SourcesAreContextDependent = Tribool::False;
} else {
this->SourcesAreContextDependent = Tribool::True;
diff --git a/Source/cmInstallCommand.cxx b/Source/cmInstallCommand.cxx
index eaf88f6..18f2f7f 100644
--- a/Source/cmInstallCommand.cxx
+++ b/Source/cmInstallCommand.cxx
@@ -6,11 +6,13 @@
#include <cassert>
#include <cstddef>
#include <iterator>
+#include <map>
#include <set>
#include <sstream>
#include <utility>
#include <cm/memory>
+#include <cm/string_view>
#include <cmext/string_view>
#include "cmsys/Glob.hxx"
@@ -18,11 +20,13 @@
#include "cmArgumentParser.h"
#include "cmExecutionStatus.h"
#include "cmExportSet.h"
+#include "cmFileSet.h"
#include "cmGeneratorExpression.h"
#include "cmGlobalGenerator.h"
#include "cmInstallCommandArguments.h"
#include "cmInstallDirectoryGenerator.h"
#include "cmInstallExportGenerator.h"
+#include "cmInstallFileSetGenerator.h"
#include "cmInstallFilesGenerator.h"
#include "cmInstallGenerator.h"
#include "cmInstallGetRuntimeDependenciesGenerator.h"
@@ -89,6 +93,9 @@ public:
bool MakeFilesFullPath(const char* modeName,
const std::vector<std::string>& relFiles,
std::vector<std::string>& absFiles);
+ bool MakeFilesFullPath(const char* modeName, const std::string& basePath,
+ const std::vector<std::string>& relFiles,
+ std::vector<std::string>& absFiles);
bool CheckCMP0006(bool& failure) const;
std::string GetDestination(const cmInstallCommandArguments* args,
@@ -177,6 +184,19 @@ std::unique_ptr<cmInstallFilesGenerator> CreateInstallFilesGenerator(
args.GetDestination());
}
+std::unique_ptr<cmInstallFileSetGenerator> CreateInstallFileSetGenerator(
+ Helper& helper, cmTarget& target, cmFileSet* fileSet,
+ const std::string& destination, const cmInstallCommandArguments& args)
+{
+ cmInstallGenerator::MessageLevel message =
+ cmInstallGenerator::SelectMessageLevel(helper.Makefile);
+ return cm::make_unique<cmInstallFileSetGenerator>(
+ target.GetName(), fileSet, destination, args.GetPermissions(),
+ args.GetConfigurations(), args.GetComponent(), message,
+ args.GetExcludeFromAll(), args.GetOptional(),
+ helper.Makefile->GetBacktrace());
+}
+
void AddInstallRuntimeDependenciesGenerator(
Helper& helper, cmInstallRuntimeDependencySet* runtimeDependencySet,
const cmInstallCommandArguments& runtimeArgs,
@@ -390,6 +410,7 @@ bool HandleTargetsMode(std::vector<std::string> const& args,
std::vector<std::string> PrivateHeader;
std::vector<std::string> PublicHeader;
std::vector<std::string> Resource;
+ std::vector<std::vector<std::string>> FileSets;
};
static auto const argHelper =
@@ -403,7 +424,8 @@ bool HandleTargetsMode(std::vector<std::string> const& args,
.Bind("INCLUDES"_s, &ArgVectors::Includes)
.Bind("PRIVATE_HEADER"_s, &ArgVectors::PrivateHeader)
.Bind("PUBLIC_HEADER"_s, &ArgVectors::PublicHeader)
- .Bind("RESOURCE"_s, &ArgVectors::Resource);
+ .Bind("RESOURCE"_s, &ArgVectors::Resource)
+ .Bind("FILE_SET"_s, &ArgVectors::FileSets);
std::vector<std::string> genericArgVector;
ArgVectors const argVectors = argHelper.Parse(args, &genericArgVector);
@@ -442,6 +464,8 @@ bool HandleTargetsMode(std::vector<std::string> const& args,
cmInstallCommandArguments publicHeaderArgs(helper.DefaultComponentName);
cmInstallCommandArguments resourceArgs(helper.DefaultComponentName);
cmInstallCommandIncludesArgument includesArgs;
+ std::vector<cmInstallCommandFileSetArguments> fileSetArgs(
+ argVectors.FileSets.size(), { helper.DefaultComponentName });
// now parse the args for specific parts of the target (e.g. LIBRARY,
// RUNTIME, ARCHIVE etc.
@@ -455,6 +479,15 @@ bool HandleTargetsMode(std::vector<std::string> const& args,
publicHeaderArgs.Parse(argVectors.PublicHeader, &unknownArgs);
resourceArgs.Parse(argVectors.Resource, &unknownArgs);
includesArgs.Parse(&argVectors.Includes, &unknownArgs);
+ for (std::size_t i = 0; i < argVectors.FileSets.size(); i++) {
+ // We have to create a separate object for the parsing because
+ // cmArgumentParser<void>::Bind() binds to a specific address, but the
+ // objects in the vector can move around. So we parse in an object with a
+ // fixed address and then copy the data into the vector.
+ cmInstallCommandFileSetArguments fileSetArg(helper.DefaultComponentName);
+ fileSetArg.Parse(argVectors.FileSets[i], &unknownArgs);
+ fileSetArgs[i] = std::move(fileSetArg);
+ }
if (!unknownArgs.empty()) {
// Unknown argument.
@@ -473,6 +506,9 @@ bool HandleTargetsMode(std::vector<std::string> const& args,
privateHeaderArgs.SetGenericArguments(&genericArgs);
publicHeaderArgs.SetGenericArguments(&genericArgs);
resourceArgs.SetGenericArguments(&genericArgs);
+ for (auto& fileSetArg : fileSetArgs) {
+ fileSetArg.SetGenericArguments(&genericArgs);
+ }
success = success && archiveArgs.Finalize();
success = success && libraryArgs.Finalize();
@@ -483,6 +519,9 @@ bool HandleTargetsMode(std::vector<std::string> const& args,
success = success && privateHeaderArgs.Finalize();
success = success && publicHeaderArgs.Finalize();
success = success && resourceArgs.Finalize();
+ for (auto& fileSetArg : fileSetArgs) {
+ success = success && fileSetArg.Finalize();
+ }
if (!success) {
return false;
@@ -493,7 +532,10 @@ bool HandleTargetsMode(std::vector<std::string> const& args,
if (archiveArgs.GetNamelinkOnly() || runtimeArgs.GetNamelinkOnly() ||
objectArgs.GetNamelinkOnly() || frameworkArgs.GetNamelinkOnly() ||
bundleArgs.GetNamelinkOnly() || privateHeaderArgs.GetNamelinkOnly() ||
- publicHeaderArgs.GetNamelinkOnly() || resourceArgs.GetNamelinkOnly()) {
+ publicHeaderArgs.GetNamelinkOnly() || resourceArgs.GetNamelinkOnly() ||
+ std::any_of(fileSetArgs.begin(), fileSetArgs.end(),
+ [](const cmInstallCommandFileSetArguments& fileSetArg)
+ -> bool { return fileSetArg.GetNamelinkOnly(); })) {
status.SetError(
"TARGETS given NAMELINK_ONLY option not in LIBRARY group. "
"The NAMELINK_ONLY option may be specified only following LIBRARY.");
@@ -502,7 +544,10 @@ bool HandleTargetsMode(std::vector<std::string> const& args,
if (archiveArgs.GetNamelinkSkip() || runtimeArgs.GetNamelinkSkip() ||
objectArgs.GetNamelinkSkip() || frameworkArgs.GetNamelinkSkip() ||
bundleArgs.GetNamelinkSkip() || privateHeaderArgs.GetNamelinkSkip() ||
- publicHeaderArgs.GetNamelinkSkip() || resourceArgs.GetNamelinkSkip()) {
+ publicHeaderArgs.GetNamelinkSkip() || resourceArgs.GetNamelinkSkip() ||
+ std::any_of(fileSetArgs.begin(), fileSetArgs.end(),
+ [](const cmInstallCommandFileSetArguments& fileSetArg)
+ -> bool { return fileSetArg.GetNamelinkSkip(); })) {
status.SetError(
"TARGETS given NAMELINK_SKIP option not in LIBRARY group. "
"The NAMELINK_SKIP option may be specified only following LIBRARY.");
@@ -515,7 +560,10 @@ bool HandleTargetsMode(std::vector<std::string> const& args,
bundleArgs.HasNamelinkComponent() ||
privateHeaderArgs.HasNamelinkComponent() ||
publicHeaderArgs.HasNamelinkComponent() ||
- resourceArgs.HasNamelinkComponent()) {
+ resourceArgs.HasNamelinkComponent() ||
+ std::any_of(fileSetArgs.begin(), fileSetArgs.end(),
+ [](const cmInstallCommandFileSetArguments& fileSetArg)
+ -> bool { return fileSetArg.HasNamelinkComponent(); })) {
status.SetError(
"TARGETS given NAMELINK_COMPONENT option not in LIBRARY group. "
"The NAMELINK_COMPONENT option may be specified only following "
@@ -531,12 +579,21 @@ bool HandleTargetsMode(std::vector<std::string> const& args,
!libraryArgs.GetType().empty() || !runtimeArgs.GetType().empty() ||
!objectArgs.GetType().empty() || !frameworkArgs.GetType().empty() ||
!bundleArgs.GetType().empty() || !privateHeaderArgs.GetType().empty() ||
- !publicHeaderArgs.GetType().empty() || !resourceArgs.GetType().empty()) {
+ !publicHeaderArgs.GetType().empty() || !resourceArgs.GetType().empty() ||
+ std::any_of(fileSetArgs.begin(), fileSetArgs.end(),
+ [](const cmInstallCommandFileSetArguments& fileSetArg)
+ -> bool { return !fileSetArg.GetType().empty(); })) {
status.SetError(
"TARGETS given TYPE option. The TYPE option may only be specified in "
" install(FILES) and install(DIRECTORIES).");
return false;
}
+ if (std::any_of(fileSetArgs.begin(), fileSetArgs.end(),
+ [](const cmInstallCommandFileSetArguments& fileSetArg)
+ -> bool { return fileSetArg.GetFileSet().empty(); })) {
+ status.SetError("TARGETS given FILE_SET option without file set name.");
+ return false;
+ }
cmInstallRuntimeDependencySet* runtimeDependencySet = nullptr;
if (withRuntimeDependencies) {
@@ -647,6 +704,7 @@ bool HandleTargetsMode(std::vector<std::string> const& args,
bool installsPrivateHeader = false;
bool installsPublicHeader = false;
bool installsResource = false;
+ std::vector<bool> installsFileSet(fileSetArgs.size(), false);
// Generate install script code to install the given targets.
for (cmTarget* ti : targets) {
@@ -662,6 +720,7 @@ bool HandleTargetsMode(std::vector<std::string> const& args,
std::unique_ptr<cmInstallFilesGenerator> privateHeaderGenerator;
std::unique_ptr<cmInstallFilesGenerator> publicHeaderGenerator;
std::unique_ptr<cmInstallFilesGenerator> resourceGenerator;
+ std::vector<std::unique_ptr<cmInstallFileSetGenerator>> fileSetGenerators;
// Avoid selecting default destinations for PUBLIC_HEADER and
// PRIVATE_HEADER if any artifacts are specified.
@@ -670,9 +729,24 @@ bool HandleTargetsMode(std::vector<std::string> const& args,
// Track whether this is a namelink-only rule.
bool namelinkOnly = false;
- auto addTargetExport = [&]() {
+ auto addTargetExport = [&]() -> bool {
// Add this install rule to an export if one was specified.
if (!exports.empty()) {
+ auto interfaceFileSets = target.GetAllInterfaceFileSets();
+ if (std::any_of(
+ interfaceFileSets.begin(), interfaceFileSets.end(),
+ [=](const std::string& name) -> bool {
+ return !std::any_of(
+ fileSetArgs.begin(), fileSetArgs.end(),
+ [=](const cmInstallCommandFileSetArguments& fileSetArg)
+ -> bool { return fileSetArg.GetFileSet() == name; });
+ })) {
+ status.SetError(cmStrCat(
+ "TARGETS target ", target.GetName(),
+ " is exported but not all of its file sets are installed"));
+ return false;
+ }
+
auto te = cm::make_unique<cmTargetExport>();
te->TargetName = target.GetName();
te->ArchiveGenerator = archiveGenerator.get();
@@ -682,6 +756,9 @@ bool HandleTargetsMode(std::vector<std::string> const& args,
te->LibraryGenerator = libraryGenerator.get();
te->RuntimeGenerator = runtimeGenerator.get();
te->ObjectsGenerator = objectGenerator.get();
+ for (auto const& gen : fileSetGenerators) {
+ te->FileSetGenerators[gen->GetFileSet()] = gen.get();
+ }
target.AddInstallIncludeDirectories(
cmMakeRange(includesArgs.GetIncludeDirs()));
te->NamelinkOnly = namelinkOnly;
@@ -689,6 +766,7 @@ bool HandleTargetsMode(std::vector<std::string> const& args,
->GetExportSets()[exports]
.AddTargetExport(std::move(te));
}
+ return true;
};
switch (target.GetType()) {
@@ -700,7 +778,9 @@ bool HandleTargetsMode(std::vector<std::string> const& args,
// When in namelink only mode skip all libraries on Windows.
if (namelinkMode == cmInstallTargetGenerator::NamelinkModeOnly) {
namelinkOnly = true;
- addTargetExport();
+ if (!addTargetExport()) {
+ return false;
+ }
continue;
}
@@ -736,7 +816,9 @@ bool HandleTargetsMode(std::vector<std::string> const& args,
// When in namelink only mode skip frameworks.
if (namelinkMode == cmInstallTargetGenerator::NamelinkModeOnly) {
namelinkOnly = true;
- addTargetExport();
+ if (!addTargetExport()) {
+ return false;
+ }
continue;
}
@@ -785,7 +867,9 @@ bool HandleTargetsMode(std::vector<std::string> const& args,
// When in namelink only mode skip frameworks.
if (namelinkMode == cmInstallTargetGenerator::NamelinkModeOnly) {
namelinkOnly = true;
- addTargetExport();
+ if (!addTargetExport()) {
+ return false;
+ }
continue;
}
@@ -991,8 +1075,39 @@ bool HandleTargetsMode(std::vector<std::string> const& args,
}
}
+ if (!namelinkOnly) {
+ for (std::size_t i = 0; i < fileSetArgs.size(); i++) {
+ auto* fileSet = target.GetFileSet(fileSetArgs[i].GetFileSet());
+ auto interfaceFileSetEntries = cmExpandedList(target.GetSafeProperty(
+ cmTarget::GetInterfaceFileSetsPropertyName(fileSet->GetType())));
+ if (fileSet &&
+ std::find(
+ interfaceFileSetEntries.begin(), interfaceFileSetEntries.end(),
+ fileSetArgs[i].GetFileSet()) != interfaceFileSetEntries.end()) {
+ std::string destination;
+ if (fileSet->GetType() == "HEADERS"_s) {
+ destination = helper.GetIncludeDestination(&fileSetArgs[i]);
+ } else {
+ destination = fileSetArgs[i].GetDestination();
+ if (destination.empty()) {
+ status.SetError(
+ cmStrCat("TARGETS given no FILE_SET DESTINATION for target \"",
+ target.GetName(), "\" file set \"",
+ fileSet->GetName(), "\"."));
+ return false;
+ }
+ }
+ fileSetGenerators.push_back(CreateInstallFileSetGenerator(
+ helper, target, fileSet, destination, fileSetArgs[i]));
+ installsFileSet[i] = true;
+ }
+ }
+ }
+
// Add this install rule to an export if one was specified.
- addTargetExport();
+ if (!addTargetExport()) {
+ return false;
+ }
// Keep track of whether we're installing anything in each category
installsArchive = installsArchive || archiveGenerator;
@@ -1016,6 +1131,9 @@ bool HandleTargetsMode(std::vector<std::string> const& args,
helper.Makefile->AddInstallGenerator(std::move(privateHeaderGenerator));
helper.Makefile->AddInstallGenerator(std::move(publicHeaderGenerator));
helper.Makefile->AddInstallGenerator(std::move(resourceGenerator));
+ for (auto& gen : fileSetGenerators) {
+ helper.Makefile->AddInstallGenerator(std::move(gen));
+ }
}
if (withRuntimeDependencies && !runtimeDependencySet->Empty()) {
@@ -1067,6 +1185,12 @@ bool HandleTargetsMode(std::vector<std::string> const& args,
helper.Makefile->GetGlobalGenerator()->AddInstallComponent(
resourceArgs.GetComponent());
}
+ for (std::size_t i = 0; i < fileSetArgs.size(); i++) {
+ if (installsFileSet[i]) {
+ helper.Makefile->GetGlobalGenerator()->AddInstallComponent(
+ fileSetArgs[i].GetComponent());
+ }
+ }
return true;
}
@@ -2063,12 +2187,20 @@ bool Helper::MakeFilesFullPath(const char* modeName,
const std::vector<std::string>& relFiles,
std::vector<std::string>& absFiles)
{
+ return this->MakeFilesFullPath(
+ modeName, this->Makefile->GetCurrentSourceDirectory(), relFiles, absFiles);
+}
+
+bool Helper::MakeFilesFullPath(const char* modeName,
+ const std::string& basePath,
+ const std::vector<std::string>& relFiles,
+ std::vector<std::string>& absFiles)
+{
for (std::string const& relFile : relFiles) {
std::string file = relFile;
std::string::size_type gpos = cmGeneratorExpression::Find(file);
if (gpos != 0 && !cmSystemTools::FileIsFullPath(file)) {
- file =
- cmStrCat(this->Makefile->GetCurrentSourceDirectory(), '/', relFile);
+ file = cmStrCat(basePath, '/', relFile);
}
// Make sure the file is not a directory.
diff --git a/Source/cmInstallCommandArguments.cxx b/Source/cmInstallCommandArguments.cxx
index cc3df2a..7309316 100644
--- a/Source/cmInstallCommandArguments.cxx
+++ b/Source/cmInstallCommandArguments.cxx
@@ -152,6 +152,11 @@ const std::string& cmInstallCommandArguments::GetType() const
return this->Type;
}
+const std::string& cmInstallCommandArguments::GetDefaultComponent() const
+{
+ return this->DefaultComponentName;
+}
+
const std::vector<std::string>& cmInstallCommandArguments::GetConfigurations()
const
{
@@ -220,3 +225,17 @@ void cmInstallCommandIncludesArgument::Parse(
this->IncludeDirs.push_back(std::move(dir));
}
}
+
+cmInstallCommandFileSetArguments::cmInstallCommandFileSetArguments(
+ std::string defaultComponent)
+ : cmInstallCommandArguments(std::move(defaultComponent))
+{
+ this->Bind("FILE_SET"_s, this->FileSet);
+}
+
+void cmInstallCommandFileSetArguments::Parse(
+ std::vector<std::string> args, std::vector<std::string>* unconsumedArgs)
+{
+ args.insert(args.begin(), "FILE_SET");
+ this->cmInstallCommandArguments::Parse(args, unconsumedArgs);
+}
diff --git a/Source/cmInstallCommandArguments.h b/Source/cmInstallCommandArguments.h
index f318a1a..79bd945 100644
--- a/Source/cmInstallCommandArguments.h
+++ b/Source/cmInstallCommandArguments.h
@@ -34,6 +34,8 @@ public:
bool HasNamelinkComponent() const;
const std::string& GetType() const;
+ const std::string& GetDefaultComponent() const;
+
static bool CheckPermissions(const std::string& onePerm, std::string& perm);
private:
@@ -71,3 +73,17 @@ public:
private:
std::vector<std::string> IncludeDirs;
};
+
+class cmInstallCommandFileSetArguments : public cmInstallCommandArguments
+{
+public:
+ cmInstallCommandFileSetArguments(std::string defaultComponent);
+
+ void Parse(std::vector<std::string> args,
+ std::vector<std::string>* unconsumedArgs);
+
+ const std::string& GetFileSet() const { return this->FileSet; }
+
+private:
+ std::string FileSet;
+};
diff --git a/Source/cmInstallFileSetGenerator.cxx b/Source/cmInstallFileSetGenerator.cxx
new file mode 100644
index 0000000..7121ea3
--- /dev/null
+++ b/Source/cmInstallFileSetGenerator.cxx
@@ -0,0 +1,88 @@
+/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
+ file Copyright.txt or https://cmake.org/licensing for details. */
+#include "cmInstallFileSetGenerator.h"
+
+#include <map>
+#include <string>
+#include <utility>
+#include <vector>
+
+#include "cmFileSet.h"
+#include "cmGeneratorExpression.h"
+#include "cmGlobalGenerator.h"
+#include "cmInstallType.h"
+#include "cmLocalGenerator.h"
+#include "cmStringAlgorithms.h"
+
+cmInstallFileSetGenerator::cmInstallFileSetGenerator(
+ std::string targetName, cmFileSet* fileSet, std::string const& dest,
+ std::string file_permissions, std::vector<std::string> const& configurations,
+ std::string const& component, MessageLevel message, bool exclude_from_all,
+ bool optional, cmListFileBacktrace backtrace)
+ : cmInstallGenerator(dest, configurations, component, message,
+ exclude_from_all, false, std::move(backtrace))
+ , TargetName(std::move(targetName))
+ , FileSet(fileSet)
+ , FilePermissions(std::move(file_permissions))
+ , Optional(optional)
+{
+ this->ActionsPerConfig = true;
+}
+
+cmInstallFileSetGenerator::~cmInstallFileSetGenerator() = default;
+
+bool cmInstallFileSetGenerator::Compute(cmLocalGenerator* lg)
+{
+ this->LocalGenerator = lg;
+
+ // Lookup this target in the current directory.
+ this->Target = lg->FindLocalNonAliasGeneratorTarget(this->TargetName);
+ if (!this->Target) {
+ // If no local target has been found, find it in the global scope.
+ this->Target =
+ lg->GetGlobalGenerator()->FindGeneratorTarget(this->TargetName);
+ }
+
+ return true;
+}
+
+std::string cmInstallFileSetGenerator::GetDestination(
+ std::string const& config) const
+{
+ return cmGeneratorExpression::Evaluate(this->Destination,
+ this->LocalGenerator, config);
+}
+
+void cmInstallFileSetGenerator::GenerateScriptForConfig(
+ std::ostream& os, const std::string& config, Indent indent)
+{
+ for (auto const& dirEntry : this->CalculateFilesPerDir(config)) {
+ std::string destSub;
+ if (!dirEntry.first.empty()) {
+ destSub = cmStrCat('/', dirEntry.first);
+ }
+ this->AddInstallRule(os, cmStrCat(this->GetDestination(config), destSub),
+ cmInstallType_FILES, dirEntry.second,
+ this->GetOptional(), this->FilePermissions.c_str(),
+ nullptr, nullptr, nullptr, indent);
+ }
+}
+
+std::map<std::string, std::vector<std::string>>
+cmInstallFileSetGenerator::CalculateFilesPerDir(
+ const std::string& config) const
+{
+ std::map<std::string, std::vector<std::string>> result;
+
+ auto dirCges = this->FileSet->CompileDirectoryEntries();
+ auto dirs = this->FileSet->EvaluateDirectoryEntries(
+ dirCges, this->LocalGenerator, config, this->Target);
+
+ auto fileCges = this->FileSet->CompileFileEntries();
+ for (auto const& fileCge : fileCges) {
+ this->FileSet->EvaluateFileEntry(
+ dirs, result, fileCge, this->LocalGenerator, config, this->Target);
+ }
+
+ return result;
+}
diff --git a/Source/cmInstallFileSetGenerator.h b/Source/cmInstallFileSetGenerator.h
new file mode 100644
index 0000000..8d067d9
--- /dev/null
+++ b/Source/cmInstallFileSetGenerator.h
@@ -0,0 +1,52 @@
+/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
+ file Copyright.txt or https://cmake.org/licensing for details. */
+#pragma once
+
+#include <iosfwd>
+#include <map>
+#include <string>
+#include <vector>
+
+#include "cmInstallGenerator.h"
+#include "cmListFileCache.h"
+#include "cmScriptGenerator.h"
+
+class cmGeneratorTarget;
+class cmFileSet;
+class cmLocalGenerator;
+
+class cmInstallFileSetGenerator : public cmInstallGenerator
+{
+public:
+ cmInstallFileSetGenerator(std::string targetName, cmFileSet* fileSet,
+ std::string const& dest,
+ std::string file_permissions,
+ std::vector<std::string> const& configurations,
+ std::string const& component, MessageLevel message,
+ bool exclude_from_all, bool optional,
+ cmListFileBacktrace backtrace);
+ ~cmInstallFileSetGenerator() override;
+
+ bool Compute(cmLocalGenerator* lg) override;
+
+ std::string GetDestination(std::string const& config) const;
+ std::string GetDestination() const { return this->Destination; }
+ bool GetOptional() const { return this->Optional; }
+ cmFileSet* GetFileSet() const { return this->FileSet; }
+ cmGeneratorTarget* GetTarget() const { return this->Target; }
+
+protected:
+ void GenerateScriptForConfig(std::ostream& os, const std::string& config,
+ Indent indent) override;
+
+private:
+ std::string TargetName;
+ cmLocalGenerator* LocalGenerator;
+ cmFileSet* const FileSet;
+ std::string const FilePermissions;
+ bool const Optional;
+ cmGeneratorTarget* Target;
+
+ std::map<std::string, std::vector<std::string>> CalculateFilesPerDir(
+ const std::string& config) const;
+};
diff --git a/Source/cmOutputConverter.cxx b/Source/cmOutputConverter.cxx
index 2b785e1..02b4821 100644
--- a/Source/cmOutputConverter.cxx
+++ b/Source/cmOutputConverter.cxx
@@ -219,10 +219,11 @@ std::string cmOutputConverter::EscapeForShell(
return Shell_GetArgument(str, flags);
}
-std::string cmOutputConverter::EscapeForCMake(cm::string_view str)
+std::string cmOutputConverter::EscapeForCMake(cm::string_view str,
+ WrapQuotes wrapQuotes)
{
// Always double-quote the argument to take care of most escapes.
- std::string result = "\"";
+ std::string result = (wrapQuotes == WrapQuotes::Wrap) ? "\"" : "";
for (const char c : str) {
if (c == '"') {
// Escape the double quote to avoid ending the argument.
@@ -238,7 +239,9 @@ std::string cmOutputConverter::EscapeForCMake(cm::string_view str)
result += c;
}
}
- result += "\"";
+ if (wrapQuotes == WrapQuotes::Wrap) {
+ result += "\"";
+ }
return result;
}
diff --git a/Source/cmOutputConverter.h b/Source/cmOutputConverter.h
index 865df71..53ec247 100644
--- a/Source/cmOutputConverter.h
+++ b/Source/cmOutputConverter.h
@@ -94,7 +94,13 @@ public:
bool forEcho = false, bool useWatcomQuote = false,
bool unescapeNinjaConfiguration = false) const;
- static std::string EscapeForCMake(cm::string_view str);
+ enum class WrapQuotes
+ {
+ Wrap,
+ NoWrap,
+ };
+ static std::string EscapeForCMake(cm::string_view str,
+ WrapQuotes wrapQuotes = WrapQuotes::Wrap);
/** Compute an escaped version of the given argument for use in a
windows shell. */
diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx
index 97d60cf..4f0dc60 100644
--- a/Source/cmTarget.cxx
+++ b/Source/cmTarget.cxx
@@ -14,11 +14,13 @@
#include <cm/memory>
#include <cmext/algorithm>
+#include <cmext/string_view>
#include "cmsys/RegularExpression.hxx"
#include "cmAlgorithms.h"
#include "cmCustomCommand.h"
+#include "cmFileSet.h"
#include "cmGeneratorExpression.h"
#include "cmGeneratorTarget.h"
#include "cmGlobalGenerator.h"
@@ -200,8 +202,11 @@ public:
std::vector<BT<std::string>> LinkOptionsEntries;
std::vector<BT<std::string>> LinkDirectoriesEntries;
std::vector<BT<std::string>> LinkImplementationPropertyEntries;
+ std::vector<BT<std::string>> HeaderSetsEntries;
+ std::vector<BT<std::string>> InterfaceHeaderSetsEntries;
std::vector<std::pair<cmTarget::TLLSignature, cmListFileContext>>
TLLCommands;
+ std::map<std::string, cmFileSet> FileSets;
cmListFileBacktrace Backtrace;
bool CheckImportedLibName(std::string const& prop,
@@ -1110,6 +1115,16 @@ cmBTStringRange cmTarget::GetLinkImplementationEntries() const
return cmMakeRange(this->impl->LinkImplementationPropertyEntries);
}
+cmBTStringRange cmTarget::GetHeaderSetsEntries() const
+{
+ return cmMakeRange(this->impl->HeaderSetsEntries);
+}
+
+cmBTStringRange cmTarget::GetInterfaceHeaderSetsEntries() const
+{
+ return cmMakeRange(this->impl->InterfaceHeaderSetsEntries);
+}
+
namespace {
#define MAKE_PROP(PROP) const std::string prop##PROP = #PROP
MAKE_PROP(C_STANDARD);
@@ -1139,6 +1154,10 @@ MAKE_PROP(BINARY_DIR);
MAKE_PROP(SOURCE_DIR);
MAKE_PROP(FALSE);
MAKE_PROP(TRUE);
+MAKE_PROP(HEADER_DIRS);
+MAKE_PROP(HEADER_SET);
+MAKE_PROP(HEADER_SETS);
+MAKE_PROP(INTERFACE_HEADER_SETS);
#undef MAKE_PROP
}
@@ -1158,6 +1177,21 @@ std::string ConvertToString<cmValue>(cmValue value)
{
return std::string(*value);
}
+
+template <typename ValueType>
+bool StringIsEmpty(ValueType value);
+
+template <>
+bool StringIsEmpty<const char*>(const char* value)
+{
+ return cmValue::IsEmpty(value);
+}
+
+template <>
+bool StringIsEmpty<cmValue>(cmValue value)
+{
+ return value.IsEmpty();
+}
}
template <typename ValueType>
@@ -1321,6 +1355,104 @@ void cmTarget::StoreProperty(const std::string& prop, ValueType value)
} else {
this->impl->LanguageStandardProperties.erase(prop);
}
+ } else if (prop == propHEADER_DIRS) {
+ auto* fileSet = this->GetFileSet("HEADERS");
+ if (!fileSet) {
+ this->impl->Makefile->IssueMessage(
+ MessageType::FATAL_ERROR,
+ "The default header set has not yet been created.");
+ return;
+ }
+ fileSet->ClearDirectoryEntries();
+ if (!StringIsEmpty(value)) {
+ fileSet->AddDirectoryEntry(
+ BT<std::string>(value, this->impl->Makefile->GetBacktrace()));
+ }
+ } else if (prop == propHEADER_SET) {
+ auto* fileSet = this->GetFileSet("HEADERS");
+ if (!fileSet) {
+ this->impl->Makefile->IssueMessage(
+ MessageType::FATAL_ERROR,
+ "The default header set has not yet been created.");
+ return;
+ }
+ fileSet->ClearFileEntries();
+ if (!StringIsEmpty(value)) {
+ fileSet->AddFileEntry(
+ BT<std::string>(value, this->impl->Makefile->GetBacktrace()));
+ }
+ } else if (cmHasLiteralPrefix(prop, "HEADER_DIRS_")) {
+ auto fileSetName = prop.substr(cmStrLen("HEADER_DIRS_"));
+ if (fileSetName.empty()) {
+ this->impl->Makefile->IssueMessage(MessageType::FATAL_ERROR,
+ "Header set name cannot be empty.");
+ return;
+ }
+ auto* fileSet = this->GetFileSet(fileSetName);
+ if (!fileSet) {
+ this->impl->Makefile->IssueMessage(
+ MessageType::FATAL_ERROR,
+ cmStrCat("Header set \"", fileSetName,
+ "\" has not yet been created."));
+ return;
+ }
+ fileSet->ClearDirectoryEntries();
+ if (!StringIsEmpty(value)) {
+ fileSet->AddDirectoryEntry(
+ BT<std::string>(value, this->impl->Makefile->GetBacktrace()));
+ }
+ } else if (cmHasLiteralPrefix(prop, "HEADER_SET_")) {
+ auto fileSetName = prop.substr(cmStrLen("HEADER_SET_"));
+ if (fileSetName.empty()) {
+ this->impl->Makefile->IssueMessage(MessageType::FATAL_ERROR,
+ "Header set name cannot be empty.");
+ return;
+ }
+ auto* fileSet = this->GetFileSet(fileSetName);
+ if (!fileSet) {
+ this->impl->Makefile->IssueMessage(
+ MessageType::FATAL_ERROR,
+ cmStrCat("Header set \"", fileSetName,
+ "\" has not yet been created."));
+ return;
+ }
+ fileSet->ClearFileEntries();
+ if (!StringIsEmpty(value)) {
+ fileSet->AddFileEntry(
+ BT<std::string>(value, this->impl->Makefile->GetBacktrace()));
+ }
+ } else if (prop == propHEADER_SETS) {
+ if (value) {
+ for (auto const& name : cmExpandedList(value)) {
+ if (!this->GetFileSet(name)) {
+ this->impl->Makefile->IssueMessage(
+ MessageType::FATAL_ERROR,
+ cmStrCat("Header set \"", name, "\" has not yet been created."));
+ return;
+ }
+ }
+ }
+ this->impl->HeaderSetsEntries.clear();
+ if (!StringIsEmpty(value)) {
+ this->impl->HeaderSetsEntries.emplace_back(
+ value, this->impl->Makefile->GetBacktrace());
+ }
+ } else if (prop == propINTERFACE_HEADER_SETS) {
+ if (value) {
+ for (auto const& name : cmExpandedList(value)) {
+ if (!this->GetFileSet(name)) {
+ this->impl->Makefile->IssueMessage(
+ MessageType::FATAL_ERROR,
+ cmStrCat("Header set \"", name, "\" has not yet been created."));
+ return;
+ }
+ }
+ }
+ this->impl->InterfaceHeaderSetsEntries.clear();
+ if (!StringIsEmpty(value)) {
+ this->impl->InterfaceHeaderSetsEntries.emplace_back(
+ value, this->impl->Makefile->GetBacktrace());
+ }
} else {
this->impl->Properties.SetProperty(prop, value);
}
@@ -1415,6 +1547,82 @@ void cmTarget::AppendProperty(const std::string& prop,
prop == "OBJC_STANDARD" || prop == "OBJCXX_STANDARD") {
this->impl->Makefile->IssueMessage(
MessageType::FATAL_ERROR, prop + " property may not be appended.");
+ } else if (prop == "HEADER_DIRS") {
+ auto* fileSet = this->GetFileSet("HEADERS");
+ if (!fileSet) {
+ this->impl->Makefile->IssueMessage(
+ MessageType::FATAL_ERROR,
+ "The default header set has not yet been created.");
+ return;
+ }
+ fileSet->AddDirectoryEntry(
+ BT<std::string>(value, this->impl->Makefile->GetBacktrace()));
+ } else if (cmHasLiteralPrefix(prop, "HEADER_DIRS_")) {
+ auto fileSetName = prop.substr(cmStrLen("HEADER_DIRS_"));
+ if (fileSetName.empty()) {
+ this->impl->Makefile->IssueMessage(MessageType::FATAL_ERROR,
+ "Header set name cannot be empty.");
+ return;
+ }
+ auto* fileSet = this->GetFileSet(fileSetName);
+ if (!fileSet) {
+ this->impl->Makefile->IssueMessage(
+ MessageType::FATAL_ERROR,
+ cmStrCat("Header set \"", fileSetName,
+ "\" has not yet been created."));
+ return;
+ }
+ fileSet->AddDirectoryEntry(
+ BT<std::string>(value, this->impl->Makefile->GetBacktrace()));
+ } else if (prop == "HEADER_SET") {
+ auto* fileSet = this->GetFileSet("HEADERS");
+ if (!fileSet) {
+ this->impl->Makefile->IssueMessage(
+ MessageType::FATAL_ERROR,
+ "The default header set has not yet been created.");
+ return;
+ }
+ fileSet->AddFileEntry(
+ BT<std::string>(value, this->impl->Makefile->GetBacktrace()));
+ } else if (cmHasLiteralPrefix(prop, "HEADER_SET_")) {
+ auto fileSetName = prop.substr(cmStrLen("HEADER_SET_"));
+ if (fileSetName.empty()) {
+ this->impl->Makefile->IssueMessage(MessageType::FATAL_ERROR,
+ "Header set name cannot be empty.");
+ return;
+ }
+ auto* fileSet = this->GetFileSet(fileSetName);
+ if (!fileSet) {
+ this->impl->Makefile->IssueMessage(
+ MessageType::FATAL_ERROR,
+ cmStrCat("Header set \"", fileSetName,
+ "\" has not yet been created."));
+ return;
+ }
+ fileSet->AddFileEntry(
+ BT<std::string>(value, this->impl->Makefile->GetBacktrace()));
+ } else if (prop == "HEADER_SETS") {
+ for (auto const& name : cmExpandedList(value)) {
+ if (!this->GetFileSet(name)) {
+ this->impl->Makefile->IssueMessage(
+ MessageType::FATAL_ERROR,
+ cmStrCat("Header set \"", name, "\" has not yet been created."));
+ return;
+ }
+ }
+ this->impl->HeaderSetsEntries.emplace_back(
+ value, this->impl->Makefile->GetBacktrace());
+ } else if (prop == "INTERFACE_HEADER_SETS") {
+ for (auto const& name : cmExpandedList(value)) {
+ if (!this->GetFileSet(name)) {
+ this->impl->Makefile->IssueMessage(
+ MessageType::FATAL_ERROR,
+ cmStrCat("Header set \"", name, "\" has not yet been created."));
+ return;
+ }
+ }
+ this->impl->InterfaceHeaderSetsEntries.emplace_back(
+ value, this->impl->Makefile->GetBacktrace());
} else {
this->impl->Properties.AppendProperty(prop, value, asString);
}
@@ -1633,7 +1841,11 @@ cmValue cmTarget::GetProperty(const std::string& prop) const
propNAME,
propBINARY_DIR,
propSOURCE_DIR,
- propSOURCES
+ propSOURCES,
+ propHEADER_DIRS,
+ propHEADER_SET,
+ propHEADER_SETS,
+ propINTERFACE_HEADER_SETS,
};
if (specialProps.count(prop)) {
if (prop == propC_STANDARD || prop == propCXX_STANDARD ||
@@ -1759,6 +1971,60 @@ cmValue cmTarget::GetProperty(const std::string& prop) const
.GetDirectory()
.GetCurrentSource());
}
+ if (prop == propHEADER_DIRS) {
+ auto const* fileSet = this->GetFileSet("HEADERS");
+ if (!fileSet) {
+ return nullptr;
+ }
+ static std::string output;
+ output = cmJoin(fileSet->GetDirectoryEntries(), ";"_s);
+ return cmValue(output);
+ }
+ if (prop == propHEADER_SET) {
+ auto const* fileSet = this->GetFileSet("HEADERS");
+ if (!fileSet) {
+ return nullptr;
+ }
+ static std::string output;
+ output = cmJoin(fileSet->GetFileEntries(), ";"_s);
+ return cmValue(output);
+ }
+ if (prop == propHEADER_SETS) {
+ static std::string output;
+ output = cmJoin(this->impl->HeaderSetsEntries, ";"_s);
+ return cmValue(output);
+ }
+ if (prop == propINTERFACE_HEADER_SETS) {
+ static std::string output;
+ output = cmJoin(this->impl->InterfaceHeaderSetsEntries, ";"_s);
+ return cmValue(output);
+ }
+ }
+ if (cmHasLiteralPrefix(prop, "HEADER_DIRS_")) {
+ std::string fileSetName = prop.substr(cmStrLen("HEADER_DIRS_"));
+ if (fileSetName.empty()) {
+ return nullptr;
+ }
+ auto const* fileSet = this->GetFileSet(fileSetName);
+ if (!fileSet) {
+ return nullptr;
+ }
+ static std::string output;
+ output = cmJoin(fileSet->GetDirectoryEntries(), ";"_s);
+ return cmValue(output);
+ }
+ if (cmHasLiteralPrefix(prop, "HEADER_SET_")) {
+ std::string fileSetName = prop.substr(cmStrLen("HEADER_SET_"));
+ if (fileSetName.empty()) {
+ return nullptr;
+ }
+ auto const* fileSet = this->GetFileSet(fileSetName);
+ if (!fileSet) {
+ return nullptr;
+ }
+ static std::string output;
+ output = cmJoin(fileSet->GetFileEntries(), ";"_s);
+ return cmValue(output);
}
cmValue retVal = this->impl->Properties.GetPropertyValue(prop);
@@ -2015,6 +2281,59 @@ std::string cmTarget::ImportedGetFullPath(
return result;
}
+const cmFileSet* cmTarget::GetFileSet(const std::string& name) const
+{
+ auto it = this->impl->FileSets.find(name);
+ return it == this->impl->FileSets.end() ? nullptr : &it->second;
+}
+
+cmFileSet* cmTarget::GetFileSet(const std::string& name)
+{
+ auto it = this->impl->FileSets.find(name);
+ return it == this->impl->FileSets.end() ? nullptr : &it->second;
+}
+
+std::pair<cmFileSet*, bool> cmTarget::GetOrCreateFileSet(
+ const std::string& name, const std::string& type)
+{
+ auto result =
+ this->impl->FileSets.emplace(std::make_pair(name, cmFileSet(name, type)));
+ return std::make_pair(&result.first->second, result.second);
+}
+
+std::string cmTarget::GetFileSetsPropertyName(const std::string& type)
+{
+ if (type == "HEADERS") {
+ return "HEADER_SETS";
+ }
+ return "";
+}
+
+std::string cmTarget::GetInterfaceFileSetsPropertyName(const std::string& type)
+{
+ if (type == "HEADERS") {
+ return "INTERFACE_HEADER_SETS";
+ }
+ return "";
+}
+
+std::vector<std::string> cmTarget::GetAllInterfaceFileSets() const
+{
+ std::vector<std::string> result;
+ auto inserter = std::back_inserter(result);
+
+ auto appendEntries = [=](const std::vector<BT<std::string>>& entries) {
+ for (auto const& entry : entries) {
+ auto expanded = cmExpandedList(entry.Value);
+ std::copy(expanded.begin(), expanded.end(), inserter);
+ }
+ };
+
+ appendEntries(this->impl->InterfaceHeaderSetsEntries);
+
+ return result;
+}
+
bool cmTargetInternals::CheckImportedLibName(std::string const& prop,
std::string const& value) const
{
diff --git a/Source/cmTarget.h b/Source/cmTarget.h
index 3cf6942..27b325a 100644
--- a/Source/cmTarget.h
+++ b/Source/cmTarget.h
@@ -20,6 +20,7 @@
#include "cmValue.h"
class cmCustomCommand;
+class cmFileSet;
class cmGlobalGenerator;
class cmInstallTargetGenerator;
class cmMakefile;
@@ -260,6 +261,10 @@ public:
cmBTStringRange GetLinkImplementationEntries() const;
+ cmBTStringRange GetHeaderSetsEntries() const;
+
+ cmBTStringRange GetInterfaceHeaderSetsEntries() const;
+
std::string ImportedGetFullPath(const std::string& config,
cmStateEnums::ArtifactType artifact) const;
@@ -268,6 +273,16 @@ public:
bool operator()(cmTarget const* t1, cmTarget const* t2) const;
};
+ const cmFileSet* GetFileSet(const std::string& name) const;
+ cmFileSet* GetFileSet(const std::string& name);
+ std::pair<cmFileSet*, bool> GetOrCreateFileSet(const std::string& name,
+ const std::string& type);
+
+ std::vector<std::string> GetAllInterfaceFileSets() const;
+
+ static std::string GetFileSetsPropertyName(const std::string& type);
+ static std::string GetInterfaceFileSetsPropertyName(const std::string& type);
+
private:
template <typename ValueType>
void StoreProperty(const std::string& prop, ValueType value);
diff --git a/Source/cmTargetExport.h b/Source/cmTargetExport.h
index 19fc931..885ac74 100644
--- a/Source/cmTargetExport.h
+++ b/Source/cmTargetExport.h
@@ -6,7 +6,9 @@
#include <string>
+class cmFileSet;
class cmGeneratorTarget;
+class cmInstallFileSetGenerator;
class cmInstallFilesGenerator;
class cmInstallTargetGenerator;
@@ -29,6 +31,7 @@ public:
cmInstallTargetGenerator* FrameworkGenerator;
cmInstallTargetGenerator* BundleGenerator;
cmInstallFilesGenerator* HeaderGenerator;
+ std::map<cmFileSet*, cmInstallFileSetGenerator*> FileSetGenerators;
///@}
bool NamelinkOnly = false;
diff --git a/Source/cmTargetPropCommandBase.cxx b/Source/cmTargetPropCommandBase.cxx
index 3bd1ea3..391b954 100644
--- a/Source/cmTargetPropCommandBase.cxx
+++ b/Source/cmTargetPropCommandBase.cxx
@@ -155,10 +155,10 @@ bool cmTargetPropCommandBase::ProcessContentArgs(
return false;
}
}
- return this->PopulateTargetProperies(scope, content, prepend, system);
+ return this->PopulateTargetProperties(scope, content, prepend, system);
}
-bool cmTargetPropCommandBase::PopulateTargetProperies(
+bool cmTargetPropCommandBase::PopulateTargetProperties(
const std::string& scope, const std::vector<std::string>& content,
bool prepend, bool system)
{
diff --git a/Source/cmTargetPropCommandBase.h b/Source/cmTargetPropCommandBase.h
index fc24fe8..6bf7c3c 100644
--- a/Source/cmTargetPropCommandBase.h
+++ b/Source/cmTargetPropCommandBase.h
@@ -40,6 +40,9 @@ protected:
virtual void HandleInterfaceContent(cmTarget* tgt,
const std::vector<std::string>& content,
bool prepend, bool system);
+ virtual bool PopulateTargetProperties(
+ const std::string& scope, const std::vector<std::string>& content,
+ bool prepend, bool system);
private:
virtual void HandleMissingTarget(const std::string& name) = 0;
@@ -52,9 +55,6 @@ private:
bool ProcessContentArgs(std::vector<std::string> const& args,
unsigned int& argIndex, bool prepend, bool system);
- bool PopulateTargetProperies(const std::string& scope,
- const std::vector<std::string>& content,
- bool prepend, bool system);
cmExecutionStatus& Status;
};
diff --git a/Source/cmTargetSourcesCommand.cxx b/Source/cmTargetSourcesCommand.cxx
index 26282ef..818e271 100644
--- a/Source/cmTargetSourcesCommand.cxx
+++ b/Source/cmTargetSourcesCommand.cxx
@@ -2,9 +2,17 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmTargetSourcesCommand.h"
+#include <algorithm>
#include <sstream>
+#include <utility>
+#include <cm/string_view>
+#include <cmext/string_view>
+
+#include "cmArgumentParser.h"
+#include "cmFileSet.h"
#include "cmGeneratorExpression.h"
+#include "cmListFileCache.h"
#include "cmMakefile.h"
#include "cmMessageType.h"
#include "cmPolicies.h"
@@ -15,6 +23,20 @@
namespace {
+struct FileSetArgs
+{
+ std::string Type;
+ std::string FileSet;
+ std::vector<std::string> BaseDirs;
+ std::vector<std::string> Files;
+};
+
+auto const FileSetArgsParser = cmArgumentParser<FileSetArgs>()
+ .Bind("TYPE"_s, &FileSetArgs::Type)
+ .Bind("FILE_SET"_s, &FileSetArgs::FileSet)
+ .Bind("BASE_DIRS"_s, &FileSetArgs::BaseDirs)
+ .Bind("FILES"_s, &FileSetArgs::Files);
+
class TargetSourcesImpl : public cmTargetPropCommandBase
{
public:
@@ -26,8 +48,10 @@ protected:
bool prepend, bool system) override
{
this->cmTargetPropCommandBase::HandleInterfaceContent(
- tgt, this->ConvertToAbsoluteContent(tgt, content, true), prepend,
- system);
+ tgt,
+ this->ConvertToAbsoluteContent(tgt, content, IsInterface::Yes,
+ CheckCMP0076::Yes),
+ prepend, system);
}
private:
@@ -43,29 +67,55 @@ private:
const std::vector<std::string>& content,
bool /*prepend*/, bool /*system*/) override
{
- tgt->AppendProperty(
- "SOURCES",
- this->Join(this->ConvertToAbsoluteContent(tgt, content, false)));
+ tgt->AppendProperty("SOURCES",
+ this->Join(this->ConvertToAbsoluteContent(
+ tgt, content, IsInterface::No, CheckCMP0076::Yes)));
return true; // Successfully handled.
}
+ bool PopulateTargetProperties(const std::string& scope,
+ const std::vector<std::string>& content,
+ bool prepend, bool system) override
+ {
+ if (!content.empty() && content.front() == "FILE_SET"_s) {
+ return this->HandleFileSetMode(scope, content, prepend, system);
+ }
+ return this->cmTargetPropCommandBase::PopulateTargetProperties(
+ scope, content, prepend, system);
+ }
+
std::string Join(const std::vector<std::string>& content) override
{
return cmJoin(content, ";");
}
+ enum class IsInterface
+ {
+ Yes,
+ No,
+ };
+ enum class CheckCMP0076
+ {
+ Yes,
+ No,
+ };
std::vector<std::string> ConvertToAbsoluteContent(
cmTarget* tgt, const std::vector<std::string>& content,
- bool isInterfaceContent);
+ IsInterface isInterfaceContent, CheckCMP0076 checkCmp0076);
+
+ bool HandleFileSetMode(const std::string& scope,
+ const std::vector<std::string>& content, bool prepend,
+ bool system);
};
std::vector<std::string> TargetSourcesImpl::ConvertToAbsoluteContent(
cmTarget* tgt, const std::vector<std::string>& content,
- bool isInterfaceContent)
+ IsInterface isInterfaceContent, CheckCMP0076 checkCmp0076)
{
// Skip conversion in case old behavior has been explicitly requested
- if (this->Makefile->GetPolicyStatus(cmPolicies::CMP0076) ==
- cmPolicies::OLD) {
+ if (checkCmp0076 == CheckCMP0076::Yes &&
+ this->Makefile->GetPolicyStatus(cmPolicies::CMP0076) ==
+ cmPolicies::OLD) {
return content;
}
@@ -76,7 +126,7 @@ std::vector<std::string> TargetSourcesImpl::ConvertToAbsoluteContent(
std::string absoluteSrc;
if (cmSystemTools::FileIsFullPath(src) ||
cmGeneratorExpression::Find(src) == 0 ||
- (!isInterfaceContent &&
+ (isInterfaceContent == IsInterface::No &&
(this->Makefile->GetCurrentSourceDirectory() ==
tgt->GetMakefile()->GetCurrentSourceDirectory()))) {
absoluteSrc = src;
@@ -95,28 +145,33 @@ std::vector<std::string> TargetSourcesImpl::ConvertToAbsoluteContent(
bool issueMessage = true;
bool useAbsoluteContent = false;
std::ostringstream e;
- switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0076)) {
- case cmPolicies::WARN:
- e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0076) << "\n";
- break;
- case cmPolicies::OLD:
- issueMessage = false;
- break;
- case cmPolicies::REQUIRED_ALWAYS:
- case cmPolicies::REQUIRED_IF_USED:
- this->Makefile->IssueMessage(
- MessageType::FATAL_ERROR,
- cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0076));
- break;
- case cmPolicies::NEW: {
- issueMessage = false;
- useAbsoluteContent = true;
- break;
+ if (checkCmp0076 == CheckCMP0076::Yes) {
+ switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0076)) {
+ case cmPolicies::WARN:
+ e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0076) << "\n";
+ break;
+ case cmPolicies::OLD:
+ issueMessage = false;
+ break;
+ case cmPolicies::REQUIRED_ALWAYS:
+ case cmPolicies::REQUIRED_IF_USED:
+ this->Makefile->IssueMessage(
+ MessageType::FATAL_ERROR,
+ cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0076));
+ break;
+ case cmPolicies::NEW: {
+ issueMessage = false;
+ useAbsoluteContent = true;
+ break;
+ }
}
+ } else {
+ issueMessage = false;
+ useAbsoluteContent = true;
}
if (issueMessage) {
- if (isInterfaceContent) {
+ if (isInterfaceContent == IsInterface::Yes) {
e << "An interface source of target \"" << tgt->GetName()
<< "\" has a relative path.";
} else {
@@ -129,6 +184,133 @@ std::vector<std::string> TargetSourcesImpl::ConvertToAbsoluteContent(
return useAbsoluteContent ? absoluteContent : content;
}
+bool TargetSourcesImpl::HandleFileSetMode(
+ const std::string& scope, const std::vector<std::string>& content,
+ bool /*prepend*/, bool /*system*/)
+{
+ std::vector<std::string> unparsed;
+ auto args = FileSetArgsParser.Parse(content, &unparsed);
+
+ if (!unparsed.empty()) {
+ this->SetError(
+ cmStrCat("Unrecognized keyword: \"", unparsed.front(), "\""));
+ return false;
+ }
+
+ if (args.FileSet.empty()) {
+ this->SetError("FILE_SET must not be empty");
+ return false;
+ }
+
+ bool const isDefault = args.Type == args.FileSet ||
+ (args.Type.empty() && args.FileSet[0] >= 'A' && args.FileSet[0] <= 'Z');
+ std::string type = isDefault ? args.FileSet : args.Type;
+
+ auto fileSet = this->Target->GetOrCreateFileSet(args.FileSet, type);
+ if (fileSet.second) {
+ if (!isDefault) {
+ if (args.FileSet[0] >= 'A' && args.FileSet[0] <= 'Z') {
+ this->SetError(
+ "Non-default file set name must not start with a capital letter");
+ return false;
+ }
+ }
+ if (type.empty()) {
+ this->SetError("Must specify a TYPE when creating file set");
+ return false;
+ }
+ if (type != "HEADERS"_s) {
+ this->SetError("File set TYPE may only be \"HEADERS\"");
+ return false;
+ }
+
+ if (args.BaseDirs.empty()) {
+ args.BaseDirs.emplace_back(this->Makefile->GetCurrentSourceDirectory());
+ }
+
+ if (scope == "PRIVATE"_s || scope == "PUBLIC"_s) {
+ this->Target->AppendProperty(cmTarget::GetFileSetsPropertyName(type),
+ args.FileSet);
+ }
+ if (scope == "INTERFACE"_s || scope == "PUBLIC"_s) {
+ this->Target->AppendProperty(
+ cmTarget::GetInterfaceFileSetsPropertyName(type), args.FileSet);
+ }
+ } else {
+ type = fileSet.first->GetType();
+ if (!args.Type.empty() && args.Type != type) {
+ this->SetError(cmStrCat(
+ "Type \"", args.Type, "\" for file set \"", fileSet.first->GetName(),
+ "\" does not match original type \"", type, "\""));
+ return false;
+ }
+
+ std::string existingScope = "PRIVATE";
+
+ auto const fileSetsProperty = cmTarget::GetFileSetsPropertyName(type);
+ auto const interfaceFileSetsProperty =
+ cmTarget::GetInterfaceFileSetsPropertyName(type);
+ std::vector<std::string> fileSets;
+ std::vector<std::string> interfaceFileSets;
+ cmExpandList(this->Target->GetSafeProperty(fileSetsProperty), fileSets);
+ cmExpandList(this->Target->GetSafeProperty(interfaceFileSetsProperty),
+ interfaceFileSets);
+
+ if (std::find(interfaceFileSets.begin(), interfaceFileSets.end(),
+ args.FileSet) != interfaceFileSets.end()) {
+ existingScope = "INTERFACE";
+ }
+ if (std::find(fileSets.begin(), fileSets.end(), args.FileSet) !=
+ fileSets.end()) {
+ if (existingScope == "INTERFACE"_s) {
+ existingScope = "PUBLIC";
+ }
+ } else if (existingScope != "INTERFACE"_s) {
+ this->SetError(cmStrCat("File set \"", args.FileSet, "\" is not in ",
+ fileSetsProperty, " or ",
+ interfaceFileSetsProperty));
+ return false;
+ }
+
+ if (scope != existingScope) {
+ this->SetError(
+ cmStrCat("Scope ", scope, " for file set \"", args.FileSet,
+ "\" does not match original scope ", existingScope));
+ return false;
+ }
+ }
+
+ auto files = this->Join(this->ConvertToAbsoluteContent(
+ this->Target, args.Files, IsInterface::Yes, CheckCMP0076::No));
+ if (!files.empty()) {
+ fileSet.first->AddFileEntry(
+ BT<std::string>(files, this->Makefile->GetBacktrace()));
+ }
+
+ auto baseDirectories = this->Join(this->ConvertToAbsoluteContent(
+ this->Target, args.BaseDirs, IsInterface::Yes, CheckCMP0076::No));
+ if (!baseDirectories.empty()) {
+ fileSet.first->AddDirectoryEntry(
+ BT<std::string>(baseDirectories, this->Makefile->GetBacktrace()));
+ if (type == "HEADERS"_s) {
+ for (auto const& dir : cmExpandedList(baseDirectories)) {
+ auto interfaceDirectoriesGenex =
+ cmStrCat("$<BUILD_INTERFACE:", dir, ">");
+ if (scope == "PRIVATE"_s || scope == "PUBLIC"_s) {
+ this->Target->AppendProperty("INCLUDE_DIRECTORIES",
+ interfaceDirectoriesGenex);
+ }
+ if (scope == "INTERFACE"_s || scope == "PUBLIC"_s) {
+ this->Target->AppendProperty("INTERFACE_INCLUDE_DIRECTORIES",
+ interfaceDirectoriesGenex);
+ }
+ }
+ }
+ }
+
+ return true;
+}
+
} // namespace
bool cmTargetSourcesCommand(std::vector<std::string> const& args,
diff --git a/Tests/RunCMake/CommandLine/E_capabilities-stdout.txt b/Tests/RunCMake/CommandLine/E_capabilities-stdout.txt
index 3df3e52..6a932f1 100644
--- a/Tests/RunCMake/CommandLine/E_capabilities-stdout.txt
+++ b/Tests/RunCMake/CommandLine/E_capabilities-stdout.txt
@@ -1 +1 @@
-^{"fileApi":{"requests":\[{"kind":"codemodel","version":\[{"major":2,"minor":3}]},{"kind":"cache","version":\[{"major":2,"minor":0}]},{"kind":"cmakeFiles","version":\[{"major":1,"minor":0}]},{"kind":"toolchains","version":\[{"major":1,"minor":0}]}]},"generators":\[.*\],"serverMode":false,"version":{.*}}$
+^{"fileApi":{"requests":\[{"kind":"codemodel","version":\[{"major":2,"minor":4}]},{"kind":"cache","version":\[{"major":2,"minor":0}]},{"kind":"cmakeFiles","version":\[{"major":1,"minor":0}]},{"kind":"toolchains","version":\[{"major":1,"minor":0}]}]},"generators":\[.*\],"serverMode":false,"version":{.*}}$
diff --git a/Tests/RunCMake/FileAPI/codemodel-v2-check.py b/Tests/RunCMake/FileAPI/codemodel-v2-check.py
index 92a64f9..b31088d 100644
--- a/Tests/RunCMake/FileAPI/codemodel-v2-check.py
+++ b/Tests/RunCMake/FileAPI/codemodel-v2-check.py
@@ -12,7 +12,7 @@ def read_codemodel_json_data(filename):
def check_objects(o, g):
assert is_list(o)
assert len(o) == 1
- check_index_object(o[0], "codemodel", 2, 3, check_object_codemodel(g))
+ check_index_object(o[0], "codemodel", 2, 4, check_object_codemodel(g))
def check_backtrace(t, b, backtrace):
btg = t["backtraceGraph"]
@@ -188,6 +188,31 @@ def check_directory(c):
expected_keys.append("runtimeDependencySetType")
assert is_string(a["runtimeDependencySetType"], e["runtimeDependencySetType"])
+ if e.get("fileSetName", None) is not None:
+ expected_keys.append("fileSetName")
+ assert is_string(a["fileSetName"], e["fileSetName"])
+
+ if e.get("fileSetType", None) is not None:
+ expected_keys.append("fileSetType")
+ assert is_string(a["fileSetType"], e["fileSetType"])
+
+ if e.get("fileSetDirectories", None) is not None:
+ expected_keys.append("fileSetDirectories")
+ assert is_list(a["fileSetDirectories"])
+ assert len(a["fileSetDirectories"]) == len(e["fileSetDirectories"])
+ for ad, ed in zip(a["fileSetDirectories"], e["fileSetDirectories"]):
+ assert matches(ad, ed)
+
+ if e.get("fileSetTarget", None) is not None:
+ expected_keys.append("fileSetTarget")
+ et = e["fileSetTarget"]
+ at = a["fileSetTarget"]
+ assert is_dict(at)
+ assert sorted(at.keys()) == ["id", "index"]
+ assert matches(at["id"], et["id"])
+ assert is_int(at["index"])
+ assert c["targets"][at["index"]]["name"] == et["index"]
+
if e["backtrace"] is not None:
expected_keys.append("backtrace")
check_backtrace(d, a["backtrace"], e["backtrace"])
@@ -628,6 +653,7 @@ def gen_check_directories(c, g):
read_codemodel_json_data("directories/dir.json"),
read_codemodel_json_data("directories/dir_dir.json"),
read_codemodel_json_data("directories/external.json"),
+ read_codemodel_json_data("directories/fileset.json"),
]
if matches(g["name"], "^Visual Studio "):
@@ -729,6 +755,9 @@ def gen_check_targets(c, g, inSource):
read_codemodel_json_data("targets/all_build_external.json"),
read_codemodel_json_data("targets/zero_check_external.json"),
read_codemodel_json_data("targets/generated_exe.json"),
+
+ read_codemodel_json_data("targets/c_headers_1.json"),
+ read_codemodel_json_data("targets/c_headers_2.json"),
]
if cxx_compiler_id in ['Clang', 'AppleClang', 'LCC', 'GNU', 'Intel', 'IntelLLVM', 'MSVC', 'Embarcadero'] and g["name"] != "Xcode":
diff --git a/Tests/RunCMake/FileAPI/codemodel-v2-data/directories/fileset.json b/Tests/RunCMake/FileAPI/codemodel-v2-data/directories/fileset.json
new file mode 100644
index 0000000..4774a13
--- /dev/null
+++ b/Tests/RunCMake/FileAPI/codemodel-v2-data/directories/fileset.json
@@ -0,0 +1,203 @@
+{
+ "source": "^fileset$",
+ "build": "^fileset$",
+ "parentSource": "^\\.$",
+ "childSources": null,
+ "targetIds": [
+ "^c_headers_1::@6b8db101d64c125f29fe$",
+ "^c_headers_2::@6b8db101d64c125f29fe$"
+ ],
+ "projectName": "codemodel-v2",
+ "minimumCMakeVersion": "3.12",
+ "hasInstallRule": true,
+ "installers": [
+ {
+ "component": "Unspecified",
+ "type": "target",
+ "destination": "lib",
+ "paths": [
+ "^fileset/((Debug|Release|MinSizeRel|RelWithDebInfo)/)?(lib)?c_headers_1\\.(a|lib)?$"
+ ],
+ "isExcludeFromAll": null,
+ "isForAllComponents": null,
+ "isOptional": null,
+ "targetId": "^c_headers_1::@6b8db101d64c125f29fe$",
+ "targetIndex": "c_headers_1",
+ "targetIsImportLibrary": null,
+ "targetInstallNamelink": null,
+ "exportName": null,
+ "exportTargets": null,
+ "scriptFile": null,
+ "backtrace": [
+ {
+ "file": "^fileset/CMakeLists\\.txt$",
+ "line": 20,
+ "command": "install",
+ "hasParent": true
+ },
+ {
+ "file": "^fileset/CMakeLists\\.txt$",
+ "line": null,
+ "command": null,
+ "hasParent": false
+ }
+ ]
+ },
+ {
+ "component": "Headers",
+ "type": "fileSet",
+ "destination": "include",
+ "paths": [
+ "^fileset/error\\.c$",
+ "^fileset/other\\.c$"
+ ],
+ "isExcludeFromAll": null,
+ "isForAllComponents": null,
+ "isOptional": null,
+ "targetId": null,
+ "targetIndex": null,
+ "targetIsImportLibrary": null,
+ "targetInstallNamelink": null,
+ "exportName": null,
+ "exportTargets": null,
+ "scriptFile": null,
+ "fileSetName": "HEADERS",
+ "fileSetType": "HEADERS",
+ "fileSetDirectories": [
+ "^fileset$"
+ ],
+ "fileSetTarget": {
+ "id": "^c_headers_1::@6b8db101d64c125f29fe$",
+ "index": "c_headers_1"
+ },
+ "backtrace": [
+ {
+ "file": "^fileset/CMakeLists\\.txt$",
+ "line": 20,
+ "command": "install",
+ "hasParent": true
+ },
+ {
+ "file": "^fileset/CMakeLists\\.txt$",
+ "line": null,
+ "command": null,
+ "hasParent": false
+ }
+ ]
+ },
+ {
+ "component": "Unspecified",
+ "type": "fileSet",
+ "destination": "include/dir",
+ "paths": [
+ "^fileset/dir/h2\\.h$"
+ ],
+ "isExcludeFromAll": null,
+ "isForAllComponents": null,
+ "isOptional": null,
+ "targetId": null,
+ "targetIndex": null,
+ "targetIsImportLibrary": null,
+ "targetInstallNamelink": null,
+ "exportName": null,
+ "exportTargets": null,
+ "scriptFile": null,
+ "fileSetName": "b",
+ "fileSetType": "HEADERS",
+ "fileSetDirectories": [
+ "^fileset/dir$"
+ ],
+ "fileSetTarget": {
+ "id": "^c_headers_1::@6b8db101d64c125f29fe$",
+ "index": "c_headers_1"
+ },
+ "backtrace": [
+ {
+ "file": "^fileset/CMakeLists\\.txt$",
+ "line": 20,
+ "command": "install",
+ "hasParent": true
+ },
+ {
+ "file": "^fileset/CMakeLists\\.txt$",
+ "line": null,
+ "command": null,
+ "hasParent": false
+ }
+ ]
+ },
+ {
+ "component": "Unspecified",
+ "type": "fileSet",
+ "destination": "include",
+ "paths": [
+ "^fileset/h3\\.h$"
+ ],
+ "isExcludeFromAll": null,
+ "isForAllComponents": null,
+ "isOptional": null,
+ "targetId": null,
+ "targetIndex": null,
+ "targetIsImportLibrary": null,
+ "targetInstallNamelink": null,
+ "exportName": null,
+ "exportTargets": null,
+ "scriptFile": null,
+ "fileSetName": "c",
+ "fileSetType": "HEADERS",
+ "fileSetDirectories": [
+ "^fileset$"
+ ],
+ "fileSetTarget": {
+ "id": "^c_headers_1::@6b8db101d64c125f29fe$",
+ "index": "c_headers_1"
+ },
+ "backtrace": [
+ {
+ "file": "^fileset/CMakeLists\\.txt$",
+ "line": 20,
+ "command": "install",
+ "hasParent": true
+ },
+ {
+ "file": "^fileset/CMakeLists\\.txt$",
+ "line": null,
+ "command": null,
+ "hasParent": false
+ }
+ ]
+ },
+ {
+ "component": "Unspecified",
+ "type": "target",
+ "destination": "lib",
+ "paths": [
+ "^fileset/((Debug|Release|MinSizeRel|RelWithDebInfo)/)?(lib)?c_headers_2\\.(a|lib)?$"
+ ],
+ "isExcludeFromAll": null,
+ "isForAllComponents": null,
+ "isOptional": null,
+ "targetId": "^c_headers_2::@6b8db101d64c125f29fe$",
+ "targetIndex": "c_headers_2",
+ "targetIsImportLibrary": null,
+ "targetInstallNamelink": null,
+ "exportName": null,
+ "exportTargets": null,
+ "scriptFile": null,
+ "backtrace": [
+ {
+ "file": "^fileset/CMakeLists\\.txt$",
+ "line": 25,
+ "command": "install",
+ "hasParent": true
+ },
+ {
+ "file": "^fileset/CMakeLists\\.txt$",
+ "line": null,
+ "command": null,
+ "hasParent": false
+ }
+ ]
+ }
+ ]
+}
diff --git a/Tests/RunCMake/FileAPI/codemodel-v2-data/directories/top.json b/Tests/RunCMake/FileAPI/codemodel-v2-data/directories/top.json
index 99287fb..22b4536 100644
--- a/Tests/RunCMake/FileAPI/codemodel-v2-data/directories/top.json
+++ b/Tests/RunCMake/FileAPI/codemodel-v2-data/directories/top.json
@@ -10,7 +10,8 @@
"^interface$",
"^object$",
"^.*/Tests/RunCMake/FileAPIExternalSource$",
- "^dir$"
+ "^dir$",
+ "^fileset$"
],
"targetIds": [
"^ALL_BUILD::@6890427a1f51a3e7e1df$",
@@ -47,7 +48,7 @@
"backtrace": [
{
"file": "^codemodel-v2\\.cmake$",
- "line": 38,
+ "line": 39,
"command": "install",
"hasParent": true
},
@@ -92,7 +93,7 @@
"backtrace": [
{
"file": "^codemodel-v2\\.cmake$",
- "line": 41,
+ "line": 42,
"command": "install",
"hasParent": true
},
@@ -140,7 +141,7 @@
"backtrace": [
{
"file": "^codemodel-v2\\.cmake$",
- "line": 41,
+ "line": 42,
"command": "install",
"hasParent": true
},
@@ -185,7 +186,7 @@
"backtrace": [
{
"file": "^codemodel-v2\\.cmake$",
- "line": 41,
+ "line": 42,
"command": "install",
"hasParent": true
},
@@ -229,7 +230,7 @@
"backtrace": [
{
"file": "^codemodel-v2\\.cmake$",
- "line": 41,
+ "line": 42,
"command": "install",
"hasParent": true
},
@@ -273,7 +274,7 @@
"backtrace": [
{
"file": "^codemodel-v2\\.cmake$",
- "line": 46,
+ "line": 47,
"command": "install",
"hasParent": true
},
@@ -320,7 +321,7 @@
"backtrace": [
{
"file": "^codemodel-v2\\.cmake$",
- "line": 48,
+ "line": 49,
"command": "install",
"hasParent": true
},
@@ -365,7 +366,7 @@
"backtrace": [
{
"file": "^codemodel-v2\\.cmake$",
- "line": 49,
+ "line": 50,
"command": "install",
"hasParent": true
},
@@ -414,7 +415,7 @@
"backtrace": [
{
"file": "^codemodel-v2\\.cmake$",
- "line": 50,
+ "line": 51,
"command": "install",
"hasParent": true
},
@@ -466,7 +467,7 @@
"backtrace": [
{
"file": "^codemodel-v2\\.cmake$",
- "line": 51,
+ "line": 52,
"command": "install",
"hasParent": true
},
@@ -515,7 +516,7 @@
"backtrace": [
{
"file": "^codemodel-v2\\.cmake$",
- "line": 52,
+ "line": 53,
"command": "install",
"hasParent": true
},
@@ -557,7 +558,7 @@
"backtrace": [
{
"file": "^codemodel-v2\\.cmake$",
- "line": 53,
+ "line": 54,
"command": "install",
"hasParent": true
},
@@ -599,7 +600,7 @@
"backtrace": [
{
"file": "^codemodel-v2\\.cmake$",
- "line": 54,
+ "line": 55,
"command": "install",
"hasParent": true
},
diff --git a/Tests/RunCMake/FileAPI/codemodel-v2-data/projects/codemodel-v2.json b/Tests/RunCMake/FileAPI/codemodel-v2-data/projects/codemodel-v2.json
index 4d0cdc0..0d6c4a1 100644
--- a/Tests/RunCMake/FileAPI/codemodel-v2-data/projects/codemodel-v2.json
+++ b/Tests/RunCMake/FileAPI/codemodel-v2-data/projects/codemodel-v2.json
@@ -13,7 +13,8 @@
"directorySources": [
"^\\.$",
"^dir$",
- "^dir/dir$"
+ "^dir/dir$",
+ "^fileset$"
],
"targetIds": [
"^ALL_BUILD::@6890427a1f51a3e7e1df$",
@@ -24,6 +25,8 @@
"^c_shared_lib::@6890427a1f51a3e7e1df$",
"^c_shared_exe::@6890427a1f51a3e7e1df$",
"^c_static_lib::@6890427a1f51a3e7e1df$",
- "^c_static_exe::@6890427a1f51a3e7e1df$"
+ "^c_static_exe::@6890427a1f51a3e7e1df$",
+ "^c_headers_1::@6b8db101d64c125f29fe$",
+ "^c_headers_2::@6b8db101d64c125f29fe$"
]
}
diff --git a/Tests/RunCMake/FileAPI/codemodel-v2-data/targets/all_build_top.json b/Tests/RunCMake/FileAPI/codemodel-v2-data/targets/all_build_top.json
index d023f99..4e772a7 100644
--- a/Tests/RunCMake/FileAPI/codemodel-v2-data/targets/all_build_top.json
+++ b/Tests/RunCMake/FileAPI/codemodel-v2-data/targets/all_build_top.json
@@ -186,6 +186,14 @@
{
"id": "^generated_exe::@[0-9a-f]+$",
"backtrace": null
+ },
+ {
+ "id": "^c_headers_1::@6b8db101d64c125f29fe$",
+ "backtrace": null
+ },
+ {
+ "id": "^c_headers_2::@6b8db101d64c125f29fe$",
+ "backtrace": null
}
]
}
diff --git a/Tests/RunCMake/FileAPI/codemodel-v2-data/targets/c_headers_1.json b/Tests/RunCMake/FileAPI/codemodel-v2-data/targets/c_headers_1.json
new file mode 100644
index 0000000..c189623
--- /dev/null
+++ b/Tests/RunCMake/FileAPI/codemodel-v2-data/targets/c_headers_1.json
@@ -0,0 +1,231 @@
+{
+ "name": "c_headers_1",
+ "id": "^c_headers_1::@6b8db101d64c125f29fe$",
+ "directorySource": "^fileset$",
+ "projectName": "codemodel-v2",
+ "type": "STATIC_LIBRARY",
+ "isGeneratorProvided": null,
+ "sources": [
+ {
+ "path": "^fileset/empty\\.c$",
+ "isGenerated": null,
+ "sourceGroupName": "Source Files",
+ "compileGroupLanguage": "C",
+ "backtrace": [
+ {
+ "file": "^fileset/CMakeLists\\.txt$",
+ "line": 1,
+ "command": "add_library",
+ "hasParent": true
+ },
+ {
+ "file": "^fileset/CMakeLists\\.txt$",
+ "line": null,
+ "command": null,
+ "hasParent": false
+ }
+ ]
+ },
+ {
+ "path": "^fileset/error\\.c$",
+ "isGenerated": null,
+ "sourceGroupName": "Header Files",
+ "compileGroupLanguage": null,
+ "backtrace": [
+ {
+ "file": "^fileset/CMakeLists\\.txt$",
+ "line": 3,
+ "command": "target_sources",
+ "hasParent": true
+ },
+ {
+ "file": "^fileset/CMakeLists\\.txt$",
+ "line": null,
+ "command": null,
+ "hasParent": false
+ }
+ ]
+ },
+ {
+ "path": "^fileset/other\\.c$",
+ "isGenerated": null,
+ "sourceGroupName": "Source Files",
+ "compileGroupLanguage": null,
+ "backtrace": [
+ {
+ "file": "^fileset/CMakeLists\\.txt$",
+ "line": 3,
+ "command": "target_sources",
+ "hasParent": true
+ },
+ {
+ "file": "^fileset/CMakeLists\\.txt$",
+ "line": null,
+ "command": null,
+ "hasParent": false
+ }
+ ]
+ },
+ {
+ "path": "^fileset/h1\\.h$",
+ "isGenerated": null,
+ "sourceGroupName": "Header Files",
+ "compileGroupLanguage": null,
+ "backtrace": [
+ {
+ "file": "^fileset/CMakeLists\\.txt$",
+ "line": 3,
+ "command": "target_sources",
+ "hasParent": true
+ },
+ {
+ "file": "^fileset/CMakeLists\\.txt$",
+ "line": null,
+ "command": null,
+ "hasParent": false
+ }
+ ]
+ },
+ {
+ "path": "^fileset/dir/h2\\.h$",
+ "isGenerated": null,
+ "sourceGroupName": "Header Files",
+ "compileGroupLanguage": null,
+ "backtrace": [
+ {
+ "file": "^fileset/CMakeLists\\.txt$",
+ "line": 7,
+ "command": "target_sources",
+ "hasParent": true
+ },
+ {
+ "file": "^fileset/CMakeLists\\.txt$",
+ "line": null,
+ "command": null,
+ "hasParent": false
+ }
+ ]
+ }
+ ],
+ "sourceGroups": [
+ {
+ "name": "Source Files",
+ "sourcePaths": [
+ "^fileset/empty\\.c$",
+ "^fileset/other\\.c$"
+ ]
+ },
+ {
+ "name": "Header Files",
+ "sourcePaths": [
+ "^fileset/error\\.c$",
+ "^fileset/h1\\.h$",
+ "^fileset/dir/h2\\.h$"
+ ]
+ }
+ ],
+ "compileGroups": [
+ {
+ "language": "C",
+ "sourcePaths": [
+ "^fileset/empty\\.c$"
+ ],
+ "includes": [
+ {
+ "path": "^.*/Tests/RunCMake/FileAPI/fileset$",
+ "isSystem": null,
+ "backtrace": [
+ {
+ "file": "^fileset/CMakeLists\\.txt$",
+ "line": 3,
+ "command": "target_sources",
+ "hasParent": true
+ },
+ {
+ "file": "^fileset/CMakeLists\\.txt$",
+ "line": null,
+ "command": null,
+ "hasParent": false
+ }
+ ]
+ },
+ {
+ "path": "^.*/Tests/RunCMake/FileAPI/fileset/dir$",
+ "isSystem": null,
+ "backtrace": [
+ {
+ "file": "^fileset/CMakeLists\\.txt$",
+ "line": 7,
+ "command": "target_sources",
+ "hasParent": true
+ },
+ {
+ "file": "^fileset/CMakeLists\\.txt$",
+ "line": null,
+ "command": null,
+ "hasParent": false
+ }
+ ]
+ }
+ ],
+ "defines": null,
+ "compileCommandFragments": null
+ }
+ ],
+ "backtrace": [
+ {
+ "file": "^fileset/CMakeLists\\.txt$",
+ "line": 1,
+ "command": "add_library",
+ "hasParent": true
+ },
+ {
+ "file": "^fileset/CMakeLists\\.txt$",
+ "line": null,
+ "command": null,
+ "hasParent": false
+ }
+ ],
+ "folder": null,
+ "nameOnDisk": "^(lib)?c_headers_1\\.(a|lib)$",
+ "artifacts": [
+ {
+ "path": "^fileset/((Debug|Release|RelWithDebInfo|MinSizeRel)/)?(lib)?c_headers_1\\.(a|lib)$",
+ "_dllExtra": false
+ }
+ ],
+ "build": "^fileset$",
+ "source": "^fileset$",
+ "install": {
+ "prefix": "^(/usr/local|[A-Za-z]:.*/codemodel-v2)$",
+ "destinations": [
+ {
+ "path": "lib",
+ "backtrace": [
+ {
+ "file": "^fileset/CMakeLists\\.txt$",
+ "line": 20,
+ "command": "install",
+ "hasParent": true
+ },
+ {
+ "file": "^fileset/CMakeLists\\.txt$",
+ "line": null,
+ "command": null,
+ "hasParent": false
+ }
+ ]
+ }
+ ]
+ },
+ "link": null,
+ "archive": {
+ "lto": null
+ },
+ "dependencies": [
+ {
+ "id": "^ZERO_CHECK::@6890427a1f51a3e7e1df$",
+ "backtrace": null
+ }
+ ]
+}
diff --git a/Tests/RunCMake/FileAPI/codemodel-v2-data/targets/c_headers_2.json b/Tests/RunCMake/FileAPI/codemodel-v2-data/targets/c_headers_2.json
new file mode 100644
index 0000000..75fe58c
--- /dev/null
+++ b/Tests/RunCMake/FileAPI/codemodel-v2-data/targets/c_headers_2.json
@@ -0,0 +1,105 @@
+{
+ "name": "c_headers_2",
+ "id": "^c_headers_2::@6b8db101d64c125f29fe$",
+ "directorySource": "^fileset$",
+ "projectName": "codemodel-v2",
+ "type": "STATIC_LIBRARY",
+ "isGeneratorProvided": null,
+ "sources": [
+ {
+ "path": "^fileset/empty\\.c$",
+ "isGenerated": null,
+ "sourceGroupName": "Source Files",
+ "compileGroupLanguage": "C",
+ "backtrace": [
+ {
+ "file": "^fileset/CMakeLists\\.txt$",
+ "line": 15,
+ "command": "add_library",
+ "hasParent": true
+ },
+ {
+ "file": "^fileset/CMakeLists\\.txt$",
+ "line": null,
+ "command": null,
+ "hasParent": false
+ }
+ ]
+ }
+ ],
+ "sourceGroups": [
+ {
+ "name": "Source Files",
+ "sourcePaths": [
+ "^fileset/empty\\.c$"
+ ]
+ }
+ ],
+ "compileGroups": [
+ {
+ "language": "C",
+ "sourcePaths": [
+ "^fileset/empty\\.c$"
+ ],
+ "includes": null,
+ "defines": null,
+ "compileCommandFragments": null
+ }
+ ],
+ "backtrace": [
+ {
+ "file": "^fileset/CMakeLists\\.txt$",
+ "line": 15,
+ "command": "add_library",
+ "hasParent": true
+ },
+ {
+ "file": "^fileset/CMakeLists\\.txt$",
+ "line": null,
+ "command": null,
+ "hasParent": false
+ }
+ ],
+ "folder": null,
+ "nameOnDisk": "^(lib)?c_headers_2\\.(a|lib)$",
+ "artifacts": [
+ {
+ "path": "^fileset/((Debug|Release|RelWithDebInfo|MinSizeRel)/)?(lib)?c_headers_2\\.(a|lib)$",
+ "_dllExtra": false
+ }
+ ],
+ "build": "^fileset$",
+ "source": "^fileset$",
+ "install": {
+ "prefix": "^(/usr/local|[A-Za-z]:.*/codemodel-v2)$",
+ "destinations": [
+ {
+ "path": "lib",
+ "backtrace": [
+ {
+ "file": "^fileset/CMakeLists\\.txt$",
+ "line": 25,
+ "command": "install",
+ "hasParent": true
+ },
+ {
+ "file": "^fileset/CMakeLists\\.txt$",
+ "line": null,
+ "command": null,
+ "hasParent": false
+ }
+ ]
+ }
+ ]
+ },
+ "link": null,
+ "archive": {
+ "lto": null
+ },
+ "dependencies": [
+ {
+ "id": "^ZERO_CHECK::@6890427a1f51a3e7e1df$",
+ "backtrace": null
+ }
+ ]
+}
diff --git a/Tests/RunCMake/FileAPI/codemodel-v2-data/targets/c_shared_lib.json b/Tests/RunCMake/FileAPI/codemodel-v2-data/targets/c_shared_lib.json
index e3a8d0b..b4318dd 100644
--- a/Tests/RunCMake/FileAPI/codemodel-v2-data/targets/c_shared_lib.json
+++ b/Tests/RunCMake/FileAPI/codemodel-v2-data/targets/c_shared_lib.json
@@ -115,7 +115,7 @@
"backtrace": [
{
"file": "^codemodel-v2\\.cmake$",
- "line": 41,
+ "line": 42,
"command": "install",
"hasParent": true
},
@@ -145,7 +145,7 @@
"backtrace": [
{
"file": "^codemodel-v2\\.cmake$",
- "line": 41,
+ "line": 42,
"command": "install",
"hasParent": true
},
@@ -175,7 +175,7 @@
"backtrace": [
{
"file": "^codemodel-v2\\.cmake$",
- "line": 46,
+ "line": 47,
"command": "install",
"hasParent": true
},
diff --git a/Tests/RunCMake/FileAPI/codemodel-v2-data/targets/cxx_exe.json b/Tests/RunCMake/FileAPI/codemodel-v2-data/targets/cxx_exe.json
index 385fa62..5769f0c 100644
--- a/Tests/RunCMake/FileAPI/codemodel-v2-data/targets/cxx_exe.json
+++ b/Tests/RunCMake/FileAPI/codemodel-v2-data/targets/cxx_exe.json
@@ -136,7 +136,7 @@
"backtrace": [
{
"file": "^codemodel-v2\\.cmake$",
- "line": 38,
+ "line": 39,
"command": "install",
"hasParent": true
},
diff --git a/Tests/RunCMake/FileAPI/codemodel-v2-data/targets/cxx_shared_lib.json b/Tests/RunCMake/FileAPI/codemodel-v2-data/targets/cxx_shared_lib.json
index 73e8e12..1fe4d67 100644
--- a/Tests/RunCMake/FileAPI/codemodel-v2-data/targets/cxx_shared_lib.json
+++ b/Tests/RunCMake/FileAPI/codemodel-v2-data/targets/cxx_shared_lib.json
@@ -91,7 +91,7 @@
"backtrace": [
{
"file": "^codemodel-v2\\.cmake$",
- "line": 41,
+ "line": 42,
"command": "install",
"hasParent": true
},
@@ -121,7 +121,7 @@
"backtrace": [
{
"file": "^codemodel-v2\\.cmake$",
- "line": 41,
+ "line": 42,
"command": "install",
"hasParent": true
},
@@ -151,7 +151,7 @@
"backtrace": [
{
"file": "^codemodel-v2\\.cmake$",
- "line": 46,
+ "line": 47,
"command": "install",
"hasParent": true
},
diff --git a/Tests/RunCMake/FileAPI/codemodel-v2.cmake b/Tests/RunCMake/FileAPI/codemodel-v2.cmake
index da928eb..019eb87 100644
--- a/Tests/RunCMake/FileAPI/codemodel-v2.cmake
+++ b/Tests/RunCMake/FileAPI/codemodel-v2.cmake
@@ -22,6 +22,7 @@ add_subdirectory(interface)
add_subdirectory(custom)
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/../FileAPIExternalSource" "${CMAKE_CURRENT_BINARY_DIR}/../FileAPIExternalBuild")
add_subdirectory(dir)
+add_subdirectory(fileset)
set_property(TARGET c_shared_lib PROPERTY LIBRARY_OUTPUT_DIRECTORY lib)
set_property(TARGET c_shared_lib PROPERTY RUNTIME_OUTPUT_DIRECTORY lib)
diff --git a/Tests/RunCMake/FileAPI/fileset/CMakeLists.txt b/Tests/RunCMake/FileAPI/fileset/CMakeLists.txt
new file mode 100644
index 0000000..f80f12b
--- /dev/null
+++ b/Tests/RunCMake/FileAPI/fileset/CMakeLists.txt
@@ -0,0 +1,25 @@
+add_library(c_headers_1 STATIC empty.c)
+
+target_sources(c_headers_1
+ PUBLIC FILE_SET HEADERS BASE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}" FILES error.c other.c
+ PRIVATE FILE_SET a TYPE HEADERS BASE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}" FILES h1.h
+ )
+target_sources(c_headers_1
+ PUBLIC FILE_SET b TYPE HEADERS BASE_DIRS "$<1:${CMAKE_CURRENT_SOURCE_DIR}/dir>" FILES "$<1:${CMAKE_CURRENT_SOURCE_DIR}/dir/h2.h>"
+ )
+target_sources(c_headers_1
+ INTERFACE FILE_SET c TYPE HEADERS BASE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}" FILES h3.h
+ )
+source_group("Source Files" FILES "${CMAKE_CURRENT_SOURCE_DIR}/other.c")
+
+add_library(c_headers_2 STATIC empty.c)
+target_sources(c_headers_2
+ INTERFACE FILE_SET HEADERS BASE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}" FILES h1.h
+ )
+
+install(TARGETS c_headers_1
+ FILE_SET HEADERS DESTINATION include COMPONENT Headers
+ FILE_SET b DESTINATION include/dir
+ FILE_SET c
+ )
+install(TARGETS c_headers_2)
diff --git a/Tests/RunCMake/FileAPI/fileset/dir/h2.h b/Tests/RunCMake/FileAPI/fileset/dir/h2.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Tests/RunCMake/FileAPI/fileset/dir/h2.h
diff --git a/Tests/RunCMake/FileAPI/fileset/empty.c b/Tests/RunCMake/FileAPI/fileset/empty.c
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Tests/RunCMake/FileAPI/fileset/empty.c
diff --git a/Tests/RunCMake/FileAPI/fileset/error.c b/Tests/RunCMake/FileAPI/fileset/error.c
new file mode 100644
index 0000000..f10e687
--- /dev/null
+++ b/Tests/RunCMake/FileAPI/fileset/error.c
@@ -0,0 +1 @@
+#error "This should not be compiled"
diff --git a/Tests/RunCMake/FileAPI/fileset/h1.h b/Tests/RunCMake/FileAPI/fileset/h1.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Tests/RunCMake/FileAPI/fileset/h1.h
diff --git a/Tests/RunCMake/FileAPI/fileset/h3.h b/Tests/RunCMake/FileAPI/fileset/h3.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Tests/RunCMake/FileAPI/fileset/h3.h
diff --git a/Tests/RunCMake/FileAPI/fileset/other.c b/Tests/RunCMake/FileAPI/fileset/other.c
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Tests/RunCMake/FileAPI/fileset/other.c
diff --git a/Tests/RunCMake/target_sources/FileSetChangeScope-result.txt b/Tests/RunCMake/target_sources/FileSetChangeScope-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/target_sources/FileSetChangeScope-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/target_sources/FileSetChangeScope-stderr.txt b/Tests/RunCMake/target_sources/FileSetChangeScope-stderr.txt
new file mode 100644
index 0000000..600d006
--- /dev/null
+++ b/Tests/RunCMake/target_sources/FileSetChangeScope-stderr.txt
@@ -0,0 +1,5 @@
+^CMake Error at FileSetChangeScope\.cmake:[0-9]+ \(target_sources\):
+ target_sources Scope PUBLIC for file set "a" does not match original scope
+ INTERFACE
+Call Stack \(most recent call first\):
+ CMakeLists\.txt:[0-9]+ \(include\)$
diff --git a/Tests/RunCMake/target_sources/FileSetChangeScope.cmake b/Tests/RunCMake/target_sources/FileSetChangeScope.cmake
new file mode 100644
index 0000000..9d835fe
--- /dev/null
+++ b/Tests/RunCMake/target_sources/FileSetChangeScope.cmake
@@ -0,0 +1,5 @@
+enable_language(C)
+
+add_library(lib1 STATIC empty.c)
+target_sources(lib1 INTERFACE FILE_SET a TYPE HEADERS)
+target_sources(lib1 PUBLIC FILE_SET a)
diff --git a/Tests/RunCMake/target_sources/FileSetChangeType-result.txt b/Tests/RunCMake/target_sources/FileSetChangeType-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/target_sources/FileSetChangeType-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/target_sources/FileSetChangeType-stderr.txt b/Tests/RunCMake/target_sources/FileSetChangeType-stderr.txt
new file mode 100644
index 0000000..85fc718
--- /dev/null
+++ b/Tests/RunCMake/target_sources/FileSetChangeType-stderr.txt
@@ -0,0 +1,5 @@
+^CMake Error at FileSetChangeType\.cmake:[0-9]+ \(target_sources\):
+ target_sources Type "RESOURCES" for file set "a" does not match original
+ type "HEADERS"
+Call Stack \(most recent call first\):
+ CMakeLists\.txt:[0-9]+ \(include\)$
diff --git a/Tests/RunCMake/target_sources/FileSetChangeType.cmake b/Tests/RunCMake/target_sources/FileSetChangeType.cmake
new file mode 100644
index 0000000..69eb6bc
--- /dev/null
+++ b/Tests/RunCMake/target_sources/FileSetChangeType.cmake
@@ -0,0 +1,5 @@
+enable_language(C)
+
+add_library(lib1 STATIC empty.c)
+target_sources(lib1 PRIVATE FILE_SET a TYPE HEADERS)
+target_sources(lib1 PRIVATE FILE_SET a TYPE RESOURCES)
diff --git a/Tests/RunCMake/target_sources/FileSetDefaultWrongType-result.txt b/Tests/RunCMake/target_sources/FileSetDefaultWrongType-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/target_sources/FileSetDefaultWrongType-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/target_sources/FileSetDefaultWrongType-stderr.txt b/Tests/RunCMake/target_sources/FileSetDefaultWrongType-stderr.txt
new file mode 100644
index 0000000..faf0f5a
--- /dev/null
+++ b/Tests/RunCMake/target_sources/FileSetDefaultWrongType-stderr.txt
@@ -0,0 +1,4 @@
+^CMake Error at FileSetDefaultWrongType\.cmake:[0-9]+ \(target_sources\):
+ target_sources File set TYPE may only be "HEADERS"
+Call Stack \(most recent call first\):
+ CMakeLists\.txt:[0-9]+ \(include\)$
diff --git a/Tests/RunCMake/target_sources/FileSetDefaultWrongType.cmake b/Tests/RunCMake/target_sources/FileSetDefaultWrongType.cmake
new file mode 100644
index 0000000..c810d66
--- /dev/null
+++ b/Tests/RunCMake/target_sources/FileSetDefaultWrongType.cmake
@@ -0,0 +1,4 @@
+enable_language(C)
+
+add_library(lib1 STATIC empty.c)
+target_sources(lib1 PRIVATE FILE_SET UNKNOWN)
diff --git a/Tests/RunCMake/target_sources/FileSetDirectories.cmake b/Tests/RunCMake/target_sources/FileSetDirectories.cmake
new file mode 100644
index 0000000..af30b1e
--- /dev/null
+++ b/Tests/RunCMake/target_sources/FileSetDirectories.cmake
@@ -0,0 +1,4 @@
+enable_language(C)
+
+add_subdirectory(dir3)
+add_subdirectory(dir4)
diff --git a/Tests/RunCMake/target_sources/FileSetExport.cmake b/Tests/RunCMake/target_sources/FileSetExport.cmake
new file mode 100644
index 0000000..cde826a
--- /dev/null
+++ b/Tests/RunCMake/target_sources/FileSetExport.cmake
@@ -0,0 +1,21 @@
+enable_language(C)
+
+add_library(lib1 STATIC lib1.c)
+target_sources(lib1
+ PUBLIC FILE_SET HEADERS BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR} FILES error.c
+ PRIVATE FILE_SET a TYPE HEADERS BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR} FILES h1.h
+ PUBLIC FILE_SET b TYPE HEADERS BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR} FILES h2.h
+ INTERFACE FILE_SET c TYPE HEADERS BASE_DIRS "$<1:${CMAKE_CURRENT_SOURCE_DIR}/dir>" FILES "$<1:dir/dir.h>"
+ INTERFACE FILE_SET d TYPE HEADERS BASE_DIRS FILES "${CMAKE_CURRENT_SOURCE_DIR}/$<IF:$<CONFIG:Debug>,debug,release>/empty.h"
+ INTERFACE FILE_SET e TYPE HEADERS BASE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/$<IF:$<CONFIG:Debug>,debug,release>" FILES "${CMAKE_CURRENT_SOURCE_DIR}/$<IF:$<CONFIG:Debug>,debug,release>/empty2.h"
+ INTERFACE FILE_SET f TYPE HEADERS BASE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}" FILES "${CMAKE_CURRENT_SOURCE_DIR}/empty3.h"
+ INTERFACE FILE_SET g TYPE HEADERS BASE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/dir1" "${CMAKE_CURRENT_SOURCE_DIR}/dir2" FILES "${CMAKE_CURRENT_SOURCE_DIR}/dir1/file1.h" "${CMAKE_CURRENT_SOURCE_DIR}/dir2/file2.h"
+ INTERFACE FILE_SET dir3 TYPE HEADERS BASE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/dir3" FILES dir3/dir3.h
+ )
+
+install(TARGETS lib1 EXPORT export FILE_SET HEADERS FILE_SET a FILE_SET b FILE_SET c DESTINATION include/dir FILE_SET d FILE_SET e FILE_SET f DESTINATION include/$<IF:$<CONFIG:Debug>,debug,release> FILE_SET g FILE_SET dir3 DESTINATION include/dir3)
+install(EXPORT export FILE export.cmake NAMESPACE install:: DESTINATION lib/cmake)
+export(EXPORT export FILE export.cmake NAMESPACE export::)
+
+add_library(lib2 STATIC lib2.c)
+target_link_libraries(lib2 PRIVATE lib1)
diff --git a/Tests/RunCMake/target_sources/FileSetFileNoExist-result.txt b/Tests/RunCMake/target_sources/FileSetFileNoExist-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/target_sources/FileSetFileNoExist-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/target_sources/FileSetFileNoExist-stderr.txt b/Tests/RunCMake/target_sources/FileSetFileNoExist-stderr.txt
new file mode 100644
index 0000000..9a2ca6a
--- /dev/null
+++ b/Tests/RunCMake/target_sources/FileSetFileNoExist-stderr.txt
@@ -0,0 +1,10 @@
+^CMake Error at FileSetFileNoExist\.cmake:[0-9]+ \(add_library\):
+ Cannot find source file:
+
+ [^
+]*/Tests/RunCMake/target_sources/noexist\.h
+Call Stack \(most recent call first\):
+ CMakeLists\.txt:[0-9]+ \(include\)
+
+
+CMake Generate step failed\. Build files cannot be regenerated correctly\.$
diff --git a/Tests/RunCMake/target_sources/FileSetFileNoExist.cmake b/Tests/RunCMake/target_sources/FileSetFileNoExist.cmake
new file mode 100644
index 0000000..0df8186
--- /dev/null
+++ b/Tests/RunCMake/target_sources/FileSetFileNoExist.cmake
@@ -0,0 +1,4 @@
+enable_language(C)
+
+add_library(lib1 STATIC empty.c)
+target_sources(lib1 PRIVATE FILE_SET HEADERS BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR} FILES noexist.h)
diff --git a/Tests/RunCMake/target_sources/FileSetImport.cmake b/Tests/RunCMake/target_sources/FileSetImport.cmake
new file mode 100644
index 0000000..9c7358a
--- /dev/null
+++ b/Tests/RunCMake/target_sources/FileSetImport.cmake
@@ -0,0 +1,97 @@
+enable_language(C)
+
+get_property(_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
+
+function(assert_prop_eq tgt prop value)
+ unset(actual_value)
+ get_property(actual_value TARGET ${tgt} PROPERTY ${prop})
+ if(NOT actual_value STREQUAL value)
+ message(SEND_ERROR "Expected value of ${prop}:\n ${value}\nActual value:\n ${actual_value}")
+ endif()
+endfunction()
+
+get_filename_component(export_build_dir "${CMAKE_BINARY_DIR}" DIRECTORY)
+string(APPEND export_build_dir "/FileSetExport-build")
+
+include("${export_build_dir}/export.cmake")
+include("${export_build_dir}/install/lib/cmake/export.cmake")
+
+assert_prop_eq(export::lib1 HEADER_SETS "")
+assert_prop_eq(export::lib1 INTERFACE_HEADER_SETS "HEADERS;b;c;d;e;f;g;dir3")
+assert_prop_eq(export::lib1 HEADER_SET "${CMAKE_CURRENT_SOURCE_DIR}/error.c")
+assert_prop_eq(export::lib1 HEADER_DIRS "${CMAKE_CURRENT_SOURCE_DIR}")
+assert_prop_eq(export::lib1 HEADER_SET_b "${CMAKE_CURRENT_SOURCE_DIR}/h2.h")
+assert_prop_eq(export::lib1 HEADER_DIRS_b "${CMAKE_CURRENT_SOURCE_DIR}")
+assert_prop_eq(export::lib1 HEADER_SET_c "$<1:dir/dir.h>")
+assert_prop_eq(export::lib1 HEADER_DIRS_c "$<1:${CMAKE_CURRENT_SOURCE_DIR}/dir>")
+assert_prop_eq(export::lib1 HEADER_SET_d "${CMAKE_CURRENT_SOURCE_DIR}/$<IF:$<CONFIG:Debug>,debug,release>/empty.h")
+assert_prop_eq(export::lib1 HEADER_DIRS_d "${CMAKE_CURRENT_SOURCE_DIR}")
+assert_prop_eq(export::lib1 HEADER_SET_e "${CMAKE_CURRENT_SOURCE_DIR}/$<IF:$<CONFIG:Debug>,debug,release>/empty2.h")
+assert_prop_eq(export::lib1 HEADER_DIRS_e "${CMAKE_CURRENT_SOURCE_DIR}/$<IF:$<CONFIG:Debug>,debug,release>")
+assert_prop_eq(export::lib1 HEADER_SET_f "${CMAKE_CURRENT_SOURCE_DIR}/empty3.h")
+assert_prop_eq(export::lib1 HEADER_DIRS_f "${CMAKE_CURRENT_SOURCE_DIR}")
+assert_prop_eq(export::lib1 HEADER_SET_g "${CMAKE_CURRENT_SOURCE_DIR}/dir1/file1.h;${CMAKE_CURRENT_SOURCE_DIR}/dir2/file2.h")
+assert_prop_eq(export::lib1 HEADER_DIRS_g "${CMAKE_CURRENT_SOURCE_DIR}/dir1;${CMAKE_CURRENT_SOURCE_DIR}/dir2")
+assert_prop_eq(export::lib1 INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR};${CMAKE_CURRENT_SOURCE_DIR};$<1:${CMAKE_CURRENT_SOURCE_DIR}/dir>;${CMAKE_CURRENT_SOURCE_DIR};${CMAKE_CURRENT_SOURCE_DIR}/$<IF:$<CONFIG:Debug>,debug,release>;${CMAKE_CURRENT_SOURCE_DIR};${CMAKE_CURRENT_SOURCE_DIR}/dir1;${CMAKE_CURRENT_SOURCE_DIR}/dir2;${CMAKE_CURRENT_SOURCE_DIR}/dir3;$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>;$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>;$<BUILD_INTERFACE:$<1:${CMAKE_CURRENT_SOURCE_DIR}/dir>>;$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>;$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/$<IF:$<CONFIG:Debug>,debug,release>>;$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>;$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/dir1>;$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/dir2>;$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/dir3>")
+
+assert_prop_eq(install::lib1 HEADER_SETS "")
+assert_prop_eq(install::lib1 INTERFACE_HEADER_SETS "HEADERS;b;c;d;e;f;g;dir3")
+assert_prop_eq(install::lib1 HEADER_SET "${export_build_dir}/install/include/error.c")
+assert_prop_eq(install::lib1 HEADER_DIRS "${export_build_dir}/install/include")
+assert_prop_eq(install::lib1 HEADER_SET_b "${export_build_dir}/install/include/h2.h")
+assert_prop_eq(install::lib1 HEADER_DIRS_b "${export_build_dir}/install/include")
+assert_prop_eq(install::lib1 HEADER_SET_c "${export_build_dir}/install/include/dir/dir.h")
+assert_prop_eq(install::lib1 HEADER_DIRS_c "${export_build_dir}/install/include/dir")
+if(_multi_config)
+ assert_prop_eq(install::lib1 HEADER_SET_d "$<$<CONFIG:Debug>:${export_build_dir}/install/include/debug/empty.h>;$<$<CONFIG:Release>:${export_build_dir}/install/include/release/empty.h>")
+else()
+ assert_prop_eq(install::lib1 HEADER_SET_d "${export_build_dir}/install/include/debug/empty.h")
+endif()
+assert_prop_eq(install::lib1 HEADER_DIRS_d "${export_build_dir}/install/include")
+if(_multi_config)
+ assert_prop_eq(install::lib1 HEADER_SET_e "$<$<CONFIG:Debug>:${export_build_dir}/install/include/empty2.h>;$<$<CONFIG:Release>:${export_build_dir}/install/include/empty2.h>")
+else()
+ assert_prop_eq(install::lib1 HEADER_SET_e "${export_build_dir}/install/include/empty2.h")
+endif()
+assert_prop_eq(install::lib1 HEADER_DIRS_e "${export_build_dir}/install/include")
+if(_multi_config)
+ assert_prop_eq(install::lib1 HEADER_SET_f "$<$<CONFIG:Debug>:${export_build_dir}/install/include/debug/empty3.h>;$<$<CONFIG:Release>:${export_build_dir}/install/include/release/empty3.h>")
+ assert_prop_eq(install::lib1 HEADER_DIRS_f "$<$<CONFIG:Debug>:${export_build_dir}/install/include/debug>;$<$<CONFIG:Release>:${export_build_dir}/install/include/release>")
+else()
+ assert_prop_eq(install::lib1 HEADER_SET_f "${export_build_dir}/install/include/debug/empty3.h")
+ assert_prop_eq(install::lib1 HEADER_DIRS_f "${export_build_dir}/install/include/debug")
+endif()
+assert_prop_eq(install::lib1 HEADER_SET_g "${export_build_dir}/install/include/file1.h;${export_build_dir}/install/include/file2.h")
+assert_prop_eq(install::lib1 HEADER_DIRS_g "${export_build_dir}/install/include")
+if(_multi_config)
+ assert_prop_eq(install::lib1 INTERFACE_INCLUDE_DIRECTORIES "$<BUILD_INTERFACE:${export_build_dir}/install/include>;$<BUILD_INTERFACE:${export_build_dir}/install/include>;$<BUILD_INTERFACE:${export_build_dir}/install/include/dir>;$<BUILD_INTERFACE:${export_build_dir}/install/include>;$<BUILD_INTERFACE:${export_build_dir}/install/include>;$<BUILD_INTERFACE:$<$<CONFIG:Debug>:${export_build_dir}/install/include/debug>>;$<BUILD_INTERFACE:$<$<CONFIG:Release>:${export_build_dir}/install/include/release>>;$<BUILD_INTERFACE:${export_build_dir}/install/include>;$<BUILD_INTERFACE:${export_build_dir}/install/include/dir3>")
+else()
+ assert_prop_eq(install::lib1 INTERFACE_INCLUDE_DIRECTORIES "$<BUILD_INTERFACE:${export_build_dir}/install/include>;$<BUILD_INTERFACE:${export_build_dir}/install/include>;$<BUILD_INTERFACE:${export_build_dir}/install/include/dir>;$<BUILD_INTERFACE:${export_build_dir}/install/include>;$<BUILD_INTERFACE:${export_build_dir}/install/include>;$<BUILD_INTERFACE:${export_build_dir}/install/include/debug>;$<BUILD_INTERFACE:${export_build_dir}/install/include>;$<BUILD_INTERFACE:${export_build_dir}/install/include/dir3>")
+endif()
+
+file(GLOB_RECURSE actual
+ LIST_DIRECTORIES TRUE
+ RELATIVE "${CMAKE_BINARY_DIR}/../FileSetExport-build/install/include"
+ "${CMAKE_BINARY_DIR}/../FileSetExport-build/install/include/*"
+ )
+if(actual)
+ list(SORT actual)
+endif()
+if(_multi_config)
+ set(expect "^debug;debug/empty\\.h;debug/empty3\\.h;dir;dir/dir\\.h;dir3;dir3/dir3\.h;empty2\\.h;error\\.c;file1\\.h;file2\\.h;h2\\.h;release;release/empty\\.h;release/empty3\\.h$")
+else()
+ set(expect "^debug;debug/empty\\.h;debug/empty3\\.h;dir;dir/dir\\.h;dir3;dir3/dir3\.h;empty2\\.h;error\\.c;file1\\.h;file2\\.h;h2\\.h$")
+endif()
+if(NOT "${actual}" MATCHES "${expect}")
+ message(SEND_ERROR "Installed files:
+ ${actual}
+do not match what we expected:
+ ${expect}
+in directory:
+ ${CMAKE_INSTALL_PREFIX}")
+endif()
+
+add_library(lib2_export STATIC lib2.c)
+target_link_libraries(lib2_export PRIVATE export::lib1)
+add_library(lib2_install STATIC lib2.c)
+target_link_libraries(lib2_install PRIVATE install::lib1)
diff --git a/Tests/RunCMake/target_sources/FileSetInstallMissingSetsInterface-result.txt b/Tests/RunCMake/target_sources/FileSetInstallMissingSetsInterface-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/target_sources/FileSetInstallMissingSetsInterface-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/target_sources/FileSetInstallMissingSetsInterface-stderr.txt b/Tests/RunCMake/target_sources/FileSetInstallMissingSetsInterface-stderr.txt
new file mode 100644
index 0000000..694f227
--- /dev/null
+++ b/Tests/RunCMake/target_sources/FileSetInstallMissingSetsInterface-stderr.txt
@@ -0,0 +1,5 @@
+^CMake Error at FileSetInstallMissingSetsInterface\.cmake:[0-9]+ \(install\):
+ install TARGETS target lib1 is exported but not all of its file sets are
+ installed
+Call Stack \(most recent call first\):
+ CMakeLists\.txt:[0-9]+ \(include\)$
diff --git a/Tests/RunCMake/target_sources/FileSetInstallMissingSetsInterface.cmake b/Tests/RunCMake/target_sources/FileSetInstallMissingSetsInterface.cmake
new file mode 100644
index 0000000..face69e
--- /dev/null
+++ b/Tests/RunCMake/target_sources/FileSetInstallMissingSetsInterface.cmake
@@ -0,0 +1,5 @@
+enable_language(C)
+
+add_library(lib1 STATIC empty.c)
+target_sources(lib1 INTERFACE FILE_SET a TYPE HEADERS BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR} FILES h1.h)
+install(TARGETS lib1 EXPORT a)
diff --git a/Tests/RunCMake/target_sources/FileSetInstallMissingSetsPrivate.cmake b/Tests/RunCMake/target_sources/FileSetInstallMissingSetsPrivate.cmake
new file mode 100644
index 0000000..84778d1
--- /dev/null
+++ b/Tests/RunCMake/target_sources/FileSetInstallMissingSetsPrivate.cmake
@@ -0,0 +1,9 @@
+enable_language(C)
+
+add_library(lib1 STATIC empty.c)
+target_sources(lib1 PRIVATE FILE_SET a TYPE HEADERS BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR} FILES h1.h)
+install(TARGETS lib1 EXPORT a)
+
+add_library(lib2 STATIC empty.c)
+target_sources(lib2 INTERFACE FILE_SET a TYPE HEADERS BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR} FILES h1.h)
+install(TARGETS lib2)
diff --git a/Tests/RunCMake/target_sources/FileSetNoExistInterface-result.txt b/Tests/RunCMake/target_sources/FileSetNoExistInterface-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/target_sources/FileSetNoExistInterface-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/target_sources/FileSetNoExistInterface-stderr.txt b/Tests/RunCMake/target_sources/FileSetNoExistInterface-stderr.txt
new file mode 100644
index 0000000..3972c89
--- /dev/null
+++ b/Tests/RunCMake/target_sources/FileSetNoExistInterface-stderr.txt
@@ -0,0 +1,4 @@
+^CMake Error at FileSetNoExistInterface\.cmake:[0-9]+ \(set_property\):
+ Header set "a" has not yet been created\.
+Call Stack \(most recent call first\):
+ CMakeLists\.txt:[0-9]+ \(include\)$
diff --git a/Tests/RunCMake/target_sources/FileSetNoExistInterface.cmake b/Tests/RunCMake/target_sources/FileSetNoExistInterface.cmake
new file mode 100644
index 0000000..266bc61
--- /dev/null
+++ b/Tests/RunCMake/target_sources/FileSetNoExistInterface.cmake
@@ -0,0 +1,7 @@
+enable_language(C)
+
+add_library(lib1 STATIC empty.c)
+set_property(TARGET lib1 PROPERTY INTERFACE_HEADER_SETS "a")
+
+# Error happens at configure-time, so this doesn't help.
+target_sources(lib1 INTERFACE FILE_SET a TYPE HEADERS)
diff --git a/Tests/RunCMake/target_sources/FileSetNoExistPrivate-result.txt b/Tests/RunCMake/target_sources/FileSetNoExistPrivate-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/target_sources/FileSetNoExistPrivate-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/target_sources/FileSetNoExistPrivate-stderr.txt b/Tests/RunCMake/target_sources/FileSetNoExistPrivate-stderr.txt
new file mode 100644
index 0000000..336bafe
--- /dev/null
+++ b/Tests/RunCMake/target_sources/FileSetNoExistPrivate-stderr.txt
@@ -0,0 +1,4 @@
+^CMake Error at FileSetNoExistPrivate\.cmake:[0-9]+ \(set_property\):
+ Header set "a" has not yet been created\.
+Call Stack \(most recent call first\):
+ CMakeLists\.txt:[0-9]+ \(include\)$
diff --git a/Tests/RunCMake/target_sources/FileSetNoExistPrivate.cmake b/Tests/RunCMake/target_sources/FileSetNoExistPrivate.cmake
new file mode 100644
index 0000000..f501912
--- /dev/null
+++ b/Tests/RunCMake/target_sources/FileSetNoExistPrivate.cmake
@@ -0,0 +1,7 @@
+enable_language(C)
+
+add_library(lib1 STATIC empty.c)
+set_property(TARGET lib1 PROPERTY HEADER_SETS "a")
+
+# Error happens at configure-time, so this doesn't help.
+target_sources(lib1 PRIVATE FILE_SET a TYPE HEADERS)
diff --git a/Tests/RunCMake/target_sources/FileSetNoScope-result.txt b/Tests/RunCMake/target_sources/FileSetNoScope-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/target_sources/FileSetNoScope-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/target_sources/FileSetNoScope-stderr.txt b/Tests/RunCMake/target_sources/FileSetNoScope-stderr.txt
new file mode 100644
index 0000000..835ffe7
--- /dev/null
+++ b/Tests/RunCMake/target_sources/FileSetNoScope-stderr.txt
@@ -0,0 +1,4 @@
+^CMake Error at FileSetNoScope\.cmake:[0-9]+ \(target_sources\):
+ target_sources File set "a" is not in HEADER_SETS or INTERFACE_HEADER_SETS
+Call Stack \(most recent call first\):
+ CMakeLists\.txt:[0-9]+ \(include\)$
diff --git a/Tests/RunCMake/target_sources/FileSetNoScope.cmake b/Tests/RunCMake/target_sources/FileSetNoScope.cmake
new file mode 100644
index 0000000..79ff341
--- /dev/null
+++ b/Tests/RunCMake/target_sources/FileSetNoScope.cmake
@@ -0,0 +1,6 @@
+enable_language(C)
+
+add_library(lib1 STATIC empty.c)
+target_sources(lib1 PRIVATE FILE_SET a TYPE HEADERS BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR} FILES h1.h)
+set_property(TARGET lib1 PROPERTY HEADER_SETS)
+target_sources(lib1 PRIVATE FILE_SET a TYPE HEADERS FILES h2.h)
diff --git a/Tests/RunCMake/target_sources/FileSetNoType-result.txt b/Tests/RunCMake/target_sources/FileSetNoType-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/target_sources/FileSetNoType-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/target_sources/FileSetNoType-stderr.txt b/Tests/RunCMake/target_sources/FileSetNoType-stderr.txt
new file mode 100644
index 0000000..5405fdb
--- /dev/null
+++ b/Tests/RunCMake/target_sources/FileSetNoType-stderr.txt
@@ -0,0 +1,4 @@
+^CMake Error at FileSetNoType\.cmake:[0-9]+ \(target_sources\):
+ target_sources Must specify a TYPE when creating file set
+Call Stack \(most recent call first\):
+ CMakeLists\.txt:[0-9]+ \(include\)$
diff --git a/Tests/RunCMake/target_sources/FileSetNoType.cmake b/Tests/RunCMake/target_sources/FileSetNoType.cmake
new file mode 100644
index 0000000..961525d
--- /dev/null
+++ b/Tests/RunCMake/target_sources/FileSetNoType.cmake
@@ -0,0 +1,4 @@
+enable_language(C)
+
+add_library(lib1 STATIC empty.c)
+target_sources(lib1 PRIVATE FILE_SET a)
diff --git a/Tests/RunCMake/target_sources/FileSetOverlappingBaseDirs-result.txt b/Tests/RunCMake/target_sources/FileSetOverlappingBaseDirs-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/target_sources/FileSetOverlappingBaseDirs-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/target_sources/FileSetOverlappingBaseDirs-stderr.txt b/Tests/RunCMake/target_sources/FileSetOverlappingBaseDirs-stderr.txt
new file mode 100644
index 0000000..551b9e7
--- /dev/null
+++ b/Tests/RunCMake/target_sources/FileSetOverlappingBaseDirs-stderr.txt
@@ -0,0 +1,9 @@
+CMake Error at FileSetOverlappingBaseDirs\.cmake:[0-9]+ \(target_sources\):
+ Base directories in file set cannot be subdirectories of each other:
+
+ [^
+]*/Tests/RunCMake/target_sources/\.
+ [^
+]*/Tests/RunCMake/target_sources/dir3
+Call Stack \(most recent call first\):
+ CMakeLists\.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/target_sources/FileSetOverlappingBaseDirs.cmake b/Tests/RunCMake/target_sources/FileSetOverlappingBaseDirs.cmake
new file mode 100644
index 0000000..eba4191
--- /dev/null
+++ b/Tests/RunCMake/target_sources/FileSetOverlappingBaseDirs.cmake
@@ -0,0 +1,4 @@
+enable_language(C)
+
+add_library(lib1 STATIC empty.c)
+target_sources(lib1 PRIVATE FILE_SET a TYPE HEADERS BASE_DIRS $<1:${CMAKE_CURRENT_SOURCE_DIR}/.$<SEMICOLON>${CMAKE_CURRENT_SOURCE_DIR}/dir3> FILES h1.h)
diff --git a/Tests/RunCMake/target_sources/FileSetProperties.cmake b/Tests/RunCMake/target_sources/FileSetProperties.cmake
new file mode 100644
index 0000000..ce010a3
--- /dev/null
+++ b/Tests/RunCMake/target_sources/FileSetProperties.cmake
@@ -0,0 +1,67 @@
+enable_language(C)
+
+function(assert_prop_undef tgt prop)
+ unset(actual_value)
+ get_property(actual_value TARGET ${tgt} PROPERTY ${prop})
+ if(DEFINED actual_value)
+ message(SEND_ERROR "${prop} should be undefined, actual value:\n ${actual_value}")
+ endif()
+endfunction()
+
+function(assert_prop_eq tgt prop value)
+ unset(actual_value)
+ get_property(actual_value TARGET ${tgt} PROPERTY ${prop})
+ if(NOT actual_value STREQUAL value)
+ message(SEND_ERROR "Expected value of ${prop}:\n ${value}\nActual value:\n ${actual_value}")
+ endif()
+endfunction()
+
+add_library(lib1 STATIC empty.c)
+assert_prop_eq(lib1 HEADER_SETS "")
+assert_prop_eq(lib1 INTERFACE_HEADER_SETS "")
+assert_prop_undef(lib1 INCLUDE_DIRECTORIES)
+assert_prop_undef(lib1 INTERFACE_INCLUDE_DIRECTORIES)
+
+target_sources(lib1 PUBLIC FILE_SET a TYPE HEADERS BASE_DIRS "." FILES h1.h h2.h)
+assert_prop_eq(lib1 HEADER_SETS "a")
+assert_prop_eq(lib1 INTERFACE_HEADER_SETS "a")
+assert_prop_eq(lib1 HEADER_DIRS_a "${CMAKE_CURRENT_SOURCE_DIR}/.")
+assert_prop_eq(lib1 HEADER_SET_a "${CMAKE_CURRENT_SOURCE_DIR}/h1.h;${CMAKE_CURRENT_SOURCE_DIR}/h2.h")
+assert_prop_eq(lib1 INCLUDE_DIRECTORIES "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/.>")
+assert_prop_eq(lib1 INTERFACE_INCLUDE_DIRECTORIES "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/.>")
+
+target_sources(lib1 PUBLIC FILE_SET a FILES h3.h)
+assert_prop_eq(lib1 HEADER_SETS "a")
+assert_prop_eq(lib1 INTERFACE_HEADER_SETS "a")
+assert_prop_eq(lib1 HEADER_DIRS_a "${CMAKE_CURRENT_SOURCE_DIR}/.")
+assert_prop_eq(lib1 HEADER_SET_a "${CMAKE_CURRENT_SOURCE_DIR}/h1.h;${CMAKE_CURRENT_SOURCE_DIR}/h2.h;${CMAKE_CURRENT_SOURCE_DIR}/h3.h")
+assert_prop_eq(lib1 INCLUDE_DIRECTORIES "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/.>")
+assert_prop_eq(lib1 INTERFACE_INCLUDE_DIRECTORIES "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/.>")
+
+target_sources(lib1 PRIVATE FILE_SET b TYPE HEADERS BASE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/dir" FILES dir/dir.h)
+assert_prop_eq(lib1 HEADER_SETS "a;b")
+assert_prop_eq(lib1 INTERFACE_HEADER_SETS "a")
+assert_prop_eq(lib1 HEADER_DIRS_b "${CMAKE_CURRENT_SOURCE_DIR}/dir")
+assert_prop_eq(lib1 HEADER_SET_b "${CMAKE_CURRENT_SOURCE_DIR}/dir/dir.h")
+assert_prop_eq(lib1 INCLUDE_DIRECTORIES "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/.>;$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/dir>")
+assert_prop_eq(lib1 INTERFACE_INCLUDE_DIRECTORIES "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/.>")
+
+target_sources(lib1 INTERFACE FILE_SET c TYPE HEADERS)
+assert_prop_eq(lib1 HEADER_SETS "a;b")
+assert_prop_eq(lib1 INTERFACE_HEADER_SETS "a;c")
+assert_prop_eq(lib1 HEADER_DIRS_c "${CMAKE_CURRENT_SOURCE_DIR}")
+assert_prop_eq(lib1 HEADER_SET_c "")
+assert_prop_eq(lib1 INCLUDE_DIRECTORIES "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/.>;$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/dir>")
+assert_prop_eq(lib1 INTERFACE_INCLUDE_DIRECTORIES "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/.>;$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>")
+
+target_sources(lib1 PUBLIC FILE_SET HEADERS BASE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}" FILES h1.h)
+assert_prop_eq(lib1 HEADER_DIRS "${CMAKE_CURRENT_SOURCE_DIR}")
+assert_prop_eq(lib1 HEADER_SET "${CMAKE_CURRENT_SOURCE_DIR}/h1.h")
+assert_prop_eq(lib1 INCLUDE_DIRECTORIES "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/.>;$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/dir>;$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>")
+assert_prop_eq(lib1 INTERFACE_INCLUDE_DIRECTORIES "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/.>;$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>;$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>")
+
+target_sources(lib1 PUBLIC FILE_SET HEADERS FILES h2.h)
+assert_prop_eq(lib1 HEADER_DIRS "${CMAKE_CURRENT_SOURCE_DIR}")
+assert_prop_eq(lib1 HEADER_SET "${CMAKE_CURRENT_SOURCE_DIR}/h1.h;${CMAKE_CURRENT_SOURCE_DIR}/h2.h")
+assert_prop_eq(lib1 INCLUDE_DIRECTORIES "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/.>;$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/dir>;$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>")
+assert_prop_eq(lib1 INTERFACE_INCLUDE_DIRECTORIES "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/.>;$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>;$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>")
diff --git a/Tests/RunCMake/target_sources/FileSetWrongBaseDirs-result.txt b/Tests/RunCMake/target_sources/FileSetWrongBaseDirs-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/target_sources/FileSetWrongBaseDirs-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/target_sources/FileSetWrongBaseDirs-stderr.txt b/Tests/RunCMake/target_sources/FileSetWrongBaseDirs-stderr.txt
new file mode 100644
index 0000000..f4bd447
--- /dev/null
+++ b/Tests/RunCMake/target_sources/FileSetWrongBaseDirs-stderr.txt
@@ -0,0 +1,12 @@
+CMake Error at FileSetWrongBaseDirs\.cmake:[0-9]+ \(target_sources\):
+ File:
+
+ [^
+]*/Tests/RunCMake/target_sources/h1\.h
+
+ must be in one of the file set's base directories:
+
+ [^
+]*/Tests/RunCMake/target_sources/dir3
+Call Stack \(most recent call first\):
+ CMakeLists\.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/target_sources/FileSetWrongBaseDirs.cmake b/Tests/RunCMake/target_sources/FileSetWrongBaseDirs.cmake
new file mode 100644
index 0000000..38d3abd
--- /dev/null
+++ b/Tests/RunCMake/target_sources/FileSetWrongBaseDirs.cmake
@@ -0,0 +1,4 @@
+enable_language(C)
+
+add_library(lib1 STATIC empty.c)
+target_sources(lib1 PRIVATE FILE_SET a TYPE HEADERS BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/dir3 FILES h1.h)
diff --git a/Tests/RunCMake/target_sources/FileSetWrongBaseDirsRelative-result.txt b/Tests/RunCMake/target_sources/FileSetWrongBaseDirsRelative-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/target_sources/FileSetWrongBaseDirsRelative-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/target_sources/FileSetWrongBaseDirsRelative-stderr.txt b/Tests/RunCMake/target_sources/FileSetWrongBaseDirsRelative-stderr.txt
new file mode 100644
index 0000000..6bb0ec6
--- /dev/null
+++ b/Tests/RunCMake/target_sources/FileSetWrongBaseDirsRelative-stderr.txt
@@ -0,0 +1,10 @@
+CMake Error at reldir/CMakeLists\.txt:[0-9]+ \(target_sources\):
+ File:
+
+ [^
+]*/Tests/RunCMake/target_sources/reldir/\.\./h1\.h
+
+ must be in one of the file set's base directories:
+
+ [^
+]*/Tests/RunCMake/target_sources/reldir/\.
diff --git a/Tests/RunCMake/target_sources/FileSetWrongBaseDirsRelative.cmake b/Tests/RunCMake/target_sources/FileSetWrongBaseDirsRelative.cmake
new file mode 100644
index 0000000..2ca8a8e
--- /dev/null
+++ b/Tests/RunCMake/target_sources/FileSetWrongBaseDirsRelative.cmake
@@ -0,0 +1,3 @@
+enable_language(C)
+
+add_subdirectory(reldir)
diff --git a/Tests/RunCMake/target_sources/FileSetWrongType-result.txt b/Tests/RunCMake/target_sources/FileSetWrongType-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/target_sources/FileSetWrongType-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/target_sources/FileSetWrongType-stderr.txt b/Tests/RunCMake/target_sources/FileSetWrongType-stderr.txt
new file mode 100644
index 0000000..8ffa786
--- /dev/null
+++ b/Tests/RunCMake/target_sources/FileSetWrongType-stderr.txt
@@ -0,0 +1,4 @@
+^CMake Error at FileSetWrongType\.cmake:[0-9]+ \(target_sources\):
+ target_sources File set TYPE may only be "HEADERS"
+Call Stack \(most recent call first\):
+ CMakeLists\.txt:[0-9]+ \(include\)$
diff --git a/Tests/RunCMake/target_sources/FileSetWrongType.cmake b/Tests/RunCMake/target_sources/FileSetWrongType.cmake
new file mode 100644
index 0000000..b7dee72
--- /dev/null
+++ b/Tests/RunCMake/target_sources/FileSetWrongType.cmake
@@ -0,0 +1,4 @@
+enable_language(C)
+
+add_library(lib1 STATIC empty.c)
+target_sources(lib1 PRIVATE FILE_SET a TYPE UNKNOWN)
diff --git a/Tests/RunCMake/target_sources/RunCMakeTest.cmake b/Tests/RunCMake/target_sources/RunCMakeTest.cmake
index 9d64927..9828fa2 100644
--- a/Tests/RunCMake/target_sources/RunCMakeTest.cmake
+++ b/Tests/RunCMake/target_sources/RunCMakeTest.cmake
@@ -21,3 +21,60 @@ run_cmake(AddCustomTargetInterfaceSources)
run_cmake(AddCustomTargetSources)
run_cmake(AddCustomTargetCheckProperty)
run_cmake(AddCustomTargetGenx)
+
+run_cmake(FileSetProperties)
+run_cmake(FileSetNoType)
+run_cmake(FileSetWrongType)
+run_cmake(FileSetDefaultWrongType)
+run_cmake(FileSetChangeScope)
+run_cmake(FileSetChangeType)
+run_cmake(FileSetWrongBaseDirs)
+run_cmake(FileSetWrongBaseDirsRelative)
+run_cmake(FileSetOverlappingBaseDirs)
+run_cmake(FileSetInstallMissingSetsPrivate)
+run_cmake(FileSetInstallMissingSetsInterface)
+run_cmake(FileSetNoScope)
+run_cmake(FileSetNoExistPrivate)
+run_cmake(FileSetNoExistInterface)
+run_cmake(FileSetDirectories)
+
+set(RunCMake_TEST_OPTIONS -DCMAKE_POLICY_DEFAULT_CMP0115=NEW)
+run_cmake(FileSetFileNoExist)
+unset(RunCMake_TEST_OPTIONS)
+
+function(run_export_import name)
+ if(RunCMake_GENERATOR_IS_MULTI_CONFIG)
+ set(_config_options "-DCMAKE_CONFIGURATION_TYPES=Debug\\\\;Release")
+ else()
+ set(_config_options -DCMAKE_BUILD_TYPE=Debug)
+ endif()
+
+ set(RunCMake_TEST_NO_CLEAN 1)
+ set(RunCMake_TEST_BINARY_DIR "${RunCMake_BINARY_DIR}/${name}Export-build")
+ set(RunCMake_TEST_OPTIONS "--install-prefix=${RunCMake_TEST_BINARY_DIR}/install" ${_config_options})
+ file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
+ file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
+ run_cmake(${name}Export)
+ run_cmake_command(${name}Export-build ${CMAKE_COMMAND} --build . --config Debug)
+ run_cmake_command(${name}Export-build ${CMAKE_COMMAND} --install . --config Debug)
+ if(RunCMake_GENERATOR_IS_MULTI_CONFIG)
+ run_cmake_command(${name}Export-build ${CMAKE_COMMAND} --build . --config Release)
+ run_cmake_command(${name}Export-build ${CMAKE_COMMAND} --install . --config Release)
+ endif()
+ unset(RunCMake_TEST_OPTIONS)
+
+ set(RunCMake_TEST_BINARY_DIR "${RunCMake_BINARY_DIR}/${name}Import-build")
+ unset(RunCMake_TEST_OPTIONS)
+ file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
+ file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
+ run_cmake(${name}Import)
+ run_cmake_command(${name}Import-build ${CMAKE_COMMAND} --build . --config Debug)
+ if(RunCMake_GENERATOR_IS_MULTI_CONFIG)
+ run_cmake_command(${name}Import-build ${CMAKE_COMMAND} --build . --config Release)
+ endif()
+
+ unset(RunCMake_TEST_BINARY_DIR)
+ unset(RunCMake_TEST_NO_CLEAN)
+endfunction()
+
+run_export_import(FileSet)
diff --git a/Tests/RunCMake/target_sources/debug/empty.h b/Tests/RunCMake/target_sources/debug/empty.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Tests/RunCMake/target_sources/debug/empty.h
diff --git a/Tests/RunCMake/target_sources/debug/empty2.h b/Tests/RunCMake/target_sources/debug/empty2.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Tests/RunCMake/target_sources/debug/empty2.h
diff --git a/Tests/RunCMake/target_sources/dir/dir.h b/Tests/RunCMake/target_sources/dir/dir.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Tests/RunCMake/target_sources/dir/dir.h
diff --git a/Tests/RunCMake/target_sources/dir1/file1.h b/Tests/RunCMake/target_sources/dir1/file1.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Tests/RunCMake/target_sources/dir1/file1.h
diff --git a/Tests/RunCMake/target_sources/dir2/file2.h b/Tests/RunCMake/target_sources/dir2/file2.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Tests/RunCMake/target_sources/dir2/file2.h
diff --git a/Tests/RunCMake/target_sources/dir3/CMakeLists.txt b/Tests/RunCMake/target_sources/dir3/CMakeLists.txt
new file mode 100644
index 0000000..e23ceb8
--- /dev/null
+++ b/Tests/RunCMake/target_sources/dir3/CMakeLists.txt
@@ -0,0 +1 @@
+add_library(lib1 STATIC ../empty.c)
diff --git a/Tests/RunCMake/target_sources/dir3/dir3.h b/Tests/RunCMake/target_sources/dir3/dir3.h
new file mode 100644
index 0000000..e45c25a
--- /dev/null
+++ b/Tests/RunCMake/target_sources/dir3/dir3.h
@@ -0,0 +1,4 @@
+#ifndef DIR3_H
+#define DIR3_H
+
+#endif
diff --git a/Tests/RunCMake/target_sources/dir4/CMakeLists.txt b/Tests/RunCMake/target_sources/dir4/CMakeLists.txt
new file mode 100644
index 0000000..6475685
--- /dev/null
+++ b/Tests/RunCMake/target_sources/dir4/CMakeLists.txt
@@ -0,0 +1,4 @@
+target_sources(lib1 PRIVATE FILE_SET HEADERS BASE_DIRS ${CMAKE_SOURCE_DIR} FILES
+ $<1:dir3.h>
+ dir4.h
+ )
diff --git a/Tests/RunCMake/target_sources/dir4/dir4.h b/Tests/RunCMake/target_sources/dir4/dir4.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Tests/RunCMake/target_sources/dir4/dir4.h
diff --git a/Tests/RunCMake/target_sources/empty.c b/Tests/RunCMake/target_sources/empty.c
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Tests/RunCMake/target_sources/empty.c
diff --git a/Tests/RunCMake/target_sources/empty3.h b/Tests/RunCMake/target_sources/empty3.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Tests/RunCMake/target_sources/empty3.h
diff --git a/Tests/RunCMake/target_sources/error.c b/Tests/RunCMake/target_sources/error.c
new file mode 100644
index 0000000..f10e687
--- /dev/null
+++ b/Tests/RunCMake/target_sources/error.c
@@ -0,0 +1 @@
+#error "This should not be compiled"
diff --git a/Tests/RunCMake/target_sources/h1.h b/Tests/RunCMake/target_sources/h1.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Tests/RunCMake/target_sources/h1.h
diff --git a/Tests/RunCMake/target_sources/h2.h b/Tests/RunCMake/target_sources/h2.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Tests/RunCMake/target_sources/h2.h
diff --git a/Tests/RunCMake/target_sources/h3.h b/Tests/RunCMake/target_sources/h3.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Tests/RunCMake/target_sources/h3.h
diff --git a/Tests/RunCMake/target_sources/lib1.c b/Tests/RunCMake/target_sources/lib1.c
new file mode 100644
index 0000000..95042de
--- /dev/null
+++ b/Tests/RunCMake/target_sources/lib1.c
@@ -0,0 +1,6 @@
+#ifdef _WIN32
+__declspec(dllexport)
+#endif
+ void lib1(void)
+{
+}
diff --git a/Tests/RunCMake/target_sources/lib2.c b/Tests/RunCMake/target_sources/lib2.c
new file mode 100644
index 0000000..a060dc9
--- /dev/null
+++ b/Tests/RunCMake/target_sources/lib2.c
@@ -0,0 +1,8 @@
+#include <dir3.h>
+
+#ifdef _WIN32
+__declspec(dllexport)
+#endif
+ void lib2(void)
+{
+}
diff --git a/Tests/RunCMake/target_sources/reldir/CMakeLists.txt b/Tests/RunCMake/target_sources/reldir/CMakeLists.txt
new file mode 100644
index 0000000..df22b25
--- /dev/null
+++ b/Tests/RunCMake/target_sources/reldir/CMakeLists.txt
@@ -0,0 +1,2 @@
+add_library(lib1 STATIC ../empty.c)
+target_sources(lib1 PRIVATE FILE_SET HEADERS BASE_DIRS . FILES ../h1.h)
diff --git a/Tests/RunCMake/target_sources/release/empty.h b/Tests/RunCMake/target_sources/release/empty.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Tests/RunCMake/target_sources/release/empty.h
diff --git a/Tests/RunCMake/target_sources/release/empty2.h b/Tests/RunCMake/target_sources/release/empty2.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Tests/RunCMake/target_sources/release/empty2.h
diff --git a/bootstrap b/bootstrap
index a487375..c3e1264 100755
--- a/bootstrap
+++ b/bootstrap
@@ -341,6 +341,7 @@ CMAKE_CXX_SOURCES="\
cmFileCommand \
cmFileCopier \
cmFileInstaller \
+ cmFileSet \
cmFileTime \
cmFileTimeCache \
cmFileTimes \
@@ -386,6 +387,7 @@ CMAKE_CXX_SOURCES="\
cmInstallCommandArguments \
cmInstallDirectoryGenerator \
cmInstallExportGenerator \
+ cmInstallFileSetGenerator \
cmInstallFilesCommand \
cmInstallFilesGenerator \
cmInstallGenerator \