comparison OrthancFramework/Resources/CMake/DownloadOrthancFramework.cmake @ 4496:9ea70ccf0c21

Possibility to generate a static library containing the Orthanc Framework
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 08 Feb 2021 18:34:40 +0100
parents cf44052fdf60
children e40148c916b8
comparison
equal deleted inserted replaced
4495:fa2311f94d9f 4496:9ea70ccf0c21
426 ## GNU/Linux distribution (typically Debian). New in Orthanc 1.7.2. 426 ## GNU/Linux distribution (typically Debian). New in Orthanc 1.7.2.
427 ## 427 ##
428 428
429 if (ORTHANC_FRAMEWORK_SOURCE STREQUAL "system") 429 if (ORTHANC_FRAMEWORK_SOURCE STREQUAL "system")
430 set(ORTHANC_FRAMEWORK_LIBDIR "" CACHE PATH "") 430 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")
431 432
432 if (CMAKE_SYSTEM_NAME STREQUAL "Windows" AND 433 if (CMAKE_SYSTEM_NAME STREQUAL "Windows" AND
433 CMAKE_COMPILER_IS_GNUCXX) # MinGW 434 CMAKE_COMPILER_IS_GNUCXX) # MinGW
434 set(DYNAMIC_MINGW_STDLIB ON) # Disable static linking against libc (to throw exceptions) 435 set(DYNAMIC_MINGW_STDLIB ON) # Disable static linking against libc (to throw exceptions)
435 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libstdc++") 436 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libstdc++")
442 include(${CMAKE_CURRENT_LIST_DIR}/Compiler.cmake) 443 include(${CMAKE_CURRENT_LIST_DIR}/Compiler.cmake)
443 include(${CMAKE_CURRENT_LIST_DIR}/DownloadPackage.cmake) 444 include(${CMAKE_CURRENT_LIST_DIR}/DownloadPackage.cmake)
444 include(${CMAKE_CURRENT_LIST_DIR}/AutoGeneratedCode.cmake) 445 include(${CMAKE_CURRENT_LIST_DIR}/AutoGeneratedCode.cmake)
445 set(EMBED_RESOURCES_PYTHON ${CMAKE_CURRENT_LIST_DIR}/EmbedResources.py) 446 set(EMBED_RESOURCES_PYTHON ${CMAKE_CURRENT_LIST_DIR}/EmbedResources.py)
446 447
448 # The "OrthancFramework" library must be the first one to be included
449 if ("${ORTHANC_FRAMEWORK_LIBDIR}" STREQUAL "")
450 set(ORTHANC_FRAMEWORK_LIBRARIES OrthancFramework)
451 else()
452 if(ORTHANC_FRAMEWORK_USE_SHARED)
453 list(GET CMAKE_FIND_LIBRARY_PREFIXES 0 Prefix)
454 list(GET CMAKE_FIND_LIBRARY_SUFFIXES 0 Suffix)
455 else()
456 list(GET CMAKE_FIND_LIBRARY_PREFIXES 0 Prefix)
457 list(GET CMAKE_FIND_LIBRARY_SUFFIXES 1 Suffix)
458 endif()
459 set(ORTHANC_FRAMEWORK_LIBRARIES
460 ${ORTHANC_FRAMEWORK_LIBDIR}/${Prefix}OrthancFramework${Suffix})
461 endif()
462
447 if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows" OR 463 if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows" OR
448 ORTHANC_FRAMEWORK_STATIC) 464 ORTHANC_FRAMEWORK_STATIC)
449 include_directories(${ORTHANC_FRAMEWORK_ROOT}/..) 465 include_directories(${ORTHANC_FRAMEWORK_ROOT}/..)
450 else() 466 else()
451 # Look for mandatory dependency JsonCpp (cf. JsonCppConfiguration.cmake) 467 # Look for mandatory dependency JsonCpp (cf. JsonCppConfiguration.cmake)
454 /usr/local/include/jsoncpp 470 /usr/local/include/jsoncpp
455 ) 471 )
456 472
457 message("JsonCpp include dir: ${JSONCPP_INCLUDE_DIR}") 473 message("JsonCpp include dir: ${JSONCPP_INCLUDE_DIR}")
458 include_directories(${JSONCPP_INCLUDE_DIR}) 474 include_directories(${JSONCPP_INCLUDE_DIR})
459 link_libraries(jsoncpp) 475 list(APPEND ORTHANC_FRAMEWORK_LIBRARIES jsoncpp)
460 476
461 CHECK_INCLUDE_FILE_CXX(${JSONCPP_INCLUDE_DIR}/json/reader.h HAVE_JSONCPP_H) 477 CHECK_INCLUDE_FILE_CXX(${JSONCPP_INCLUDE_DIR}/json/reader.h HAVE_JSONCPP_H)
462 if (NOT HAVE_JSONCPP_H) 478 if (NOT HAVE_JSONCPP_H)
463 message(FATAL_ERROR "Please install the libjsoncpp-dev package") 479 message(FATAL_ERROR "Please install the libjsoncpp-dev package")
464 endif() 480 endif()
491 else() 507 else()
492 message("Unable to detect the major version of JsonCpp, assuming < 1.0.0") 508 message("Unable to detect the major version of JsonCpp, assuming < 1.0.0")
493 endif() 509 endif()
494 510
495 # Look for mandatory dependency Boost (cf. BoostConfiguration.cmake) 511 # Look for mandatory dependency Boost (cf. BoostConfiguration.cmake)
512 # NB: "locale" and "iostreams" are not required if using the shared library
496 include(FindBoost) 513 include(FindBoost)
497 find_package(Boost COMPONENTS filesystem thread system date_time regex ${ORTHANC_BOOST_COMPONENTS}) 514 find_package(Boost COMPONENTS filesystem thread system date_time
515 iostreams locale regex ${ORTHANC_BOOST_COMPONENTS})
498 516
499 if (NOT Boost_FOUND) 517 if (NOT Boost_FOUND)
500 message(FATAL_ERROR "Unable to locate Boost on this system") 518 message(FATAL_ERROR "Unable to locate Boost on this system")
501 endif() 519 endif()
502 520
503 include_directories(${Boost_INCLUDE_DIRS}) 521 include_directories(${Boost_INCLUDE_DIRS})
504 link_libraries(${Boost_LIBRARIES}) 522 list(APPEND ORTHANC_FRAMEWORK_LIBRARIES ${Boost_LIBRARIES})
505 523
506 # Optional component - Lua 524 # Optional component - Lua
507 if (ENABLE_LUA) 525 if (ENABLE_LUA)
508 include(FindLua) 526 include(FindLua)
509 527
510 if (NOT LUA_FOUND) 528 if (NOT LUA_FOUND)
511 message(FATAL_ERROR "Please install the liblua-dev package") 529 message(FATAL_ERROR "Please install the liblua-dev package")
512 endif() 530 endif()
513 531
514 include_directories(${LUA_INCLUDE_DIR}) 532 include_directories(${LUA_INCLUDE_DIR})
515 link_libraries(${LUA_LIBRARIES}) 533 list(APPEND ORTHANC_FRAMEWORK_LIBRARIES ${LUA_LIBRARIES})
516 endif() 534 endif()
517 535
518 # Optional component - SQLite 536 # Optional component - SQLite
519 if (ENABLE_SQLITE) 537 if (ENABLE_SQLITE)
520 CHECK_INCLUDE_FILE(sqlite3.h HAVE_SQLITE_H) 538 CHECK_INCLUDE_FILE(sqlite3.h HAVE_SQLITE_H)
521 if (NOT HAVE_SQLITE_H) 539 if (NOT HAVE_SQLITE_H)
522 message(FATAL_ERROR "Please install the libsqlite3-dev package") 540 message(FATAL_ERROR "Please install the libsqlite3-dev package")
523 endif() 541 endif()
524 link_libraries(sqlite3) 542 list(APPEND ORTHANC_FRAMEWORK_LIBRARIES sqlite3)
525 endif() 543 endif()
526 544
527 # Optional component - Pugixml 545 # Optional component - Pugixml
528 if (ENABLE_PUGIXML) 546 if (ENABLE_PUGIXML)
529 CHECK_INCLUDE_FILE_CXX(pugixml.hpp HAVE_PUGIXML_H) 547 CHECK_INCLUDE_FILE_CXX(pugixml.hpp HAVE_PUGIXML_H)
530 if (NOT HAVE_PUGIXML_H) 548 if (NOT HAVE_PUGIXML_H)
531 message(FATAL_ERROR "Please install the libpugixml-dev package") 549 message(FATAL_ERROR "Please install the libpugixml-dev package")
532 endif() 550 endif()
533 link_libraries(pugixml) 551 list(APPEND ORTHANC_FRAMEWORK_LIBRARIES pugixml)
534 endif() 552 endif()
535 553
536 # Optional component - DCMTK 554 # Optional component - DCMTK
537 if (ENABLE_DCMTK) 555 if (ENABLE_DCMTK)
538 include(FindDCMTK) 556 include(FindDCMTK NO_MODULE)
557 list(APPEND ORTHANC_FRAMEWORK_LIBRARIES ${DCMTK_LIBRARIES})
539 include_directories(${DCMTK_INCLUDE_DIRS}) 558 include_directories(${DCMTK_INCLUDE_DIRS})
540 link_libraries(${DCMTK_LIBRARIES})
541 endif() 559 endif()
542 560
543 # Optional component - OpenSSL 561 # Optional component - OpenSSL
544 if (ENABLE_SSL) 562 if (ENABLE_SSL)
545 include(FindOpenSSL) 563 include(FindOpenSSL)
546 if (NOT ${OPENSSL_FOUND}) 564 if (NOT ${OPENSSL_FOUND})
547 message(FATAL_ERROR "Unable to find OpenSSL") 565 message(FATAL_ERROR "Unable to find OpenSSL")
548 endif() 566 endif()
549 include_directories(${OPENSSL_INCLUDE_DIR}) 567 include_directories(${OPENSSL_INCLUDE_DIR})
550 link_libraries(${OPENSSL_LIBRARIES}) 568 list(APPEND ORTHANC_FRAMEWORK_LIBRARIES ${OPENSSL_LIBRARIES})
569 endif()
570 endif()
571
572 if (NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "Windows" AND
573 NOT ORTHANC_FRAMEWORK_USE_SHARED)
574 # Static library has more dependencies
575
576 # Mandatory dependency: libuuid
577 CHECK_INCLUDE_FILE(uuid/uuid.h HAVE_UUID_H)
578 if (NOT HAVE_UUID_H)
579 message(FATAL_ERROR "Please install uuid-dev, e2fsprogs (OpenBSD) or e2fsprogs-libuuid (FreeBSD)")
580 endif()
581
582 find_library(LIBUUID uuid
583 PATHS
584 /usr/lib
585 /usr/local/lib
586 )
587
588 check_library_exists(${LIBUUID} uuid_generate_random "" HAVE_LIBUUID)
589 if (NOT HAVE_LIBUUID)
590 message(FATAL_ERROR "Unable to find the uuid library")
591 endif()
592
593 list(APPEND ORTHANC_FRAMEWORK_LIBRARIES ${LIBUUID})
594
595 # Optional component - libcurl
596 if (ENABLE_WEB_CLIENT)
597 include(FindCURL)
598 include_directories(${CURL_INCLUDE_DIRS})
599 list(APPEND ORTHANC_FRAMEWORK_LIBRARIES ${CURL_LIBRARIES})
551 endif() 600 endif()
552 endif() 601 endif()
553 602
554 # Look for Orthanc framework shared library 603 # Look for Orthanc framework shared library
555 include(CheckCXXSymbolExists) 604 include(CheckCXXSymbolExists)
568 message(FATAL_ERROR "Cannot locate the OrthancFramework.h header") 617 message(FATAL_ERROR "Cannot locate the OrthancFramework.h header")
569 endif() 618 endif()
570 619
571 message("Orthanc framework include dir: ${ORTHANC_FRAMEWORK_INCLUDE_DIR}") 620 message("Orthanc framework include dir: ${ORTHANC_FRAMEWORK_INCLUDE_DIR}")
572 include_directories(${ORTHANC_FRAMEWORK_INCLUDE_DIR}) 621 include_directories(${ORTHANC_FRAMEWORK_INCLUDE_DIR})
573
574 if ("${ORTHANC_FRAMEWORK_LIBDIR}" STREQUAL "")
575 set(ORTHANC_FRAMEWORK_LIBRARIES OrthancFramework)
576 else()
577 if (MSVC)
578 set(Suffix ".lib")
579 set(Prefix "")
580 else()
581 list(GET CMAKE_FIND_LIBRARY_PREFIXES 0 Prefix)
582 list(GET CMAKE_FIND_LIBRARY_SUFFIXES 0 Suffix)
583 endif()
584 set(ORTHANC_FRAMEWORK_LIBRARIES ${ORTHANC_FRAMEWORK_LIBDIR}/${Prefix}OrthancFramework${Suffix})
585 endif()
586 622
587 set(CMAKE_REQUIRED_INCLUDES "${ORTHANC_FRAMEWORK_INCLUDE_DIR}") 623 set(CMAKE_REQUIRED_INCLUDES "${ORTHANC_FRAMEWORK_INCLUDE_DIR}")
588 set(CMAKE_REQUIRED_LIBRARIES "${ORTHANC_FRAMEWORK_LIBRARIES}") 624 set(CMAKE_REQUIRED_LIBRARIES "${ORTHANC_FRAMEWORK_LIBRARIES}")
589 625
590 check_cxx_symbol_exists("Orthanc::InitializeFramework" "OrthancFramework.h" HAVE_ORTHANC_FRAMEWORK) 626 check_cxx_symbol_exists("Orthanc::InitializeFramework" "OrthancFramework.h" HAVE_ORTHANC_FRAMEWORK)