view Plugin/CMakeLists.txt @ 59:1873eecbc592

auto-generation of C++ wrapper is now part of the build
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 14 Aug 2025 16:05:18 +0200
parents bdbf74525d86
children 0d20b470a75a
line wrap: on
line source

# SPDX-FileCopyrightText: 2023-2025 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
# SPDX-License-Identifier: GPL-3.0-or-later

# Java plugin for Orthanc
# Copyright (C) 2023-2025 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
#
# This program is free software: you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.


cmake_minimum_required(VERSION 3.1)

project(OrthancJavaPlugin)

set(PLUGIN_VERSION "mainline")

set(ORTHANC_SDK_DEFAULT_VERSION "1.10.0")

# This list must correspond to the content of "./Resources/SyncOrthancFolder.py"
set(ORTHANC_SDK_AVAILABLE_VERSIONS "1.10.0" "1.12.6")

set(CMAKE_CXX_STANDARD 11)


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

include(CheckIncludeFileCXX)
include(FindPythonInterp)

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

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

# Support of static compilation
set(ALLOW_DOWNLOADS OFF CACHE BOOL "Allow CMake to download packages")
set(STATIC_BUILD OFF CACHE BOOL "Static build of the third-party libraries (necessary for Windows)")
set(USE_SYSTEM_JSONCPP ON CACHE BOOL "Use the system version of JsonCpp")
set(USE_SYSTEM_JNI 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(${CMAKE_SOURCE_DIR}/../Resources/Orthanc/CMake/JsonCppConfiguration.cmake)

include(${CMAKE_SOURCE_DIR}/../OrthancSDKVersion.cmake)


#####################################################################
## Configure JNI
#####################################################################

if (CMAKE_SYSTEM_NAME STREQUAL "Windows" AND
    (STATIC_BUILD OR NOT USE_SYSTEM_JNI))
  if (CMAKE_SIZEOF_VOID_P EQUAL 8)
    include_directories(
      ${CMAKE_SOURCE_DIR}/../Resources/jdk8u382-b05-win64/include
      ${CMAKE_SOURCE_DIR}/../Resources/jdk8u382-b05-win64/include/win32
      )
    link_libraries(
      ${CMAKE_SOURCE_DIR}/../Resources/jdk8u382-b05-win64/lib/jvm.lib
      )
  elseif (CMAKE_SIZEOF_VOID_P EQUAL 4)
    include_directories(
      ${CMAKE_SOURCE_DIR}/../Resources/jdk8u382-b05-win32/include
      ${CMAKE_SOURCE_DIR}/../Resources/jdk8u382-b05-win32/include/win32
      )
    link_libraries(
      ${CMAKE_SOURCE_DIR}/../Resources/jdk8u382-b05-win32/lib/jvm.lib
      )
  else()
    message(FATAL_ERROR "Unknown architecture")
  endif()
else()
  if (NOT USE_SYSTEM_JNI)
    message(FATAL_ERROR "Cannot statically link against JNI on this platform")
  endif()
  
  find_package(JNI REQUIRED COMPONENTS JVM)
  if (NOT JNI_FOUND)
    message(FATAL_ERROR "Unable to find JNI")
  endif()
  
  link_libraries(${JNI_LIBRARIES})
  include_directories(${JNI_INCLUDE_DIRS})
endif()


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

include_directories(BEFORE
  ${CMAKE_SOURCE_DIR}/../Resources/Orthanc/Sdk-${ORTHANC_SDK_VERSION}/
  )
set(ORTHANC_SDK ${CMAKE_SOURCE_DIR}/../Resources/Orthanc/Sdk-${ORTHANC_SDK_VERSION}/orthanc/OrthancCPlugin.h)


#####################################################################
## Auto-generate the wrapper
#####################################################################

set(ORTHANC_CODE_MODEL ${CMAKE_SOURCE_DIR}/../Resources/Orthanc/OrthancPluginCodeModel.json)

add_custom_command(
  OUTPUT
  ${AUTOGENERATED_DIR}/NativeSDK.cpp

  COMMAND
  ${PYTHON_EXECUTABLE}
  ${CMAKE_SOURCE_DIR}/../CodeGeneration/CppCodeGeneration.py
  --sdk ${ORTHANC_SDK}
  --model ${ORTHANC_CODE_MODEL}
  --target ${AUTOGENERATED_DIR}/NativeSDK.cpp

  DEPENDS
  ${CMAKE_SOURCE_DIR}/../CodeGeneration/
  ${ORTHANC_SDK}
  ${ORTHANC_CODE_MODEL}
  )

set_source_files_properties(
  ${AUTOGENERATED_DIR}/NativeSDK.cpp
  PROPERTIES INCLUDE_DIRECTORIES ${CMAKE_SOURCE_DIR}
  )

list(APPEND AUTOGENERATED_SOURCES
  ${AUTOGENERATED_DIR}/NativeSDK.cpp
  )

add_custom_target(
  AutogeneratedTarget
  DEPENDS
  ${AUTOGENERATED_SOURCES}
  )


#####################################################################
## Build the plugin
#####################################################################

if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
  execute_process(
    COMMAND 
    ${PYTHON_EXECUTABLE} ${CMAKE_SOURCE_DIR}/../Resources/Orthanc/CMake/WindowsResources.py
    ${PLUGIN_VERSION} OrthancJava OrthancJava.dll "Java plugin for Orthanc"
    ERROR_VARIABLE Failure
    OUTPUT_FILE ${AUTOGENERATED_DIR}/OrthancJava.rc
    )
  
  if (Failure)
    message(FATAL_ERROR "Error while computing the version information: ${Failure}")
  endif()
  
  list(APPEND AUTOGENERATED_SOURCES ${AUTOGENERATED_DIR}/OrthancJava.rc)
endif()


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

add_library(OrthancJava SHARED
  ${JSONCPP_SOURCES}
  ${AUTOGENERATED_SOURCES}

  JavaBytes.cpp
  JavaEnvironment.cpp
  JavaGlobalReference.cpp
  JavaLocalObject.cpp
  JavaString.cpp
  JavaVirtualMachine.cpp
  Mutex.cpp
  OrthancBytes.cpp
  OrthancString.cpp
  Plugin.cpp
  )

add_dependencies(OrthancJava AutogeneratedTarget)

set_target_properties(
  OrthancJava PROPERTIES 
  VERSION ${PLUGIN_VERSION} 
  SOVERSION ${PLUGIN_VERSION}
  SKIP_BUILD_RPATH ON
  )

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