diff options
-rw-r--r-- | Source/CMakeVersion.cmake | 2 | ||||
-rw-r--r-- | Source/cmGlobalNinjaGenerator.cxx | 38 | ||||
-rw-r--r-- | Source/cmGlobalNinjaGenerator.h | 11 | ||||
-rw-r--r-- | Source/cmLocalNinjaGenerator.cxx | 5 | ||||
-rw-r--r-- | Source/cmVisualStudio10TargetGenerator.cxx | 4 | ||||
-rw-r--r-- | Source/kwsys/CMakeLists.txt | 5 | ||||
-rw-r--r-- | Source/kwsys/Configure.hxx.in | 7 | ||||
-rw-r--r-- | Source/kwsys/FStream.hxx.in | 234 | ||||
-rw-r--r-- | Source/kwsys/kwsysPlatformTestsCXX.cxx | 5 | ||||
-rw-r--r-- | Tests/RunCMake/add_custom_target/RunCMakeTest.cmake | 14 | ||||
-rw-r--r-- | Tests/RunCMake/add_custom_target/TargetOrder.cmake | 31 | ||||
-rwxr-xr-x | bootstrap | 13 |
12 files changed, 292 insertions, 77 deletions
diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake index c377549..2e503f9 100644 --- a/Source/CMakeVersion.cmake +++ b/Source/CMakeVersion.cmake @@ -1,5 +1,5 @@ # CMake version number components. set(CMake_VERSION_MAJOR 3) set(CMake_VERSION_MINOR 6) -set(CMake_VERSION_PATCH 20160720) +set(CMake_VERSION_PATCH 20160721) #set(CMake_VERSION_RC 1) diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx index 91f08e6..51175c7 100644 --- a/Source/cmGlobalNinjaGenerator.cxx +++ b/Source/cmGlobalNinjaGenerator.cxx @@ -493,6 +493,8 @@ void cmGlobalNinjaGenerator::Generate() this->OpenBuildFileStream(); this->OpenRulesFileStream(); + this->TargetDependsClosures.clear(); + this->InitOutputPathPrefix(); this->TargetAll = this->NinjaOutputPath("all"); this->CMakeCacheFile = this->NinjaOutputPath("CMakeCache.txt"); @@ -905,6 +907,42 @@ void cmGlobalNinjaGenerator::AppendTargetDepends( } } +void cmGlobalNinjaGenerator::AppendTargetDependsClosure( + cmGeneratorTarget const* target, cmNinjaDeps& outputs) +{ + TargetDependsClosureMap::iterator i = + this->TargetDependsClosures.find(target); + if (i == this->TargetDependsClosures.end()) { + TargetDependsClosureMap::value_type e( + target, std::set<cmGeneratorTarget const*>()); + i = this->TargetDependsClosures.insert(e).first; + this->ComputeTargetDependsClosure(target, i->second); + } + std::set<cmGeneratorTarget const*> const& targets = i->second; + cmNinjaDeps outs; + for (std::set<cmGeneratorTarget const*>::const_iterator ti = targets.begin(); + ti != targets.end(); ++ti) { + this->AppendTargetOutputs(*ti, outs); + } + std::sort(outs.begin(), outs.end()); + outputs.insert(outputs.end(), outs.begin(), outs.end()); +} + +void cmGlobalNinjaGenerator::ComputeTargetDependsClosure( + cmGeneratorTarget const* target, std::set<cmGeneratorTarget const*>& depends) +{ + cmTargetDependSet const& targetDeps = this->GetTargetDirectDepends(target); + for (cmTargetDependSet::const_iterator i = targetDeps.begin(); + i != targetDeps.end(); ++i) { + if ((*i)->GetType() == cmState::INTERFACE_LIBRARY) { + continue; + } + if (depends.insert(*i).second) { + this->ComputeTargetDependsClosure(*i, depends); + } + } +} + void cmGlobalNinjaGenerator::AddTargetAlias(const std::string& alias, cmGeneratorTarget* target) { diff --git a/Source/cmGlobalNinjaGenerator.h b/Source/cmGlobalNinjaGenerator.h index c74973e..52fa5c9 100644 --- a/Source/cmGlobalNinjaGenerator.h +++ b/Source/cmGlobalNinjaGenerator.h @@ -301,6 +301,8 @@ public: cmNinjaDeps& outputs); void AppendTargetDepends(cmGeneratorTarget const* target, cmNinjaDeps& outputs); + void AppendTargetDependsClosure(cmGeneratorTarget const* target, + cmNinjaDeps& outputs); void AddDependencyToAll(cmGeneratorTarget* target); void AddDependencyToAll(const std::string& input); @@ -361,6 +363,10 @@ private: void WriteTargetClean(std::ostream& os); void WriteTargetHelp(std::ostream& os); + void ComputeTargetDependsClosure( + cmGeneratorTarget const* target, + std::set<cmGeneratorTarget const*>& depends); + std::string ninjaCmd() const; /// The file containing the build statement. (the relationship of the @@ -410,6 +416,11 @@ private: typedef std::map<std::string, cmGeneratorTarget*> TargetAliasMap; TargetAliasMap TargetAliases; + typedef std::map<cmGeneratorTarget const*, + std::set<cmGeneratorTarget const*> > + TargetDependsClosureMap; + TargetDependsClosureMap TargetDependsClosures; + std::string NinjaCommand; std::string NinjaVersion; diff --git a/Source/cmLocalNinjaGenerator.cxx b/Source/cmLocalNinjaGenerator.cxx index 0f488a6..46d7e18 100644 --- a/Source/cmLocalNinjaGenerator.cxx +++ b/Source/cmLocalNinjaGenerator.cxx @@ -450,13 +450,14 @@ void cmLocalNinjaGenerator::WriteCustomCommandBuildStatements() std::set<cmGeneratorTarget*>::iterator j = i->second.begin(); assert(j != i->second.end()); std::vector<std::string> ccTargetDeps; - this->AppendTargetDepends(*j, ccTargetDeps); + this->GetGlobalNinjaGenerator()->AppendTargetDependsClosure(*j, + ccTargetDeps); std::sort(ccTargetDeps.begin(), ccTargetDeps.end()); ++j; for (; j != i->second.end(); ++j) { std::vector<std::string> jDeps, depsIntersection; - this->AppendTargetDepends(*j, jDeps); + this->GetGlobalNinjaGenerator()->AppendTargetDependsClosure(*j, jDeps); std::sort(jDeps.begin(), jDeps.end()); std::set_intersection(ccTargetDeps.begin(), ccTargetDeps.end(), jDeps.begin(), jDeps.end(), diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index 29459db..7624f78 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -531,7 +531,9 @@ void cmVisualStudio10TargetGenerator::WriteEmbeddedResourceGroup() this->Configurations.begin(); i != this->Configurations.end(); ++i) { this->WritePlatformConfigTag("LogicalName", i->c_str(), 3); - if (this->GeneratorTarget->GetProperty("VS_GLOBAL_ROOTNAMESPACE")) { + if (this->GeneratorTarget->GetProperty("VS_GLOBAL_ROOTNAMESPACE") || + // Handle variant of VS_GLOBAL_<variable> for RootNamespace. + this->GeneratorTarget->GetProperty("VS_GLOBAL_RootNamespace")) { (*this->BuildFileStream) << "$(RootNamespace)."; } (*this->BuildFileStream) << "%(Filename)"; diff --git a/Source/kwsys/CMakeLists.txt b/Source/kwsys/CMakeLists.txt index 39b03b3..87f6048 100644 --- a/Source/kwsys/CMakeLists.txt +++ b/Source/kwsys/CMakeLists.txt @@ -632,6 +632,11 @@ IF(KWSYS_USE_SystemInformation) ENDIF() ENDIF() +IF(KWSYS_USE_FStream) + KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS_EXT_STDIO_FILEBUF_H + "Checking whether <ext/stdio_filebuf.h> is available" DIRECT) +ENDIF() + #----------------------------------------------------------------------------- # Choose a directory for the generated headers. IF(NOT KWSYS_HEADER_ROOT) diff --git a/Source/kwsys/Configure.hxx.in b/Source/kwsys/Configure.hxx.in index ff8e49d..4ce680d 100644 --- a/Source/kwsys/Configure.hxx.in +++ b/Source/kwsys/Configure.hxx.in @@ -17,6 +17,8 @@ /* Whether wstring is available. */ #define @KWSYS_NAMESPACE@_STL_HAS_WSTRING @KWSYS_STL_HAS_WSTRING@ +/* Whether <ext/stdio_filebuf.h> is available. */ +#define @KWSYS_NAMESPACE@_CXX_HAS_EXT_STDIO_FILEBUF_H @KWSYS_CXX_HAS_EXT_STDIO_FILEBUF_H@ /* If building a C++ file in kwsys itself, give the source file access to the macros without a configured namespace. */ @@ -24,8 +26,9 @@ # if !@KWSYS_NAMESPACE@_NAME_IS_KWSYS # define kwsys @KWSYS_NAMESPACE@ # endif -# define KWSYS_NAME_IS_KWSYS @KWSYS_NAMESPACE@_NAME_IS_KWSYS -# define KWSYS_STL_HAS_WSTRING @KWSYS_NAMESPACE@_STL_HAS_WSTRING +# define KWSYS_NAME_IS_KWSYS @KWSYS_NAMESPACE@_NAME_IS_KWSYS +# define KWSYS_STL_HAS_WSTRING @KWSYS_NAMESPACE@_STL_HAS_WSTRING +# define KWSYS_CXX_HAS_EXT_STDIO_FILEBUF_H @KWSYS_NAMESPACE@_CXX_HAS_EXT_STDIO_FILEBUF_H #endif #endif diff --git a/Source/kwsys/FStream.hxx.in b/Source/kwsys/FStream.hxx.in index 681e4d8..5471247 100644 --- a/Source/kwsys/FStream.hxx.in +++ b/Source/kwsys/FStream.hxx.in @@ -12,154 +12,248 @@ #ifndef @KWSYS_NAMESPACE@_FStream_hxx #define @KWSYS_NAMESPACE@_FStream_hxx +#include <@KWSYS_NAMESPACE@/Configure.hxx> #include <@KWSYS_NAMESPACE@/Encoding.hxx> #include <fstream> +#if defined(_WIN32) +# if !defined(_MSC_VER) && @KWSYS_NAMESPACE@_CXX_HAS_EXT_STDIO_FILEBUF_H +# include <ext/stdio_filebuf.h> +# endif +#endif namespace @KWSYS_NAMESPACE@ { -#if defined(_MSC_VER) && _MSC_VER >= 1400 +#if defined(_WIN32) && (defined(_MSC_VER) || @KWSYS_NAMESPACE@_CXX_HAS_EXT_STDIO_FILEBUF_H) # if defined(_NOEXCEPT) # define @KWSYS_NAMESPACE@_FStream_NOEXCEPT _NOEXCEPT # else # define @KWSYS_NAMESPACE@_FStream_NOEXCEPT # endif + +#if defined(_MSC_VER) + template<typename CharType,typename Traits> class basic_filebuf : public std::basic_filebuf<CharType,Traits> { +# if _MSC_VER >= 1400 public: typedef std::basic_filebuf<CharType,Traits> my_base_type; basic_filebuf *open(char const *s,std::ios_base::openmode mode) { + const std::wstring wstr = Encoding::ToWide(s); return static_cast<basic_filebuf*>( - my_base_type::open(Encoding::ToWide(s).c_str(), mode) + my_base_type::open(wstr.c_str(), mode) ); } +# endif + }; + +#else + + inline std::wstring getcmode(const std::ios_base::openmode mode) { + std::wstring cmode; + bool plus = false; + if (mode & std::ios_base::app) { + cmode += L"a"; + plus = mode & std::ios_base::in ? true : false; + } else if (mode & std::ios_base::trunc || + (mode & std::ios_base::out && (mode & std::ios_base::in) == 0)) { + cmode += L"w"; + plus = mode & std::ios_base::in ? true : false; + } else { + cmode += L"r"; + plus = mode & std::ios_base::out ? true : false; + } + if (plus) { + cmode += L"+"; + } + if (mode & std::ios_base::binary) { + cmode += L"b"; + } else { + cmode += L"t"; + } + return cmode; }; +#endif + template<typename CharType,typename Traits = std::char_traits<CharType> > - class basic_ifstream : public std::basic_istream<CharType,Traits> + class basic_efilebuf { + public: +#if defined(_MSC_VER) + typedef basic_filebuf<CharType,Traits> internal_buffer_type; +#else + typedef __gnu_cxx::stdio_filebuf<CharType,Traits> internal_buffer_type; +#endif + + basic_efilebuf() : file_(0) + { + buf_ = 0; + } + + bool _open(char const *file_name,std::ios_base::openmode mode) + { + if (is_open() || file_) { + return false; + } +#if defined(_MSC_VER) + const bool success = buf_->open(file_name,mode) != 0; +#else + const std::wstring wstr = Encoding::ToWide(file_name); + bool success = false; + std::wstring cmode = getcmode(mode); + file_ = _wfopen(wstr.c_str(), cmode.c_str()); + if (file_) { + if (buf_) { + delete buf_; + } + buf_ = new internal_buffer_type(file_, mode); + success = true; + } +#endif + return success; + } + + bool is_open() + { + if (!buf_) { + return false; + } + return buf_->is_open(); + } + + bool is_open() const + { + if (!buf_) { + return false; + } + return buf_->is_open(); + } + + bool _close() + { + bool success = false; + if (buf_) { + success = buf_->close() != 0; +#if !defined(_MSC_VER) + if (file_) { + success = fclose(file_) == 0 ? success : false; + file_ = 0; + } +#endif + } + return success; + } + + static void _set_state(bool success, std::basic_ios<CharType,Traits> *ios, basic_efilebuf* efilebuf) + { +#if !defined(_MSC_VER) + ios->rdbuf(efilebuf->buf_); +#endif + if (!success) { + ios->setstate(std::ios_base::failbit); + } else { + ios->clear(); + } + } + + ~basic_efilebuf() + { + if (buf_) { + delete buf_; + } + } + + protected: + internal_buffer_type* buf_; + FILE *file_; + }; + +template<typename CharType,typename Traits = std::char_traits<CharType> > +class basic_ifstream : public std::basic_istream<CharType,Traits>, + public basic_efilebuf<CharType,Traits> +{ + using basic_efilebuf<CharType,Traits>::is_open; + public: - typedef basic_filebuf<CharType,Traits> internal_buffer_type; + typedef typename basic_efilebuf<CharType, Traits>::internal_buffer_type internal_buffer_type; typedef std::basic_istream<CharType,Traits> internal_stream_type; basic_ifstream() : internal_stream_type(new internal_buffer_type()) { - buf_ = static_cast<internal_buffer_type *>(internal_stream_type::rdbuf()); + this->buf_ = static_cast<internal_buffer_type *>(internal_stream_type::rdbuf()); } explicit basic_ifstream(char const *file_name, std::ios_base::openmode mode = std::ios_base::in) : internal_stream_type(new internal_buffer_type()) { - buf_ = static_cast<internal_buffer_type *>(internal_stream_type::rdbuf()); + this->buf_ = static_cast<internal_buffer_type *>(internal_stream_type::rdbuf()); open(file_name,mode); } + void open(char const *file_name,std::ios_base::openmode mode = std::ios_base::in) { - if(!buf_->open(file_name,mode | std::ios_base::in)) - { - this->setstate(std::ios_base::failbit); - } - else - { - this->clear(); - } - } - bool is_open() - { - return buf_->is_open(); - } - bool is_open() const - { - return buf_->is_open(); + mode = mode | std::ios_base::in; + this->_set_state(this->_open(file_name, mode), this, this); } + void close() { - if(!buf_->close()) - { - this->setstate(std::ios_base::failbit); - } - else - { - this->clear(); - } + this->_set_state(this->_close(), this, this); } internal_buffer_type *rdbuf() const { - return buf_; + return this->buf_; } ~basic_ifstream() @KWSYS_NAMESPACE@_FStream_NOEXCEPT { - buf_->close(); - delete buf_; + close(); } - - private: - internal_buffer_type* buf_; }; template<typename CharType,typename Traits = std::char_traits<CharType> > -class basic_ofstream : public std::basic_ostream<CharType,Traits> +class basic_ofstream : public std::basic_ostream<CharType,Traits>, + public basic_efilebuf<CharType,Traits> { + using basic_efilebuf<CharType,Traits>::is_open; + public: - typedef basic_filebuf<CharType,Traits> internal_buffer_type; + typedef typename basic_efilebuf<CharType, Traits>::internal_buffer_type internal_buffer_type; typedef std::basic_ostream<CharType,Traits> internal_stream_type; basic_ofstream() : internal_stream_type(new internal_buffer_type()) { - buf_ = static_cast<internal_buffer_type *>(internal_stream_type::rdbuf()); + this->buf_ = static_cast<internal_buffer_type *>(internal_stream_type::rdbuf()); } explicit basic_ofstream(char const *file_name,std::ios_base::openmode mode = std::ios_base::out) : internal_stream_type(new internal_buffer_type()) { - buf_ = static_cast<internal_buffer_type *>(internal_stream_type::rdbuf()); + this->buf_ = static_cast<internal_buffer_type *>(internal_stream_type::rdbuf()); open(file_name,mode); } void open(char const *file_name,std::ios_base::openmode mode = std::ios_base::out) { - if(!buf_->open(file_name,mode | std::ios_base::out)) - { - this->setstate(std::ios_base::failbit); - } - else - { - this->clear(); - } - } - bool is_open() - { - return buf_->is_open(); - } - bool is_open() const - { - return buf_->is_open(); + mode = mode | std::ios_base::out; + this->_set_state(this->_open(file_name, mode), this, this); } + void close() { - if(!buf_->close()) - { - this->setstate(std::ios_base::failbit); - } - else - { - this->clear(); - } + this->_set_state(this->_close(), this, this); } internal_buffer_type *rdbuf() const { - return buf_.get(); + return this->buf_; } + ~basic_ofstream() @KWSYS_NAMESPACE@_FStream_NOEXCEPT { - buf_->close(); - delete buf_; + close(); } - - private: - internal_buffer_type* buf_; }; typedef basic_ifstream<char> ifstream; diff --git a/Source/kwsys/kwsysPlatformTestsCXX.cxx b/Source/kwsys/kwsysPlatformTestsCXX.cxx index fc87f91..b35808b 100644 --- a/Source/kwsys/kwsysPlatformTestsCXX.cxx +++ b/Source/kwsys/kwsysPlatformTestsCXX.cxx @@ -349,3 +349,8 @@ int main() void f(std ::wstring*) {} int main() { return 0; } #endif + +#ifdef TEST_KWSYS_CXX_HAS_EXT_STDIO_FILEBUF_H +#include <ext/stdio_filebuf.h> +int main() { return 0; } +#endif diff --git a/Tests/RunCMake/add_custom_target/RunCMakeTest.cmake b/Tests/RunCMake/add_custom_target/RunCMakeTest.cmake index 92c4a38..6c4e91b 100644 --- a/Tests/RunCMake/add_custom_target/RunCMakeTest.cmake +++ b/Tests/RunCMake/add_custom_target/RunCMakeTest.cmake @@ -4,3 +4,17 @@ run_cmake(NoArguments) run_cmake(BadTargetName) run_cmake(ByproductsNoCommand) run_cmake(UsesTerminalNoCommand) + +function(run_TargetOrder) + # Use a single build tree for a few tests without cleaning. + set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/TargetOrder-build) + set(RunCMake_TEST_NO_CLEAN 1) + file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}") + file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}") + run_cmake(TargetOrder) + if(RunCMake_GENERATOR STREQUAL "Ninja") + set(build_flags -j 1 -v) + endif() + run_cmake_command(TargetOrder-build ${CMAKE_COMMAND} --build . -- ${build_flags}) +endfunction() +run_TargetOrder() diff --git a/Tests/RunCMake/add_custom_target/TargetOrder.cmake b/Tests/RunCMake/add_custom_target/TargetOrder.cmake new file mode 100644 index 0000000..21669c0 --- /dev/null +++ b/Tests/RunCMake/add_custom_target/TargetOrder.cmake @@ -0,0 +1,31 @@ +# Add a target that requires step1 to run first but enforces +# it only by target-level ordering dependency. +add_custom_command( + OUTPUT step2.txt + COMMAND ${CMAKE_COMMAND} -E copy step1.txt step2.txt + ) +add_custom_target(step2 DEPENDS step2.txt) +add_dependencies(step2 step1) + +# Add a target that requires step1 and step2 to work, +# only depends on step1 transitively through step2, but +# also gets a copy of step2's custom command. +# The Ninja generator in particular must be careful with +# this case because it needs to compute the proper set of +# target ordering dependencies for the step2 custom command +# even though it appears in both the step2 and step3 +# targets due to dependency propagation. +add_custom_command( + OUTPUT step3.txt + COMMAND ${CMAKE_COMMAND} -E copy step1.txt step3-1.txt + COMMAND ${CMAKE_COMMAND} -E copy step2.txt step3.txt + DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/step2.txt + ) +add_custom_target(step3 ALL DEPENDS step3.txt) +add_dependencies(step3 step2) + +# We want this target to always run first. Add it last so +# that serial builds require dependencies to order it first. +add_custom_target(step1 + COMMAND ${CMAKE_COMMAND} -E touch step1.txt + ) @@ -90,7 +90,7 @@ else fi # Determine whether this is a MinGW environment. -if echo "${cmake_system}" | grep MINGW >/dev/null 2>&1; then +if echo "${cmake_system}" | grep 'MINGW\|MSYS' >/dev/null 2>&1; then cmake_system_mingw=true else cmake_system_mingw=false @@ -511,6 +511,7 @@ cmake_kwsys_config_replace_string () s/@KWSYS_LFS_REQUESTED@/${KWSYS_LFS_REQUESTED}/g; s/@KWSYS_NAME_IS_KWSYS@/${KWSYS_NAME_IS_KWSYS}/g; s/@KWSYS_STL_HAS_WSTRING@/${KWSYS_STL_HAS_WSTRING}/g; + s/@KWSYS_CXX_HAS_EXT_STDIO_FILEBUF_H@/${KWSYS_CXX_HAS_EXT_STDIO_FILEBUF_H}/g; }" >> "${OUTFILE}${_tmp}" if [ -f "${OUTFILE}${_tmp}" ]; then if "${_diff}" "${OUTFILE}" "${OUTFILE}${_tmp}" > /dev/null 2> /dev/null ; then @@ -1182,6 +1183,7 @@ KWSYS_BUILD_SHARED=0 KWSYS_LFS_AVAILABLE=0 KWSYS_LFS_REQUESTED=0 KWSYS_STL_HAS_WSTRING=0 +KWSYS_CXX_HAS_EXT_STDIO_FILEBUF_H=0 KWSYS_CXX_HAS_SETENV=0 KWSYS_CXX_HAS_UNSETENV=0 KWSYS_CXX_HAS_ENVIRON_IN_STDLIB_H=0 @@ -1224,6 +1226,15 @@ else echo "${cmake_cxx_compiler} does not have stl wstring" fi +if cmake_try_run "${cmake_cxx_compiler}" \ + "${cmake_cxx_flags} -DTEST_KWSYS_CXX_HAS_EXT_STDIO_FILEBUF_H" \ + "${cmake_source_dir}/Source/kwsys/kwsysPlatformTestsCXX.cxx" >> cmake_bootstrap.log 2>&1; then + KWSYS_CXX_HAS_EXT_STDIO_FILEBUF_H=1 + echo "${cmake_cxx_compiler} has <ext/stdio_filebuf.h>" +else + echo "${cmake_cxx_compiler} does not have <ext/stdio_filebuf.h>" +fi + # Just to be safe, let us store compiler and flags to the header file cmake_bootstrap_version='$Revision$' |