view Plugin/CMakeLists.txt @ 43:678bbed285a1 default tip

improved import of JNI in cmake
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 06 Sep 2024 13:53:54 +0200
parents 4faec1378b89
children
line wrap: on
line source

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

# Java plugin for Orthanc
# Copyright (C) 2023-2024 Sebastien Jodogne, 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(CMAKE_CXX_STANDARD 11)

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_directories(BEFORE
  ${CMAKE_SOURCE_DIR}/../Resources/Orthanc/Sdk-1.10.0/
  )

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()

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 PLUGIN_RESOURCES ${AUTOGENERATED_DIR}/OrthancJava.rc)
endif()


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

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

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

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
  )