diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index f9d1c03594..c01c490f6f 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -355,18 +355,18 @@ IF (WIN32) ENDIF(NOT UNIX) ENDIF (WIN32) -# turn on Ninja by default +# Turn on Ninja by default, but disable it +# on platforms where it does not pass all tests. +# Enforce Ninja support by setting CMAKE_USE_NINJA set(_CMAKE_DEFAULT_NINJA_VALUE TRUE) -# turn it off for platforms where it does not pass all the -# tests if(WIN32 OR APPLE) SET(_CMAKE_DEFAULT_NINJA_VALUE FALSE) endif() SET(CMAKE_ENABLE_NINJA ${_CMAKE_DEFAULT_NINJA_VALUE} CACHE BOOL - "Enable the ninja generator for CMake. currently not fully working for Windows or OSX") + "Enable the ninja generator for CMake. On Windows and OSX broken") MARK_AS_ADVANCED(CMAKE_ENABLE_NINJA) IF(CMAKE_ENABLE_NINJA) - MESSAGE(STATUS "Enable ninja generator.") + MESSAGE(STATUS "Ninja generator enabled.") SET(SRCS ${SRCS} cmGlobalNinjaGenerator.cxx cmGlobalNinjaGenerator.h @@ -382,7 +382,7 @@ IF(CMAKE_ENABLE_NINJA) ) ADD_DEFINITIONS(-DCMAKE_USE_NINJA) ELSE() - MESSAGE(STATUS "Disable ninja generator.") + MESSAGE(STATUS "Ninja generator disabled, enforce with -DCMAKE_ENABLE_NINJA=ON") ENDIF() # create a library used by the command line and the GUI diff --git a/Source/cmExtraCodeBlocksGenerator.cxx b/Source/cmExtraCodeBlocksGenerator.cxx index ccb17f0992..084c904e09 100644 --- a/Source/cmExtraCodeBlocksGenerator.cxx +++ b/Source/cmExtraCodeBlocksGenerator.cxx @@ -59,6 +59,9 @@ cmExtraCodeBlocksGenerator::cmExtraCodeBlocksGenerator() this->SupportedGlobalGenerators.push_back("NMake Makefiles"); // disable until somebody actually tests it: // this->SupportedGlobalGenerators.push_back("MSYS Makefiles"); +#endif +#ifdef CMAKE_USE_NINJA + this->SupportedGlobalGenerators.push_back("Ninja"); #endif this->SupportedGlobalGenerators.push_back("Unix Makefiles"); } diff --git a/Source/cmNinjaNormalTargetGenerator.cxx b/Source/cmNinjaNormalTargetGenerator.cxx index 2bad32c5d4..cf2b4271e9 100644 --- a/Source/cmNinjaNormalTargetGenerator.cxx +++ b/Source/cmNinjaNormalTargetGenerator.cxx @@ -47,8 +47,7 @@ cmNinjaNormalTargetGenerator(cmTarget* target) { // on Windows the output dir is already needed at compile time // ensure the directory exists (OutDir test) - std::string outpath = target->GetDirectory(this->GetConfigName()); - cmSystemTools::MakeDirectory(outpath.c_str()); + EnsureDirectoryExists(target->GetDirectory(this->GetConfigName())); } } @@ -56,6 +55,21 @@ cmNinjaNormalTargetGenerator::~cmNinjaNormalTargetGenerator() { } +void +cmNinjaNormalTargetGenerator +::EnsureDirectoryExists(const std::string& dir) +{ + cmSystemTools::MakeDirectory(dir.c_str()); +} + +void +cmNinjaNormalTargetGenerator +::EnsureParentDirectoryExists(const std::string& path) +{ + EnsureDirectoryExists(cmSystemTools::GetParentDirectory(path.c_str())); +} + + void cmNinjaNormalTargetGenerator::Generate() { if (!this->TargetLinkLanguage) { @@ -380,13 +394,18 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement() } } + std::string path; if (!this->TargetNameImport.empty()) { - vars["TARGET_IMPLIB"] = this->GetLocalGenerator()->ConvertToOutputFormat( - targetOutputImplib.c_str(), cmLocalGenerator::SHELL); + path = this->GetLocalGenerator()->ConvertToOutputFormat( + targetOutputImplib.c_str(), cmLocalGenerator::SHELL); + vars["TARGET_IMPLIB"] = path; + EnsureParentDirectoryExists(path); } - vars["TARGET_PDB"] = this->GetLocalGenerator()->ConvertToOutputFormat( - this->GetTargetPDB().c_str(), cmLocalGenerator::SHELL); + path = this->GetLocalGenerator()->ConvertToOutputFormat( + this->GetTargetPDB().c_str(), cmLocalGenerator::SHELL); + vars["TARGET_PDB"] = path; + EnsureParentDirectoryExists(path); std::vector *cmdLists[3] = { &this->GetTarget()->GetPreBuildCommands(), @@ -413,7 +432,7 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement() // If we have any PRE_LINK commands, we need to go back to HOME_OUTPUT for // the link commands. if (!preLinkCmdLines.empty()) { - std::string path = this->GetLocalGenerator()->ConvertToOutputFormat( + path = this->GetLocalGenerator()->ConvertToOutputFormat( this->GetMakefile()->GetHomeOutputDirectory(), cmLocalGenerator::SHELL); preLinkCmdLines.push_back("cd " + path); diff --git a/Source/cmNinjaNormalTargetGenerator.h b/Source/cmNinjaNormalTargetGenerator.h index 1702cafe85..7acbe8f6f7 100644 --- a/Source/cmNinjaNormalTargetGenerator.h +++ b/Source/cmNinjaNormalTargetGenerator.h @@ -35,6 +35,9 @@ private: void WriteObjectLibStatement(); std::vector ComputeLinkCmd(); + void EnsureDirectoryExists(const std::string& dir); + void EnsureParentDirectoryExists(const std::string& path); + private: // Target name info. std::string TargetNameOut;