Mercurial > hg > orthanc
changeset 4535:c40c1234a696
simplification of DownloadOrthancFramework.cmake
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 26 Feb 2021 13:50:37 +0100 |
parents | d9700b9f4ad9 |
children | 237ec4c5a24d |
files | OrthancFramework/Resources/CMake/BoostConfiguration.cmake OrthancFramework/Resources/CMake/DownloadOrthancFramework.cmake OrthancFramework/SharedLibrary/CMakeLists.txt OrthancFramework/UnitTestsSources/CMakeLists.txt |
diffstat | 4 files changed, 97 insertions(+), 159 deletions(-) [+] |
line wrap: on
line diff
--- a/OrthancFramework/Resources/CMake/BoostConfiguration.cmake Thu Feb 25 18:27:28 2021 +0100 +++ b/OrthancFramework/Resources/CMake/BoostConfiguration.cmake Fri Feb 26 13:50:37 2021 +0100 @@ -130,10 +130,11 @@ if (ORTHANC_BUILDING_FRAMEWORK_LIBRARY) add_definitions( - # Packaging Boost inside the Orthanc Framework DLL, not exposing - # the Boost symbols + # Packaging Boost inside the Orthanc Framework DLL + -DBOOST_ALL_DYN_LINK # Expose Boost symbols into the DLL -DBOOST_THREAD_BUILD_DLL -DBOOST_REGEX_BUILD_DLL + -DBOOST_IOSTREAMS_SOURCE ) else() add_definitions(
--- a/OrthancFramework/Resources/CMake/DownloadOrthancFramework.cmake Thu Feb 25 18:27:28 2021 +0100 +++ b/OrthancFramework/Resources/CMake/DownloadOrthancFramework.cmake Fri Feb 26 13:50:37 2021 +0100 @@ -431,7 +431,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") - set(ORTHANC_FRAMEWORK_ADDITIONAL_LIBRARIES "" CACHE STRING "Additional libraries to link against, separated by whitespaces, typically needed if using the static library (a typical value is \"uuid curl civetweb\")") + set(ORTHANC_FRAMEWORK_ADDITIONAL_LIBRARIES "" CACHE STRING "Additional libraries to link against, separated by whitespaces, typically needed if using the static library (a common minimal value is \"boost_filesystem boost_iostreams boost_locale boost_regex boost_thread jsoncpp pugixml uuid\")") if (CMAKE_SYSTEM_NAME STREQUAL "Windows" AND CMAKE_COMPILER_IS_GNUCXX) # MinGW @@ -448,19 +448,19 @@ include(${CMAKE_CURRENT_LIST_DIR}/AutoGeneratedCode.cmake) set(EMBED_RESOURCES_PYTHON ${CMAKE_CURRENT_LIST_DIR}/EmbedResources.py) + 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() + # 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}) + set(ORTHANC_FRAMEWORK_LIBRARIES ${Prefix}OrthancFramework${Suffix}) + else () + set(ORTHANC_FRAMEWORK_LIBRARIES ${ORTHANC_FRAMEWORK_LIBDIR}/${Prefix}OrthancFramework${Suffix}) endif() if (NOT ORTHANC_FRAMEWORK_ADDITIONAL_LIBRARIES STREQUAL "") @@ -469,118 +469,52 @@ list(APPEND ORTHANC_FRAMEWORK_LIBRARIES ${tmp}) endif() - if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows" OR - ORTHANC_FRAMEWORK_STATIC) - include_directories(${ORTHANC_FRAMEWORK_ROOT}/..) + # Look for the version of the mandatory dependency JsonCpp (cf. JsonCppConfiguration.cmake) + if (CMAKE_CROSSCOMPILING) + set(JSONCPP_INCLUDE_DIR ${ORTHANC_FRAMEWORK_ROOT}/..) else() - # Look for mandatory dependency JsonCpp (cf. JsonCppConfiguration.cmake) find_path(JSONCPP_INCLUDE_DIR json/reader.h + ${ORTHANC_FRAMEWORK_ROOT}/.. /usr/include/jsoncpp /usr/local/include/jsoncpp ) + endif() - message("JsonCpp include dir: ${JSONCPP_INCLUDE_DIR}") - include_directories(${JSONCPP_INCLUDE_DIR}) - list(APPEND ORTHANC_FRAMEWORK_LIBRARIES jsoncpp) + message("JsonCpp include dir: ${JSONCPP_INCLUDE_DIR}") + include_directories(${JSONCPP_INCLUDE_DIR}) - CHECK_INCLUDE_FILE_CXX(${JSONCPP_INCLUDE_DIR}/json/reader.h HAVE_JSONCPP_H) - if (NOT HAVE_JSONCPP_H) - message(FATAL_ERROR "Please install the libjsoncpp-dev package") - endif() - - # Switch to the C++11 standard if the version of JsonCpp is 1.y.z - # (same as variable JSONCPP_CXX11 in the source code of Orthanc) - if (EXISTS ${JSONCPP_INCLUDE_DIR}/json/version.h) - file(STRINGS - "${JSONCPP_INCLUDE_DIR}/json/version.h" - JSONCPP_VERSION_MAJOR1 REGEX - ".*define JSONCPP_VERSION_MAJOR.*") + CHECK_INCLUDE_FILE_CXX(${JSONCPP_INCLUDE_DIR}/json/reader.h HAVE_JSONCPP_H) + if (NOT HAVE_JSONCPP_H) + message(FATAL_ERROR "Please install the libjsoncpp-dev package") + endif() - if (NOT JSONCPP_VERSION_MAJOR1) - message(FATAL_ERROR "Unable to extract the major version of JsonCpp") - endif() - - string(REGEX REPLACE - ".*JSONCPP_VERSION_MAJOR.*([0-9]+)$" "\\1" - JSONCPP_VERSION_MAJOR ${JSONCPP_VERSION_MAJOR1}) - message("JsonCpp major version: ${JSONCPP_VERSION_MAJOR}") + # Switch to the C++11 standard if the version of JsonCpp is 1.y.z + # (same as variable JSONCPP_CXX11 in the source code of Orthanc) + if (EXISTS ${JSONCPP_INCLUDE_DIR}/json/version.h) + file(STRINGS + "${JSONCPP_INCLUDE_DIR}/json/version.h" + JSONCPP_VERSION_MAJOR1 REGEX + ".*define JSONCPP_VERSION_MAJOR.*") - if (JSONCPP_VERSION_MAJOR GREATER 0) - message("Switching to C++11 standard, as version of JsonCpp is >= 1.0.0") - if (CMAKE_COMPILER_IS_GNUCXX) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11") - elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") - endif() - endif() - else() - message("Unable to detect the major version of JsonCpp, assuming < 1.0.0") - 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 - iostreams locale regex ${ORTHANC_BOOST_COMPONENTS}) - - if (NOT Boost_FOUND) - message(FATAL_ERROR "Unable to locate Boost on this system") + if (NOT JSONCPP_VERSION_MAJOR1) + message(FATAL_ERROR "Unable to extract the major version of JsonCpp") endif() - include_directories(${Boost_INCLUDE_DIRS}) - list(APPEND ORTHANC_FRAMEWORK_LIBRARIES ${Boost_LIBRARIES}) - - # Optional component - Lua - if (ENABLE_LUA OR - NOT ORTHANC_FRAMEWORK_USE_SHARED) - include(FindLua) - - if (NOT LUA_FOUND) - message(FATAL_ERROR "Please install the liblua-dev package") - endif() - - include_directories(${LUA_INCLUDE_DIR}) - list(APPEND ORTHANC_FRAMEWORK_LIBRARIES ${LUA_LIBRARIES}) - endif() - - # Optional component - SQLite - if (ENABLE_SQLITE OR - NOT ORTHANC_FRAMEWORK_USE_SHARED) - CHECK_INCLUDE_FILE(sqlite3.h HAVE_SQLITE_H) - if (NOT HAVE_SQLITE_H) - message(FATAL_ERROR "Please install the libsqlite3-dev package") - endif() - list(APPEND ORTHANC_FRAMEWORK_LIBRARIES sqlite3) - endif() + string(REGEX REPLACE + ".*JSONCPP_VERSION_MAJOR.*([0-9]+)$" "\\1" + JSONCPP_VERSION_MAJOR ${JSONCPP_VERSION_MAJOR1}) + message("JsonCpp major version: ${JSONCPP_VERSION_MAJOR}") - # Optional component - Pugixml - if (ENABLE_PUGIXML OR - NOT ORTHANC_FRAMEWORK_USE_SHARED) - CHECK_INCLUDE_FILE_CXX(pugixml.hpp HAVE_PUGIXML_H) - if (NOT HAVE_PUGIXML_H) - message(FATAL_ERROR "Please install the libpugixml-dev package") - endif() - list(APPEND ORTHANC_FRAMEWORK_LIBRARIES pugixml) + if (JSONCPP_VERSION_MAJOR GREATER 0) + message("Switching to C++11 standard, as version of JsonCpp is >= 1.0.0") + if (CMAKE_COMPILER_IS_GNUCXX) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11") + elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") + endif() endif() - - # Optional component - DCMTK - if (ENABLE_DCMTK OR - NOT ORTHANC_FRAMEWORK_USE_SHARED) - include(FindDCMTK NO_MODULE) - list(APPEND ORTHANC_FRAMEWORK_LIBRARIES ${DCMTK_LIBRARIES}) - include_directories(${DCMTK_INCLUDE_DIRS}) - endif() - - # Optional component - OpenSSL - if (ENABLE_SSL OR - NOT ORTHANC_FRAMEWORK_USE_SHARED) - include(FindOpenSSL) - if (NOT ${OPENSSL_FOUND}) - message(FATAL_ERROR "Unable to find OpenSSL") - endif() - include_directories(${OPENSSL_INCLUDE_DIR}) - list(APPEND ORTHANC_FRAMEWORK_LIBRARIES ${OPENSSL_LIBRARIES}) - endif() + else() + message("Unable to detect the major version of JsonCpp, assuming < 1.0.0") endif() # Look for Orthanc framework shared library @@ -603,14 +537,16 @@ message("Orthanc framework include dir: ${ORTHANC_FRAMEWORK_INCLUDE_DIR}") include_directories(${ORTHANC_FRAMEWORK_INCLUDE_DIR}) - set(CMAKE_REQUIRED_INCLUDES "${ORTHANC_FRAMEWORK_INCLUDE_DIR}") - set(CMAKE_REQUIRED_LIBRARIES "${ORTHANC_FRAMEWORK_LIBRARIES}") - - check_cxx_symbol_exists("Orthanc::InitializeFramework" "OrthancFramework.h" HAVE_ORTHANC_FRAMEWORK) - if (NOT HAVE_ORTHANC_FRAMEWORK) - message(FATAL_ERROR "Cannot find the Orthanc framework") + if (ORTHANC_FRAMEWORK_USE_SHARED) + set(CMAKE_REQUIRED_INCLUDES "${ORTHANC_FRAMEWORK_INCLUDE_DIR}") + set(CMAKE_REQUIRED_LIBRARIES "${ORTHANC_FRAMEWORK_LIBRARIES}") + + check_cxx_symbol_exists("Orthanc::InitializeFramework" "OrthancFramework.h" HAVE_ORTHANC_FRAMEWORK) + if (NOT HAVE_ORTHANC_FRAMEWORK) + message(FATAL_ERROR "Cannot find the Orthanc framework") + endif() + + unset(CMAKE_REQUIRED_INCLUDES) + unset(CMAKE_REQUIRED_LIBRARIES) endif() - - unset(CMAKE_REQUIRED_INCLUDES) - unset(CMAKE_REQUIRED_LIBRARIES) endif()
--- a/OrthancFramework/SharedLibrary/CMakeLists.txt Thu Feb 25 18:27:28 2021 +0100 +++ b/OrthancFramework/SharedLibrary/CMakeLists.txt Fri Feb 26 13:50:37 2021 +0100 @@ -45,7 +45,7 @@ set(ORTHANC_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}" CACHE PATH "") SET(UNIT_TESTS_WITH_HTTP_CONNEXIONS ON CACHE BOOL "Allow unit tests to make HTTP requests") set(BUILD_SHARED_LIBRARY ON CACHE BOOL "Whether to build a shared library instead of a static library") -set(ORTHANC_FRAMEWORK_ADDITIONAL_LIBRARIES "" CACHE STRING "Additional libraries to link against, separated by whitespaces, typically needed if using the static library (a typical value is \"uuid curl civetweb\")") +set(ORTHANC_FRAMEWORK_ADDITIONAL_LIBRARIES "" CACHE STRING "Additional libraries to link against, separated by whitespaces, typically needed if building the static library (a common minimal value is \"boost_filesystem boost_iostreams boost_locale boost_regex boost_thread jsoncpp pugixml uuid\")") @@ -507,32 +507,23 @@ ) endif() - if (JSONCPP_CXX11) - list(APPEND Flags -DUSE_CXX11=1) - endif() - # Build the unit tests, linking them against the just-created # "OrthancFramework" library externalproject_add(UnitTests SOURCE_DIR "${CMAKE_SOURCE_DIR}/../UnitTestsSources" CMAKE_ARGS + ${Flags} -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE} + -DORTHANC_FRAMEWORK_ADDITIONAL_LIBRARIES:STRING=${ORTHANC_FRAMEWORK_ADDITIONAL_LIBRARIES} -DORTHANC_FRAMEWORK_LIBDIR:PATH=${CMAKE_CURRENT_BINARY_DIR} -DORTHANC_FRAMEWORK_ROOT:PATH=${CMAKE_CURRENT_BINARY_DIR}/Include/orthanc-framework -DORTHANC_FRAMEWORK_SOURCE:STRING=system -DORTHANC_FRAMEWORK_STATIC:BOOL=${STATIC_BUILD} - - -DALLOW_DOWNLOADS:BOOL=${ALLOW_DOWNLOADS} - -DBOOST_LOCALE_BACKEND:STRING=${BOOST_LOCALE_BACKEND} + -DORTHANC_FRAMEWORK_USE_SHARED:BOOL=${BUILD_SHARED_LIBRARY} -DSTATIC_BUILD:BOOL=${STATIC_BUILD} -DUNIT_TESTS_WITH_HTTP_CONNEXIONS:BOOL=${UNIT_TESTS_WITH_HTTP_CONNEXIONS} -DUSE_GOOGLE_TEST_DEBIAN_PACKAGE:BOOL=${USE_GOOGLE_TEST_DEBIAN_PACKAGE} - -DUSE_SYSTEM_BOOST:BOOL=${USE_SYSTEM_BOOST} -DUSE_SYSTEM_GOOGLE_TEST:BOOL=${USE_SYSTEM_GOOGLE_TEST} - -DORTHANC_FRAMEWORK_USE_SHARED:BOOL=${BUILD_SHARED_LIBRARY} - -DORTHANC_FRAMEWORK_ADDITIONAL_LIBRARIES:STRING=${ORTHANC_FRAMEWORK_ADDITIONAL_LIBRARIES} - - ${Flags} ) add_dependencies(UnitTests OrthancFramework)
--- a/OrthancFramework/UnitTestsSources/CMakeLists.txt Thu Feb 25 18:27:28 2021 +0100 +++ b/OrthancFramework/UnitTestsSources/CMakeLists.txt Fri Feb 26 13:50:37 2021 +0100 @@ -25,48 +25,58 @@ cmake_minimum_required(VERSION 2.8) project(UnitTestsProject) -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(UNIT_TESTS_WITH_HTTP_CONNEXIONS ON CACHE BOOL "Allow unit tests to make HTTP requests") set(USE_GOOGLE_TEST_DEBIAN_PACKAGE OFF CACHE BOOL "Use the sources of Google Test shipped with libgtest-dev (Debian only)") -set(USE_SYSTEM_BOOST ON CACHE BOOL "Use the system version of Boost") set(USE_SYSTEM_GOOGLE_TEST ON CACHE BOOL "Use the system version of Google Test") -set(BOOST_LOCALE_BACKEND "libiconv" CACHE STRING "Back-end for locales that is used by Boost (can be \"gcc\", \"libiconv\", \"icu\", or \"wconv\" on Windows)") -set(USE_CXX11 OFF CACHE BOOL "Whether to enable compiler support for C++11") - if (UNIT_TESTS_WITH_HTTP_CONNEXIONS) add_definitions(-DUNIT_TESTS_WITH_HTTP_CONNEXIONS=1) else() add_definitions(-DUNIT_TESTS_WITH_HTTP_CONNEXIONS=0) endif() -set(ENABLE_DCMTK ON) -set(ENABLE_GOOGLE_TEST ON) -set(ENABLE_LUA ON) -set(ENABLE_PUGIXML ON) -set(ENABLE_SQLITE ON) -set(ENABLE_WEB_CLIENT ON) +if (ORTHANC_FRAMEWORK_STATIC) + include_directories(${ORTHANC_FRAMEWORK_ROOT}/..) +else() + include(CheckIncludeFile) + include(CheckIncludeFileCXX) + + link_libraries(jsoncpp) + + include(FindLua) + if (NOT LUA_FOUND) + message(FATAL_ERROR "Please install the liblua-dev package") + endif() + include_directories(${LUA_INCLUDE_DIR}) + link_libraries(${LUA_LIBRARIES}) -if (NOT ORTHANC_FRAMEWORK_STATIC) - set(USE_SYSTEM_GOOGLE_TEST ON CACHE BOOL "Use the system version of Google Test") -else() - set(USE_SYSTEM_GOOGLE_TEST OFF CACHE INTERNAL "") + check_include_file(sqlite3.h HAVE_SQLITE_H) + if (NOT HAVE_SQLITE_H) + message(FATAL_ERROR "Please install the libsqlite3-dev package") + endif() + link_libraries(sqlite3) + + check_include_file_cxx(pugixml.hpp HAVE_PUGIXML_H) + if (NOT HAVE_PUGIXML_H) + message(FATAL_ERROR "Please install the libpugixml-dev package") + endif() + link_libraries(pugixml) + + find_package(Boost COMPONENTS filesystem thread system date_time iostreams locale regex) + if (NOT Boost_FOUND) + message(FATAL_ERROR "Unable to locate Boost on this system") + endif() + link_libraries(${Boost_LIBRARIES}) + + include(FindDCMTK NO_MODULE) + link_libraries(${DCMTK_LIBRARIES}) endif() include(${CMAKE_SOURCE_DIR}/../Resources/CMake/DownloadOrthancFramework.cmake) -include(${CMAKE_SOURCE_DIR}/../Resources/CMake/BoostConfiguration.cmake) include(${CMAKE_SOURCE_DIR}/../Resources/CMake/GoogleTestConfiguration.cmake) -if (USE_CXX11) - if (CMAKE_COMPILER_IS_GNUCXX) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11") - elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") - endif() -endif() - add_definitions( -DORTHANC_UNIT_TESTS_LINK_FRAMEWORK=1 -DORTHANC_BUILD_UNIT_TESTS=1 # For "HierarchicalZipWriter" tests