changeset 4030:100fbe970762

DANGEROUS commit: removing HAS_EMBEDDED_RESOURCES
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 09 Jun 2020 20:50:20 +0200
parents 156fece692e3
children e3b3af80732d
files CMakeLists.txt Core/DicomParsing/FromDcmtkBridge.cpp Core/HttpServer/EmbeddedResourceHttpHandler.h Core/Images/Font.h Core/Images/FontRegistry.h Core/Lua/LuaContext.h Core/OrthancFramework.cpp Core/Toolbox.cpp OrthancServer/Database/SQLiteDatabaseWrapper.cpp OrthancServer/LuaScripting.cpp OrthancServer/OrthancConfiguration.h OrthancServer/ServerContext.cpp OrthancServer/ServerIndex.cpp Resources/CMake/AutoGeneratedCode.cmake Resources/CMake/OrthancFrameworkConfiguration.cmake Resources/CMake/OrthancFrameworkParameters.cmake Resources/EmbedResources.py
diffstat 17 files changed, 69 insertions(+), 70 deletions(-) [+]
line wrap: on
line diff
--- a/CMakeLists.txt	Tue Jun 09 16:40:43 2020 +0200
+++ b/CMakeLists.txt	Tue Jun 09 20:50:20 2020 +0200
@@ -26,8 +26,6 @@
 set(ENABLE_WEB_SERVER ON)
 set(ENABLE_ZLIB ON)
 
-set(HAS_EMBEDDED_RESOURCES ON)
-
 
 #####################################################################
 ## CMake parameters tunable at the command line to configure the
@@ -35,6 +33,7 @@
 #####################################################################
 
 # Parameters of the build
+set(STANDALONE_BUILD ON CACHE BOOL "Standalone build (all the resources are embedded, necessary for releases)")
 SET(BUILD_MODALITY_WORKLISTS ON CACHE BOOL "Whether to build the sample plugin to serve modality worklists")
 SET(BUILD_RECOVER_COMPRESSED_FILE ON CACHE BOOL "Whether to build the companion tool to recover files compressed using Orthanc")
 SET(BUILD_SERVE_FOLDERS ON CACHE BOOL "Whether to build the ServeFolders plugin")
@@ -196,8 +195,12 @@
 
 if (STANDALONE_BUILD)
   # We embed all the resources in the binaries for standalone builds
-  add_definitions(-DORTHANC_STANDALONE=1)
+  add_definitions(
+    -DORTHANC_HAS_EMBEDDED_RESOURCES=1
+    -DORTHANC_STANDALONE=1
+    )
   EmbedResources(
+    --target=OrthancEmbeddedResources
     ${ORTHANC_EMBEDDED_FILES}
     ORTHANC_EXPLORER ${CMAKE_CURRENT_SOURCE_DIR}/OrthancExplorer
     ${DCMTK_DICTIONARIES}
@@ -205,10 +208,12 @@
     )
 else()
   add_definitions(
+    -DORTHANC_HAS_EMBEDDED_RESOURCES=1
+    -DORTHANC_PATH=\"${CMAKE_SOURCE_DIR}\"
     -DORTHANC_STANDALONE=0
-    -DORTHANC_PATH=\"${CMAKE_SOURCE_DIR}\"
     )
   EmbedResources(
+    --target=OrthancEmbeddedResources
     ${ORTHANC_EMBEDDED_FILES}
     ${LIBICU_RESOURCES}
     )
--- a/Core/DicomParsing/FromDcmtkBridge.cpp	Tue Jun 09 16:40:43 2020 +0200
+++ b/Core/DicomParsing/FromDcmtkBridge.cpp	Tue Jun 09 20:50:20 2020 +0200
@@ -103,7 +103,7 @@
 #endif
 
 #if DCMTK_USE_EMBEDDED_DICTIONARIES == 1
-#  include <EmbeddedResources.h>
+#  include <OrthancEmbeddedResources.h>
 #endif
 
 #if ORTHANC_ENABLE_DCMTK_JPEG == 1
@@ -171,7 +171,7 @@
 
   namespace
   {
-    class DictionaryLocker
+    class DictionaryLocker : public boost::noncopyable
     {
     private:
       DcmDataDictionary& dictionary_;
--- a/Core/HttpServer/EmbeddedResourceHttpHandler.h	Tue Jun 09 16:40:43 2020 +0200
+++ b/Core/HttpServer/EmbeddedResourceHttpHandler.h	Tue Jun 09 20:50:20 2020 +0200
@@ -35,7 +35,7 @@
 
 #include "IHttpHandler.h"
 
-#include <EmbeddedResources.h>   // Autogenerated file
+#include <OrthancEmbeddedResources.h>   // Autogenerated file
 #include <boost/shared_ptr.hpp>
 
 namespace Orthanc
--- a/Core/Images/Font.h	Tue Jun 09 16:40:43 2020 +0200
+++ b/Core/Images/Font.h	Tue Jun 09 20:50:20 2020 +0200
@@ -41,7 +41,7 @@
 #endif
 
 #if ORTHANC_HAS_EMBEDDED_RESOURCES == 1
-#  include <EmbeddedResources.h>   // Autogenerated file
+#  include <OrthancEmbeddedResources.h>   // Autogenerated file
 #endif
 
 #include "ImageAccessor.h"
--- a/Core/Images/FontRegistry.h	Tue Jun 09 16:40:43 2020 +0200
+++ b/Core/Images/FontRegistry.h	Tue Jun 09 20:50:20 2020 +0200
@@ -40,7 +40,7 @@
 #endif
 
 #if ORTHANC_HAS_EMBEDDED_RESOURCES == 1
-#  include <EmbeddedResources.h>   // Autogenerated file
+#  include <OrthancEmbeddedResources.h>   // Autogenerated file
 #endif
 
 namespace Orthanc
--- a/Core/Lua/LuaContext.h	Tue Jun 09 16:40:43 2020 +0200
+++ b/Core/Lua/LuaContext.h	Tue Jun 09 20:50:20 2020 +0200
@@ -53,7 +53,7 @@
 #endif
 
 #if ORTHANC_HAS_EMBEDDED_RESOURCES == 1
-#  include <EmbeddedResources.h>   // Autogenerated file
+#  include <OrthancEmbeddedResources.h>   // Autogenerated file
 #endif
 
 #if ORTHANC_ENABLE_CURL == 1
--- a/Core/OrthancFramework.cpp	Tue Jun 09 16:40:43 2020 +0200
+++ b/Core/OrthancFramework.cpp	Tue Jun 09 20:50:20 2020 +0200
@@ -72,7 +72,7 @@
   {
     Logging::Initialize();
 
-#if !defined(__EMSCRIPTEN__)  // No global locale in wasm/asm.js
+#if (ORTHANC_ENABLE_LOCALE == 1) && !defined(__EMSCRIPTEN__)  // No global locale in wasm/asm.js
     if (locale.empty())
     {
       Toolbox::InitializeGlobalLocale(NULL);
@@ -113,7 +113,11 @@
 #endif
     
     Toolbox::FinalizeOpenSsl();
+
+#if (ORTHANC_ENABLE_LOCALE == 1) && !defined(__EMSCRIPTEN__)
     Toolbox::FinalizeGlobalLocale();
+#endif
+    
     Logging::Finalize();
   }
 }
--- a/Core/Toolbox.cpp	Tue Jun 09 16:40:43 2020 +0200
+++ b/Core/Toolbox.cpp	Tue Jun 09 20:50:20 2020 +0200
@@ -118,7 +118,7 @@
 
 #if defined(ORTHANC_STATIC_ICU)
 #  if (ORTHANC_STATIC_ICU == 1 && ORTHANC_ENABLE_LOCALE == 1)
-#    include <EmbeddedResources.h>
+#    include <OrthancEmbeddedResources.h>
 #    include <unicode/udata.h>
 #    include <unicode/uloc.h>
 #    include "Compression/GzipCompressor.h"
--- a/OrthancServer/Database/SQLiteDatabaseWrapper.cpp	Tue Jun 09 16:40:43 2020 +0200
+++ b/OrthancServer/Database/SQLiteDatabaseWrapper.cpp	Tue Jun 09 20:50:20 2020 +0200
@@ -40,7 +40,7 @@
 #include "../Search/ISqlLookupFormatter.h"
 #include "../ServerToolbox.h"
 
-#include <EmbeddedResources.h>
+#include <OrthancEmbeddedResources.h>
 
 #include <stdio.h>
 #include <boost/lexical_cast.hpp>
--- a/OrthancServer/LuaScripting.cpp	Tue Jun 09 16:40:43 2020 +0200
+++ b/OrthancServer/LuaScripting.cpp	Tue Jun 09 20:50:20 2020 +0200
@@ -42,7 +42,7 @@
 #include "../Core/Logging.h"
 #include "../Core/Lua/LuaFunctionCall.h"
 
-#include <EmbeddedResources.h>
+#include <OrthancEmbeddedResources.h>
 
 
 namespace Orthanc
--- a/OrthancServer/OrthancConfiguration.h	Tue Jun 09 16:40:43 2020 +0200
+++ b/OrthancServer/OrthancConfiguration.h	Tue Jun 09 20:50:20 2020 +0200
@@ -37,7 +37,7 @@
 #include "../Core/WebServiceParameters.h"
 #include "../Core/DicomNetworking/RemoteModalityParameters.h"
 
-#include <EmbeddedResources.h>
+#include <OrthancEmbeddedResources.h>
 
 #include <boost/filesystem.hpp>
 #include <boost/thread/shared_mutex.hpp>
--- a/OrthancServer/ServerContext.cpp	Tue Jun 09 16:40:43 2020 +0200
+++ b/OrthancServer/ServerContext.cpp	Tue Jun 09 20:50:20 2020 +0200
@@ -53,7 +53,7 @@
 #include "ServerToolbox.h"
 #include "StorageCommitmentReports.h"
 
-#include <EmbeddedResources.h>
+#include <OrthancEmbeddedResources.h>
 #include <dcmtk/dcmdata/dcfilefo.h>
 
 
--- a/OrthancServer/ServerIndex.cpp	Tue Jun 09 16:40:43 2020 +0200
+++ b/OrthancServer/ServerIndex.cpp	Tue Jun 09 20:50:20 2020 +0200
@@ -46,7 +46,7 @@
 
 #include "Database/ResourcesContent.h"
 #include "DicomInstanceToStore.h"
-#include "EmbeddedResources.h"
+#include "OrthancEmbeddedResources.h"
 #include "OrthancConfiguration.h"
 #include "Search/DatabaseLookup.h"
 #include "Search/DicomTagConstraint.h"
--- a/Resources/CMake/AutoGeneratedCode.cmake	Tue Jun 09 16:40:43 2020 +0200
+++ b/Resources/CMake/AutoGeneratedCode.cmake	Tue Jun 09 20:50:20 2020 +0200
@@ -11,6 +11,8 @@
   set(DEPENDENCIES)
   set(IS_PATH_NAME false)
 
+  set(TARGET_BASE "${AUTOGENERATED_DIR}/EmbeddedResources")
+
   # Loop over the arguments of the function
   foreach(arg ${ARGN})
     # Extract the first character of the argument
@@ -18,7 +20,13 @@
     if (${FIRST_CHAR} STREQUAL "-")
       # If the argument starts with a dash "-", this is an option to
       # EmbedResources.py
-      list(APPEND SCRIPT_OPTIONS ${arg})
+      if (${arg} MATCHES "--target=.*")
+        # Does the argument starts with "--target="?
+        string(SUBSTRING "${arg}" 9 -1 TARGET)  # 9 is the length of "--target="
+        set(TARGET_BASE "${AUTOGENERATED_DIR}/${TARGET}")
+      else()
+        list(APPEND SCRIPT_OPTIONS ${arg})
+      endif()
     else()
       if (${IS_PATH_NAME})
         list(APPEND SCRIPT_ARGUMENTS "${arg}")
@@ -31,7 +39,6 @@
     endif()
   endforeach()
 
-  set(TARGET_BASE "${AUTOGENERATED_DIR}/EmbeddedResources")
   add_custom_command(
     OUTPUT
     "${TARGET_BASE}.h"
@@ -40,7 +47,7 @@
     ${PYTHON_EXECUTABLE}
     "${ORTHANC_ROOT}/Resources/EmbedResources.py"
     ${SCRIPT_OPTIONS}
-    "${AUTOGENERATED_DIR}/EmbeddedResources"
+    "${TARGET_BASE}"
     ${SCRIPT_ARGUMENTS}
     DEPENDS
     "${ORTHANC_ROOT}/Resources/EmbedResources.py"
@@ -48,6 +55,6 @@
     )
 
   list(APPEND AUTOGENERATED_SOURCES
-    "${AUTOGENERATED_DIR}/EmbeddedResources.cpp"
+    "${TARGET_BASE}.cpp"
     ) 
 endmacro()
--- a/Resources/CMake/OrthancFrameworkConfiguration.cmake	Tue Jun 09 16:40:43 2020 +0200
+++ b/Resources/CMake/OrthancFrameworkConfiguration.cmake	Tue Jun 09 20:50:20 2020 +0200
@@ -604,36 +604,6 @@
   add_definitions(-DORTHANC_ENABLE_LOGGING_STDIO=0)
 endif()
 
-      
-if (HAS_EMBEDDED_RESOURCES)
-  add_definitions(-DORTHANC_HAS_EMBEDDED_RESOURCES=1)
-
-  if (ENABLE_WEB_SERVER)
-    list(APPEND ORTHANC_CORE_SOURCES_INTERNAL
-      ${ORTHANC_ROOT}/Core/HttpServer/EmbeddedResourceHttpHandler.cpp
-      )
-  endif()
-
-elseif (STANDALONE_BUILD)
-  # No embedded resources are provided by the external project, but
-  # some are required by the Orthanc framework (DCMTK and ICU)
-  add_definitions(-DORTHANC_HAS_EMBEDDED_RESOURCES=1)
-
-  EmbedResources(
-    ${DCMTK_DICTIONARIES}
-    ${LIBICU_RESOURCES}
-    )
-
-  list(APPEND ORTHANC_DICOM_SOURCES_DEPENDENCIES
-    ${AUTOGENERATED_SOURCES}
-    )
-  
-else()
-  # Neither the external project, nor the Orthanc framework have to
-  # embed external resources
-  add_definitions(-DORTHANC_HAS_EMBEDDED_RESOURCES=0)
-endif()
-
 
 
 #####################################################################
@@ -706,6 +676,13 @@
 endif()
 
 
+if (NOT ORTHANC_BUILDING_FRAMEWORK_LIBRARY)
+  list(APPEND ORTHANC_CORE_SOURCES_INTERNAL
+    ${ORTHANC_ROOT}/Core/HttpServer/EmbeddedResourceHttpHandler.cpp
+    )
+endif()
+
+
 set(ORTHANC_CORE_SOURCES
   ${ORTHANC_CORE_SOURCES_INTERNAL}
   ${ORTHANC_CORE_SOURCES_DEPENDENCIES}
--- a/Resources/CMake/OrthancFrameworkParameters.cmake	Tue Jun 09 16:40:43 2020 +0200
+++ b/Resources/CMake/OrthancFrameworkParameters.cmake	Tue Jun 09 20:50:20 2020 +0200
@@ -27,7 +27,6 @@
 # Support of static compilation
 set(ALLOW_DOWNLOADS OFF CACHE BOOL "Allow CMake to download packages")
 set(STATIC_BUILD OFF CACHE BOOL "Static build of the third-party libraries (necessary for Windows)")
-set(STANDALONE_BUILD ON CACHE BOOL "Standalone build (all the resources are embedded, necessary for releases)")
 
 # Generic parameters of the build
 set(ENABLE_CIVETWEB ON CACHE BOOL "Use Civetweb instead of Mongoose (Mongoose was the default embedded HTTP server in Orthanc <= 1.5.1)")
@@ -106,9 +105,6 @@
 set(ENABLE_DCMTK_TRANSCODING OFF CACHE INTERNAL "Enable DICOM transcoding in DCMTK")
 set(ENABLE_OPENSSL_ENGINES OFF CACHE INTERNAL "Enable support of engines in OpenSSL")
 
-set(HAS_EMBEDDED_RESOURCES OFF CACHE INTERNAL
-  "Whether resources are auto-generated using EmbedResources.py")
-
 set(ORTHANC_SANDBOXED OFF CACHE INTERNAL
   "Whether Orthanc runs inside a sandboxed environment (such as Google NaCl or WebAssembly)")
 
--- a/Resources/EmbedResources.py	Tue Jun 09 16:40:43 2020 +0200
+++ b/Resources/EmbedResources.py	Tue Jun 09 20:50:20 2020 +0200
@@ -42,7 +42,7 @@
 EXCEPTION_CLASS = 'OrthancException'
 OUT_OF_RANGE_EXCEPTION = '::Orthanc::OrthancException(::Orthanc::ErrorCode_ParameterOutOfRange)'
 INEXISTENT_PATH_EXCEPTION = '::Orthanc::OrthancException(::Orthanc::ErrorCode_InexistentItem)'
-NAMESPACE = 'Orthanc'
+NAMESPACE = 'Orthanc.EmbeddedResources'
 
 ARGS = []
 for i in range(len(sys.argv)):
@@ -166,13 +166,17 @@
 #  pragma warning(disable: 4065)  // "Switch statement contains 'default' but no 'case' labels"
 #endif
 
-namespace %s
-{
-  namespace EmbeddedResources
-  {
+""")
+
+
+for ns in NAMESPACE.split('.'):
+    header.write('namespace %s {\n' % ns)
+    
+
+header.write("""
     enum FileResourceId
     {
-""" % NAMESPACE)
+""")
 
 isFirst = True
 for name in resources:
@@ -211,9 +215,13 @@
     void GetDirectoryResource(std::string& result, DirectoryResourceId id, const char* path);
 
     void ListResources(std::list<std::string>& result, DirectoryResourceId id);
-  }
-}
+
 """)
+
+
+for ns in NAMESPACE.split('.'):
+    header.write('}\n')
+
 header.close()
 
 
@@ -279,11 +287,10 @@
 #include <stdint.h>
 #include <string.h>
 
-namespace %s
-{
-  namespace EmbeddedResources
-  {
-""" % NAMESPACE)
+""")
+
+for ns in NAMESPACE.split('.'):
+    cpp.write('namespace %s {\n' % ns)
 
 
 for name in resources:
@@ -434,7 +441,10 @@
       if (size > 0)
         memcpy(&result[0], GetDirectoryResourceBuffer(id, path), size);
     }
-  }
-}
 """)
+
+
+for ns in NAMESPACE.split('.'):
+    cpp.write('}\n')
+
 cpp.close()