comparison Resources/Orthanc/CMake/DownloadOrthancFramework.cmake @ 300:7dc18c36dd3d

sync + no more need of "-DORTHANC_FRAMEWORK_ADDITIONAL_LIBRARIES" to dynamically link against system-wide orthanc framework
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sat, 12 Jun 2021 08:35:27 +0200
parents 165723f96767
children fb7d62e3235e
comparison
equal deleted inserted replaced
299:5ffad296d194 300:7dc18c36dd3d
122 set(ORTHANC_FRAMEWORK_MD5 "db094f96399cbe8b9bbdbce34884c220") 122 set(ORTHANC_FRAMEWORK_MD5 "db094f96399cbe8b9bbdbce34884c220")
123 elseif (ORTHANC_FRAMEWORK_VERSION STREQUAL "1.8.2") 123 elseif (ORTHANC_FRAMEWORK_VERSION STREQUAL "1.8.2")
124 set(ORTHANC_FRAMEWORK_MD5 "8bfa10e66c9931e74111be0bfb1f4548") 124 set(ORTHANC_FRAMEWORK_MD5 "8bfa10e66c9931e74111be0bfb1f4548")
125 elseif (ORTHANC_FRAMEWORK_VERSION STREQUAL "1.9.0") 125 elseif (ORTHANC_FRAMEWORK_VERSION STREQUAL "1.9.0")
126 set(ORTHANC_FRAMEWORK_MD5 "cea0b02ce184671eaf1bd668beefbf28") 126 set(ORTHANC_FRAMEWORK_MD5 "cea0b02ce184671eaf1bd668beefbf28")
127 elseif (ORTHANC_FRAMEWORK_VERSION STREQUAL "1.9.1")
128 set(ORTHANC_FRAMEWORK_MD5 "08eebc66ef93c3b40115c38501db5fbd")
129 elseif (ORTHANC_FRAMEWORK_VERSION STREQUAL "1.9.2")
130 set(ORTHANC_FRAMEWORK_MD5 "3ea66c09f64aca990016683b6375734e")
131 elseif (ORTHANC_FRAMEWORK_VERSION STREQUAL "1.9.3")
132 set(ORTHANC_FRAMEWORK_MD5 "9b86e6f00e03278293cd15643cc0233f")
127 133
128 # Below this point are development snapshots that were used to 134 # Below this point are development snapshots that were used to
129 # release some plugin, before an official release of the Orthanc 135 # release some plugin, before an official release of the Orthanc
130 # framework was available. Here is the command to be used to 136 # framework was available. Here is the command to be used to
131 # generate a proper archive: 137 # generate a proper archive:
427 ## 433 ##
428 434
429 if (ORTHANC_FRAMEWORK_SOURCE STREQUAL "system") 435 if (ORTHANC_FRAMEWORK_SOURCE STREQUAL "system")
430 set(ORTHANC_FRAMEWORK_LIBDIR "" CACHE PATH "") 436 set(ORTHANC_FRAMEWORK_LIBDIR "" CACHE PATH "")
431 set(ORTHANC_FRAMEWORK_USE_SHARED ON CACHE BOOL "Whether to use the shared library or the static library") 437 set(ORTHANC_FRAMEWORK_USE_SHARED ON CACHE BOOL "Whether to use the shared library or the static library")
432 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\")") 438 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\")")
433 439
434 if (CMAKE_SYSTEM_NAME STREQUAL "Windows" AND 440 if (CMAKE_SYSTEM_NAME STREQUAL "Windows" AND
435 CMAKE_COMPILER_IS_GNUCXX) # MinGW 441 CMAKE_COMPILER_IS_GNUCXX) # MinGW
436 set(DYNAMIC_MINGW_STDLIB ON) # Disable static linking against libc (to throw exceptions) 442 set(DYNAMIC_MINGW_STDLIB ON) # Disable static linking against libc (to throw exceptions)
437 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libstdc++") 443 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libstdc++")
444 include(${CMAKE_CURRENT_LIST_DIR}/Compiler.cmake) 450 include(${CMAKE_CURRENT_LIST_DIR}/Compiler.cmake)
445 include(${CMAKE_CURRENT_LIST_DIR}/DownloadPackage.cmake) 451 include(${CMAKE_CURRENT_LIST_DIR}/DownloadPackage.cmake)
446 include(${CMAKE_CURRENT_LIST_DIR}/AutoGeneratedCode.cmake) 452 include(${CMAKE_CURRENT_LIST_DIR}/AutoGeneratedCode.cmake)
447 set(EMBED_RESOURCES_PYTHON ${CMAKE_CURRENT_LIST_DIR}/EmbedResources.py) 453 set(EMBED_RESOURCES_PYTHON ${CMAKE_CURRENT_LIST_DIR}/EmbedResources.py)
448 454
455 if (ORTHANC_FRAMEWORK_USE_SHARED)
456 list(GET CMAKE_FIND_LIBRARY_PREFIXES 0 Prefix)
457 list(GET CMAKE_FIND_LIBRARY_SUFFIXES 0 Suffix)
458 else()
459 list(GET CMAKE_FIND_LIBRARY_PREFIXES 0 Prefix)
460 list(GET CMAKE_FIND_LIBRARY_SUFFIXES 1 Suffix)
461 endif()
462
449 # The "OrthancFramework" library must be the first one to be included 463 # The "OrthancFramework" library must be the first one to be included
450 if ("${ORTHANC_FRAMEWORK_LIBDIR}" STREQUAL "") 464 if ("${ORTHANC_FRAMEWORK_LIBDIR}" STREQUAL "")
451 set(ORTHANC_FRAMEWORK_LIBRARIES OrthancFramework) 465 set(ORTHANC_FRAMEWORK_LIBRARIES ${Prefix}OrthancFramework${Suffix})
452 else() 466 else ()
453 if(ORTHANC_FRAMEWORK_USE_SHARED) 467 set(ORTHANC_FRAMEWORK_LIBRARIES ${ORTHANC_FRAMEWORK_LIBDIR}/${Prefix}OrthancFramework${Suffix})
454 list(GET CMAKE_FIND_LIBRARY_PREFIXES 0 Prefix)
455 list(GET CMAKE_FIND_LIBRARY_SUFFIXES 0 Suffix)
456 else()
457 list(GET CMAKE_FIND_LIBRARY_PREFIXES 0 Prefix)
458 list(GET CMAKE_FIND_LIBRARY_SUFFIXES 1 Suffix)
459 endif()
460 set(ORTHANC_FRAMEWORK_LIBRARIES
461 ${ORTHANC_FRAMEWORK_LIBDIR}/${Prefix}OrthancFramework${Suffix})
462 endif() 468 endif()
463 469
464 if (NOT ORTHANC_FRAMEWORK_ADDITIONAL_LIBRARIES STREQUAL "") 470 if (NOT ORTHANC_FRAMEWORK_ADDITIONAL_LIBRARIES STREQUAL "")
465 # https://stackoverflow.com/a/5272993/881731 471 # https://stackoverflow.com/a/5272993/881731
466 string(REPLACE " " ";" tmp ${ORTHANC_FRAMEWORK_ADDITIONAL_LIBRARIES}) 472 string(REPLACE " " ";" tmp ${ORTHANC_FRAMEWORK_ADDITIONAL_LIBRARIES})
467 list(APPEND ORTHANC_FRAMEWORK_LIBRARIES ${tmp}) 473 list(APPEND ORTHANC_FRAMEWORK_LIBRARIES ${tmp})
468 endif() 474 endif()
469 475
470 if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows" OR 476 # Look for the version of the mandatory dependency JsonCpp (cf. JsonCppConfiguration.cmake)
471 ORTHANC_FRAMEWORK_STATIC) 477 if (CMAKE_CROSSCOMPILING)
472 include_directories(${ORTHANC_FRAMEWORK_ROOT}/..) 478 set(JSONCPP_INCLUDE_DIR ${ORTHANC_FRAMEWORK_ROOT}/..)
473 else() 479 else()
474 # Look for mandatory dependency JsonCpp (cf. JsonCppConfiguration.cmake)
475 find_path(JSONCPP_INCLUDE_DIR json/reader.h 480 find_path(JSONCPP_INCLUDE_DIR json/reader.h
481 ${ORTHANC_FRAMEWORK_ROOT}/..
476 /usr/include/jsoncpp 482 /usr/include/jsoncpp
477 /usr/local/include/jsoncpp 483 /usr/local/include/jsoncpp
478 ) 484 )
479 485 endif()
480 message("JsonCpp include dir: ${JSONCPP_INCLUDE_DIR}") 486
481 include_directories(${JSONCPP_INCLUDE_DIR}) 487 message("JsonCpp include dir: ${JSONCPP_INCLUDE_DIR}")
482 list(APPEND ORTHANC_FRAMEWORK_LIBRARIES jsoncpp) 488 include_directories(${JSONCPP_INCLUDE_DIR})
483 489
484 CHECK_INCLUDE_FILE_CXX(${JSONCPP_INCLUDE_DIR}/json/reader.h HAVE_JSONCPP_H) 490 CHECK_INCLUDE_FILE_CXX(${JSONCPP_INCLUDE_DIR}/json/reader.h HAVE_JSONCPP_H)
485 if (NOT HAVE_JSONCPP_H) 491 if (NOT HAVE_JSONCPP_H)
486 message(FATAL_ERROR "Please install the libjsoncpp-dev package") 492 message(FATAL_ERROR "Please install the libjsoncpp-dev package")
487 endif() 493 endif()
488 494
489 # Switch to the C++11 standard if the version of JsonCpp is 1.y.z 495 # Switch to the C++11 standard if the version of JsonCpp is 1.y.z
490 # (same as variable JSONCPP_CXX11 in the source code of Orthanc) 496 # (same as variable JSONCPP_CXX11 in the source code of Orthanc)
491 if (EXISTS ${JSONCPP_INCLUDE_DIR}/json/version.h) 497 if (EXISTS ${JSONCPP_INCLUDE_DIR}/json/version.h)
492 file(STRINGS 498 file(STRINGS
493 "${JSONCPP_INCLUDE_DIR}/json/version.h" 499 "${JSONCPP_INCLUDE_DIR}/json/version.h"
494 JSONCPP_VERSION_MAJOR1 REGEX 500 JSONCPP_VERSION_MAJOR1 REGEX
495 ".*define JSONCPP_VERSION_MAJOR.*") 501 ".*define JSONCPP_VERSION_MAJOR.*")
496 502
497 if (NOT JSONCPP_VERSION_MAJOR1) 503 if (NOT JSONCPP_VERSION_MAJOR1)
498 message(FATAL_ERROR "Unable to extract the major version of JsonCpp") 504 message(FATAL_ERROR "Unable to extract the major version of JsonCpp")
505 endif()
506
507 string(REGEX REPLACE
508 ".*JSONCPP_VERSION_MAJOR.*([0-9]+)$" "\\1"
509 JSONCPP_VERSION_MAJOR ${JSONCPP_VERSION_MAJOR1})
510 message("JsonCpp major version: ${JSONCPP_VERSION_MAJOR}")
511
512 if (JSONCPP_VERSION_MAJOR GREATER 0)
513 message("Switching to C++11 standard, as version of JsonCpp is >= 1.0.0")
514 if (CMAKE_COMPILER_IS_GNUCXX)
515 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
516 elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
517 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
499 endif() 518 endif()
500 519 endif()
501 string(REGEX REPLACE 520 else()
502 ".*JSONCPP_VERSION_MAJOR.*([0-9]+)$" "\\1" 521 message("Unable to detect the major version of JsonCpp, assuming < 1.0.0")
503 JSONCPP_VERSION_MAJOR ${JSONCPP_VERSION_MAJOR1})
504 message("JsonCpp major version: ${JSONCPP_VERSION_MAJOR}")
505
506 if (JSONCPP_VERSION_MAJOR GREATER 0)
507 message("Switching to C++11 standard, as version of JsonCpp is >= 1.0.0")
508 if (CMAKE_COMPILER_IS_GNUCXX)
509 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
510 elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
511 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
512 endif()
513 endif()
514 else()
515 message("Unable to detect the major version of JsonCpp, assuming < 1.0.0")
516 endif()
517
518 # Look for mandatory dependency Boost (cf. BoostConfiguration.cmake)
519 # NB: "locale" and "iostreams" are not required if using the shared library
520 include(FindBoost)
521 find_package(Boost COMPONENTS filesystem thread system date_time
522 iostreams locale regex ${ORTHANC_BOOST_COMPONENTS})
523
524 if (NOT Boost_FOUND)
525 message(FATAL_ERROR "Unable to locate Boost on this system")
526 endif()
527
528 include_directories(${Boost_INCLUDE_DIRS})
529 list(APPEND ORTHANC_FRAMEWORK_LIBRARIES ${Boost_LIBRARIES})
530
531 # Optional component - Lua
532 if (ENABLE_LUA OR
533 NOT ORTHANC_FRAMEWORK_USE_SHARED)
534 include(FindLua)
535
536 if (NOT LUA_FOUND)
537 message(FATAL_ERROR "Please install the liblua-dev package")
538 endif()
539
540 include_directories(${LUA_INCLUDE_DIR})
541 list(APPEND ORTHANC_FRAMEWORK_LIBRARIES ${LUA_LIBRARIES})
542 endif()
543
544 # Optional component - SQLite
545 if (ENABLE_SQLITE OR
546 NOT ORTHANC_FRAMEWORK_USE_SHARED)
547 CHECK_INCLUDE_FILE(sqlite3.h HAVE_SQLITE_H)
548 if (NOT HAVE_SQLITE_H)
549 message(FATAL_ERROR "Please install the libsqlite3-dev package")
550 endif()
551 list(APPEND ORTHANC_FRAMEWORK_LIBRARIES sqlite3)
552 endif()
553
554 # Optional component - Pugixml
555 if (ENABLE_PUGIXML OR
556 NOT ORTHANC_FRAMEWORK_USE_SHARED)
557 CHECK_INCLUDE_FILE_CXX(pugixml.hpp HAVE_PUGIXML_H)
558 if (NOT HAVE_PUGIXML_H)
559 message(FATAL_ERROR "Please install the libpugixml-dev package")
560 endif()
561 list(APPEND ORTHANC_FRAMEWORK_LIBRARIES pugixml)
562 endif()
563
564 # Optional component - DCMTK
565 if (ENABLE_DCMTK OR
566 NOT ORTHANC_FRAMEWORK_USE_SHARED)
567 include(FindDCMTK NO_MODULE)
568 list(APPEND ORTHANC_FRAMEWORK_LIBRARIES ${DCMTK_LIBRARIES})
569 include_directories(${DCMTK_INCLUDE_DIRS})
570 endif()
571
572 # Optional component - OpenSSL
573 if (ENABLE_SSL OR
574 NOT ORTHANC_FRAMEWORK_USE_SHARED)
575 include(FindOpenSSL)
576 if (NOT ${OPENSSL_FOUND})
577 message(FATAL_ERROR "Unable to find OpenSSL")
578 endif()
579 include_directories(${OPENSSL_INCLUDE_DIR})
580 list(APPEND ORTHANC_FRAMEWORK_LIBRARIES ${OPENSSL_LIBRARIES})
581 endif()
582 endif() 522 endif()
583 523
584 # Look for Orthanc framework shared library 524 # Look for Orthanc framework shared library
585 include(CheckCXXSymbolExists) 525 include(CheckCXXSymbolExists)
586 526
599 endif() 539 endif()
600 540
601 message("Orthanc framework include dir: ${ORTHANC_FRAMEWORK_INCLUDE_DIR}") 541 message("Orthanc framework include dir: ${ORTHANC_FRAMEWORK_INCLUDE_DIR}")
602 include_directories(${ORTHANC_FRAMEWORK_INCLUDE_DIR}) 542 include_directories(${ORTHANC_FRAMEWORK_INCLUDE_DIR})
603 543
604 set(CMAKE_REQUIRED_INCLUDES "${ORTHANC_FRAMEWORK_INCLUDE_DIR}") 544 if (ORTHANC_FRAMEWORK_USE_SHARED)
605 set(CMAKE_REQUIRED_LIBRARIES "${ORTHANC_FRAMEWORK_LIBRARIES}") 545 set(CMAKE_REQUIRED_INCLUDES "${ORTHANC_FRAMEWORK_INCLUDE_DIR}")
606 546 set(CMAKE_REQUIRED_LIBRARIES "${ORTHANC_FRAMEWORK_LIBRARIES}")
607 check_cxx_symbol_exists("Orthanc::InitializeFramework" "OrthancFramework.h" HAVE_ORTHANC_FRAMEWORK) 547
608 if (NOT HAVE_ORTHANC_FRAMEWORK) 548 check_cxx_symbol_exists("Orthanc::InitializeFramework" "OrthancFramework.h" HAVE_ORTHANC_FRAMEWORK)
609 message(FATAL_ERROR "Cannot find the Orthanc framework") 549 if (NOT HAVE_ORTHANC_FRAMEWORK)
610 endif() 550 message(FATAL_ERROR "Cannot find the Orthanc framework")
611 551 endif()
612 unset(CMAKE_REQUIRED_INCLUDES) 552
613 unset(CMAKE_REQUIRED_LIBRARIES) 553 unset(CMAKE_REQUIRED_INCLUDES)
614 endif() 554 unset(CMAKE_REQUIRED_LIBRARIES)
555 endif()
556 endif()