view ViewerPlugin/CMakeLists.txt @ 286:b917f6466730 OrthancWSI-0.7

closing branch OrthancWSI-0.7
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 12 Jul 2023 21:24:12 +0200
parents 030c3729ff0c
children 7bfdc9b3c4d5
line wrap: on
line source

cmake_minimum_required(VERSION 2.8)
project(OrthancWSIPlugin)

include(${CMAKE_SOURCE_DIR}/../Resources/CMake/Version.cmake)


#####################################################################
## 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_OPENJPEG ON CACHE BOOL "Use the system version of OpenJpeg")
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(USE_OPENJPEG_JP2 ON)

include(${CMAKE_SOURCE_DIR}/../Resources/Orthanc/DownloadOrthancFramework.cmake)

set(ORTHANC_FRAMEWORK_PLUGIN ON)
include(${ORTHANC_ROOT}/Resources/CMake/OrthancFrameworkParameters.cmake)

set(ENABLE_LOCALE OFF)         # Disable support for locales (notably in Boost)
set(ENABLE_ZLIB ON)
set(ENABLE_PNG ON)
set(ENABLE_JPEG ON)

include(${ORTHANC_ROOT}/Resources/CMake/VisualStudioPrecompiledHeaders.cmake)
include(${ORTHANC_ROOT}/Resources/CMake/OrthancFrameworkConfiguration.cmake)
include_directories(${ORTHANC_ROOT})

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


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

if (STATIC_BUILD OR NOT USE_SYSTEM_ORTHANC_SDK)
  include_directories(${CMAKE_SOURCE_DIR}/../Resources/Orthanc/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
#####################################################################

add_definitions(
  -DHAS_ORTHANC_EXCEPTION=1
  -DORTHANC_ENABLE_LOGGING_PLUGIN=1
  )

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://orthanc.osimis.io/ThirdPartyDownloads/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

  ${ORTHANC_ROOT}/Plugins/Samples/Common/DicomDatasetReader.cpp
  ${ORTHANC_ROOT}/Plugins/Samples/Common/DicomPath.cpp
  ${ORTHANC_ROOT}/Plugins/Samples/Common/DicomTag.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_ROOT}/Core/PrecompiledHeaders.cpp"
    ORTHANC_CORE_SOURCES_INTERNAL ORTHANC_CORE_PCH)

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

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


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

add_library(OrthancWSI SHARED
  ${ORTHANC_CORE_PCH}
  ${ORTHANC_CORE_SOURCES_INTERNAL}
  ${ORTHANC_CORE_SOURCES_DEPENDENCIES}
  ${ORTHANC_WSI_PCH}
  ${ORTHANC_WSI_SOURCES}
  ${AUTOGENERATED_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
  )