Re: [cmake-developers] [PATCH v3 7/7] Add MinGW support for FStream
2016-07-07 3:51 GMT+03:00 Mike Gelfand: > On 07/07/2016 03:33 AM, Dāvis Mosāns wrote: >> 2016-07-07 1:22 GMT+03:00 Mike Gelfand : @@ -92,19 +159,26 @@ namespace @KWSYS_NAMESPACE@ [snip] private: internal_buffer_type* buf_; +#if !defined(_MSC_VER) +FILE *file_ = 0; +#endif }; template > >>> In-place member initialization... As Brad wrote earlier, using C++11 in >>> KWSys is not advised. >>> >> This was already there but only used for _MSC_VER >= 1400 >> Maybe could just guard this with __cplusplus >= 201103L and not support >> Unicode for older, it would be much easier... > > Apologies, don't quite get your response. Maybe the quote was too big; I > surely meant to point to "FILE *file_ = 0;" line, not the template > declaration or something else. Oh sorry, I misunderstood you earlier and yeah I see, will fix. -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: http://public.kitware.com/mailman/listinfo/cmake-developers
Re: [cmake-developers] [PATCH v3 5/7] For consoles output on Windows use our own std::streambuf
2016-07-07 1:36 GMT+03:00 Mike Gelfand: > On 07/07/2016 12:42 AM, clin...@elemtech.com wrote: >> From what I remember, WriteConsoleW doesn't support redirection to a >> file or pipe. I don't see an alternative in the patch for the case >> where stdout is not attached to the console. > The SO thread I pointed at actually contained a check for whether > corresponding stream is linked to terminal or not. Replacing stream > buffers unconditionally is not right. > Sorry, I missed this... Will fix. 2016-07-07 2:21 GMT+03:00 Mike Gelfand : > Just a small nore: as I failed to mention this before, the approach > taken in this patch will lead to messages to be printed to stdout and > stderr in CMake's internal encoding (UTF-8?) when ConsoleBuf is not > used, i.e. 1) on non-Windows and 2) on Windows with one or another > stream redirected to file/pipe (considering corresponding check is in > place). Seems to be the case anyway now, but maybe something to think about. > I know this, it always have been the case and with this patch I fix only output to console because currently it would output internal encoding which is unreadable for non-ASCII because console expects different codepage. As for encoding used for files it doesn't matter because we use same one for both writing and reading. It would matter if other applications would want to read it. And because it's set as UTF-8 it should work fine. > On 07/06/2016 10:12 PM, Dāvis Mosāns wrote: >> --- a/Source/cmakemain.cxx >> +++ b/Source/cmakemain.cxx >> @@ -171,6 +189,16 @@ int main(int ac, char const* const* av) >> #ifdef CMAKE_BUILD_WITH_CMAKE >>cmDynamicLoader::FlushCache(); >> #endif >> +#if defined(_WIN32) >> + if (cbufio) { >> +delete cbufio; >> +std::cout.rdbuf(coutbuf); >> + } >> + if (cbuferr) { >> +delete cbuferr; >> +std::cerr.rdbuf(cerrbuf); >> + } >> +#endif >>return ret; >> } >> > If exception was thrown in the beginning of main (as it seems you expect > one there), `coutbuf` and/or `cerrbuf` could be nullptr, and passing > nullptr here will fail. coutbuf can be null only if cbufio = new cmsys::ConsoleBuf(); threw an exception in which case cbufio will be null and so it won't be set here. And same for cerrbuf, it will be set if cbuferr is set in which case it means there weren't any exception. While I think it's not needed, I can add check for it and set rdbuf only when not null. > >> +this->setg((char_type *)m_ibuffer.data(), (char_type >> *)m_ibuffer.data(), (char_type *)m_ibuffer.data() + m_ibuffer.size()); >> +this->setp((char_type *)m_obuffer.data(), (char_type >> *)m_obuffer.data() + m_obuffer.size()); > This pattern over and over again. Needs to be put into separate member > function, otherwise some day someone will mix "i" and "o" and wonder why > doesn't it work. > > Also, I don't see that many calls to set(g|p) in that SO snipped, are > they all really needed? > There aren't really that many calls, we set both once in constructor, both once in sync and setg twice (differently) in underflow, because two cases: "The function may update gptr, egptr and eback pointers to define the location of newly loaded data (if any). On failure, the function ensures that either gptr() == nullptr or gptr() == egptr" from http://en.cppreference.com/w/cpp/io/basic_streambuf/underflow -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: http://public.kitware.com/mailman/listinfo/cmake-developers
Re: [cmake-developers] [PATCH v3 7/7] Add MinGW support for FStream
On 07/07/2016 03:33 AM, Dāvis Mosāns wrote: > 2016-07-07 1:22 GMT+03:00 Mike Gelfand: >>> @@ -92,19 +159,26 @@ namespace @KWSYS_NAMESPACE@ >>> [snip] >>>private: >>> internal_buffer_type* buf_; >>> +#if !defined(_MSC_VER) >>> +FILE *file_ = 0; >>> +#endif >>> }; >>> >>> template > >> In-place member initialization... As Brad wrote earlier, using C++11 in >> KWSys is not advised. >> > This was already there but only used for _MSC_VER >= 1400 > Maybe could just guard this with __cplusplus >= 201103L and not support > Unicode for older, it would be much easier... Apologies, don't quite get your response. Maybe the quote was too big; I surely meant to point to "FILE *file_ = 0;" line, not the template declaration or something else. Regards, Mike -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: http://public.kitware.com/mailman/listinfo/cmake-developers
Re: [cmake-developers] [PATCH v3 5/7] For consoles output on Windows use our own std::streambuf
On 07/07/2016 12:42 AM, clin...@elemtech.com wrote: > From what I remember, WriteConsoleW doesn't support redirection to a > file or pipe. I don't see an alternative in the patch for the case > where stdout is not attached to the console. The SO thread I pointed at actually contained a check for whether corresponding stream is linked to terminal or not. Replacing stream buffers unconditionally is not right. Regards, Mike -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: http://public.kitware.com/mailman/listinfo/cmake-developers
Re: [cmake-developers] [PATCH v3 7/7] Add MinGW support for FStream
On 07/06/2016 10:12 PM, Dāvis Mosāns wrote: > --- a/Source/kwsys/FStream.hxx.in > +++ b/Source/kwsys/FStream.hxx.in > @@ -14,33 +14,76 @@ > > #include <@KWSYS_NAMESPACE@/Encoding.hxx> > #include > +#if defined(_WIN32) && !defined(_MSC_VER) > +#include > +#endif > > namespace @KWSYS_NAMESPACE@ > { AFAIK, libc++ doesn't have this header, but only libstdc++ does. Not sure if Clang on Windows defines _MSC_VER (the one included with recent MSVS versions might, but standalone one is another story), might be better to check for HAVE_EXT_STDIO_FILEBUF_H macro instead (or in addition), to be defined externally on configuration phase. Same goes for a few checks down in the same file. > + inline const std::wstring getcmode(const std::ios_base::openmode mode) { Const on return value makes no sense. Some compilers may even warn about it. > @@ -56,7 +99,24 @@ namespace @KWSYS_NAMESPACE@ > } > 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)) > + mode = mode | std::ios_base::in; > +#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); > +this->set_rdbuf(buf_); > +success = true; > + } > +#endif > + if(!success) > { > this->setstate(std::ios_base::failbit); > } Looks odd that you check whether `buf_` is set before assigning, but don't check if `file_` is. Either one check is missing or another is redundant; the former is more probable since per STL documentation (e.g. http://www.cplusplus.com/reference/fstream/fstream/open/), "If the stream is already associated with a file (i.e., it is already open), calling this function fails." > @@ -75,7 +135,14 @@ namespace @KWSYS_NAMESPACE@ > } > void close() > { > - if(!buf_->close()) > + bool success = buf_->close() != 0; > +#if !defined(_MSC_VER) > + if (file_) { > +success = fclose(file_) == 0 ? success : false; > +file_ = 0; > + } > +#endif > + if(!success) > { > this->setstate(std::ios_base::failbit); > } `success` is overwritten inside newly added condition w/o checking previous value; looks odd as well. > @@ -92,19 +159,26 @@ namespace @KWSYS_NAMESPACE@ > [snip] >private: > internal_buffer_type* buf_; > +#if !defined(_MSC_VER) > +FILE *file_ = 0; > +#endif > }; > > template > In-place member initialization... As Brad wrote earlier, using C++11 in KWSys is not advised. > @@ -119,7 +193,24 @@ class basic_ofstream : public > std::basic_ostream>} >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)) > +mode = mode | std::ios_base::out; > +#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); > + this->set_rdbuf(buf_); > + success = true; > +} > +#endif > +if(!success) > { > this->setstate(std::ios_base::failbit); > } Mostly duplicate from istream, consider factoring out in some way. Regards, Mike -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: http://public.kitware.com/mailman/listinfo/cmake-developers
Re: [cmake-developers] [PATCH v3 5/7] For consoles output on Windows use our own std::streambuf
From what I remember, WriteConsoleW doesn't support redirection to a file or pipe. I don't see an alternative in the patch for the case where stdout is not attached to the console. Clint -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: http://public.kitware.com/mailman/listinfo/cmake-developers
Re: [cmake-developers] [PATCH v3 3/7] Use SystemTools::GetEnv and HasEnv functions
On 07/06/2016 10:12 PM, Dāvis Mosāns wrote: > --- a/Source/kwsys/SystemInformation.cxx > +++ b/Source/kwsys/SystemInformation.cxx > @@ -219,6 +219,8 @@ typedef struct rlimit ResourceLimitType; > # define USE_CPUID 0 > #endif > > +#include > + > #if USE_CPUID > > #define CPUID_AWARE_COMPILER IIUC, in kwsys/ subdirectory it should be `#include KWSYS_HEADER(SystemTools.hxx)` instead, with corresponding `#include "SystemTools.hxx.in"` inside `#if 0 ... #endif` block. Regards, Mike -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: http://public.kitware.com/mailman/listinfo/cmake-developers
[cmake-developers] [PATCH v3 4/7] For Windows encode process output to internally used encoding
Typically Windows applications (eg. MSVC compiler) use current console's codepage for output to pipes so we need to encode that to internally used encoding (KWSYS_ENCODING_DEFAULT_CODEPAGE). --- Source/kwsys/CMakeLists.txt | 2 ++ Source/kwsys/ProcessWin32.c | 25 - 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/Source/kwsys/CMakeLists.txt b/Source/kwsys/CMakeLists.txt index 39b03b3..65203c0 100644 --- a/Source/kwsys/CMakeLists.txt +++ b/Source/kwsys/CMakeLists.txt @@ -708,6 +708,8 @@ IF(KWSYS_USE_Process) IF(NOT UNIX) # Use the Windows implementation. SET(KWSYS_C_SRCS ${KWSYS_C_SRCS} ProcessWin32.c) +SET_PROPERTY(SOURCE ProcessWin32.c APPEND PROPERTY COMPILE_DEFINITIONS + KWSYS_ENCODING_DEFAULT_CODEPAGE=${KWSYS_ENCODING_DEFAULT_CODEPAGE}) ELSE() # Use the UNIX implementation. SET(KWSYS_C_SRCS ${KWSYS_C_SRCS} ProcessUNIX.c) diff --git a/Source/kwsys/ProcessWin32.c b/Source/kwsys/ProcessWin32.c index 2b93e69..153dc0b 100644 --- a/Source/kwsys/ProcessWin32.c +++ b/Source/kwsys/ProcessWin32.c @@ -181,7 +181,7 @@ struct kwsysProcessPipeData_s /* - Data managed per call to Execute - */ /* Buffer for data read in this pipe's thread. */ - char DataBuffer[KWSYSPE_PIPE_BUFFER_SIZE]; + char DataBuffer[KWSYSPE_PIPE_BUFFER_SIZE*2]; /* The length of the data stored in the buffer. */ DWORD DataLength; @@ -319,6 +319,9 @@ struct kwsysProcess_s /* Own handles for the child's ends of the pipes in the parent process. Used temporarily during process creation. */ HANDLE PipeChildStd[3]; + + /* Console's active codepage */ + UINT codepage; }; /*--*/ @@ -1626,6 +1629,21 @@ void kwsysProcessPipeThreadReadPipe(kwsysProcess* cp, kwsysProcessPipeData* td) KWSYSPE_DEBUG((stderr, "read closed %d\n", td->Index)); } +if (td->DataLength > 0) { + if (cp->codepage != KWSYS_ENCODING_DEFAULT_CODEPAGE) { +const int wlength = MultiByteToWideChar(cp->codepage, 0, td->DataBuffer, td->DataLength, NULL, 0); +wchar_t* wdata = malloc(wlength * sizeof(wchar_t)); +int r = MultiByteToWideChar(cp->codepage, 0, td->DataBuffer, td->DataLength, wdata, wlength); +if (r > 0) { + r = WideCharToMultiByte(KWSYS_ENCODING_DEFAULT_CODEPAGE, 0, wdata, wlength, td->DataBuffer, KWSYSPE_PIPE_BUFFER_SIZE * 2, NULL, NULL); + if (r > 0) { +td->DataLength = r; + } +} +free(wdata); + } +} + KWSYSPE_DEBUG((stderr, "read %d\n", td->Index)); /* Wait for our turn to be handled by the main thread. */ @@ -1761,6 +1779,11 @@ int kwsysProcessInitialize(kwsysProcess* cp) } } + cp->codepage = GetConsoleCP(); + if (!cp->codepage) { +cp->codepage = GetACP(); + } + return 1; } -- 2.9.0 -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: http://public.kitware.com/mailman/listinfo/cmake-developers
[cmake-developers] [PATCH v3 2/7] Deprecate const char* SystemTools::GetEnv function
On Windows this function returns environment variable encoded in ANSI codepage which might not match internally used encoding. --- Source/kwsys/SystemTools.hxx.in | 14 -- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Source/kwsys/SystemTools.hxx.in b/Source/kwsys/SystemTools.hxx.in index c9b18b7..51fb206 100644 --- a/Source/kwsys/SystemTools.hxx.in +++ b/Source/kwsys/SystemTools.hxx.in @@ -26,6 +26,16 @@ # include // For access permissions for use with access() #endif +#if __cplusplus >= 201402L +# define DEPRECATED [[deprecated]] +#elif defined(__GNUC__) +# define DEPRECATED __attribute__ ((deprecated)) +#elif defined(_MSC_VER) +# define DEPRECATED __declspec(deprecated) +#else +# define DEPRECATED +#endif + // Required for va_list #include // Required for FILE* @@ -839,8 +849,8 @@ public: /** * Read an environment variable */ - static const char* GetEnv(const char* key); - static const char* GetEnv(const std::string& key); + DEPRECATED static const char* GetEnv(const char* key); + DEPRECATED static const char* GetEnv(const std::string& key); static bool GetEnv(const char* key, std::string& result); static bool GetEnv(const std::string& key, std::string& result); static bool HasEnv(const char* key); -- 2.9.0 -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: http://public.kitware.com/mailman/listinfo/cmake-developers
[cmake-developers] [PATCH v3 6/7] Use Windows version of Directory::Load for MinGW too
Otherwise it would use POSIX functions which works only for ASCII paths. --- Source/kwsys/Directory.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/kwsys/Directory.cxx b/Source/kwsys/Directory.cxx index c549792..659c559 100644 --- a/Source/kwsys/Directory.cxx +++ b/Source/kwsys/Directory.cxx @@ -86,7 +86,7 @@ void Directory::Clear() // First microsoft compilers -#if defined(_MSC_VER) || defined(__WATCOMC__) +#if defined(_WIN32) || defined(__WATCOMC__) #include #include #include -- 2.9.0 -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: http://public.kitware.com/mailman/listinfo/cmake-developers
[cmake-developers] [PATCH v3 1/7] On Windows use correct encoding for SystemTools::GetEnv
On Windows getenv (and putenv) uses ANSI codepage so it needs to be encoded to internally used encoding (eg. UTF-8). Here we use _wgetenv (and _wputenv) instead and encode that. Also add SystemTools::HasEnv function. --- Source/kwsys/SystemTools.cxx| 56 ++--- Source/kwsys/SystemTools.hxx.in | 2 ++ 2 files changed, 49 insertions(+), 9 deletions(-) diff --git a/Source/kwsys/SystemTools.cxx b/Source/kwsys/SystemTools.cxx index c6e668d..2b1db4d 100644 --- a/Source/kwsys/SystemTools.cxx +++ b/Source/kwsys/SystemTools.cxx @@ -468,16 +468,21 @@ const char* SystemTools::GetEnv(const std::string& key) bool SystemTools::GetEnv(const char* key, std::string& result) { +#if defined(_WIN32) + const std::wstring wkey = Encoding::ToWide(key); + const wchar_t* wv = _wgetenv(wkey.c_str()); + if (wv) { +result = Encoding::ToNarrow(wv); +return true; + } +#else const char* v = getenv(key); - if(v) -{ + if (v) { result = v; return true; -} - else -{ -return false; -} + } +#endif + return false; } bool SystemTools::GetEnv(const std::string& key, std::string& result) @@ -485,6 +490,22 @@ bool SystemTools::GetEnv(const std::string& key, std::string& result) return SystemTools::GetEnv(key.c_str(), result); } +bool SystemTools::HasEnv(const char* key) +{ +#if defined(_WIN32) + const std::wstring wkey = Encoding::ToWide(key); + const wchar_t* v = _wgetenv(wkey.c_str()); +#else + const char* v = getenv(key); +#endif + return v != 0; +} + +bool SystemTools::HasEnv(const std::string& key) +{ + return SystemTools::HasEnv(key.c_str()); +} + // #if defined(__CYGWIN__) || defined(__GLIBC__) @@ -533,13 +554,25 @@ static int kwsysUnPutEnv(const std::string& env) # ifdef KWSYS_PUTENV_EMPTY buf[len] = '='; buf[len+1] = 0; - if(putenv(buf) < 0) +#if defined(_WIN32) + const std::wstring wbuf = Encoding::ToWide(buf); + const int r = _wputenv(wbuf.c_str()); +#else + const int r = putenv(buf); +#endif + if(r < 0) { err = errno; } # else buf[len] = 0; - if(putenv(buf) < 0 && errno != EINVAL) +#if defined(_WIN32) + const std::wstring wbuf = Encoding::ToWide(buf); + const int r = _wputenv(wbuf.c_str()); +#else + const int r = putenv(buf); +#endif + if(r < 0 && errno != EINVAL) { err = errno; } @@ -679,7 +712,12 @@ public: static_cast(oldEnv); char* newEnv = strdup(env); this->insert(newEnv); +#if defined(_WIN32) +const std::wstring wEnv = Encoding::ToWide(newEnv); +return _wputenv(wEnv.c_str()) == 0; +#else return putenv(newEnv) == 0; +#endif } bool UnPut(const char* env) { diff --git a/Source/kwsys/SystemTools.hxx.in b/Source/kwsys/SystemTools.hxx.in index bba5a5c..c9b18b7 100644 --- a/Source/kwsys/SystemTools.hxx.in +++ b/Source/kwsys/SystemTools.hxx.in @@ -843,6 +843,8 @@ public: static const char* GetEnv(const std::string& key); static bool GetEnv(const char* key, std::string& result); static bool GetEnv(const std::string& key, std::string& result); + static bool HasEnv(const char* key); + static bool HasEnv(const std::string& key); /** Put a string into the environment of the form var=value */ -- 2.9.0 -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: http://public.kitware.com/mailman/listinfo/cmake-developers
[cmake-developers] [PATCH v3 7/7] Add MinGW support for FStream
std::basic_filebuf::open(const wchar_t *) isn't part of C++ standard and it's only present for MSVC but it's not present in libstdc++ (MinGW) so we implement this functionality using GNU stdio_filebuf extension and _wfopen function. --- Source/kwsys/FStream.hxx.in | 117 +--- 1 file changed, 109 insertions(+), 8 deletions(-) diff --git a/Source/kwsys/FStream.hxx.in b/Source/kwsys/FStream.hxx.in index 681e4d8..f39f95a 100644 --- a/Source/kwsys/FStream.hxx.in +++ b/Source/kwsys/FStream.hxx.in @@ -14,33 +14,76 @@ #include <@KWSYS_NAMESPACE@/Encoding.hxx> #include +#if defined(_WIN32) && !defined(_MSC_VER) +#include +#endif namespace @KWSYS_NAMESPACE@ { -#if defined(_MSC_VER) && _MSC_VER >= 1400 +#if defined(_WIN32) # if defined(_NOEXCEPT) # define @KWSYS_NAMESPACE@_FStream_NOEXCEPT _NOEXCEPT # else # define @KWSYS_NAMESPACE@_FStream_NOEXCEPT # endif + +#if defined(_MSC_VER) + template class basic_filebuf : public std::basic_filebuf{ +# if _MSC_VER >= 1400 public: typedef std::basic_filebuf my_base_type; basic_filebuf *open(char const *s,std::ios_base::openmode mode) { +const std::wstring wstr = Encoding::ToWide(s); return static_cast ( - my_base_type::open(Encoding::ToWide(s).c_str(), mode) + my_base_type::open(wstr.c_str(), mode) ); } +# else +# pragma message("Warning! Opening non-ASCII files might fail!") +# endif + }; +#else + + inline const 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) { + cmode += L"w"; + plus = mode & std::ios_base::in ? true : false; +} else { + cmode += L"r"; +} +if (mode & std::ios_base::binary) { + cmode += L"b"; +} else { + cmode += L"t"; +} +if (plus) { + cmode += L"+"; +} +return cmode; + }; + +#endif + template > class basic_ifstream : public std::basic_istream { public: +#if defined(_MSC_VER) typedef basic_filebuf internal_buffer_type; +#else +typedef __gnu_cxx::stdio_filebuf internal_buffer_type; +#endif typedef std::basic_istream internal_stream_type; basic_ifstream() : internal_stream_type(new internal_buffer_type()) @@ -56,7 +99,24 @@ namespace @KWSYS_NAMESPACE@ } 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)) + mode = mode | std::ios_base::in; +#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); +this->set_rdbuf(buf_); +success = true; + } +#endif + if(!success) { this->setstate(std::ios_base::failbit); } @@ -75,7 +135,14 @@ namespace @KWSYS_NAMESPACE@ } void close() { - if(!buf_->close()) + bool success = buf_->close() != 0; +#if !defined(_MSC_VER) + if (file_) { +success = fclose(file_) == 0 ? success : false; +file_ = 0; + } +#endif + if(!success) { this->setstate(std::ios_base::failbit); } @@ -92,19 +159,26 @@ namespace @KWSYS_NAMESPACE@ ~basic_ifstream() @KWSYS_NAMESPACE@_FStream_NOEXCEPT { - buf_->close(); + close(); delete buf_; } private: internal_buffer_type* buf_; +#if !defined(_MSC_VER) +FILE *file_ = 0; +#endif }; template > class basic_ofstream : public std::basic_ostream { public: +#if defined(_MSC_VER) typedef basic_filebuf internal_buffer_type; +#else + typedef __gnu_cxx::stdio_filebuf internal_buffer_type; +#endif typedef std::basic_ostream internal_stream_type; basic_ofstream() : internal_stream_type(new internal_buffer_type()) @@ -119,7 +193,24 @@ class basic_ofstream : public std::basic_ostream } 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)) +mode = mode | std::ios_base::out; +#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 =
[cmake-developers] [PATCH v3 5/7] For consoles output on Windows use our own std::streambuf
Currently Microsoft's C++ libraries implementation of std::cout/cerr can't output Unicode characters but only ASCII or ANSI if locale is set so we implement and use our own ConsoleBuf which can output Unicode characters to console and it doesn't matter what locale or console's codepage is set. --- CMakeLists.txt | 1 + Source/cmakemain.cxx | 28 + Source/kwsys/CMakeLists.txt| 6 +- Source/kwsys/ConsoleBuf.hxx.in | 131 + bootstrap | 1 + 5 files changed, 166 insertions(+), 1 deletion(-) create mode 100644 Source/kwsys/ConsoleBuf.hxx.in diff --git a/CMakeLists.txt b/CMakeLists.txt index ae5990e..792b5a5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -258,6 +258,7 @@ macro (CMAKE_BUILD_UTILITIES) set(KWSYS_USE_MD5 1) set(KWSYS_USE_Process 1) set(KWSYS_USE_CommandLineArguments 1) + set(KWSYS_USE_ConsoleBuf 1) set(KWSYS_HEADER_ROOT ${CMake_BINARY_DIR}/Source) set(KWSYS_INSTALL_DOC_DIR "${CMAKE_DOC_DIR}") add_subdirectory(Source/kwsys) diff --git a/Source/cmakemain.cxx b/Source/cmakemain.cxx index 521a5bf..2002e4b 100644 --- a/Source/cmakemain.cxx +++ b/Source/cmakemain.cxx @@ -26,6 +26,7 @@ #include "cmake.h" #include "cmcmd.h" #include +#include #ifdef CMAKE_BUILD_WITH_CMAKE static const char* cmDocumentationName[][2] = { @@ -153,6 +154,23 @@ static void cmakemainProgressCallback(const char* m, float prog, int main(int ac, char const* const* av) { +#if defined(_WIN32) + // Replace streambuf so we can output Unicode to console + cmsys::ConsoleBuf *cbufio = CM_NULLPTR; + cmsys::ConsoleBuf *cbuferr = CM_NULLPTR; + std::streambuf *coutbuf = CM_NULLPTR; + std::streambuf *cerrbuf = CM_NULLPTR; + try { +cbufio = new cmsys::ConsoleBuf(); +coutbuf = std::cout.rdbuf(cbufio); +cbuferr = new cmsys::ConsoleBuf(true); +cerrbuf = std::cerr.rdbuf(cbuferr); + } catch (const std::system_error& ex) { +std::cerr << "Failed to create ConsoleBuf!" << std::endl + << "Error code: " << ex.code() << std::endl + << ex.what() << std::endl; + }; +#endif cmsys::Encoding::CommandLineArguments args = cmsys::Encoding::CommandLineArguments::Main(ac, av); ac = args.argc(); @@ -171,6 +189,16 @@ int main(int ac, char const* const* av) #ifdef CMAKE_BUILD_WITH_CMAKE cmDynamicLoader::FlushCache(); #endif +#if defined(_WIN32) + if (cbufio) { +delete cbufio; +std::cout.rdbuf(coutbuf); + } + if (cbuferr) { +delete cbuferr; +std::cerr.rdbuf(cerrbuf); + } +#endif return ret; } diff --git a/Source/kwsys/CMakeLists.txt b/Source/kwsys/CMakeLists.txt index 65203c0..33a97e6 100644 --- a/Source/kwsys/CMakeLists.txt +++ b/Source/kwsys/CMakeLists.txt @@ -123,6 +123,7 @@ IF(KWSYS_STANDALONE OR CMake_SOURCE_DIR) SET(KWSYS_USE_FStream 1) SET(KWSYS_USE_String 1) SET(KWSYS_USE_SystemInformation 1) + SET(KWSYS_USE_ConsoleBuf 1) ENDIF() # Enforce component dependencies. @@ -154,6 +155,9 @@ ENDIF() IF(KWSYS_USE_FStream) SET(KWSYS_USE_Encoding 1) ENDIF() +IF(KWSYS_USE_ConsoleBuf) + SET(KWSYS_USE_Encoding 1) +ENDIF() # Setup the large file support default. IF(KWSYS_LFS_DISABLE) @@ -668,7 +672,7 @@ SET(KWSYS_HXX_FILES Configure String # Add selected C++ classes. SET(cppclasses Directory DynamicLoader Encoding Glob RegularExpression SystemTools - CommandLineArguments IOStream FStream SystemInformation + CommandLineArguments IOStream FStream SystemInformation ConsoleBuf ) FOREACH(cpp ${cppclasses}) IF(KWSYS_USE_${cpp}) diff --git a/Source/kwsys/ConsoleBuf.hxx.in b/Source/kwsys/ConsoleBuf.hxx.in new file mode 100644 index 000..90adc03 --- /dev/null +++ b/Source/kwsys/ConsoleBuf.hxx.in @@ -0,0 +1,131 @@ +/* + KWSys - Kitware System Library + Copyright 2000-2016 Kitware, Inc., Insight Software Consortium + + Distributed under the OSI-approved BSD License (the "License"); + see accompanying file Copyright.txt for details. + + This software is distributed WITHOUT ANY WARRANTY; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the License for more information. +*/ +#ifndef @KWSYS_NAMESPACE@_ConsoleBuf_hxx +#define @KWSYS_NAMESPACE@_ConsoleBuf_hxx + +#include <@KWSYS_NAMESPACE@/Configure.hxx> +#include <@KWSYS_NAMESPACE@/Encoding.hxx> +#include + +namespace @KWSYS_NAMESPACE@ +{ +#if defined(_WIN32) + + template> + class @KWSYS_NAMESPACE@_EXPORT BasicConsoleBuf : public std::basic_streambuf{ +public: + typedef typename Traits::int_type int_type; + typedef typename Traits::char_type char_type; + + BasicConsoleBuf(const bool err = false) { +m_hInput = ::GetStdHandle(STD_INPUT_HANDLE); +if (m_hInput == INVALID_HANDLE_VALUE) { + throw
[cmake-developers] [PATCH v3 3/7] Use SystemTools::GetEnv and HasEnv functions
--- Source/CPack/cmCPackGenerator.cxx | 8 +++--- Source/CTest/cmCTestCoverageHandler.cxx | 12 - Source/CTest/cmCTestCurl.cxx| 27 ++-- Source/CTest/cmCTestMultiProcessHandler.cxx | 8 +++--- Source/cmBuildCommand.cxx | 25 +-- Source/cmCLocaleEnvironmentScope.cxx| 5 ++-- Source/cmCTest.cxx | 11 + Source/cmCommandArgumentParserHelper.cxx| 8 +++--- Source/cmConditionEvaluator.cxx | 2 +- Source/cmExportCommand.cxx | 5 ++-- Source/cmExtraEclipseCDT4Generator.cxx | 9 --- Source/cmFileCommand.cxx| 11 + Source/cmFindPackageCommand.cxx | 4 +-- Source/cmGlobalVisualStudio7Generator.cxx | 6 ++--- Source/cmMakefile.cxx | 5 +++- Source/cmNinjaTargetGenerator.cxx | 2 +- Source/cmQtAutoGenerators.cxx | 2 +- Source/cmSetCommand.cxx | 7 +++--- Source/cmState.cxx | 5 ++-- Source/cmSystemTools.cxx| 6 ++--- Source/cmTimestamp.cxx | 7 +++--- Source/cmUtils.hxx | 26 Source/cmake.cxx| 21 +--- Source/cmcmd.cxx| 16 +--- Source/kwsys/SystemInformation.cxx | 20 +++ Source/kwsys/SystemTools.cxx| 38 +++-- Source/kwsys/testSystemTools.cxx| 9 --- 27 files changed, 156 insertions(+), 149 deletions(-) create mode 100644 Source/cmUtils.hxx diff --git a/Source/CPack/cmCPackGenerator.cxx b/Source/CPack/cmCPackGenerator.cxx index df8bb0f..76609e1 100644 --- a/Source/CPack/cmCPackGenerator.cxx +++ b/Source/CPack/cmCPackGenerator.cxx @@ -1074,11 +1074,11 @@ const char* cmCPackGenerator::GetInstallPath() return this->InstallPath.c_str(); } #if defined(_WIN32) && !defined(__CYGWIN__) - const char* prgfiles = cmsys::SystemTools::GetEnv("ProgramFiles"); - const char* sysDrive = cmsys::SystemTools::GetEnv("SystemDrive"); - if (prgfiles) { + std::string prgfiles; + std::string sysDrive; + if (cmsys::SystemTools::GetEnv("ProgramFiles", prgfiles)) { this->InstallPath = prgfiles; - } else if (sysDrive) { + } else if (cmsys::SystemTools::GetEnv("SystemDrive", sysDrive)) { this->InstallPath = sysDrive; this->InstallPath += "/Program Files"; } else { diff --git a/Source/CTest/cmCTestCoverageHandler.cxx b/Source/CTest/cmCTestCoverageHandler.cxx index 7102533..9410a52 100644 --- a/Source/CTest/cmCTestCoverageHandler.cxx +++ b/Source/CTest/cmCTestCoverageHandler.cxx @@ -727,10 +727,7 @@ int cmCTestCoverageHandler::HandleCoberturaCoverage( // if it doesn't exist or is empty, assume the // binary directory is used. std::string coverageXMLFile; - const char* covDir = cmSystemTools::GetEnv("COBERTURADIR"); - if (covDir && strlen(covDir) != 0) { -coverageXMLFile = std::string(covDir); - } else { + if (!cmSystemTools::GetEnv("COBERTURADIR", coverageXMLFile) || coverageXMLFile.empty()) { coverageXMLFile = this->CTest->GetBinaryDir(); } // build the find file string with the directory from above @@ -791,7 +788,8 @@ struct cmCTestCoverageHandlerLocale { cmCTestCoverageHandlerLocale() { -if (const char* l = cmSystemTools::GetEnv("LC_ALL")) { +std::string l; +if (cmSystemTools::GetEnv("LC_ALL", l)) { lc_all = l; } if (lc_all != "C") { @@ -2121,8 +2119,8 @@ int cmCTestCoverageHandler::RunBullseyeSourceSummary( int cmCTestCoverageHandler::HandleBullseyeCoverage( cmCTestCoverageHandlerContainer* cont) { - const char* covfile = cmSystemTools::GetEnv("COVFILE"); - if (!covfile || strlen(covfile) == 0) { + std::string covfile; + if (!cmSystemTools::GetEnv("COVFILE", covfile) || covfile.empty()) { cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, " COVFILE environment variable not found, not running " " bullseye\n", diff --git a/Source/CTest/cmCTestCurl.cxx b/Source/CTest/cmCTestCurl.cxx index 6b8e5b5..b335e32 100644 --- a/Source/CTest/cmCTestCurl.cxx +++ b/Source/CTest/cmCTestCurl.cxx @@ -219,16 +219,18 @@ bool cmCTestCurl::HttpRequest(std::string const& url, void cmCTestCurl::SetProxyType() { - if (cmSystemTools::GetEnv("HTTP_PROXY")) { -this->HTTPProxy = cmSystemTools::GetEnv("HTTP_PROXY"); -if (cmSystemTools::GetEnv("HTTP_PROXY_PORT")) { + this->HTTPProxy = ""; + // this is the default + this->HTTPProxyType = CURLPROXY_HTTP; + this->HTTPProxyAuth = ""; + if (cmSystemTools::GetEnv("HTTP_PROXY", this->HTTPProxy)) { +std::string port; +if (cmSystemTools::GetEnv("HTTP_PROXY_PORT", port)) { this->HTTPProxy += ":"; - this->HTTPProxy += cmSystemTools::GetEnv("HTTP_PROXY_PORT"); +
Re: [cmake-developers] ExternalProject default downloaded file name
On 07/05/2016 05:14 PM, Ruslan Baratov wrote: > if it will work in most cases then why not? Most users will not > even notice this. Okay. The changes for the new pattern are now in `master` and are worthwhile regardless of having a default filename fallback because they help extract a more readable name in more cases. Please rebase your default filename fallback on that. Thanks, -Brad -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: http://public.kitware.com/mailman/listinfo/cmake-developers
Re: [cmake-developers] Green Hills MULTI Generator Recommendations
> I am interested in using CMake with Green Hills MULTI Great! > 2. Is there a way in a toolchain file or on the command line to specify the > directory where CMake should look for the compiler executables? Take a look at https://gitlab.kitware.com/cmake/cmake/blob/master/Source/cmGlobalGhsMultiGenerator.cxx#L50-82. It's hard coded to find gbuild and the Green Hills arm compiler. Ideally it would find an arbitrary compiler on the system, unless specified in the toolchain file. Probably, CMake should search with some priority like x86 and then the others. For a typical use case, you can take a look at the tests https://gitlab.kitware.com/cmake/cmake/blob/master/Tests/CMakeLists.txt#L2113-2139. There are two GHS specific test projects: Tests/GhsMulti and Tests/GhsMultiDuplicateSourceFilenames. These run nightly. Ideally, you should be able to run them without specifying anything arm related. The tests only confirms that it configures and compiles without errors. I use these as test projects, when developing. This message contains confidential information and is intended only for the recipient. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately if you have received this e-mail by mistake and delete this e-mail from your system. Finally, the recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email. -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: http://public.kitware.com/mailman/listinfo/cmake-developers