[Cmake-commits] CMake branch, next, updated. v3.5.0-535-g36e31e3
Brad King
brad.king at kitware.com
Fri Mar 18 11:01:32 EDT 2016
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "CMake".
The branch, next has been updated
via 36e31e35a08e2c63ee13d2919519aaf35def13ec (commit)
via 133aed8fac8d95a253d751c61e8908447ed3ee3f (commit)
via 86c851e6fa1d0ee3c10e26afc2cd5ace9e901d7e (commit)
via ca575fe9355a2be2b9fadcc84b05bcfa095c5e64 (commit)
from 3f41a53534a9df440745658161a8e083873df521 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=36e31e35a08e2c63ee13d2919519aaf35def13ec
commit 36e31e35a08e2c63ee13d2919519aaf35def13ec
Merge: 3f41a53 133aed8
Author: Brad King <brad.king at kitware.com>
AuthorDate: Fri Mar 18 11:01:31 2016 -0400
Commit: CMake Topic Stage <kwrobot at kitware.com>
CommitDate: Fri Mar 18 11:01:31 2016 -0400
Merge topic 'ninja-directory-targets' into next
133aed8f Help: Add notes for topic 'ninja-directory-targets'
86c851e6 Ninja: Add test for `$subdir/all` targets
ca575fe9 Ninja: Add `$subdir/all` targets
https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=133aed8fac8d95a253d751c61e8908447ed3ee3f
commit 133aed8fac8d95a253d751c61e8908447ed3ee3f
Author: Brad King <brad.king at kitware.com>
AuthorDate: Fri Mar 18 10:52:46 2016 -0400
Commit: Brad King <brad.king at kitware.com>
CommitDate: Fri Mar 18 10:59:23 2016 -0400
Help: Add notes for topic 'ninja-directory-targets'
diff --git a/Help/release/dev/ninja-directory-targets.rst b/Help/release/dev/ninja-directory-targets.rst
new file mode 100644
index 0000000..4826228
--- /dev/null
+++ b/Help/release/dev/ninja-directory-targets.rst
@@ -0,0 +1,7 @@
+ninja-directory-targets
+-----------------------
+
+* The :generator:`Ninja` generator learned to produce phony targets
+ of the form ``sub/dir/all`` to drive the build of a subdirectory.
+ This is equivalent to ``cd sub/dir; make all`` with
+ :ref:`Makefile Generators`.
https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=86c851e6fa1d0ee3c10e26afc2cd5ace9e901d7e
commit 86c851e6fa1d0ee3c10e26afc2cd5ace9e901d7e
Author: Brad King <brad.king at kitware.com>
AuthorDate: Fri Mar 18 10:52:37 2016 -0400
Commit: Brad King <brad.king at kitware.com>
CommitDate: Fri Mar 18 10:59:01 2016 -0400
Ninja: Add test for `$subdir/all` targets
diff --git a/Tests/RunCMake/Ninja/RunCMakeTest.cmake b/Tests/RunCMake/Ninja/RunCMakeTest.cmake
index 64f97bc..cdf51d9 100644
--- a/Tests/RunCMake/Ninja/RunCMakeTest.cmake
+++ b/Tests/RunCMake/Ninja/RunCMakeTest.cmake
@@ -16,3 +16,14 @@ run_CMP0058(WARN-no)
run_CMP0058(WARN-by)
run_CMP0058(NEW-no)
run_CMP0058(NEW-by)
+
+function(run_SubDir)
+ # Use a single build tree for a few tests without cleaning.
+ set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/SubDir-build)
+ set(RunCMake_TEST_NO_CLEAN 1)
+ file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
+ file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
+ run_cmake(SubDir)
+ run_cmake_command(SubDir-build ${CMAKE_COMMAND} --build . --target SubDir/all)
+endfunction()
+run_SubDir()
diff --git a/Tests/RunCMake/Ninja/SubDir-build-stdout.txt b/Tests/RunCMake/Ninja/SubDir-build-stdout.txt
new file mode 100644
index 0000000..e4b4662
--- /dev/null
+++ b/Tests/RunCMake/Ninja/SubDir-build-stdout.txt
@@ -0,0 +1 @@
+Building InAll
diff --git a/Tests/RunCMake/Ninja/SubDir.cmake b/Tests/RunCMake/Ninja/SubDir.cmake
new file mode 100644
index 0000000..7224ec3
--- /dev/null
+++ b/Tests/RunCMake/Ninja/SubDir.cmake
@@ -0,0 +1,2 @@
+add_subdirectory(SubDir)
+add_custom_target(TopFail ALL COMMAND does_not_exist)
diff --git a/Tests/RunCMake/Ninja/SubDir/CMakeLists.txt b/Tests/RunCMake/Ninja/SubDir/CMakeLists.txt
new file mode 100644
index 0000000..73ae431
--- /dev/null
+++ b/Tests/RunCMake/Ninja/SubDir/CMakeLists.txt
@@ -0,0 +1,2 @@
+add_custom_target(SubFail COMMAND does_not_exist)
+add_custom_target(InAll ALL COMMAND ${CMAKE_COMMAND} -E echo "Building InAll")
https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=ca575fe9355a2be2b9fadcc84b05bcfa095c5e64
commit ca575fe9355a2be2b9fadcc84b05bcfa095c5e64
Author: Charles Huet <charles.huet at gmail.com>
AuthorDate: Fri Mar 11 16:26:29 2016 +0100
Commit: Brad King <brad.king at kitware.com>
CommitDate: Fri Mar 18 10:59:01 2016 -0400
Ninja: Add `$subdir/all` targets
With the Makefile generator one can use `cd $subdir; make all` to build
all targets associated with a given subdirectory. This is not possible
to do with the Ninja generator since there is only one `build.ninja`
file at the top of the build tree. However, we can approximate it by
allowing one to run `ninja $subdir/all` at the top of the tree to build
the targets in the corresponding subdirectory.
Port logic from cmGlobalUnixMakefileGenerator3::WriteDirectoryRule2 to
cmGlobalNinjaGenerator in order to produce equivalent directory-level
targets.
diff --git a/Help/generator/Ninja.rst b/Help/generator/Ninja.rst
index 920abcb..d94e5f6 100644
--- a/Help/generator/Ninja.rst
+++ b/Help/generator/Ninja.rst
@@ -6,3 +6,7 @@ Generates build.ninja files.
A build.ninja file is generated into the build tree. Recent versions
of the ninja program can build the project through the "all" target.
An "install" target is also provided.
+
+For each subdirectory ``sub/dir`` of the project an additional target
+named ``sub/dir/all`` is generated that depends on all targets required
+by that subdirectory.
diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx
index 83422b7..f12396f 100644
--- a/Source/cmGlobalNinjaGenerator.cxx
+++ b/Source/cmGlobalNinjaGenerator.cxx
@@ -577,6 +577,7 @@ void cmGlobalNinjaGenerator::Generate()
this->WriteAssumedSourceDependencies();
this->WriteTargetAliases(*this->BuildFileStream);
+ this->WriteFolderTargets(*this->BuildFileStream);
this->WriteUnknownExplicitDependencies(*this->BuildFileStream);
this->WriteBuiltinTargets(*this->BuildFileStream);
@@ -848,6 +849,18 @@ std::string cmGlobalNinjaGenerator::ConvertToNinjaPath(const std::string& path)
return convPath;
}
+std::string
+cmGlobalNinjaGenerator::ConvertToNinjaFolderRule(const std::string& path)
+{
+ cmLocalNinjaGenerator *ng =
+ static_cast<cmLocalNinjaGenerator *>(this->LocalGenerators[0]);
+ std::string convPath = ng->Convert(path+"/all", cmOutputConverter::HOME);
+#ifdef _WIN32
+ cmSystemTools::ReplaceString(convPath, "/", "\\");
+#endif
+ return convPath;
+}
+
void cmGlobalNinjaGenerator::AddCXXCompileCommand(
const std::string &commandLine,
const std::string &sourceFile)
@@ -1044,6 +1057,75 @@ void cmGlobalNinjaGenerator::WriteTargetAliases(std::ostream& os)
}
}
+void cmGlobalNinjaGenerator::WriteFolderTargets(std::ostream& os)
+{
+ cmGlobalNinjaGenerator::WriteDivider(os);
+ os << "# Folder targets.\n\n";
+
+ std::map<std::string, cmNinjaDeps> targetsPerFolder;
+ for (std::vector<cmLocalGenerator *>::const_iterator
+ lgi = this->LocalGenerators.begin();
+ lgi != this->LocalGenerators.end(); ++lgi)
+ {
+ cmLocalGenerator const* lg = *lgi;
+ const std::string currentSourceFolder(
+ lg->GetStateSnapshot().GetDirectory().GetCurrentSource());
+ // The directory-level rule should depend on the target-level rules
+ // for all targets in the directory.
+ targetsPerFolder[currentSourceFolder] = cmNinjaDeps();
+ for (std::vector<cmGeneratorTarget*>::const_iterator
+ ti = lg->GetGeneratorTargets().begin();
+ ti != lg->GetGeneratorTargets().end(); ++ti)
+ {
+ cmGeneratorTarget const* gt = *ti;
+ cmState::TargetType const type = gt->GetType();
+ if((type == cmState::EXECUTABLE ||
+ type == cmState::STATIC_LIBRARY ||
+ type == cmState::SHARED_LIBRARY ||
+ type == cmState::MODULE_LIBRARY ||
+ type == cmState::OBJECT_LIBRARY ||
+ type == cmState::UTILITY) &&
+ !gt->GetPropertyAsBool("EXCLUDE_FROM_ALL"))
+ {
+ targetsPerFolder[currentSourceFolder].push_back(gt->GetName());
+ }
+ }
+
+ // The directory-level rule should depend on the directory-level
+ // rules of the subdirectories.
+ std::vector<cmState::Snapshot> const& children =
+ lg->GetStateSnapshot().GetChildren();
+ for(std::vector<cmState::Snapshot>::const_iterator
+ stateIt = children.begin(); stateIt != children.end(); ++stateIt)
+ {
+ targetsPerFolder[currentSourceFolder].push_back(
+ this->ConvertToNinjaFolderRule(
+ stateIt->GetDirectory().GetCurrentSource()));
+ }
+ }
+
+ std::string const rootSourceDir =
+ this->LocalGenerators[0]->GetSourceDirectory();
+ for (std::map<std::string, cmNinjaDeps >::const_iterator it =
+ targetsPerFolder.begin(); it != targetsPerFolder.end(); ++it)
+ {
+ cmGlobalNinjaGenerator::WriteDivider( os );
+ std::string const& currentSourceDir = it->first;
+
+ // Do not generate a rule for the root source dir.
+ if (rootSourceDir.length() >= currentSourceDir.length())
+ {
+ continue;
+ }
+
+ std::string const comment = "Folder: " + currentSourceDir;
+ cmNinjaDeps output(1);
+ output.push_back(this->ConvertToNinjaFolderRule(currentSourceDir));
+
+ this->WritePhonyBuild(os, comment, output, it->second);
+ }
+}
+
void cmGlobalNinjaGenerator::WriteUnknownExplicitDependencies(std::ostream& os)
{
if (!this->ComputingUnknownDependencies)
diff --git a/Source/cmGlobalNinjaGenerator.h b/Source/cmGlobalNinjaGenerator.h
index 8656590..3023a95 100644
--- a/Source/cmGlobalNinjaGenerator.h
+++ b/Source/cmGlobalNinjaGenerator.h
@@ -228,6 +228,8 @@ public:
return this->RulesFileStream; }
std::string ConvertToNinjaPath(const std::string& path);
+ std::string ConvertToNinjaFolderRule(const std::string& path);
+
struct MapToNinjaPathImpl {
cmGlobalNinjaGenerator* GG;
@@ -342,6 +344,7 @@ private:
void WriteAssumedSourceDependencies();
void WriteTargetAliases(std::ostream& os);
+ void WriteFolderTargets(std::ostream& os);
void WriteUnknownExplicitDependencies(std::ostream& os);
void WriteBuiltinTargets(std::ostream& os);
-----------------------------------------------------------------------
Summary of changes:
Help/generator/Ninja.rst | 4 ++
Help/release/dev/ninja-directory-targets.rst | 7 +++
Source/cmGlobalNinjaGenerator.cxx | 82 ++++++++++++++++++++++++++
Source/cmGlobalNinjaGenerator.h | 3 +
Tests/RunCMake/Ninja/RunCMakeTest.cmake | 11 ++++
Tests/RunCMake/Ninja/SubDir-build-stdout.txt | 1 +
Tests/RunCMake/Ninja/SubDir.cmake | 2 +
Tests/RunCMake/Ninja/SubDir/CMakeLists.txt | 2 +
8 files changed, 112 insertions(+)
create mode 100644 Help/release/dev/ninja-directory-targets.rst
create mode 100644 Tests/RunCMake/Ninja/SubDir-build-stdout.txt
create mode 100644 Tests/RunCMake/Ninja/SubDir.cmake
create mode 100644 Tests/RunCMake/Ninja/SubDir/CMakeLists.txt
hooks/post-receive
--
CMake
More information about the Cmake-commits
mailing list