view ViewerPlugin/CMakeLists.txt @ 95:8dfc5bbf80f5 OrthancWSI-0.3

set version
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 23 Dec 2016 17:06:27 +0100
parents 4b0e0f7c9957
children a3e8ac8b7256
line wrap: on
line source

cmake_minimum_required(VERSION 2.8)
project(OrthancWSIPlugin)


#####################################################################
## 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")

# 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_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_OPENJPEG ON CACHE BOOL "Use the system version of OpenJpeg")
SET(USE_SYSTEM_ZLIB ON CACHE BOOL "Use the system version of ZLib")
SET(USE_SYSTEM_ORTHANC_SDK ON CACHE BOOL "Use the system version of the Orthanc plugin SDK")

# Parameters related to OpenLayers
SET(USE_SYSTEM_OPENLAYERS OFF CACHE BOOL "Use the system version of OpenLayers")
SET(OPENLAYERS_CSS "" CACHE FILEPATH "Path to the system version of OpenLayers CSS")
SET(OPENLAYERS_JS "" CACHE FILEPATH "Path to the system version of OpenLayers JavaScript")


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

SET(ORTHANC_WSI_DIR ${CMAKE_CURRENT_LIST_DIR}/..)
SET(ORTHANC_ROOT ${ORTHANC_WSI_DIR}/Resources/Orthanc)

SET(USE_OPENJPEG_JP2 ON)

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

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

# Third-party components shipped with Orthanc
include(${ORTHANC_ROOT}/Resources/CMake/BoostConfiguration.cmake)
include(${ORTHANC_ROOT}/Resources/CMake/JsonCppConfiguration.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/OpenJpegConfiguration.cmake)

add_definitions(
  -DORTHANC_ENABLE_BASE64=0
  -DORTHANC_ENABLE_CURL=0
  -DORTHANC_ENABLE_DCMTK=0
  -DORTHANC_ENABLE_LOGGING=1
  -DORTHANC_ENABLE_LOGGING_PLUGIN=1
  -DORTHANC_ENABLE_MD5=0
  -DORTHANC_ENABLE_PUGIXML=0
  -DORTHANC_SANDBOXED=0
  -DHAS_ORTHANC_EXCEPTION=1
  )


#####################################################################
## Find the Orthanc SDK
#####################################################################

if (STATIC_BUILD OR NOT USE_SYSTEM_ORTHANC_SDK)
  include_directories(${ORTHANC_ROOT}/Sdk-1.0.0)
else ()
  CHECK_INCLUDE_FILE_CXX(orthanc/OrthancCPlugin.h HAVE_ORTHANC_H)
  if (NOT HAVE_ORTHANC_H)
    message(FATAL_ERROR "Please install the headers of the Orthanc plugins SDK")
  endif()
endif()


#####################################################################
## Platform-specific configuration
#####################################################################

if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux" OR
    ${CMAKE_SYSTEM_NAME} STREQUAL "kFreeBSD" OR
    ${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD")
  link_libraries(rt)

elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
  execute_process(
    COMMAND 
    ${PYTHON_EXECUTABLE} ${ORTHANC_ROOT}/Resources/WindowsResources.py
    ${ORTHANC_WSI_VERSION} "OrthancWSI" OrthancWSI.dll "Whole-slide imaging plugin for Orthanc"
    ERROR_VARIABLE Failure
    OUTPUT_FILE ${AUTOGENERATED_DIR}/Version.rc
    )

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

  list(APPEND AUTOGENERATED_SOURCES  ${AUTOGENERATED_DIR}/Version.rc)
endif()

if (APPLE)
  SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -framework CoreFoundation")
  SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -framework CoreFoundation")
endif()


#####################################################################
## Prepare OpenLayers
#####################################################################

if (STATIC_BUILD OR NOT USE_SYSTEM_OPENLAYERS)
  DownloadPackage(
    "77e57aad873c2d4deea8bb1446e9b87a"
    "http://www.orthanc-server.com/downloads/third-party/WSI/openlayers-3.19.0-dist.zip"
    "v3.19.0-dist")
  
  set(OPENLAYERS_RESOURCES
    OPENLAYERS_CSS  ${CMAKE_CURRENT_BINARY_DIR}/v3.19.0-dist/ol.css
    OPENLAYERS_JS   ${CMAKE_CURRENT_BINARY_DIR}/v3.19.0-dist/ol.js
    )

else()
  if (OPENLAYERS_CSS STREQUAL "")
    message(FATAL_ERROR "The option OPENLAYERS_CSS is not set")
  endif()

  if (OPENLAYERS_JS STREQUAL "")
    message(FATAL_ERROR "The option OPENLAYERS_JS is not set")
  endif()

  set(OPENLAYERS_RESOURCES
    OPENLAYERS_CSS  ${OPENLAYERS_CSS}
    OPENLAYERS_JS   ${OPENLAYERS_JS}
    )  
endif()

EmbedResources(
  ${OPENLAYERS_RESOURCES}
  ORTHANC_EXPLORER  ${CMAKE_SOURCE_DIR}/OrthancExplorer.js
  VIEWER_HTML       ${CMAKE_SOURCE_DIR}/viewer.html
  VIEWER_JS         ${CMAKE_SOURCE_DIR}/viewer.js
  )


#####################################################################
## Create the list of the source files that depend upon the
## precompiled headers
#####################################################################

set(ORTHANC_WSI_SOURCES
  DicomPyramidCache.cpp
  Plugin.cpp
  ${ORTHANC_WSI_DIR}/Framework/DicomToolbox.cpp
  ${ORTHANC_WSI_DIR}/Framework/Enumerations.cpp
  ${ORTHANC_WSI_DIR}/Framework/ImageToolbox.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/PyramidWithRawTiles.cpp
  ${ORTHANC_WSI_DIR}/Framework/Jpeg2000Reader.cpp
  ${ORTHANC_WSI_DIR}/Framework/Jpeg2000Writer.cpp
  )

set(ORTHANC_CORE_SOURCES
  ${ORTHANC_ROOT}/Core/ChunkedBuffer.cpp
  ${ORTHANC_ROOT}/Core/Enumerations.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/Semaphore.cpp
  ${ORTHANC_ROOT}/Core/SystemToolbox.cpp
  ${ORTHANC_ROOT}/Core/Toolbox.cpp
  ${ORTHANC_ROOT}/Plugins/Samples/Common/DicomDatasetReader.cpp
  ${ORTHANC_ROOT}/Plugins/Samples/Common/DicomPath.cpp
  ${ORTHANC_ROOT}/Plugins/Samples/Common/FullOrthancDataset.cpp
  ${ORTHANC_ROOT}/Plugins/Samples/Common/IOrthancConnection.cpp
  ${ORTHANC_ROOT}/Plugins/Samples/Common/OrthancPluginConnection.cpp
  ${ORTHANC_ROOT}/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp
  )


#####################################################################
## Setup precompiled headers for Microsoft Visual Studio
#####################################################################

if (MSVC)
  add_definitions(-DORTHANC_USE_PRECOMPILED_HEADERS=1)

  ADD_VISUAL_STUDIO_PRECOMPILED_HEADERS(
    "PrecompiledHeaders.h" "${ORTHANC_WSI_DIR}/Resources/Orthanc/Core/PrecompiledHeaders.cpp" ORTHANC_CORE_SOURCES)

  ADD_VISUAL_STUDIO_PRECOMPILED_HEADERS(
    "PrecompiledHeadersWSI.h" "${ORTHANC_WSI_DIR}/Framework/PrecompiledHeadersWSI.cpp" ORTHANC_WSI_SOURCES)

  source_group(ThirdParty\\OrthancCore FILES ${ORTHANC_CORE_SOURCES})
endif()


#####################################################################
## Create the plugin
#####################################################################

add_library(OrthancWSI SHARED
  ${ORTHANC_CORE_SOURCES}
  ${ORTHANC_WSI_SOURCES}
  ${AUTOGENERATED_SOURCES}

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

message("Setting the version of the library to ${ORTHANC_WSI_VERSION}")
set_target_properties(OrthancWSI PROPERTIES 
  VERSION ${ORTHANC_WSI_VERSION} 
  SOVERSION ${ORTHANC_WSI_VERSION})

install(
  TARGETS OrthancWSI
  RUNTIME DESTINATION lib    # Destination for Windows
  LIBRARY DESTINATION share/orthanc/plugins    # Destination for Linux
  )