view PostgreSQL/CMakeLists.txt @ 179:9b500ad566c0 OrthancPostgreSQL-3.3

OrthancPostgreSQL-3.3
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 14 Dec 2020 15:55:55 +0100
parents 8c7bb94adff7
children 5e604adfd41f 3f4fa9ca637b
line wrap: on
line source

cmake_minimum_required(VERSION 2.8)
project(OrthancPostgreSQL)

set(ORTHANC_PLUGIN_VERSION "3.3")

set(ORTHANC_OPTIMAL_VERSION_MAJOR    1)
set(ORTHANC_OPTIMAL_VERSION_MINOR    5)
set(ORTHANC_OPTIMAL_VERSION_REVISION 4)

if (ORTHANC_PLUGIN_VERSION STREQUAL "mainline")
  set(ORTHANC_FRAMEWORK_VERSION "mainline")
  set(ORTHANC_FRAMEWORK_DEFAULT_SOURCE "hg")
else()
  set(ORTHANC_FRAMEWORK_VERSION "1.8.1")
  set(ORTHANC_FRAMEWORK_DEFAULT_SOURCE "web")
endif()

set(ENABLE_SSL ON)
include(${CMAKE_SOURCE_DIR}/../Resources/CMake/DatabasesPluginParameters.cmake)

set(ENABLE_POSTGRESQL_BACKEND ON)
set(OPENSSL_STATIC_VERSION "1.1.1" CACHE STRING "Force the use of OpenSSL 1.1.1" FORCE)

include(${CMAKE_SOURCE_DIR}/../Resources/CMake/DatabasesPluginConfiguration.cmake)


if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
  execute_process(
    COMMAND 
    ${PYTHON_EXECUTABLE} ${ORTHANC_FRAMEWORK_ROOT}/../Resources/WindowsResources.py
    ${ORTHANC_PLUGIN_VERSION} "PostgreSQL storage area plugin" OrthancPostgreSQLStorage.dll
    "PostgreSQL as a database back-end to Orthanc (storage area)"
    ERROR_VARIABLE Failure
    OUTPUT_FILE ${AUTOGENERATED_DIR}/StorageVersion.rc
    )

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

  execute_process(
    COMMAND 
    ${PYTHON_EXECUTABLE} ${ORTHANC_FRAMEWORK_ROOT}/../Resources/WindowsResources.py
    ${ORTHANC_PLUGIN_VERSION} "PostgreSQL index plugin" OrthancPostgreSQLIndex.dll
    "PostgreSQL as a database back-end to Orthanc (index)"
    ERROR_VARIABLE Failure
    OUTPUT_FILE ${AUTOGENERATED_DIR}/IndexVersion.rc
    )

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

  set(INDEX_RESOURCES ${AUTOGENERATED_DIR}/IndexVersion.rc)
  set(STORAGE_RESOURCES ${AUTOGENERATED_DIR}/StorageVersion.rc)
endif()


EmbedResources(
  POSTGRESQL_PREPARE_INDEX          ${CMAKE_SOURCE_DIR}/Plugins/PrepareIndex.sql
  POSTGRESQL_CREATE_INSTANCE        ${CMAKE_SOURCE_DIR}/Plugins/CreateInstance.sql
  POSTGRESQL_FAST_TOTAL_SIZE        ${CMAKE_SOURCE_DIR}/Plugins/FastTotalSize.sql
  POSTGRESQL_FAST_COUNT_RESOURCES   ${CMAKE_SOURCE_DIR}/Plugins/FastCountResources.sql
  POSTGRESQL_GET_LAST_CHANGE_INDEX  ${CMAKE_SOURCE_DIR}/Plugins/GetLastChangeIndex.sql
  )

add_custom_target(
  AutogeneratedTarget
  DEPENDS 
  ${AUTOGENERATED_SOURCES}
  )

add_library(OrthancPostgreSQLIndex SHARED
  ${INDEX_RESOURCES}
  ${ORTHANC_DATABASES_ROOT}/Framework/Plugins/PluginInitialization.cpp
  Plugins/IndexPlugin.cpp
  Plugins/PostgreSQLIndex.cpp

  ${DATABASES_SOURCES}
  ${AUTOGENERATED_SOURCES}
  )

add_dependencies(OrthancPostgreSQLIndex AutogeneratedTarget)

add_library(OrthancPostgreSQLStorage SHARED
  ${ORTHANC_DATABASES_ROOT}/Framework/Plugins/PluginInitialization.cpp
  ${STORAGE_RESOURCES}
  Plugins/PostgreSQLStorageArea.cpp
  Plugins/StoragePlugin.cpp

  ${DATABASES_SOURCES}
  ${AUTOGENERATED_SOURCES}
  )

add_dependencies(OrthancPostgreSQLStorage AutogeneratedTarget)

message("Setting the version of the libraries to ${ORTHANC_PLUGIN_VERSION}")

add_definitions(
  -DORTHANC_PLUGIN_VERSION="${ORTHANC_PLUGIN_VERSION}"
  )

set_target_properties(OrthancPostgreSQLStorage PROPERTIES 
  VERSION ${ORTHANC_PLUGIN_VERSION} 
  SOVERSION ${ORTHANC_PLUGIN_VERSION}
  COMPILE_FLAGS -DORTHANC_ENABLE_LOGGING_PLUGIN=1
  )

set_target_properties(OrthancPostgreSQLIndex PROPERTIES 
  VERSION ${ORTHANC_PLUGIN_VERSION} 
  SOVERSION ${ORTHANC_PLUGIN_VERSION}
  COMPILE_FLAGS -DORTHANC_ENABLE_LOGGING_PLUGIN=1
  )

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


add_executable(UnitTests
  Plugins/PostgreSQLIndex.cpp
  Plugins/PostgreSQLStorageArea.cpp
  UnitTests/PostgreSQLTests.cpp
  UnitTests/UnitTestsMain.cpp
  ${DATABASES_SOURCES}
  ${GOOGLE_TEST_SOURCES}
  ${AUTOGENERATED_SOURCES}
  )

add_dependencies(UnitTests AutogeneratedTarget)

target_link_libraries(UnitTests ${GOOGLE_TEST_LIBRARIES})
set_target_properties(UnitTests PROPERTIES
  COMPILE_FLAGS -DORTHANC_ENABLE_LOGGING_PLUGIN=0
  )