view Applications/CMakeLists.txt @ 9:021482366dac

Windows resources for command-line tools
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 26 Oct 2016 17:11:24 +0200
parents 62adabb8c122
children e944d00a8a9e
line wrap: on
line source

cmake_minimum_required(VERSION 2.8)
project(OrthancWSIApplications)


#####################################################################
## Parameters of the build
#####################################################################

# Generic parameters
SET(STATIC_BUILD OFF CACHE BOOL "Static build of the third-party libraries (necessary for Windows)")
SET(ALLOW_DOWNLOADS OFF CACHE BOOL "Allow CMake to download packages")

# Optional components
SET(ENABLE_SSL OFF CACHE BOOL "Include support for SSL")
SET(USE_DCMTK_361 OFF CACHE BOOL "Use forthcoming DCMTK version 3.6.1 in static builds (instead of 3.6.0)")

if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
  set(TMP ON)
else()
  set(TMP OFF)
endif()


# Advanced parameters to fine-tune linking against system libraries
SET(USE_SYSTEM_BOOST ON CACHE BOOL "Use the system version of Boost")
SET(USE_SYSTEM_CURL ON CACHE BOOL "Use the system version of LibCurl")
SET(USE_SYSTEM_DCMTK ON CACHE BOOL "Use the system version of DCMTK")
SET(USE_SYSTEM_JSONCPP ON CACHE BOOL "Use the system version of JsonCpp")
SET(USE_SYSTEM_LIBJPEG ON CACHE BOOL "Use the system version of libjpeg")
SET(USE_SYSTEM_LIBPNG ON CACHE BOOL "Use the system version of libpng")
SET(USE_SYSTEM_LIBTIFF ON CACHE BOOL "Use the system version of libtiff")
SET(USE_SYSTEM_OPENJPEG ON CACHE BOOL "Use the system version of OpenJpeg")
SET(USE_SYSTEM_OPENSSL ON CACHE BOOL "Use the system version of OpenSSL")
SET(USE_SYSTEM_ZLIB ON CACHE BOOL "Use the system version of ZLib")

SET(DCMTK_DICTIONARY_DIR "" CACHE PATH "Directory containing the DCMTK dictionaries \"dicom.dic\" and \"private.dic\" (only when using system version of DCMTK)") 


#####################################################################
## Configure mandatory third-party components
#####################################################################

SET(ORTHANC_WSI_DIR ${CMAKE_CURRENT_LIST_DIR}/..)
SET(ORTHANC_ROOT ${ORTHANC_WSI_DIR}/Framework/Orthanc)
SET(USE_OPENJPEG_JP2 ON)
SET(ENABLE_JPEG OFF)           # Disable DCMTK's support for JPEG, that clashes with libtiff
SET(ENABLE_JPEG_LOSSLESS OFF)  # Disable DCMTK's support for JPEG-LS
SET(ENABLE_DCMTK_NETWORK OFF)  # Disable DCMTK's support for DICOM networking
SET(STANDALONE_BUILD ON)       # Embed DCMTK's dictionaries for static builds

include(CheckIncludeFiles)
include(CheckIncludeFileCXX)
include(CheckLibraryExists)
include(FindPythonInterp)
include(FindPkgConfig)

include(${ORTHANC_ROOT}/Resources/CMake/Compiler.cmake)
include(${ORTHANC_ROOT}/Resources/CMake/AutoGeneratedCode.cmake)
include(${ORTHANC_ROOT}/Resources/CMake/DownloadPackage.cmake)

# Third-party components shipped with Orthanc
include(${ORTHANC_ROOT}/Resources/CMake/DcmtkConfiguration.cmake)
include(${ORTHANC_ROOT}/Resources/CMake/JsonCppConfiguration.cmake)
include(${ORTHANC_ROOT}/Resources/CMake/LibCurlConfiguration.cmake)
include(${ORTHANC_ROOT}/Resources/CMake/LibJpegConfiguration.cmake)
include(${ORTHANC_ROOT}/Resources/CMake/LibPngConfiguration.cmake)
include(${ORTHANC_ROOT}/Resources/CMake/ZlibConfiguration.cmake)

# Include components specific to WSI
include(${ORTHANC_WSI_DIR}/Resources/CMake/Version.cmake)
include(${ORTHANC_WSI_DIR}/Resources/CMake/BoostExtendedConfiguration.cmake)
include(${ORTHANC_WSI_DIR}/Resources/CMake/OpenJpegConfiguration.cmake)
include(${ORTHANC_WSI_DIR}/Resources/CMake/LibTiffConfiguration.cmake)

add_definitions(
  -DORTHANC_ENABLE_BASE64=1
  -DORTHANC_ENABLE_CURL=1
  -DORTHANC_ENABLE_DCMTK=1
  -DORTHANC_ENABLE_LOGGING=1
  -DORTHANC_ENABLE_MD5=0
  -DORTHANC_JPEG_ENABLED=0     # Disable DCMTK's support for JPEG
  -DORTHANC_PKCS11_ENABLED=0
  -DORTHANC_PLUGINS_ENABLED=1  # To enable class Orthanc::SharedLibrary
  -DORTHANC_PUGIXML_ENABLED=0
  )


#####################################################################
## Configure optional third-party components
#####################################################################

if (ENABLE_SSL)
  set(ENABLE_PKCS11 OFF)
  add_definitions(-DORTHANC_SSL_ENABLED=1)
  include(${ORTHANC_ROOT}/Resources/CMake/OpenSslConfiguration.cmake)
else()
  add_definitions(-DORTHANC_SSL_ENABLED=0)
endif()


#####################################################################
## Create the static library containing the framework
#####################################################################

EmbedResources(
  ${DCMTK_DICTIONARIES}
  BRIGHTFIELD_OPTICAL_PATH  ${ORTHANC_WSI_DIR}/Resources/BrightfieldOpticalPath.json
  SAMPLE_DATASET            ${ORTHANC_WSI_DIR}/Resources/SampleDataset.json
  SRGB_ICC_PROFILE          ${ORTHANC_WSI_DIR}/Resources/sRGB.icc
  )


add_library(OrthancWSIFramework STATIC
  #${ORTHANC_WSI_DIR}/Framework/Messaging/PluginOrthancConnection.cpp
  ${ORTHANC_WSI_DIR}/Framework/Algorithms/PyramidReader.cpp
  ${ORTHANC_WSI_DIR}/Framework/Algorithms/ReconstructPyramidCommand.cpp
  ${ORTHANC_WSI_DIR}/Framework/Algorithms/TranscodeTileCommand.cpp
  ${ORTHANC_WSI_DIR}/Framework/DicomToolbox.cpp
  ${ORTHANC_WSI_DIR}/Framework/DicomizerParameters.cpp
  ${ORTHANC_WSI_DIR}/Framework/Enumerations.cpp
  ${ORTHANC_WSI_DIR}/Framework/ImageToolbox.cpp
  ${ORTHANC_WSI_DIR}/Framework/ImagedVolumeParameters.cpp
  ${ORTHANC_WSI_DIR}/Framework/Inputs/DecodedTiledPyramid.cpp
  ${ORTHANC_WSI_DIR}/Framework/Inputs/DicomPyramid.cpp
  ${ORTHANC_WSI_DIR}/Framework/Inputs/DicomPyramidInstance.cpp
  ${ORTHANC_WSI_DIR}/Framework/Inputs/DicomPyramidLevel.cpp
  ${ORTHANC_WSI_DIR}/Framework/Inputs/HierarchicalTiff.cpp
  ${ORTHANC_WSI_DIR}/Framework/Inputs/OpenSlideLibrary.cpp
  ${ORTHANC_WSI_DIR}/Framework/Inputs/OpenSlidePyramid.cpp
  ${ORTHANC_WSI_DIR}/Framework/Inputs/PyramidWithRawTiles.cpp
  ${ORTHANC_WSI_DIR}/Framework/Inputs/SingleLevelDecodedPyramid.cpp
  ${ORTHANC_WSI_DIR}/Framework/Inputs/TiledPyramidStatistics.cpp
  ${ORTHANC_WSI_DIR}/Framework/Jpeg2000Reader.cpp
  ${ORTHANC_WSI_DIR}/Framework/Jpeg2000Writer.cpp
  ${ORTHANC_WSI_DIR}/Framework/Messaging/CurlOrthancConnection.cpp
  ${ORTHANC_WSI_DIR}/Framework/Messaging/FolderTarget.cpp
  ${ORTHANC_WSI_DIR}/Framework/Messaging/IOrthancConnection.cpp
  ${ORTHANC_WSI_DIR}/Framework/Messaging/OrthancConnectionBase.cpp
  ${ORTHANC_WSI_DIR}/Framework/Messaging/OrthancTarget.cpp
  ${ORTHANC_WSI_DIR}/Framework/Outputs/DicomPyramidWriter.cpp
  ${ORTHANC_WSI_DIR}/Framework/Outputs/HierarchicalTiffWriter.cpp
  ${ORTHANC_WSI_DIR}/Framework/Outputs/InMemoryTiledImage.cpp
  ${ORTHANC_WSI_DIR}/Framework/Outputs/MultiframeDicomWriter.cpp
  ${ORTHANC_WSI_DIR}/Framework/Outputs/PyramidWriterBase.cpp
  ${ORTHANC_WSI_DIR}/Framework/Outputs/TruncatedPyramidWriter.cpp

  ${ORTHANC_ROOT}/Core/ChunkedBuffer.cpp
  ${ORTHANC_ROOT}/Core/DicomFormat/DicomArray.cpp
  ${ORTHANC_ROOT}/Core/DicomFormat/DicomMap.cpp
  ${ORTHANC_ROOT}/Core/DicomFormat/DicomTag.cpp
  ${ORTHANC_ROOT}/Core/DicomFormat/DicomValue.cpp
  ${ORTHANC_ROOT}/Core/Enumerations.cpp
  ${ORTHANC_ROOT}/Core/HttpClient.cpp
  ${ORTHANC_ROOT}/Core/Images/IImageWriter.cpp
  ${ORTHANC_ROOT}/Core/Images/Image.cpp
  ${ORTHANC_ROOT}/Core/Images/ImageAccessor.cpp
  ${ORTHANC_ROOT}/Core/Images/ImageBuffer.cpp
  ${ORTHANC_ROOT}/Core/Images/ImageProcessing.cpp
  ${ORTHANC_ROOT}/Core/Images/JpegErrorManager.cpp
  ${ORTHANC_ROOT}/Core/Images/JpegReader.cpp
  ${ORTHANC_ROOT}/Core/Images/JpegWriter.cpp
  ${ORTHANC_ROOT}/Core/Images/PngReader.cpp
  ${ORTHANC_ROOT}/Core/Images/PngWriter.cpp
  ${ORTHANC_ROOT}/Core/Logging.cpp
  ${ORTHANC_ROOT}/Core/MultiThreading/BagOfTasksProcessor.cpp
  ${ORTHANC_ROOT}/Core/MultiThreading/SharedMessageQueue.cpp
  ${ORTHANC_ROOT}/Core/Toolbox.cpp
  ${ORTHANC_ROOT}/Core/Uuid.cpp
  ${ORTHANC_ROOT}/Core/WebServiceParameters.cpp
  ${ORTHANC_ROOT}/OrthancServer/FromDcmtkBridge.cpp
  ${ORTHANC_ROOT}/OrthancServer/ServerEnumerations.cpp
  ${ORTHANC_ROOT}/OrthancServer/ToDcmtkBridge.cpp
  ${ORTHANC_ROOT}/Plugins/Engine/SharedLibrary.cpp
  ${ORTHANC_ROOT}/Resources/ThirdParty/base64/base64.cpp

  # Mandatory components
  ${BOOST_SOURCES}
  ${JSONCPP_SOURCES}
  ${ZLIB_SOURCES}
  ${LIBPNG_SOURCES}
  ${LIBJPEG_SOURCES}
  ${DCMTK_SOURCES}
  ${LIBTIFF_SOURCES}
  ${OPENJPEG_SOURCES}

  # Optional components
  ${OPENSSL_SOURCES}
  ${CURL_SOURCES}

  ${AUTOGENERATED_SOURCES}
  )


#####################################################################
## Build the WSI DICOM-izer
#####################################################################

# Create the Windows resources, if need be
if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
  execute_process(
    COMMAND 
    ${PYTHON_EXECUTABLE} ${ORTHANC_ROOT}/Resources/WindowsResources.py
    ${ORTHANC_WSI_VERSION} OrthancWSIDicomizer OrthancWSIDicomizer.exe "Companion tool to Orthanc for whole-slide imaging"
    ERROR_VARIABLE Failure
    OUTPUT_FILE ${AUTOGENERATED_DIR}/OrthancWSIDicomizer.rc
    )

  if (Failure)
    message(FATAL_ERROR "Error while computing the version information: ${Failure}")
  endif()

  set(DICOMIZER_RESOURCES ${AUTOGENERATED_DIR}/OrthancWSIDicomizer.rc)
endif()


add_executable(OrthancWSIDicomizer
  Dicomizer.cpp
  ApplicationToolbox.cpp
  ${DICOMIZER_RESOURCES}
  )

target_link_libraries(OrthancWSIDicomizer OrthancWSIFramework ${DCMTK_LIBRARIES})

install(
  TARGETS OrthancWSIDicomizer
  RUNTIME DESTINATION bin
  )


#####################################################################
## Build the DICOM-to-TIFF conversion tool
#####################################################################

# Create the Windows resources, if need be
if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
  execute_process(
    COMMAND 
    ${PYTHON_EXECUTABLE} ${ORTHANC_ROOT}/Resources/WindowsResources.py
    ${ORTHANC_WSI_VERSION} OrthancWSIDicomToTiff OrthancWSIDicomToTiff.exe "Companion tool to Orthanc for whole-slide imaging"
    ERROR_VARIABLE Failure
    OUTPUT_FILE ${AUTOGENERATED_DIR}/OrthancWSIDicomToTiff.rc
    )

  if (Failure)
    message(FATAL_ERROR "Error while computing the version information: ${Failure}")
  endif()

  set(DICOM_TO_TIFF_RESOURCES ${AUTOGENERATED_DIR}/OrthancWSIDicomToTiff.rc)
endif()


add_executable(OrthancWSIDicomToTiff
  DicomToTiff.cpp
  ApplicationToolbox.cpp
  ${DICOM_TO_TIFF_RESOURCES}
  )

target_link_libraries(OrthancWSIDicomToTiff OrthancWSIFramework ${DCMTK_LIBRARIES})

install(
  TARGETS OrthancWSIDicomToTiff
  RUNTIME DESTINATION bin
  )


#####################################################################
## Generate the documentation if Doxygen is present
#####################################################################

find_package(Doxygen)
if (DOXYGEN_FOUND)
  configure_file(
    ${ORTHANC_WSI_DIR}/Resources/OrthancWSI.doxygen
    ${CMAKE_CURRENT_BINARY_DIR}/OrthancWSI.doxygen
    @ONLY)

  add_custom_target(doc
    ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/OrthancWSI.doxygen
    COMMENT "Generating documentation with Doxygen" VERBATIM
    )
else()
  message("Doxygen not found. The documentation will not be built.")
endif()