view CMakeLists.txt @ 24:3bed39e4b85f

fix prefix and suffix for Windows Python libraries
author Benjamin Golinvaux <bgo@osimis.io>
date Fri, 03 Apr 2020 12:12:09 +0200
parents 874a3fef26ff
children 3b59f5dd7e72
line wrap: on
line source

cmake_minimum_required(VERSION 2.8)
project(OrthancPython)

set(PLUGIN_VERSION "mainline")


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)

string(REGEX REPLACE "^([0-9]*)\\.([0-9]*)$" "\\1" PYTHON_VERSION_MAJOR ${PYTHON_VERSION})
string(REGEX REPLACE "^([0-9]*)\\.([0-9]*)$" "\\2" PYTHON_VERSION_MINOR ${PYTHON_VERSION})

if (NOT PYTHON_VERSION STREQUAL
    "${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}")
  message(FATAL_ERROR "Error in the (x.y) format of the Python version: ${PYTHON_VERSION}")
endif()

if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
  if (MSVC)
    set(Prefix "")
    set(Suffix ".lib")
  else()
    set(Prefix "lib")
    set(Suffix ".a")
  endif()
  
  set(PYTHON_LIBRARY_NAME ${Prefix}python${PYTHON_VERSION_MAJOR}${PYTHON_VERSION_MINOR}${Suffix})
  set(PYTHON_INCLUDE_DIRS ${PYTHON_WINDOWS_ROOT}/include)
  set(PYTHON_LIBRARIES ${PYTHON_WINDOWS_ROOT}/libs/${PYTHON_LIBRARY_NAME})
  
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
  )