changeset 35:7c6cf09d838b

toolchains for MinGW-w64
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 30 Jun 2015 11:55:34 +0200
parents 86299731dc4e
children dbc1c9ca0030
files Orthanc/Core/Toolbox.cpp Orthanc/Core/Toolbox.h Orthanc/Resources/MinGW-W64-Toolchain32.cmake Orthanc/Resources/MinGW-W64-Toolchain64.cmake Orthanc/Resources/MinGWToolchain.cmake Resources/BuildInstructions.txt Resources/MinGWToolchain.cmake Resources/SyncOrthancFolder.py
diffstat 8 files changed, 175 insertions(+), 44 deletions(-) [+]
line wrap: on
line diff
--- a/Orthanc/Core/Toolbox.cpp	Fri Jun 26 16:37:42 2015 +0200
+++ b/Orthanc/Core/Toolbox.cpp	Tue Jun 30 11:55:34 2015 +0200
@@ -685,7 +685,43 @@
 
   bool Toolbox::IsSHA1(const std::string& str)
   {
-    if (str.size() != 44)
+    if (str.size() == 0)
+    {
+      return false;
+    }
+
+    const char* start = &str[0];
+    const char* end = start + str.size();
+
+    // Trim the beginning of the string
+    while (start < end)
+    {
+      if (*start == '\0' ||
+          isspace(*start))
+      {
+        start++;
+      }
+      else
+      {
+        break;
+      }
+    }
+
+    // Trim the trailing of the string
+    while (start < end)
+    {
+      if (*(end - 1) == '\0' ||
+          isspace(*(end - 1)))
+      {
+        end--;
+      }
+      else
+      {
+        break;
+      }
+    }
+
+    if (end - start != 44)
     {
       return false;
     }
@@ -697,12 +733,12 @@
           i == 26 ||
           i == 35)
       {
-        if (str[i] != '-')
+        if (start[i] != '-')
           return false;
       }
       else
       {
-        if (!isalnum(str[i]))
+        if (!isalnum(start[i]))
           return false;
       }
     }
@@ -1137,5 +1173,80 @@
 
     return true;
   }
+
+
+  void Toolbox::CopyJsonWithoutComments(Json::Value& target,
+                                        const Json::Value& source)
+  {
+    switch (source.type())
+    {
+      case Json::nullValue:
+        target = Json::nullValue;
+        break;
+
+      case Json::intValue:
+        target = source.asInt64();
+        break;
+
+      case Json::uintValue:
+        target = source.asUInt64();
+        break;
+
+      case Json::realValue:
+        target = source.asDouble();
+        break;
+
+      case Json::stringValue:
+        target = source.asString();
+        break;
+
+      case Json::booleanValue:
+        target = source.asBool();
+        break;
+
+      case Json::arrayValue:
+      {
+        target = Json::arrayValue;
+        for (Json::Value::ArrayIndex i = 0; i < source.size(); i++)
+        {
+          Json::Value& item = target.append(Json::nullValue);
+          CopyJsonWithoutComments(item, source[i]);
+        }
+
+        break;
+      }
+
+      case Json::objectValue:
+      {
+        target = Json::objectValue;
+        Json::Value::Members members = source.getMemberNames();
+        for (Json::Value::ArrayIndex i = 0; i < members.size(); i++)
+        {
+          const std::string item = members[i];
+          CopyJsonWithoutComments(target[item], source[item]);
+        }
+
+        break;
+      }
+
+      default:
+        break;
+    }
+  }
+
+
+  bool Toolbox::StartsWith(const std::string& str,
+                           const std::string& prefix)
+  {
+    if (str.size() < prefix.size())
+    {
+      return false;
+    }
+    else
+    {
+      return str.compare(0, prefix.size(), prefix) == 0;
+    }
+  }
+
 }
 
--- a/Orthanc/Core/Toolbox.h	Fri Jun 26 16:37:42 2015 +0200
+++ b/Orthanc/Core/Toolbox.h	Tue Jun 30 11:55:34 2015 +0200
@@ -37,10 +37,7 @@
 #include <stdint.h>
 #include <vector>
 #include <string>
-
-#if ORTHANC_PUGIXML_ENABLED == 1
 #include <json/json.h>
-#endif
 
 namespace Orthanc
 {
@@ -160,5 +157,11 @@
                               const std::vector<std::string>& arguments);
 
     bool IsInteger(const std::string& str);
+
+    void CopyJsonWithoutComments(Json::Value& target,
+                                 const Json::Value& source);
+
+    bool StartsWith(const std::string& str,
+                    const std::string& prefix);
   }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Orthanc/Resources/MinGW-W64-Toolchain32.cmake	Tue Jun 30 11:55:34 2015 +0200
@@ -0,0 +1,17 @@
+# the name of the target operating system
+set(CMAKE_SYSTEM_NAME Windows)
+
+# which compilers to use for C and C++
+set(CMAKE_C_COMPILER i686-w64-mingw32-gcc)
+set(CMAKE_CXX_COMPILER i686-w64-mingw32-g++)
+set(CMAKE_RC_COMPILER i686-w64-mingw32-windres)
+
+# here is the target environment located
+set(CMAKE_FIND_ROOT_PATH /usr/i686-w64-mingw32)
+
+# adjust the default behaviour of the FIND_XXX() commands:
+# search headers and libraries in the target environment, search 
+# programs in the host environment
+set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
+set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
+set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Orthanc/Resources/MinGW-W64-Toolchain64.cmake	Tue Jun 30 11:55:34 2015 +0200
@@ -0,0 +1,17 @@
+# the name of the target operating system
+set(CMAKE_SYSTEM_NAME Windows)
+
+# which compilers to use for C and C++
+set(CMAKE_C_COMPILER x86_64-w64-mingw32-gcc)
+set(CMAKE_CXX_COMPILER x86_64-w64-mingw32-g++)
+set(CMAKE_RC_COMPILER x86_64-w64-mingw32-windres)
+
+# here is the target environment located
+set(CMAKE_FIND_ROOT_PATH /usr/i686-w64-mingw32)
+
+# adjust the default behaviour of the FIND_XXX() commands:
+# search headers and libraries in the target environment, search 
+# programs in the host environment
+set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
+set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
+set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Orthanc/Resources/MinGWToolchain.cmake	Tue Jun 30 11:55:34 2015 +0200
@@ -0,0 +1,17 @@
+# the name of the target operating system
+set(CMAKE_SYSTEM_NAME Windows)
+
+# which compilers to use for C and C++
+set(CMAKE_C_COMPILER i586-mingw32msvc-gcc)
+set(CMAKE_CXX_COMPILER i586-mingw32msvc-g++)
+set(CMAKE_RC_COMPILER i586-mingw32msvc-windres)
+
+# here is the target environment located
+set(CMAKE_FIND_ROOT_PATH /usr/i586-mingw32msvc)
+
+# adjust the default behaviour of the FIND_XXX() commands:
+# search headers and libraries in the target environment, search 
+# programs in the host environment
+set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
+set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
+set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
--- a/Resources/BuildInstructions.txt	Fri Jun 26 16:37:42 2015 +0200
+++ b/Resources/BuildInstructions.txt	Tue Jun 30 11:55:34 2015 +0200
@@ -25,5 +25,5 @@
 
 # mkdir Build
 # cd Build
-# cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=../Resources/MinGWToolchain.cmake
+# cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=../Orthanc/Resources/MinGWToolchain.cmake
 # make
--- a/Resources/MinGWToolchain.cmake	Fri Jun 26 16:37:42 2015 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,37 +0,0 @@
-# Orthanc - A Lightweight, RESTful DICOM Store
-# Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics
-# Department, University Hospital of Liege, Belgium
-#
-# This program is free software: you can redistribute it and/or
-# modify it under the terms of the GNU Affero General Public License
-# as published by the Free Software Foundation, either version 3 of
-# the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Affero General Public License for more details.
-# 
-# You should have received a copy of the GNU Affero General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-
-# http://www.vtk.org/Wiki/CmakeMingw
-
-# the name of the target operating system
-set(CMAKE_SYSTEM_NAME Windows)
-
-# which compilers to use for C and C++
-set(CMAKE_C_COMPILER i586-mingw32msvc-gcc)
-set(CMAKE_CXX_COMPILER i586-mingw32msvc-g++)
-set(CMAKE_RC_COMPILER i586-mingw32msvc-windres)
-
-# here is the target environment located
-set(CMAKE_FIND_ROOT_PATH /usr/i586-mingw32msvc)
-
-# adjust the default behaviour of the FIND_XXX() commands:
-# search headers and libraries in the target environment, search 
-# programs in the host environment
-set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
-set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
-set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
--- a/Resources/SyncOrthancFolder.py	Fri Jun 26 16:37:42 2015 +0200
+++ b/Resources/SyncOrthancFolder.py	Tue Jun 30 11:55:34 2015 +0200
@@ -57,6 +57,9 @@
     'Core/Uuid.cpp',
     'Core/Uuid.h',
     'Resources/EmbedResources.py',
+    'Resources/MinGWToolchain.cmake',
+    'Resources/MinGW-W64-Toolchain32.cmake',
+    'Resources/MinGW-W64-Toolchain64.cmake',
     'Resources/CMake/AutoGeneratedCode.cmake',
     'Resources/CMake/BoostConfiguration.cmake',
     'Resources/CMake/Compiler.cmake',