Mercurial > hg > orthanc
comparison OrthancFramework/Resources/CMake/DownloadOrthancFramework.cmake @ 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 | c638dd444de0 |
comparison
equal
deleted
inserted
replaced
4534:d9700b9f4ad9 | 4535:c40c1234a696 |
---|---|
429 ## | 429 ## |
430 | 430 |
431 if (ORTHANC_FRAMEWORK_SOURCE STREQUAL "system") | 431 if (ORTHANC_FRAMEWORK_SOURCE STREQUAL "system") |
432 set(ORTHANC_FRAMEWORK_LIBDIR "" CACHE PATH "") | 432 set(ORTHANC_FRAMEWORK_LIBDIR "" CACHE PATH "") |
433 set(ORTHANC_FRAMEWORK_USE_SHARED ON CACHE BOOL "Whether to use the shared library or the static library") | 433 set(ORTHANC_FRAMEWORK_USE_SHARED ON CACHE BOOL "Whether to use the shared library or the static library") |
434 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\")") | 434 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\")") |
435 | 435 |
436 if (CMAKE_SYSTEM_NAME STREQUAL "Windows" AND | 436 if (CMAKE_SYSTEM_NAME STREQUAL "Windows" AND |
437 CMAKE_COMPILER_IS_GNUCXX) # MinGW | 437 CMAKE_COMPILER_IS_GNUCXX) # MinGW |
438 set(DYNAMIC_MINGW_STDLIB ON) # Disable static linking against libc (to throw exceptions) | 438 set(DYNAMIC_MINGW_STDLIB ON) # Disable static linking against libc (to throw exceptions) |
439 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libstdc++") | 439 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libstdc++") |
446 include(${CMAKE_CURRENT_LIST_DIR}/Compiler.cmake) | 446 include(${CMAKE_CURRENT_LIST_DIR}/Compiler.cmake) |
447 include(${CMAKE_CURRENT_LIST_DIR}/DownloadPackage.cmake) | 447 include(${CMAKE_CURRENT_LIST_DIR}/DownloadPackage.cmake) |
448 include(${CMAKE_CURRENT_LIST_DIR}/AutoGeneratedCode.cmake) | 448 include(${CMAKE_CURRENT_LIST_DIR}/AutoGeneratedCode.cmake) |
449 set(EMBED_RESOURCES_PYTHON ${CMAKE_CURRENT_LIST_DIR}/EmbedResources.py) | 449 set(EMBED_RESOURCES_PYTHON ${CMAKE_CURRENT_LIST_DIR}/EmbedResources.py) |
450 | 450 |
451 if (ORTHANC_FRAMEWORK_USE_SHARED) | |
452 list(GET CMAKE_FIND_LIBRARY_PREFIXES 0 Prefix) | |
453 list(GET CMAKE_FIND_LIBRARY_SUFFIXES 0 Suffix) | |
454 else() | |
455 list(GET CMAKE_FIND_LIBRARY_PREFIXES 0 Prefix) | |
456 list(GET CMAKE_FIND_LIBRARY_SUFFIXES 1 Suffix) | |
457 endif() | |
458 | |
451 # The "OrthancFramework" library must be the first one to be included | 459 # The "OrthancFramework" library must be the first one to be included |
452 if ("${ORTHANC_FRAMEWORK_LIBDIR}" STREQUAL "") | 460 if ("${ORTHANC_FRAMEWORK_LIBDIR}" STREQUAL "") |
453 set(ORTHANC_FRAMEWORK_LIBRARIES OrthancFramework) | 461 set(ORTHANC_FRAMEWORK_LIBRARIES ${Prefix}OrthancFramework${Suffix}) |
454 else() | 462 else () |
455 if(ORTHANC_FRAMEWORK_USE_SHARED) | 463 set(ORTHANC_FRAMEWORK_LIBRARIES ${ORTHANC_FRAMEWORK_LIBDIR}/${Prefix}OrthancFramework${Suffix}) |
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 set(ORTHANC_FRAMEWORK_LIBRARIES | |
463 ${ORTHANC_FRAMEWORK_LIBDIR}/${Prefix}OrthancFramework${Suffix}) | |
464 endif() | 464 endif() |
465 | 465 |
466 if (NOT ORTHANC_FRAMEWORK_ADDITIONAL_LIBRARIES STREQUAL "") | 466 if (NOT ORTHANC_FRAMEWORK_ADDITIONAL_LIBRARIES STREQUAL "") |
467 # https://stackoverflow.com/a/5272993/881731 | 467 # https://stackoverflow.com/a/5272993/881731 |
468 string(REPLACE " " ";" tmp ${ORTHANC_FRAMEWORK_ADDITIONAL_LIBRARIES}) | 468 string(REPLACE " " ";" tmp ${ORTHANC_FRAMEWORK_ADDITIONAL_LIBRARIES}) |
469 list(APPEND ORTHANC_FRAMEWORK_LIBRARIES ${tmp}) | 469 list(APPEND ORTHANC_FRAMEWORK_LIBRARIES ${tmp}) |
470 endif() | 470 endif() |
471 | 471 |
472 if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows" OR | 472 # Look for the version of the mandatory dependency JsonCpp (cf. JsonCppConfiguration.cmake) |
473 ORTHANC_FRAMEWORK_STATIC) | 473 if (CMAKE_CROSSCOMPILING) |
474 include_directories(${ORTHANC_FRAMEWORK_ROOT}/..) | 474 set(JSONCPP_INCLUDE_DIR ${ORTHANC_FRAMEWORK_ROOT}/..) |
475 else() | 475 else() |
476 # Look for mandatory dependency JsonCpp (cf. JsonCppConfiguration.cmake) | |
477 find_path(JSONCPP_INCLUDE_DIR json/reader.h | 476 find_path(JSONCPP_INCLUDE_DIR json/reader.h |
477 ${ORTHANC_FRAMEWORK_ROOT}/.. | |
478 /usr/include/jsoncpp | 478 /usr/include/jsoncpp |
479 /usr/local/include/jsoncpp | 479 /usr/local/include/jsoncpp |
480 ) | 480 ) |
481 | 481 endif() |
482 message("JsonCpp include dir: ${JSONCPP_INCLUDE_DIR}") | 482 |
483 include_directories(${JSONCPP_INCLUDE_DIR}) | 483 message("JsonCpp include dir: ${JSONCPP_INCLUDE_DIR}") |
484 list(APPEND ORTHANC_FRAMEWORK_LIBRARIES jsoncpp) | 484 include_directories(${JSONCPP_INCLUDE_DIR}) |
485 | 485 |
486 CHECK_INCLUDE_FILE_CXX(${JSONCPP_INCLUDE_DIR}/json/reader.h HAVE_JSONCPP_H) | 486 CHECK_INCLUDE_FILE_CXX(${JSONCPP_INCLUDE_DIR}/json/reader.h HAVE_JSONCPP_H) |
487 if (NOT HAVE_JSONCPP_H) | 487 if (NOT HAVE_JSONCPP_H) |
488 message(FATAL_ERROR "Please install the libjsoncpp-dev package") | 488 message(FATAL_ERROR "Please install the libjsoncpp-dev package") |
489 endif() | 489 endif() |
490 | 490 |
491 # Switch to the C++11 standard if the version of JsonCpp is 1.y.z | 491 # Switch to the C++11 standard if the version of JsonCpp is 1.y.z |
492 # (same as variable JSONCPP_CXX11 in the source code of Orthanc) | 492 # (same as variable JSONCPP_CXX11 in the source code of Orthanc) |
493 if (EXISTS ${JSONCPP_INCLUDE_DIR}/json/version.h) | 493 if (EXISTS ${JSONCPP_INCLUDE_DIR}/json/version.h) |
494 file(STRINGS | 494 file(STRINGS |
495 "${JSONCPP_INCLUDE_DIR}/json/version.h" | 495 "${JSONCPP_INCLUDE_DIR}/json/version.h" |
496 JSONCPP_VERSION_MAJOR1 REGEX | 496 JSONCPP_VERSION_MAJOR1 REGEX |
497 ".*define JSONCPP_VERSION_MAJOR.*") | 497 ".*define JSONCPP_VERSION_MAJOR.*") |
498 | 498 |
499 if (NOT JSONCPP_VERSION_MAJOR1) | 499 if (NOT JSONCPP_VERSION_MAJOR1) |
500 message(FATAL_ERROR "Unable to extract the major version of JsonCpp") | 500 message(FATAL_ERROR "Unable to extract the major version of JsonCpp") |
501 endif() | |
502 | |
503 string(REGEX REPLACE | |
504 ".*JSONCPP_VERSION_MAJOR.*([0-9]+)$" "\\1" | |
505 JSONCPP_VERSION_MAJOR ${JSONCPP_VERSION_MAJOR1}) | |
506 message("JsonCpp major version: ${JSONCPP_VERSION_MAJOR}") | |
507 | |
508 if (JSONCPP_VERSION_MAJOR GREATER 0) | |
509 message("Switching to C++11 standard, as version of JsonCpp is >= 1.0.0") | |
510 if (CMAKE_COMPILER_IS_GNUCXX) | |
511 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11") | |
512 elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") | |
513 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") | |
501 endif() | 514 endif() |
502 | 515 endif() |
503 string(REGEX REPLACE | 516 else() |
504 ".*JSONCPP_VERSION_MAJOR.*([0-9]+)$" "\\1" | 517 message("Unable to detect the major version of JsonCpp, assuming < 1.0.0") |
505 JSONCPP_VERSION_MAJOR ${JSONCPP_VERSION_MAJOR1}) | |
506 message("JsonCpp major version: ${JSONCPP_VERSION_MAJOR}") | |
507 | |
508 if (JSONCPP_VERSION_MAJOR GREATER 0) | |
509 message("Switching to C++11 standard, as version of JsonCpp is >= 1.0.0") | |
510 if (CMAKE_COMPILER_IS_GNUCXX) | |
511 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11") | |
512 elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") | |
513 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") | |
514 endif() | |
515 endif() | |
516 else() | |
517 message("Unable to detect the major version of JsonCpp, assuming < 1.0.0") | |
518 endif() | |
519 | |
520 # Look for mandatory dependency Boost (cf. BoostConfiguration.cmake) | |
521 # NB: "locale" and "iostreams" are not required if using the shared library | |
522 include(FindBoost) | |
523 find_package(Boost COMPONENTS filesystem thread system date_time | |
524 iostreams locale regex ${ORTHANC_BOOST_COMPONENTS}) | |
525 | |
526 if (NOT Boost_FOUND) | |
527 message(FATAL_ERROR "Unable to locate Boost on this system") | |
528 endif() | |
529 | |
530 include_directories(${Boost_INCLUDE_DIRS}) | |
531 list(APPEND ORTHANC_FRAMEWORK_LIBRARIES ${Boost_LIBRARIES}) | |
532 | |
533 # Optional component - Lua | |
534 if (ENABLE_LUA OR | |
535 NOT ORTHANC_FRAMEWORK_USE_SHARED) | |
536 include(FindLua) | |
537 | |
538 if (NOT LUA_FOUND) | |
539 message(FATAL_ERROR "Please install the liblua-dev package") | |
540 endif() | |
541 | |
542 include_directories(${LUA_INCLUDE_DIR}) | |
543 list(APPEND ORTHANC_FRAMEWORK_LIBRARIES ${LUA_LIBRARIES}) | |
544 endif() | |
545 | |
546 # Optional component - SQLite | |
547 if (ENABLE_SQLITE OR | |
548 NOT ORTHANC_FRAMEWORK_USE_SHARED) | |
549 CHECK_INCLUDE_FILE(sqlite3.h HAVE_SQLITE_H) | |
550 if (NOT HAVE_SQLITE_H) | |
551 message(FATAL_ERROR "Please install the libsqlite3-dev package") | |
552 endif() | |
553 list(APPEND ORTHANC_FRAMEWORK_LIBRARIES sqlite3) | |
554 endif() | |
555 | |
556 # Optional component - Pugixml | |
557 if (ENABLE_PUGIXML OR | |
558 NOT ORTHANC_FRAMEWORK_USE_SHARED) | |
559 CHECK_INCLUDE_FILE_CXX(pugixml.hpp HAVE_PUGIXML_H) | |
560 if (NOT HAVE_PUGIXML_H) | |
561 message(FATAL_ERROR "Please install the libpugixml-dev package") | |
562 endif() | |
563 list(APPEND ORTHANC_FRAMEWORK_LIBRARIES pugixml) | |
564 endif() | |
565 | |
566 # Optional component - DCMTK | |
567 if (ENABLE_DCMTK OR | |
568 NOT ORTHANC_FRAMEWORK_USE_SHARED) | |
569 include(FindDCMTK NO_MODULE) | |
570 list(APPEND ORTHANC_FRAMEWORK_LIBRARIES ${DCMTK_LIBRARIES}) | |
571 include_directories(${DCMTK_INCLUDE_DIRS}) | |
572 endif() | |
573 | |
574 # Optional component - OpenSSL | |
575 if (ENABLE_SSL OR | |
576 NOT ORTHANC_FRAMEWORK_USE_SHARED) | |
577 include(FindOpenSSL) | |
578 if (NOT ${OPENSSL_FOUND}) | |
579 message(FATAL_ERROR "Unable to find OpenSSL") | |
580 endif() | |
581 include_directories(${OPENSSL_INCLUDE_DIR}) | |
582 list(APPEND ORTHANC_FRAMEWORK_LIBRARIES ${OPENSSL_LIBRARIES}) | |
583 endif() | |
584 endif() | 518 endif() |
585 | 519 |
586 # Look for Orthanc framework shared library | 520 # Look for Orthanc framework shared library |
587 include(CheckCXXSymbolExists) | 521 include(CheckCXXSymbolExists) |
588 | 522 |
601 endif() | 535 endif() |
602 | 536 |
603 message("Orthanc framework include dir: ${ORTHANC_FRAMEWORK_INCLUDE_DIR}") | 537 message("Orthanc framework include dir: ${ORTHANC_FRAMEWORK_INCLUDE_DIR}") |
604 include_directories(${ORTHANC_FRAMEWORK_INCLUDE_DIR}) | 538 include_directories(${ORTHANC_FRAMEWORK_INCLUDE_DIR}) |
605 | 539 |
606 set(CMAKE_REQUIRED_INCLUDES "${ORTHANC_FRAMEWORK_INCLUDE_DIR}") | 540 if (ORTHANC_FRAMEWORK_USE_SHARED) |
607 set(CMAKE_REQUIRED_LIBRARIES "${ORTHANC_FRAMEWORK_LIBRARIES}") | 541 set(CMAKE_REQUIRED_INCLUDES "${ORTHANC_FRAMEWORK_INCLUDE_DIR}") |
608 | 542 set(CMAKE_REQUIRED_LIBRARIES "${ORTHANC_FRAMEWORK_LIBRARIES}") |
609 check_cxx_symbol_exists("Orthanc::InitializeFramework" "OrthancFramework.h" HAVE_ORTHANC_FRAMEWORK) | 543 |
610 if (NOT HAVE_ORTHANC_FRAMEWORK) | 544 check_cxx_symbol_exists("Orthanc::InitializeFramework" "OrthancFramework.h" HAVE_ORTHANC_FRAMEWORK) |
611 message(FATAL_ERROR "Cannot find the Orthanc framework") | 545 if (NOT HAVE_ORTHANC_FRAMEWORK) |
612 endif() | 546 message(FATAL_ERROR "Cannot find the Orthanc framework") |
613 | 547 endif() |
614 unset(CMAKE_REQUIRED_INCLUDES) | 548 |
615 unset(CMAKE_REQUIRED_LIBRARIES) | 549 unset(CMAKE_REQUIRED_INCLUDES) |
616 endif() | 550 unset(CMAKE_REQUIRED_LIBRARIES) |
551 endif() | |
552 endif() |