Mercurial > hg > orthanc-webviewer
changeset 297:d386d2933022
sync
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 25 Feb 2021 11:04:08 +0100 |
parents | d179f3928342 |
children | 165723f96767 |
files | Resources/Orthanc/CMake/DownloadOrthancFramework.cmake Resources/Orthanc/Plugins/OrthancPluginCppWrapper.cpp Resources/Orthanc/Plugins/OrthancPluginCppWrapper.h |
diffstat | 3 files changed, 123 insertions(+), 42 deletions(-) [+] |
line wrap: on
line diff
--- a/Resources/Orthanc/CMake/DownloadOrthancFramework.cmake Sat Jan 30 12:26:50 2021 +0100 +++ b/Resources/Orthanc/CMake/DownloadOrthancFramework.cmake Thu Feb 25 11:04:08 2021 +0100 @@ -122,6 +122,8 @@ set(ORTHANC_FRAMEWORK_MD5 "db094f96399cbe8b9bbdbce34884c220") elseif (ORTHANC_FRAMEWORK_VERSION STREQUAL "1.8.2") set(ORTHANC_FRAMEWORK_MD5 "8bfa10e66c9931e74111be0bfb1f4548") + elseif (ORTHANC_FRAMEWORK_VERSION STREQUAL "1.9.0") + set(ORTHANC_FRAMEWORK_MD5 "cea0b02ce184671eaf1bd668beefbf28") # Below this point are development snapshots that were used to # release some plugin, before an official release of the Orthanc @@ -426,6 +428,7 @@ if (ORTHANC_FRAMEWORK_SOURCE STREQUAL "system") set(ORTHANC_FRAMEWORK_LIBDIR "" CACHE PATH "") + set(ORTHANC_FRAMEWORK_USE_SHARED ON CACHE BOOL "Whether to use the shared library or the static library") if (CMAKE_SYSTEM_NAME STREQUAL "Windows" AND CMAKE_COMPILER_IS_GNUCXX) # MinGW @@ -442,6 +445,21 @@ include(${CMAKE_CURRENT_LIST_DIR}/AutoGeneratedCode.cmake) set(EMBED_RESOURCES_PYTHON ${CMAKE_CURRENT_LIST_DIR}/EmbedResources.py) + # The "OrthancFramework" library must be the first one to be included + if ("${ORTHANC_FRAMEWORK_LIBDIR}" STREQUAL "") + set(ORTHANC_FRAMEWORK_LIBRARIES OrthancFramework) + else() + if(ORTHANC_FRAMEWORK_USE_SHARED) + list(GET CMAKE_FIND_LIBRARY_PREFIXES 0 Prefix) + list(GET CMAKE_FIND_LIBRARY_SUFFIXES 0 Suffix) + else() + list(GET CMAKE_FIND_LIBRARY_PREFIXES 0 Prefix) + list(GET CMAKE_FIND_LIBRARY_SUFFIXES 1 Suffix) + endif() + set(ORTHANC_FRAMEWORK_LIBRARIES + ${ORTHANC_FRAMEWORK_LIBDIR}/${Prefix}OrthancFramework${Suffix}) + endif() + if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows" OR ORTHANC_FRAMEWORK_STATIC) include_directories(${ORTHANC_FRAMEWORK_ROOT}/..) @@ -454,7 +472,7 @@ message("JsonCpp include dir: ${JSONCPP_INCLUDE_DIR}") include_directories(${JSONCPP_INCLUDE_DIR}) - link_libraries(jsoncpp) + list(APPEND ORTHANC_FRAMEWORK_LIBRARIES jsoncpp) CHECK_INCLUDE_FILE_CXX(${JSONCPP_INCLUDE_DIR}/json/reader.h HAVE_JSONCPP_H) if (NOT HAVE_JSONCPP_H) @@ -491,15 +509,17 @@ endif() # Look for mandatory dependency Boost (cf. BoostConfiguration.cmake) + # NB: "locale" and "iostreams" are not required if using the shared library include(FindBoost) - find_package(Boost COMPONENTS filesystem thread system date_time regex ${ORTHANC_BOOST_COMPONENTS}) + find_package(Boost COMPONENTS filesystem thread system date_time + iostreams locale regex ${ORTHANC_BOOST_COMPONENTS}) if (NOT Boost_FOUND) message(FATAL_ERROR "Unable to locate Boost on this system") endif() include_directories(${Boost_INCLUDE_DIRS}) - link_libraries(${Boost_LIBRARIES}) + list(APPEND ORTHANC_FRAMEWORK_LIBRARIES ${Boost_LIBRARIES}) # Optional component - Lua if (ENABLE_LUA) @@ -510,7 +530,7 @@ endif() include_directories(${LUA_INCLUDE_DIR}) - link_libraries(${LUA_LIBRARIES}) + list(APPEND ORTHANC_FRAMEWORK_LIBRARIES ${LUA_LIBRARIES}) endif() # Optional component - SQLite @@ -519,7 +539,7 @@ if (NOT HAVE_SQLITE_H) message(FATAL_ERROR "Please install the libsqlite3-dev package") endif() - link_libraries(sqlite3) + list(APPEND ORTHANC_FRAMEWORK_LIBRARIES sqlite3) endif() # Optional component - Pugixml @@ -528,14 +548,14 @@ if (NOT HAVE_PUGIXML_H) message(FATAL_ERROR "Please install the libpugixml-dev package") endif() - link_libraries(pugixml) + list(APPEND ORTHANC_FRAMEWORK_LIBRARIES pugixml) endif() # Optional component - DCMTK if (ENABLE_DCMTK) - include(FindDCMTK) + include(FindDCMTK NO_MODULE) + list(APPEND ORTHANC_FRAMEWORK_LIBRARIES ${DCMTK_LIBRARIES}) include_directories(${DCMTK_INCLUDE_DIRS}) - link_libraries(${DCMTK_LIBRARIES}) endif() # Optional component - OpenSSL @@ -545,7 +565,47 @@ message(FATAL_ERROR "Unable to find OpenSSL") endif() include_directories(${OPENSSL_INCLUDE_DIR}) - link_libraries(${OPENSSL_LIBRARIES}) + list(APPEND ORTHANC_FRAMEWORK_LIBRARIES ${OPENSSL_LIBRARIES}) + endif() + endif() + + if (NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "Windows" AND + NOT ORTHANC_FRAMEWORK_USE_SHARED) + # Static library has more dependencies + + # Mandatory dependency: libuuid + CHECK_INCLUDE_FILE(uuid/uuid.h HAVE_UUID_H) + if (NOT HAVE_UUID_H) + message(FATAL_ERROR "Please install uuid-dev, e2fsprogs (OpenBSD) or e2fsprogs-libuuid (FreeBSD)") + endif() + + find_library(LIBUUID uuid + PATHS + /usr/lib + /usr/local/lib + ) + + check_library_exists(${LIBUUID} uuid_generate_random "" HAVE_LIBUUID) + if (NOT HAVE_LIBUUID) + message(FATAL_ERROR "Unable to find the uuid library") + endif() + + list(APPEND ORTHANC_FRAMEWORK_LIBRARIES ${LIBUUID}) + + # Optional component - libcurl + if (ENABLE_WEB_CLIENT) + include(FindCURL) + include_directories(${CURL_INCLUDE_DIRS}) + list(APPEND ORTHANC_FRAMEWORK_LIBRARIES ${CURL_LIBRARIES}) + endif() + + # Optional component - civetweb + if (ENABLE_WEB_SERVER) + CHECK_INCLUDE_FILE_CXX(civetweb.h HAVE_CIVETWEB_H) + if (NOT HAVE_CIVETWEB_H) + message(FATAL_ERROR "Please install the libcivetweb-dev package") + endif() + list(APPEND ORTHANC_FRAMEWORK_LIBRARIES civetweb) endif() endif() @@ -568,19 +628,6 @@ message("Orthanc framework include dir: ${ORTHANC_FRAMEWORK_INCLUDE_DIR}") include_directories(${ORTHANC_FRAMEWORK_INCLUDE_DIR}) - - if ("${ORTHANC_FRAMEWORK_LIBDIR}" STREQUAL "") - set(ORTHANC_FRAMEWORK_LIBRARIES OrthancFramework) - else() - if (MSVC) - set(Suffix ".lib") - set(Prefix "") - else() - list(GET CMAKE_FIND_LIBRARY_PREFIXES 0 Prefix) - list(GET CMAKE_FIND_LIBRARY_SUFFIXES 0 Suffix) - endif() - set(ORTHANC_FRAMEWORK_LIBRARIES ${ORTHANC_FRAMEWORK_LIBDIR}/${Prefix}OrthancFramework${Suffix}) - endif() set(CMAKE_REQUIRED_INCLUDES "${ORTHANC_FRAMEWORK_INCLUDE_DIR}") set(CMAKE_REQUIRED_LIBRARIES "${ORTHANC_FRAMEWORK_LIBRARIES}")
--- a/Resources/Orthanc/Plugins/OrthancPluginCppWrapper.cpp Sat Jan 30 12:26:50 2021 +0100 +++ b/Resources/Orthanc/Plugins/OrthancPluginCppWrapper.cpp Thu Feb 25 11:04:08 2021 +0100 @@ -313,6 +313,37 @@ } + static bool ReadJsonInternal(Json::Value& target, + const void* buffer, + size_t size, + bool collectComments) + { +#if JSONCPP_USE_DEPRECATED == 1 + Json::Reader reader; + return reader.parse(reinterpret_cast<const char*>(buffer), + reinterpret_cast<const char*>(buffer) + size, target, collectComments); +#else + Json::CharReaderBuilder builder; + builder.settings_["collectComments"] = collectComments; + + const std::unique_ptr<Json::CharReader> reader(builder.newCharReader()); + assert(reader.get() != NULL); + + JSONCPP_STRING err; + if (reader->parse(reinterpret_cast<const char*>(buffer), + reinterpret_cast<const char*>(buffer) + size, &target, &err)) + { + return true; + } + else + { + LogError("Cannot parse JSON: " + std::string(err)); + return false; + } +#endif + } + + bool ReadJson(Json::Value& target, const std::string& source) { @@ -324,29 +355,25 @@ const void* buffer, size_t size) { -#if JSONCPP_USE_DEPRECATED == 1 - Json::Reader reader; - return reader.parse(reinterpret_cast<const char*>(buffer), - reinterpret_cast<const char*>(buffer) + size, target); -#else - Json::CharReaderBuilder builder; - const std::unique_ptr<Json::CharReader> reader(builder.newCharReader()); - assert(reader.get() != NULL); - JSONCPP_STRING err; - if (reader->parse(reinterpret_cast<const char*>(buffer), - reinterpret_cast<const char*>(buffer) + size, &target, &err)) - { - return true; - } - else - { - LogError("Cannot parse JSON: " + err); - return false; - } -#endif + return ReadJsonInternal(target, buffer, size, true); } + bool ReadJsonWithoutComments(Json::Value& target, + const std::string& source) + { + return ReadJsonWithoutComments(target, source.empty() ? NULL : source.c_str(), source.size()); + } + + + bool ReadJsonWithoutComments(Json::Value& target, + const void* buffer, + size_t size) + { + return ReadJsonInternal(target, buffer, size, false); + } + + void WriteFastJson(std::string& target, const Json::Value& source) {
--- a/Resources/Orthanc/Plugins/OrthancPluginCppWrapper.h Sat Jan 30 12:26:50 2021 +0100 +++ b/Resources/Orthanc/Plugins/OrthancPluginCppWrapper.h Thu Feb 25 11:04:08 2021 +0100 @@ -483,6 +483,13 @@ const void* buffer, size_t size); + bool ReadJsonWithoutComments(Json::Value& target, + const std::string& source); + + bool ReadJsonWithoutComments(Json::Value& target, + const void* buffer, + size_t size); + void WriteFastJson(std::string& target, const Json::Value& source);