summaryrefslogtreecommitdiffstats
path: root/Help/command/add_custom_command.rst
diff options
context:
space:
mode:
authorAbdelmaged Khalifa <abdelmaged.khalifa@gmail.com>2023-02-11 23:00:40 (GMT)
committerBrad King <brad.king@kitware.com>2023-02-14 13:56:59 (GMT)
commit082ccd75301cd02efd09bb9882bb9d2a8957193b (patch)
tree92611f898b4b3253c12687faa610f0bc8a0d0de8 /Help/command/add_custom_command.rst
parent48c69eeafe5e480b5baa0c6766d4d2e3c7f5a4ad (diff)
downloadCMake-082ccd75301cd02efd09bb9882bb9d2a8957193b.zip
CMake-082ccd75301cd02efd09bb9882bb9d2a8957193b.tar.gz
CMake-082ccd75301cd02efd09bb9882bb9d2a8957193b.tar.bz2
add_custom_command: Add DEPENDS_EXPLICIT_ONLY option for Ninja
Add option `DEPENDS_EXPLICIT_ONLY` to `add_custom_command` to indicate that implicit dependencies coming from users of the output are not needed, and only consider dependencies explicitly specified in the custom command. Fixes: #17097
Diffstat (limited to 'Help/command/add_custom_command.rst')
-rw-r--r--Help/command/add_custom_command.rst18
1 files changed, 17 insertions, 1 deletions
diff --git a/Help/command/add_custom_command.rst b/Help/command/add_custom_command.rst
index 293d3f0..2cf88fc 100644
--- a/Help/command/add_custom_command.rst
+++ b/Help/command/add_custom_command.rst
@@ -25,7 +25,8 @@ The first signature is for adding a custom command to produce an output:
[DEPFILE depfile]
[JOB_POOL job_pool]
[VERBATIM] [APPEND] [USES_TERMINAL]
- [COMMAND_EXPAND_LISTS])
+ [COMMAND_EXPAND_LISTS]
+ [DEPENDS_EXPLICIT_ONLY])
This defines a command to generate specified ``OUTPUT`` file(s).
A target created in the same directory (``CMakeLists.txt`` file)
@@ -357,6 +358,21 @@ The options are:
:ref:`Makefile Generators`, :ref:`Visual Studio Generators`,
and the :generator:`Xcode` generator.
+``DEPENDS_EXPLICIT_ONLY``
+
+ .. versionadded:: 3.27
+
+ Indicate that the command's ``DEPENDS`` argument represents all files
+ required by the command and implicit dependencies are not required.
+
+ Without this option, if any target uses the output of the custom command,
+ CMake will consider that target's dependencies as implicit dependencies for
+ the custom command in case this custom command requires files implicitly
+ created by those targets.
+
+ Only the :ref:`Ninja Generators` actually use this information to remove
+ unnecessary implicit dependencies.
+
Examples: Generating Files
^^^^^^^^^^^^^^^^^^^^^^^^^^
class="hl kwd">GetRealPath(currentBinDir); parentDirs[2].first = cmsys::SystemTools::GetRealPath(projectSrcDir); parentDirs[3].first = cmsys::SystemTools::GetRealPath(projectBinDir); parentDirs[0].second = "CurrentSource"; parentDirs[1].second = "CurrentBinary"; parentDirs[2].second = "ProjectSource"; parentDirs[3].second = "ProjectBinary"; } std::string cmFilePathChecksum::get(const std::string& filePath) const { std::string relPath; std::string relSeed; { const std::string fileReal = cmsys::SystemTools::GetRealPath(filePath); std::string parentDir; // Find closest project parent directory for (size_t ii = 0; ii != numParentDirs; ++ii) { const std::string& pDir = parentDirs[ii].first; if (!pDir.empty() && cmsys::SystemTools::IsSubDirectory(fileReal, pDir)) { relSeed = parentDirs[ii].second; parentDir = pDir; break; } } // Use file system root as fallback parent directory if (parentDir.empty()) { relSeed = "FileSystemRoot"; cmsys::SystemTools::SplitPathRootComponent(fileReal, &parentDir); } // Calculate relative path from project parent directory relPath = cmsys::SystemTools::RelativePath( parentDir, cmsys::SystemTools::GetParentDirectory(fileReal)); } // Calculate the file ( seed + relative path ) binary checksum std::vector<unsigned char> hashBytes = cmCryptoHash(cmCryptoHash::AlgoSHA256).ByteHashString(relSeed + relPath); // Convert binary checksum to string return cmBase32Encoder().encodeString(&hashBytes[0], hashBytes.size(), false); } std::string cmFilePathChecksum::getPart(const std::string& filePath, size_t length) const { return get(filePath).substr(0, length); }