Merge branch 'backport-ninja-subdir-binary-dir' into release

This commit is contained in:
Brad King 2016-10-24 10:31:14 -04:00
commit 6cd02f08c7
8 changed files with 35 additions and 29 deletions

View File

@ -843,20 +843,6 @@ std::string cmGlobalNinjaGenerator::ConvertToNinjaPath(const std::string& path)
return convPath; return convPath;
} }
std::string cmGlobalNinjaGenerator::ConvertToNinjaFolderRule(
const std::string& path)
{
cmLocalNinjaGenerator* ng =
static_cast<cmLocalNinjaGenerator*>(this->LocalGenerators[0]);
std::string convPath = ng->ConvertToRelativePath(
this->LocalGenerators[0]->GetState()->GetSourceDirectory(), path + "/all");
convPath = this->NinjaOutputPath(convPath);
#ifdef _WIN32
std::replace(convPath.begin(), convPath.end(), '/', '\\');
#endif
return convPath;
}
void cmGlobalNinjaGenerator::AddCXXCompileCommand( void cmGlobalNinjaGenerator::AddCXXCompileCommand(
const std::string& commandLine, const std::string& sourceFile) const std::string& commandLine, const std::string& sourceFile)
{ {
@ -1083,11 +1069,11 @@ void cmGlobalNinjaGenerator::WriteFolderTargets(std::ostream& os)
this->LocalGenerators.begin(); this->LocalGenerators.begin();
lgi != this->LocalGenerators.end(); ++lgi) { lgi != this->LocalGenerators.end(); ++lgi) {
cmLocalGenerator const* lg = *lgi; cmLocalGenerator const* lg = *lgi;
const std::string currentSourceFolder( const std::string currentBinaryFolder(
lg->GetStateSnapshot().GetDirectory().GetCurrentSource()); lg->GetStateSnapshot().GetDirectory().GetCurrentBinary());
// The directory-level rule should depend on the target-level rules // The directory-level rule should depend on the target-level rules
// for all targets in the directory. // for all targets in the directory.
targetsPerFolder[currentSourceFolder] = cmNinjaDeps(); targetsPerFolder[currentBinaryFolder] = cmNinjaDeps();
for (std::vector<cmGeneratorTarget*>::const_iterator ti = for (std::vector<cmGeneratorTarget*>::const_iterator ti =
lg->GetGeneratorTargets().begin(); lg->GetGeneratorTargets().begin();
ti != lg->GetGeneratorTargets().end(); ++ti) { ti != lg->GetGeneratorTargets().end(); ++ti) {
@ -1098,7 +1084,7 @@ void cmGlobalNinjaGenerator::WriteFolderTargets(std::ostream& os)
type == cmState::MODULE_LIBRARY || type == cmState::MODULE_LIBRARY ||
type == cmState::OBJECT_LIBRARY || type == cmState::UTILITY) && type == cmState::OBJECT_LIBRARY || type == cmState::UTILITY) &&
!gt->GetPropertyAsBool("EXCLUDE_FROM_ALL")) { !gt->GetPropertyAsBool("EXCLUDE_FROM_ALL")) {
targetsPerFolder[currentSourceFolder].push_back(gt->GetName()); targetsPerFolder[currentBinaryFolder].push_back(gt->GetName());
} }
} }
@ -1109,28 +1095,30 @@ void cmGlobalNinjaGenerator::WriteFolderTargets(std::ostream& os)
for (std::vector<cmState::Snapshot>::const_iterator stateIt = for (std::vector<cmState::Snapshot>::const_iterator stateIt =
children.begin(); children.begin();
stateIt != children.end(); ++stateIt) { stateIt != children.end(); ++stateIt) {
targetsPerFolder[currentSourceFolder].push_back( std::string const currentBinaryDir =
this->ConvertToNinjaFolderRule( stateIt->GetDirectory().GetCurrentBinary();
stateIt->GetDirectory().GetCurrentSource()));
targetsPerFolder[currentBinaryFolder].push_back(
this->ConvertToNinjaPath(currentBinaryDir + "/all"));
} }
} }
std::string const rootSourceDir = std::string const rootBinaryDir =
this->LocalGenerators[0]->GetSourceDirectory(); this->LocalGenerators[0]->GetBinaryDirectory();
for (std::map<std::string, cmNinjaDeps>::const_iterator it = for (std::map<std::string, cmNinjaDeps>::const_iterator it =
targetsPerFolder.begin(); targetsPerFolder.begin();
it != targetsPerFolder.end(); ++it) { it != targetsPerFolder.end(); ++it) {
cmGlobalNinjaGenerator::WriteDivider(os); cmGlobalNinjaGenerator::WriteDivider(os);
std::string const& currentSourceDir = it->first; std::string const& currentBinaryDir = it->first;
// Do not generate a rule for the root source dir. // Do not generate a rule for the root binary dir.
if (rootSourceDir.length() >= currentSourceDir.length()) { if (rootBinaryDir.length() >= currentBinaryDir.length()) {
continue; continue;
} }
std::string const comment = "Folder: " + currentSourceDir; std::string const comment = "Folder: " + currentBinaryDir;
cmNinjaDeps output(1); cmNinjaDeps output(1);
output.push_back(this->ConvertToNinjaFolderRule(currentSourceDir)); output.push_back(this->ConvertToNinjaPath(currentBinaryDir + "/all"));
this->WritePhonyBuild(os, comment, output, it->second); this->WritePhonyBuild(os, comment, output, it->second);
} }

View File

@ -234,7 +234,6 @@ public:
} }
std::string ConvertToNinjaPath(const std::string& path); std::string ConvertToNinjaPath(const std::string& path);
std::string ConvertToNinjaFolderRule(const std::string& path);
struct MapToNinjaPathImpl struct MapToNinjaPathImpl
{ {

View File

@ -45,14 +45,23 @@ function(run_SubDir)
set(SubDir_all [[SubDir\all]]) set(SubDir_all [[SubDir\all]])
set(SubDir_test [[SubDir\test]]) set(SubDir_test [[SubDir\test]])
set(SubDir_install [[SubDir\install]]) set(SubDir_install [[SubDir\install]])
set(SubDirBinary_test [[SubDirBinary\test]])
set(SubDirBinary_all [[SubDirBinary\all]])
set(SubDirBinary_install [[SubDirBinary\install]])
else() else()
set(SubDir_all [[SubDir/all]]) set(SubDir_all [[SubDir/all]])
set(SubDir_test [[SubDir/test]]) set(SubDir_test [[SubDir/test]])
set(SubDir_install [[SubDir/install]]) set(SubDir_install [[SubDir/install]])
set(SubDirBinary_all [[SubDirBinary/all]])
set(SubDirBinary_test [[SubDirBinary/test]])
set(SubDirBinary_install [[SubDirBinary/install]])
endif() endif()
run_cmake_command(SubDir-build ${CMAKE_COMMAND} --build . --target ${SubDir_all}) run_cmake_command(SubDir-build ${CMAKE_COMMAND} --build . --target ${SubDir_all})
run_cmake_command(SubDir-test ${CMAKE_COMMAND} --build . --target ${SubDir_test}) run_cmake_command(SubDir-test ${CMAKE_COMMAND} --build . --target ${SubDir_test})
run_cmake_command(SubDir-install ${CMAKE_COMMAND} --build . --target ${SubDir_install}) run_cmake_command(SubDir-install ${CMAKE_COMMAND} --build . --target ${SubDir_install})
run_cmake_command(SubDirBinary-build ${CMAKE_COMMAND} --build . --target ${SubDirBinary_all})
run_cmake_command(SubDirBinary-test ${CMAKE_COMMAND} --build . --target ${SubDirBinary_test})
run_cmake_command(SubDirBinary-install ${CMAKE_COMMAND} --build . --target ${SubDirBinary_install})
endfunction() endfunction()
run_SubDir() run_SubDir()

View File

@ -1,5 +1,6 @@
include(CTest) include(CTest)
add_subdirectory(SubDir) add_subdirectory(SubDir)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/SubDirSource SubDirBinary)
add_custom_target(TopFail ALL COMMAND does_not_exist) add_custom_target(TopFail ALL COMMAND does_not_exist)
add_test(NAME TopTest COMMAND ${CMAKE_COMMAND} -E echo "Running TopTest") add_test(NAME TopTest COMMAND ${CMAKE_COMMAND} -E echo "Running TopTest")
install(CODE [[ install(CODE [[

View File

@ -0,0 +1 @@
Building SubDirSourceInAll

View File

@ -0,0 +1 @@
-- Installing SubDirSource

View File

@ -0,0 +1 @@
1/1 Test #1: SubDirSourceTest

View File

@ -0,0 +1,6 @@
add_custom_target(SubDirSourceFail COMMAND does_not_exist)
add_custom_target(SubDirSourceInAll ALL COMMAND ${CMAKE_COMMAND} -E echo "Building SubDirSourceInAll")
add_test(NAME SubDirSourceTest COMMAND ${CMAKE_COMMAND} -E echo "Running SubDirSourceTest")
install(CODE [[
message(STATUS "Installing SubDirSource")
]])