Mercurial > hg > orthanc-java
view Plugin/CMakeLists.txt @ 62:cc91717e2354
auto-generation of Java wrapper is now part of the build
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 14 Aug 2025 17:27:40 +0200 |
parents | 97047be8435a |
children | 037a2b0d06ca |
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...4.0) project(OrthancJavaPlugin) set(PLUGIN_VERSION "mainline") set(CMAKE_CXX_STANDARD 11) ##################################################################### ## Parameters of the build ##################################################################### include(CheckIncludeFileCXX) if(CMAKE_VERSION VERSION_GREATER "3.11") find_package(Python REQUIRED COMPONENTS Interpreter) set(PYTHON_EXECUTABLE ${Python_EXECUTABLE}) else() include(FindPythonInterp) find_package(PythonInterp REQUIRED) endif() 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}/../OrthancSDKVersion.cmake) include(${CMAKE_SOURCE_DIR}/../Resources/Orthanc/CMake/JsonCppConfiguration.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 ##################################################################### if (STATIC_BUILD OR NOT USE_SYSTEM_ORTHANC_SDK) if (ORTHANC_SDK_VERSION STREQUAL "path") include_directories(${ORTHANC_SDK_PATH}) set(ORTHANC_SDK ${ORTHANC_SDK_PATH}/orthanc/OrthancCPlugin.h) else() list(FIND ORTHANC_SDK_AVAILABLE_VERSIONS ${ORTHANC_SDK_VERSION} tmp) if (tmp EQUAL -1) message(FATAL_ERROR "The source distribution of this plugin does not contain Orthanc SDK ${ORTHANC_SDK_VERSION}") endif() include_directories(${CMAKE_SOURCE_DIR}/../Resources/Orthanc/Sdk-${ORTHANC_SDK_VERSION}) set(ORTHANC_SDK ${CMAKE_SOURCE_DIR}/../Resources/Orthanc/Sdk-${ORTHANC_SDK_VERSION}/orthanc/OrthancCPlugin.h) endif() else() find_path(ORTHANC_SDK_SYSTEM_DIR OrthancCPlugin.h /usr/ /usr/local/ PATH_SUFFIXES include/orthanc ) if (${ORTHANC_SDK_SYSTEM_DIR} STREQUAL "ORTHANC_SDK_SYSTEM_DIR-NOTFOUND") message(FATAL_ERROR "Cannot locate the orthanc/OrthancCPlugin.h header") endif() set(ORTHANC_SDK ${ORTHANC_SDK_SYSTEM_DIR}/OrthancCPlugin.h) endif() ##################################################################### ## 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} ) if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU") # Don't report warnings about deprecated functions in the Orthanc SDK set_source_files_properties( ${AUTOGENERATED_DIR}/NativeSDK.cpp COMPILE_FLAGS -Wno-deprecated-declarations ) endif() ##################################################################### ## 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 )