[cmake-developers] [PATCH] Improve FindGIF version detection (fix for issue #16196)

2016-07-12 Thread Ben Campbell

A fix for https://gitlab.kitware.com/cmake/cmake/issues/16196

This is my first attempt at doing anything with CMake, so I'd appreciate 
any feedback on my patch! In particular, the pairs of file()/string() 
commands seem a bit convoluted for extracting strings out of the header 
file - is there a more idiomatic approach?
Also, I'm a bit concerned that they are polluting scope by leaking out 
the GIFMAJ/GIFMIN/GIFREL working variables... how would I improve this?



---
 Modules/FindGIF.cmake | 20 ++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/Modules/FindGIF.cmake b/Modules/FindGIF.cmake
index 7bbb8cf..283a299 100644
--- a/Modules/FindGIF.cmake
+++ b/Modules/FindGIF.cmake
@@ -61,7 +61,8 @@ set(GIF_LIBRARIES ${GIF_LIBRARY})
 # to be always " Version 2.0, " in versions 3.x of giflib.
 # In version 4 the member UserData was added to GifFileType, so we 
check for this

 # one.
-# http://giflib.sourcearchive.com/documentation/4.1.4/files.html
+# Versions after 4.1.6 define GIFLIB_MAJOR, GIFLIB_MINOR, and 
GIFLIB_RELEASE

+# see http://giflib.sourceforge.net/gif_lib.html#compatibility
 if(GIF_INCLUDE_DIR)
   include(${CMAKE_CURRENT_LIST_DIR}/CMakePushCheckState.cmake)
   include(${CMAKE_CURRENT_LIST_DIR}/CheckStructHasMember.cmake)
@@ -71,7 +72,22 @@ if(GIF_INCLUDE_DIR)
   set(CMAKE_REQUIRED_INCLUDES "${GIF_INCLUDE_DIR}")
   CHECK_STRUCT_HAS_MEMBER(GifFileType UserData gif_lib.h 
GIF_GifFileType_UserData )

   if(GIF_GifFileType_UserData)
-set(GIF_VERSION 4)
+# OK. So we're version 4 or higher. Check for specific version defines
+file(STRINGS ${GIF_INCLUDE_DIR}/gif_lib.h GIFMAJ REGEX "^[ 
\t]*#define[ \t]+GIFLIB_MAJOR")
+string(REGEX REPLACE "^.*GIFLIB_MAJOR ([0-9]+).*$" "\\1" GIFMAJ 
${GIFMAJ})

+# extract minor version
+file(STRINGS ${GIF_INCLUDE_DIR}/gif_lib.h GIFMIN REGEX "^[ 
\t]*#define[ \t]+GIFLIB_MINOR")
+string(REGEX REPLACE "^.*GIFLIB_MINOR ([0-9]+).*$" "\\1" GIFMIN 
${GIFMIN})

+# point release
+file(STRINGS ${GIF_INCLUDE_DIR}/gif_lib.h GIFREL REGEX "^[ 
\t]*#define[ \t]+GIFLIB_RELEASE")
+string(REGEX REPLACE "^.*GIFLIB_RELEASE ([0-9]+).*$" "\\1" GIFREL 
${GIFREL})

+if(GIFMAJ)
+  # yay - got exact version info
+  set(GIF_VERSION ${GIFMAJ}.${GIFMIN}.${GIFREL})
+else(GIFMAJ)
+  # couldn't find the defines - assume version 4
+  set(GIF_VERSION 4)
+endif(GIFMAJ)
   endif()
   CMAKE_POP_CHECK_STATE()
 endif()
--
2.7.4
--

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 v4] Add MinGW support for FStream

2016-07-12 Thread Dāvis Mosāns
std::basic_filebuf::open(const wchar_t *) isn't part of C++ standard
and it's only present for MSVC but it isn't present in libstdc++ (MinGW)
so we implement this functionality using GNU libstdc++ stdio_filebuf
extension and _wfopen function.
---
 CMakeLists.txt  |  14 +++
 Source/kwsys/CMakeLists.txt |   8 ++
 Source/kwsys/FStream.hxx.in | 235 +++-
 3 files changed, 187 insertions(+), 70 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 792b5a5..b53c6b1 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -273,6 +273,20 @@ macro (CMAKE_BUILD_UTILITIES)
 CMAKE_SET_TARGET_FOLDER(${KWSYS_NAMESPACE}TestSharedForward 
"${kwsys_folder}")
   endif()
 
+  IF(KWSYS_USE_SystemTools)
+SET(KWSYS_USE_Directory 1)
+SET(KWSYS_USE_FStream 1)
+SET(KWSYS_USE_Encoding 1)
+  ENDIF()
+
+  IF(KWSYS_USE_FStream)
+INCLUDE(CheckIncludeFileCXX)
+CHECK_INCLUDE_FILE_CXX(ext/stdio_filebuf.h HAVE_EXT_STDIO_FILEBUF_H)
+IF(HAVE_EXT_STDIO_FILEBUF_H)
+  add_definitions(-DHAVE_EXT_STDIO_FILEBUF_H=1)
+ENDIF()
+  ENDIF()
+
   #-
   # Setup third-party libraries.
   # Everything in the tree should be able to include files from the
diff --git a/Source/kwsys/CMakeLists.txt b/Source/kwsys/CMakeLists.txt
index 33a97e6..02ba2db 100644
--- a/Source/kwsys/CMakeLists.txt
+++ b/Source/kwsys/CMakeLists.txt
@@ -636,6 +636,14 @@ IF(KWSYS_USE_SystemInformation)
   ENDIF()
 ENDIF()
 
+IF(KWSYS_USE_FStream)
+  INCLUDE(CheckIncludeFileCXX)
+  CHECK_INCLUDE_FILE_CXX(ext/stdio_filebuf.h HAVE_EXT_STDIO_FILEBUF_H)
+  IF(HAVE_EXT_STDIO_FILEBUF_H)
+add_definitions(-DHAVE_EXT_STDIO_FILEBUF_H=1)
+  ENDIF()
+ENDIF()
+
 #-
 # Choose a directory for the generated headers.
 IF(NOT KWSYS_HEADER_ROOT)
diff --git a/Source/kwsys/FStream.hxx.in b/Source/kwsys/FStream.hxx.in
index 681e4d8..eb911c9 100644
--- a/Source/kwsys/FStream.hxx.in
+++ b/Source/kwsys/FStream.hxx.in
@@ -14,152 +14,247 @@
 
 #include <@KWSYS_NAMESPACE@/Encoding.hxx>
 #include 
+#if defined(_WIN32)
+#  if !defined(_MSC_VER) && defined(HAVE_EXT_STDIO_FILEBUF_H)
+#include 
+#  elif !defined(_MSC_VER) || _MSC_VER < 1400
+#pragma message("WARNING: Opening non-ASCII files might fail!")
+#  endif
+#endif
 
 namespace @KWSYS_NAMESPACE@
 {
-#if defined(_MSC_VER) && _MSC_VER >= 1400
+#if defined(_WIN32) && (defined(_MSC_VER) || defined(HAVE_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
   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)
   );
   }
+# 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 >
-  class basic_ifstream : public std::basic_istream
+  class basic_efilebuf
   {
+public:
+#if defined(_MSC_VER)
+  typedef basic_filebuf internal_buffer_type;
+#else
+  typedef __gnu_cxx::stdio_filebuf 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
+  

[cmake-developers] [PATCH] CMake installation improvements

2016-07-12 Thread Konstantin Podsvirov
Hello Brad,

please apply my changes.

--
Regards,
Konstantin Podsvirov
From 56137a0f7096bae99eeb45ca83567a5ee87d4cee Mon Sep 17 00:00:00 2001
From: Konstantin Podsvirov 
Date: Wed, 13 Jul 2016 00:10:28 +0300
Subject: [PATCH 1/3] CMake: install COMPONENT cmcldeps

Added in Tools group with IFW installer
---
 CMakeCPack.cmake   |  3 +++
 CMakeCPackOptions.cmake.in | 10 +-
 Source/CMakeLists.txt  | 18 +++---
 3 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/CMakeCPack.cmake b/CMakeCPack.cmake
index 8879cb9..60011ae 100644
--- a/CMakeCPack.cmake
+++ b/CMakeCPack.cmake
@@ -70,6 +70,9 @@ if(EXISTS "${CMAKE_ROOT}/Modules/CPack.cmake")
   # Components
   if(CMake_INSTALL_COMPONENTS)
 set(_CPACK_IFW_COMPONENTS_ALL cmake ctest cpack)
+if(WIN32 AND NOT CYGWIN)
+list(APPEND _CPACK_IFW_COMPONENTS_ALL cmcldeps)
+endif()
 if(APPLE)
   list(APPEND _CPACK_IFW_COMPONENTS_ALL cmakexbuild)
 endif()
diff --git a/CMakeCPackOptions.cmake.in b/CMakeCPackOptions.cmake.in
index 59ae224..1d61613 100644
--- a/CMakeCPackOptions.cmake.in
+++ b/CMakeCPackOptions.cmake.in
@@ -102,13 +102,21 @@ if(CPACK_GENERATOR MATCHES "IFW")
   set(CPACK_IFW_COMPONENT_CPACK_PRIORITY 87)
   set(CPACK_IFW_COMPONENT_CPACK_VERSION "@_CPACK_IFW_PACKAGE_VERSION@")
 
+  set(CPACK_COMPONENT_CMCLDEPS_DISPLAY_NAME "cmcldeps")
+  set(CPACK_COMPONENT_CMCLDEPS_DESCRIPTION
+"The \"cmcldeps\" executable is wrapper around \"cl\" program")
+  set(CPACK_COMPONENT_CMCLDEPS_GROUP Tools)
+  set(CPACK_IFW_COMPONENT_CMCLDEPS_NAME "CMClDeps")
+  set(CPACK_IFW_COMPONENT_CMCLDEPS_PRIORITY 86)
+  set(CPACK_IFW_COMPONENT_CMCLDEPS_VERSION "@_CPACK_IFW_PACKAGE_VERSION@")
+
   set(CPACK_COMPONENT_CMAKEXBUILD_DISPLAY_NAME "cmakexbuild")
   set(CPACK_COMPONENT_CMAKEXBUILD_DESCRIPTION
 "The \"cmakexbuild\" executable is a wrapper program for \"xcodebuild\"")
   set(CPACK_COMPONENT_CMAKEXBUILD_REQUIRED TRUE)
   set(CPACK_COMPONENT_CMAKEXBUILD_GROUP Tools)
   set(CPACK_IFW_COMPONENT_CMAKEXBUILD_NAME "CMakeXBuild")
-  set(CPACK_IFW_COMPONENT_CMAKEXBUILD_PRIORITY 86)
+  set(CPACK_IFW_COMPONENT_CMAKEXBUILD_PRIORITY 85)
   set(CPACK_IFW_COMPONENT_CMAKEXBUILD_VERSION "@_CPACK_IFW_PACKAGE_VERSION@")
 
   # Dialogs
diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt
index d49ebbb..a790994 100644
--- a/Source/CMakeLists.txt
+++ b/Source/CMakeLists.txt
@@ -530,11 +530,14 @@ set(SRCS ${SRCS}
   cmNinjaUtilityTargetGenerator.h
   )
 
+# Temporary variable for tools targets
+set(_tools)
+
 if(WIN32 AND NOT CYGWIN)
   set_source_files_properties(cmcldeps.cxx PROPERTIES COMPILE_DEFINITIONS _WIN32_WINNT=0x0501)
   add_executable(cmcldeps cmcldeps.cxx ${MANIFEST_FILE})
+  list(APPEND _tools cmcldeps)
   target_link_libraries(cmcldeps CMakeLib)
-  install(TARGETS cmcldeps DESTINATION bin)
 endif()
 
 foreach(v CURL_CA_BUNDLE CURL_CA_PATH)
@@ -746,6 +749,7 @@ endif()
 
 if(APPLE)
   add_executable(cmakexbuild cmakexbuild.cxx)
+  list(APPEND _tools cmakexbuild)
   target_link_libraries(cmakexbuild CMakeLib)
   add_executable(OSXScriptLauncher
 CPack/OSXScriptLauncher.cxx)
@@ -755,14 +759,17 @@ endif()
 
 # Build CMake executable
 add_executable(cmake cmakemain.cxx cmcmd.cxx cmcmd.h ${MANIFEST_FILE})
+list(APPEND _tools cmake)
 target_link_libraries(cmake CMakeLib)
 
 # Build CTest executable
 add_executable(ctest ctest.cxx ${MANIFEST_FILE})
+list(APPEND _tools ctest)
 target_link_libraries(ctest CTestLib)
 
 # Build CPack executable
 add_executable(cpack CPack/cpack.cxx ${MANIFEST_FILE})
+list(APPEND _tools cpack)
 target_link_libraries(cpack CPackLib)
 
 # Curses GUI
@@ -781,15 +788,12 @@ include (${CMake_SOURCE_DIR}/Source/LocalUserOptions.cmake OPTIONAL)
 
 # Install tools
 
-set(_tools cmake ctest cpack)
-
-if(APPLE)
-  list(APPEND _tools cmakexbuild)
-endif()
-
 foreach(_tool ${_tools})
   CMake_OPTIONAL_COMPONENT(${_tool})
   install(TARGETS ${_tool} DESTINATION ${CMAKE_BIN_DIR} ${COMPONENT})
 endforeach()
 
 install(FILES cmCPluginAPI.h DESTINATION ${CMAKE_DATA_DIR}/include)
+
+# Unset temporary variables
+unset(_tools)
-- 
2.8.3.windows.1

From bfa20dc8074c0c70b94ebbc8b150df001590088e Mon Sep 17 00:00:00 2001
From: Konstantin Podsvirov 
Date: Wed, 13 Jul 2016 00:50:10 +0300
Subject: [PATCH 2/3] QtIFW: process USE_LGPL when CMake_INSTALL_COMPONENTS

---
 CMakeCPack.cmake | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/CMakeCPack.cmake b/CMakeCPack.cmake
index 60011ae..34bb6bb 100644
--- a/CMakeCPack.cmake
+++ b/CMakeCPack.cmake
@@ -90,8 +90,10 @@ if(EXISTS "${CMAKE_ROOT}/Modules/CPack.cmake")
 endif()
 if(BUILD_QtDialog)
   list(APPEND _CPACK_IFW_COMPONENTS_ALL cmake-gui)
-  set(_CPACK_IFW_COMPONENT_CMAKE-GUI_LICENSES "set(CPACK_IFW_COMPONENT_CMAKE-GUI_LICENSES
-\"LGPLv2.1\" \"${CMake_SOURCE_DIR}/Licenses/LGPLv2.1.txt\")")
+  if(USE_LGPL)
+set(_CPACK_IFW_COMPONENT_CMAKE-GUI_LICENSES 

Re: [cmake-developers] CpackRPM doesn't escape filenames

2016-07-12 Thread Harry Mallon
Hi Brad,

A simple version, which covers the main test case is shown here. The %files 
list in the auto spec file shows "%dist.txt" when I think it should show 
"%%dist.txt". Even when I manually changed it to %% it didn't work for me 
though. Maybe someone who knows RPM better would be able to tell me why. Other 
cases could also be tested by adding more files (for those who have any of 
?|*.\'" in their file names).

--

CMakeLists.txt:

cmake_minimum_required(VERSION 3.5)

set(CPACK_GENERATOR "RPM")

project(Test)
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/%dist.txt" "")

install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/%dist.txt"
DESTINATION foo
)

include(CPack)



Harry Mallon
CODEX | Software Engineer
60 Poland Street | London | England | W1F 7NT
E ha...@codexdigital.com | T +44 203 7000 989
> On 11 Jul 2016, at 19:10, Brad King  wrote:
>
> On 07/11/2016 11:32 AM, Harry Mallon wrote:
>> When using CPackRPM my filenames in auto generated RPM SPEC
>> look like "/usr/share/foo/bar10%.xml" when the "%" symbol
>> (which is in the filename should be escaped to "%%".
>
> Thanks.  Please open an issue here:
>
> https://gitlab.kitware.com/cmake/cmake/issues
>
> Ideally please include a http://sscce.org/ showing how to
> reproduce the problem.  Then perhaps it can be adapted as
> a test case.
>
> 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] QtAutoGenerators output in Ninja

2016-07-12 Thread Kevin Funk
On Tuesday, July 12, 2016 10:43:52 AM CEST Daniel Pfeifer wrote:
> Hi,
> 
> CMake currently puts messages like "Generating moc source" into the
> buildlog. This conflicts with the convention "no output == all good".

+1

> The messages blend nicely in the colorful output of Unix Makefiles,
> but when using the Ninja generator, they create quite some noise.

Indeed.

> How can this be improved?
> * remove the messages (no output == all good)
> * add an option to silence them
> * add an option to show them and hide them per default
> * ...

While it probably still makes sense to have it for Unix Makefiles; can we just 
disable this particular output in case Ninja files are used?

After all it's just a call to `cmake -E cmake_autogen`, right? Can we 
parameterize this call?

Just my 2 ct.

Cheers,
Kevin

> Cheers, Daniel


-- 
Kevin Funk | kf...@kde.org | http://kfunk.org

signature.asc
Description: This is a digitally signed message part.
-- 

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] QtAutoGenerators output in Ninja

2016-07-12 Thread Daniel Pfeifer
Hi,

CMake currently puts messages like "Generating moc source" into the
buildlog. This conflicts with the convention "no output == all good".
The messages blend nicely in the colorful output of Unix Makefiles,
but when using the Ninja generator, they create quite some noise.

How can this be improved?
* remove the messages (no output == all good)
* add an option to silence them
* add an option to show them and hide them per default
* ...

Cheers, Daniel
-- 

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