diff options
| -rw-r--r-- | Help/command/target_sources.rst | 3 | ||||
| -rw-r--r-- | Help/manual/cmake-presets.7.rst | 106 | ||||
| -rw-r--r-- | Help/manual/presets/example.json | 6 | ||||
| -rw-r--r-- | Source/CMakeVersion.cmake | 2 | ||||
| -rw-r--r-- | Source/cmFindPathCommand.cxx | 11 | ||||
| -rw-r--r-- | Source/cmFindPathCommand.h | 3 | ||||
| -rw-r--r-- | Source/cmTargetSourcesCommand.cxx | 6 | ||||
| -rw-r--r-- | Tests/RunCMake/CMakePresets/RunCMakeTest.cmake | 5 | ||||
| -rw-r--r-- | Tests/RunCMake/CMakePresets/moreThings.json.in | 3 | ||||
| -rw-r--r-- | Tests/RunCMake/CMakePresets/otherThings.json.in | 3 | ||||
| -rw-r--r-- | Tests/RunCMake/target_sources/FileSetCustomTarget-result.txt | 1 | ||||
| -rw-r--r-- | Tests/RunCMake/target_sources/FileSetCustomTarget-stderr.txt | 4 | ||||
| -rw-r--r-- | Tests/RunCMake/target_sources/FileSetCustomTarget.cmake | 2 | ||||
| -rw-r--r-- | Tests/RunCMake/target_sources/RunCMakeTest.cmake | 1 |
14 files changed, 107 insertions, 49 deletions
diff --git a/Help/command/target_sources.rst b/Help/command/target_sources.rst index f4833e7..e482117 100644 --- a/Help/command/target_sources.rst +++ b/Help/command/target_sources.rst @@ -75,7 +75,8 @@ 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. +optional default file sets are named after their type. The target may not be a +custom target. Files in a ``PRIVATE`` or ``PUBLIC`` file set are marked as source files for the purposes of IDE integration. Additionally, files in ``HEADERS`` file sets diff --git a/Help/manual/cmake-presets.7.rst b/Help/manual/cmake-presets.7.rst index 69d0543..4620984 100644 --- a/Help/manual/cmake-presets.7.rst +++ b/Help/manual/cmake-presets.7.rst @@ -19,28 +19,16 @@ supports files included with the ``include`` field. ``CMakePresets.json`` and ``CMakeUserPresets.json`` live in the project's root directory. They both have exactly the same format, and both are optional -(though at least one must be present if ``--preset`` is specified.) -``CMakePresets.json`` is meant to save project-wide builds, while -``CMakeUserPresets.json`` is meant for developers to save their own local -builds. ``CMakePresets.json`` may be checked into a version control system, and -``CMakeUserPresets.json`` should NOT be checked in. For example, if a project -is using Git, ``CMakePresets.json`` may be tracked, and +(though at least one must be present if ``--preset`` is specified). +``CMakePresets.json`` is meant to specify project-wide build details, while +``CMakeUserPresets.json`` is meant for developers to specify their own local +build details. + +``CMakePresets.json`` may be checked into a version control system, and +``CMakeUserPresets.json`` should NOT be checked in. For example, if a +project is using Git, ``CMakePresets.json`` may be tracked, and ``CMakeUserPresets.json`` should be added to the ``.gitignore``. -``CMakePresets.json`` and ``CMakeUserPresets.json`` can include other files -with the ``include`` field in file version ``4`` and later. Files included by -these files can also include other files. If a preset file contains presets -that inherit from presets in another file, the file must include the other file -either directly or indirectly. Include cycles are not allowed among files (if -``a.json`` includes ``b.json``, ``b.json`` cannot include ``a.json``). However, -a file may be included multiple times from the same file or from different -files. If ``CMakePresets.json`` and ``CMakeUserPresets.json`` are both present, -``CMakeUserPresets.json`` implicitly includes ``CMakePresets.json``, even with -no ``include`` field, in all versions of the format. Files directly or -indirectly included from ``CMakePresets.json`` should be guaranteed to be -provided by the project. ``CMakeUserPresets.json`` may include files from -anywhere. - Format ====== @@ -73,6 +61,13 @@ The root object recognizes the following fields: An optional integer representing the patch version. +``include`` + + An optional array of strings representing files to include. If the filenames + are not absolute, they are considered relative to the current file. + This is allowed in preset files specifying version ``4`` or above. + See `Includes`_ for discussion of the constraints on included files. + ``vendor`` An optional map containing vendor-specific information. CMake does not @@ -97,11 +92,25 @@ The root object recognizes the following fields: An optional array of `Test Preset`_ objects. This is allowed in preset files specifying version ``2`` or above. -``include`` +Includes +^^^^^^^^ - An optional array of strings representing files to include. If the filenames - are not absolute, they are considered relative to the current file. - This is allowed in preset files specifying version ``4`` or above. +``CMakePresets.json`` and ``CMakeUserPresets.json`` can include other files +with the ``include`` field in file version ``4`` and later. Files included +by these files can also include other files. If ``CMakePresets.json`` and +``CMakeUserPresets.json`` are both present, ``CMakeUserPresets.json`` +implicitly includes ``CMakePresets.json``, even with no ``include`` field, +in all versions of the format. + +If a preset file contains presets that inherit from presets in another file, +the file must include the other file either directly or indirectly. +Include cycles are not allowed among files. If ``a.json`` includes +``b.json``, ``b.json`` cannot include ``a.json``. However, a file may be +included multiple times from the same file or from different files. + +Files directly or indirectly included from ``CMakePresets.json`` should be +guaranteed to be provided by the project. ``CMakeUserPresets.json`` may +include files from anywhere. Configure Preset ^^^^^^^^^^^^^^^^ @@ -129,16 +138,20 @@ that may contain the following fields: ``inherits`` An optional array of strings representing the names of presets to inherit - from. The preset will inherit all of the fields from the ``inherits`` + from. This field can also be a string, which is equivalent to an array + containing one string. + + The preset will inherit all of the fields from the ``inherits`` presets by default (except ``name``, ``hidden``, ``inherits``, ``description``, and ``displayName``), but can override them as desired. If multiple ``inherits`` presets provide conflicting values for the same field, the earlier preset in the ``inherits`` list will be - preferred. Presets in ``CMakePresets.json`` may not inherit from presets - in ``CMakeUserPresets.json``. + preferred. - This field can also be a string, which is equivalent to an array - containing one string. + A preset can only inherit from another preset that is defined in the + same file or in one of the files it includes (directly or indirectly). + Presets in ``CMakePresets.json`` may not inherit from presets in + ``CMakeUserPresets.json``. ``condition`` @@ -371,17 +384,21 @@ that may contain the following fields: ``inherits`` - An optional array of strings representing the names of presets to - inherit from. The preset will inherit all of the fields from the + An optional array of strings representing the names of presets to inherit + from. This field can also be a string, which is equivalent to an array + containing one string. + + The preset will inherit all of the fields from the ``inherits`` presets by default (except ``name``, ``hidden``, ``inherits``, ``description``, and ``displayName``), but can override them as desired. If multiple ``inherits`` presets provide conflicting values for the same field, the earlier preset in the ``inherits`` list - will be preferred. Presets in ``CMakePresets.json`` may not inherit from - presets in ``CMakeUserPresets.json``. + will be preferred. - This field can also be a string, which is equivalent to an array - containing one string. + A preset can only inherit from another preset that is defined in the + same file or in one of the files it includes (directly or indirectly). + Presets in ``CMakePresets.json`` may not inherit from presets in + ``CMakeUserPresets.json``. ``condition`` @@ -544,17 +561,21 @@ that may contain the following fields: ``inherits`` - An optional array of strings representing the names of presets to - inherit from. The preset will inherit all of the fields from the + An optional array of strings representing the names of presets to inherit + from. This field can also be a string, which is equivalent to an array + containing one string. + + The preset will inherit all of the fields from the ``inherits`` presets by default (except ``name``, ``hidden``, ``inherits``, ``description``, and ``displayName``), but can override them as desired. If multiple ``inherits`` presets provide conflicting values for the same field, the earlier preset in the ``inherits`` list - will be preferred. Presets in ``CMakePresets.json`` may not inherit from - presets in ``CMakeUserPresets.json``. + will be preferred. - This field can also be a string, which is equivalent to an array - containing one string. + A preset can only inherit from another preset that is defined in the + same file or in one of the files it includes (directly or indirectly). + Presets in ``CMakePresets.json`` may not inherit from presets in + ``CMakeUserPresets.json``. ``condition`` @@ -1004,7 +1025,8 @@ Recognized macros include: ``${sourceDir}`` - Path to the project source directory. + Path to the project source directory (i.e. the same as + :variable:`CMAKE_SOURCE_DIR`). ``${sourceParentDir}`` diff --git a/Help/manual/presets/example.json b/Help/manual/presets/example.json index a7ec10e..873c4ad 100644 --- a/Help/manual/presets/example.json +++ b/Help/manual/presets/example.json @@ -2,9 +2,13 @@ "version": 4, "cmakeMinimumRequired": { "major": 3, - "minor": 21, + "minor": 23, "patch": 0 }, + "include": [ + "otherThings.json", + "moreThings.json" + ], "configurePresets": [ { "name": "default", diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake index 699c8cf..655fe37 100644 --- a/Source/CMakeVersion.cmake +++ b/Source/CMakeVersion.cmake @@ -1,7 +1,7 @@ # CMake version number components. set(CMake_VERSION_MAJOR 3) set(CMake_VERSION_MINOR 23) -set(CMake_VERSION_PATCH 20220301) +set(CMake_VERSION_PATCH 20220302) #set(CMake_VERSION_RC 0) set(CMake_VERSION_IS_DIRTY 0) diff --git a/Source/cmFindPathCommand.cxx b/Source/cmFindPathCommand.cxx index a0a8570..27074ff 100644 --- a/Source/cmFindPathCommand.cxx +++ b/Source/cmFindPathCommand.cxx @@ -65,7 +65,8 @@ std::string cmFindPathCommand::FindHeader() } std::string cmFindPathCommand::FindHeaderInFramework( - std::string const& file, std::string const& dir) const + std::string const& file, std::string const& dir, + cmFindBaseDebugState& debug) const { std::string fileName = file; std::string frameWorkName; @@ -88,11 +89,13 @@ std::string cmFindPathCommand::FindHeaderInFramework( std::string fpath = cmStrCat(dir, frameWorkName, ".framework"); std::string intPath = cmStrCat(fpath, "/Headers/", fileName); if (cmSystemTools::FileExists(intPath)) { + debug.FoundAt(intPath); if (this->IncludeFileInPath) { return intPath; } return fpath; } + debug.FailedAt(intPath); } } // if it is not found yet or not a framework header, then do a glob search @@ -103,12 +106,15 @@ std::string cmFindPathCommand::FindHeaderInFramework( std::vector<std::string> files = globIt.GetFiles(); if (!files.empty()) { std::string fheader = cmSystemTools::CollapseFullPath(files[0]); + debug.FoundAt(fheader); if (this->IncludeFileInPath) { return fheader; } fheader.resize(fheader.size() - file.size()); return fheader; } + + // No frameworks matched the glob, so nothing more to add to debug.FailedAt() return ""; } @@ -135,8 +141,7 @@ std::string cmFindPathCommand::FindFrameworkHeader(cmFindBaseDebugState& debug) { for (std::string const& n : this->Names) { for (std::string const& sp : this->SearchPaths) { - std::string fwPath = this->FindHeaderInFramework(n, sp); - fwPath.empty() ? debug.FailedAt(fwPath) : debug.FoundAt(fwPath); + std::string fwPath = this->FindHeaderInFramework(n, sp, debug); if (!fwPath.empty()) { return fwPath; } diff --git a/Source/cmFindPathCommand.h b/Source/cmFindPathCommand.h index c7281f1..a7746f6 100644 --- a/Source/cmFindPathCommand.h +++ b/Source/cmFindPathCommand.h @@ -30,7 +30,8 @@ public: private: std::string FindHeaderInFramework(std::string const& file, - std::string const& dir) const; + std::string const& dir, + cmFindBaseDebugState& debug) const; std::string FindHeader(); std::string FindNormalHeader(cmFindBaseDebugState& debug); std::string FindFrameworkHeader(cmFindBaseDebugState& debug); diff --git a/Source/cmTargetSourcesCommand.cxx b/Source/cmTargetSourcesCommand.cxx index 818e271..b425acb 100644 --- a/Source/cmTargetSourcesCommand.cxx +++ b/Source/cmTargetSourcesCommand.cxx @@ -16,6 +16,7 @@ #include "cmMakefile.h" #include "cmMessageType.h" #include "cmPolicies.h" +#include "cmStateTypes.h" #include "cmStringAlgorithms.h" #include "cmSystemTools.h" #include "cmTarget.h" @@ -202,6 +203,11 @@ bool TargetSourcesImpl::HandleFileSetMode( return false; } + if (this->Target->GetType() == cmStateEnums::UTILITY) { + this->SetError("FILE_SETs may not be added to custom targets"); + 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; diff --git a/Tests/RunCMake/CMakePresets/RunCMakeTest.cmake b/Tests/RunCMake/CMakePresets/RunCMakeTest.cmake index 51e786e..955cf53 100644 --- a/Tests/RunCMake/CMakePresets/RunCMakeTest.cmake +++ b/Tests/RunCMake/CMakePresets/RunCMakeTest.cmake @@ -372,4 +372,9 @@ if(CMAKE_HOST_WIN32) endif() file(WRITE "${RunCMake_BINARY_DIR}/example.json.in" "${_example}") set(CMakePresets_FILE "${RunCMake_BINARY_DIR}/example.json.in") +set(CMakePresets_EXTRA_FILES + "${RunCMake_SOURCE_DIR}/otherThings.json.in" + "${RunCMake_SOURCE_DIR}/moreThings.json.in" +) run_cmake_presets(DocumentationExample --preset=default) +unset(CMakePresets_EXTRA_FILES) diff --git a/Tests/RunCMake/CMakePresets/moreThings.json.in b/Tests/RunCMake/CMakePresets/moreThings.json.in new file mode 100644 index 0000000..61a2092 --- /dev/null +++ b/Tests/RunCMake/CMakePresets/moreThings.json.in @@ -0,0 +1,3 @@ +{ + "version": 1 +} diff --git a/Tests/RunCMake/CMakePresets/otherThings.json.in b/Tests/RunCMake/CMakePresets/otherThings.json.in new file mode 100644 index 0000000..61a2092 --- /dev/null +++ b/Tests/RunCMake/CMakePresets/otherThings.json.in @@ -0,0 +1,3 @@ +{ + "version": 1 +} diff --git a/Tests/RunCMake/target_sources/FileSetCustomTarget-result.txt b/Tests/RunCMake/target_sources/FileSetCustomTarget-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/target_sources/FileSetCustomTarget-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/target_sources/FileSetCustomTarget-stderr.txt b/Tests/RunCMake/target_sources/FileSetCustomTarget-stderr.txt new file mode 100644 index 0000000..8ab3de7 --- /dev/null +++ b/Tests/RunCMake/target_sources/FileSetCustomTarget-stderr.txt @@ -0,0 +1,4 @@ +^CMake Error at FileSetCustomTarget\.cmake:[0-9]+ \(target_sources\): + target_sources FILE_SETs may not be added to custom targets +Call Stack \(most recent call first\): + CMakeLists\.txt:[0-9]+ \(include\)$ diff --git a/Tests/RunCMake/target_sources/FileSetCustomTarget.cmake b/Tests/RunCMake/target_sources/FileSetCustomTarget.cmake new file mode 100644 index 0000000..ce26400 --- /dev/null +++ b/Tests/RunCMake/target_sources/FileSetCustomTarget.cmake @@ -0,0 +1,2 @@ +add_custom_target(tgt) +target_sources(tgt PRIVATE FILE_SET HEADERS FILES h1.h) diff --git a/Tests/RunCMake/target_sources/RunCMakeTest.cmake b/Tests/RunCMake/target_sources/RunCMakeTest.cmake index 171de60..da9944d 100644 --- a/Tests/RunCMake/target_sources/RunCMakeTest.cmake +++ b/Tests/RunCMake/target_sources/RunCMakeTest.cmake @@ -38,6 +38,7 @@ run_cmake(FileSetNoExistPrivate) run_cmake(FileSetNoExistInterface) run_cmake(FileSetNoExistInstall) run_cmake(FileSetDirectories) +run_cmake(FileSetCustomTarget) set(RunCMake_TEST_OPTIONS -DCMAKE_POLICY_DEFAULT_CMP0115=NEW) run_cmake(FileSetFileNoExist) |
