view CMakeLists.txt @ 16:777b677cc9fc OrthancPython-1.0

generation of windows resources
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 01 Apr 2020 10:43:11 +0200
parents 13589c36243d
children 3848f5b1d993
line wrap: on
line source

cmake_minimum_required(VERSION 2.8)
project(OrthancPython)

set(PLUGIN_VERSION "1.0")


set(PYTHON_VERSION "3.6" CACHE STRING "Version of Python to be used")
set(PYTHON_WINDOWS_ROOT "" CACHE STRING "")
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_LEGACY_JSONCPP OFF CACHE BOOL "Use the old branch 0.x.y of JsonCpp, that does not require a C++11 compiler (for LSB and old versions of Visual Studio)")

include(CheckIncludeFile)
include(CheckIncludeFileCXX)
include(CheckIncludeFiles)
include(CheckLibraryExists)
include(FindPythonInterp)

if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
  set(PYTHON_INCLUDE_DIRS ${PYTHON_WINDOWS_ROOT}/include)
  set(PYTHON_LIBRARIES ${PYTHON_WINDOWS_ROOT}/libs/libpython27.a)
  
else()
  find_package(PkgConfig REQUIRED)
  pkg_check_modules(PYTHON_1 python-${PYTHON_VERSION}-embed)

  if (PYTHON_1_FOUND)
    set(PYTHON_INCLUDE_DIRS ${PYTHON_1_INCLUDE_DIRS})
    set(PYTHON_LIBRARIES ${PYTHON_1_LIBRARIES})
  else()
    pkg_check_modules(PYTHON_2 REQUIRED python-${PYTHON_VERSION})
    set(PYTHON_INCLUDE_DIRS ${PYTHON_2_INCLUDE_DIRS})
    set(PYTHON_LIBRARIES ${PYTHON_2_LIBRARIES})
  endif()
endif()

set(ORTHANC_ROOT ${CMAKE_SOURCE_DIR}/Resources/Orthanc)
include(${ORTHANC_ROOT}/Resources/CMake/Compiler.cmake)
include(${ORTHANC_ROOT}/Resources/CMake/DownloadPackage.cmake)
include(${ORTHANC_ROOT}/Resources/CMake/BoostConfiguration.cmake)
include(${ORTHANC_ROOT}/Resources/CMake/JsonCppConfiguration.cmake)


if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
  execute_process(
    COMMAND 
    ${PYTHON_EXECUTABLE} ${ORTHANC_ROOT}/Resources/WindowsResources.py
    ${PLUGIN_VERSION} "Python plugin" OrthancPython.dll
    "Plugin to create Orthanc plugins using Python"
    ERROR_VARIABLE Failure
    OUTPUT_FILE ${CMAKE_CURRENT_BINARY_DIR}/Version.rc
    )

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

  set(WINDOWS_RESOURCES ${CMAKE_CURRENT_BINARY_DIR}/Version.rc)
endif()


include_directories(
  ${ORTHANC_ROOT}/Sdk-1.5.7
  )

add_definitions(
  -DHAS_ORTHANC_EXCEPTION=0
  )

include_directories(
  ${ORTHANC_ROOT}/Plugins/Samples/Common
  ${PYTHON_INCLUDE_DIRS}
  )

add_library(OrthancPython SHARED
  ${BOOST_SOURCES}
  ${JSONCPP_SOURCES}
  ${ORTHANC_ROOT}/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp
  ${WINDOWS_RESOURCES}
  Sources/Autogenerated/sdk.cpp
  Sources/OnChangeCallback.cpp
  Sources/OnStoredInstanceCallback.cpp
  Sources/Plugin.cpp
  Sources/PythonFunction.cpp
  Sources/PythonLock.cpp
  Sources/PythonModule.cpp
  Sources/PythonObject.cpp
  Sources/PythonString.cpp
  Sources/RestCallbacks.cpp
  )

target_link_libraries(OrthancPython ${PYTHON_LIBRARIES})

add_definitions(-DPLUGIN_VERSION="${PLUGIN_VERSION}")

set_target_properties(OrthancPython PROPERTIES 
  VERSION ${PLUGIN_VERSION} 
  SOVERSION ${PLUGIN_VERSION}
  )

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