view CMakeLists.txt @ 110:fd7b0a3e6260

support of boost 1.42 for debian
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 04 Oct 2012 12:33:31 +0200
parents 7593b57dc1bf
children 5af0a4345d06
line wrap: on
line source

cmake_minimum_required(VERSION 2.8)

project(Orthanc)
include(${CMAKE_SOURCE_DIR}/Resources/CMake/AutoGeneratedCode.cmake)
include(${CMAKE_SOURCE_DIR}/Resources/CMake/DownloadPackage.cmake)
include(CheckIncludeFiles)
include(CheckIncludeFileCXX)

SET(STATIC_BUILD ON CACHE BOOL "Static build of the third-party libraries (necessary for Windows)")
SET(STANDALONE_BUILD OFF CACHE BOOL "Standalone build (necessary for cross-compilation or binary releases)")
SET(ENABLE_SSL ON CACHE BOOL "Include support for SSL")
SET(DEBIAN_HARDENING OFF CACHE BOOL "Use Debian hardening flags")

if (${CMAKE_CROSSCOMPILING})
  SET(STANDALONE_BUILD ON)
endif()

if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
  CHECK_INCLUDE_FILES(rpc.h HAVE_UUID_H)
else()
  CHECK_INCLUDE_FILES(uuid/uuid.h HAVE_UUID_H)
endif()

if (NOT HAVE_UUID_H)
  message(FATAL_ERROR "Please install the uuid-dev package")
endif()


SET(THIRD_PARTY_SOURCES
  ${CMAKE_SOURCE_DIR}/Resources/md5/md5.c
  ${CMAKE_SOURCE_DIR}/Resources/base64/base64.cpp
  )

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

if (${ENABLE_SSL})
  add_definitions(-DORTHANC_SSL_ENABLED=1)
  include(${CMAKE_SOURCE_DIR}/Resources/CMake/OpenSslConfiguration.cmake)
else()
  add_definitions(-DORTHANC_SSL_ENABLED=0)
endif()

include(${CMAKE_SOURCE_DIR}/Resources/CMake/BoostConfiguration.cmake)
include(${CMAKE_SOURCE_DIR}/Resources/CMake/DcmtkConfiguration.cmake)
include(${CMAKE_SOURCE_DIR}/Resources/CMake/GoogleTestConfiguration.cmake)
include(${CMAKE_SOURCE_DIR}/Resources/CMake/MongooseConfiguration.cmake)
include(${CMAKE_SOURCE_DIR}/Resources/CMake/ZlibConfiguration.cmake)
include(${CMAKE_SOURCE_DIR}/Resources/CMake/SQLiteConfiguration.cmake)
include(${CMAKE_SOURCE_DIR}/Resources/CMake/JsonCppConfiguration.cmake)
include(${CMAKE_SOURCE_DIR}/Resources/CMake/LibCurlConfiguration.cmake)
include(${CMAKE_SOURCE_DIR}/Resources/CMake/LibPngConfiguration.cmake)


if (${CMAKE_COMPILER_IS_GNUCXX})
  set(CMAKE_C_FLAGS "-Wall -Wno-long-long -Wno-implicit-function-declaration")  
  # --std=c99 makes libcurl not to compile
  # -pedantic gives a lot of warnings on OpenSSL 
  set(CMAKE_CXX_FLAGS "-Wall -pedantic -Wno-long-long -Wno-variadic-macros")
elseif (${MSVC})
  # http://stackoverflow.com/a/6510446
  foreach(flag_var
    CMAKE_C_FLAGS_DEBUG
    CMAKE_CXX_FLAGS_DEBUG
    CMAKE_C_FLAGS_RELEASE 
    CMAKE_CXX_FLAGS_RELEASE
    CMAKE_C_FLAGS_MINSIZEREL 
    CMAKE_CXX_FLAGS_MINSIZEREL 
    CMAKE_C_FLAGS_RELWITHDEBINFO 
    CMAKE_CXX_FLAGS_RELWITHDEBINFO) 
    string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
    string(REGEX REPLACE "/MDd" "/MTd" ${flag_var} "${${flag_var}}")
  endforeach(flag_var)
  add_definitions(
    -D_CRT_SECURE_NO_WARNINGS=1
    -D_CRT_SECURE_NO_DEPRECATE=1
    )
  include_directories(${CMAKE_SOURCE_DIR}/Resources/VisualStudio)
  link_libraries(netapi32)
endif()


if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
  if (DEBIAN_HARDENING)
    execute_process(
      COMMAND dpkg-buildflags --get CPPFLAGS 
      OUTPUT_VARIABLE DEBIAN_CPP_FLAGS
      OUTPUT_STRIP_TRAILING_WHITESPACE)
    execute_process(
      COMMAND dpkg-buildflags --get CFLAGS 
      OUTPUT_VARIABLE DEBIAN_C_FLAGS
      OUTPUT_STRIP_TRAILING_WHITESPACE)
    execute_process(
      COMMAND dpkg-buildflags --get CXXFLAGS 
      OUTPUT_VARIABLE DEBIAN_CXX_FLAGS
      OUTPUT_STRIP_TRAILING_WHITESPACE)
    execute_process(
      COMMAND dpkg-buildflags --get LDFLAGS 
      OUTPUT_VARIABLE DEBIAN_LD_FLAGS
      OUTPUT_STRIP_TRAILING_WHITESPACE)

    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${DEBIAN_C_FLAGS} ${DEBIAN_CPP_FLAGS}")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${DEBIAN_CXX_FLAGS} ${DEBIAN_CPP_FLAGS}")
  endif()

  add_definitions(
    -D_LARGEFILE64_SOURCE=1 
    -D_FILE_OFFSET_BITS=64
    )
  set(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed ${DEBIAN_LD_FLAGS}")
  set(CMAKE_MODULE_LINKER_FLAGS "-Wl,--no-undefined ${DEBIAN_LD_FLAGS}")
  set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--no-undefined ${DEBIAN_LD_FLAGS}")

  # http://www.mail-archive.com/cmake@cmake.org/msg08837.html
  set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
  link_libraries(uuid pthread rt)

elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
  add_definitions(
    -DWINVER=0x0501
    -D_CRT_SECURE_NO_WARNINGS=1
    )
  link_libraries(rpcrt4 ws2_32)
endif()


if (${STATIC_BUILD})
  add_definitions(-DORTHANC_STATIC=1)
else()
  add_definitions(-DORTHANC_STATIC=0)
endif()

if (${STANDALONE_BUILD})
  add_definitions(
    -DORTHANC_STANDALONE=1
    )

  EmbedResources(
    PREPARE_DATABASE OrthancServer/PrepareDatabase.sql
    ORTHANC_EXPLORER OrthancExplorer
    )

else()
  add_definitions(
    -DORTHANC_STANDALONE=0
    -DORTHANC_PATH=\"${CMAKE_SOURCE_DIR}\"
    )

  EmbedResources(
    PREPARE_DATABASE OrthancServer/PrepareDatabase.sql
    )
endif()


add_library(CoreLibrary
  STATIC
  ${AUTOGENERATED_SOURCES}
  ${THIRD_PARTY_SOURCES}

  Core/ChunkedBuffer.cpp
  Core/Compression/BufferCompressor.cpp
  Core/Compression/ZlibCompressor.cpp
  Core/Compression/ZipWriter.cpp
  Core/OrthancException.cpp
  Core/DicomFormat/DicomArray.cpp
  Core/DicomFormat/DicomMap.cpp
  Core/DicomFormat/DicomTag.cpp
  Core/DicomFormat/DicomIntegerPixelAccessor.cpp
  Core/FileStorage.cpp
  Core/HttpServer/EmbeddedResourceHttpHandler.cpp
  Core/HttpServer/FilesystemHttpHandler.cpp
  Core/HttpServer/HttpHandler.cpp
  Core/HttpServer/HttpOutput.cpp
  Core/HttpServer/MongooseServer.cpp
  Core/MultiThreading/BagOfRunnablesBySteps.cpp
  Core/PngWriter.cpp
  Core/SQLite/Connection.cpp
  Core/SQLite/FunctionContext.cpp
  Core/SQLite/Statement.cpp
  Core/SQLite/StatementId.cpp
  Core/SQLite/StatementReference.cpp
  Core/SQLite/Transaction.cpp
  Core/Toolbox.cpp
  Core/Uuid.cpp

  OrthancCppClient/HttpClient.cpp
  OrthancCppClient/HttpException.cpp
  )  

add_library(ServerLibrary
  OrthancServer/DicomProtocol/DicomFindAnswers.cpp
  OrthancServer/DicomProtocol/DicomServer.cpp
  OrthancServer/DicomProtocol/DicomUserConnection.cpp
  OrthancServer/FromDcmtkBridge.cpp
  OrthancServer/Internals/CommandDispatcher.cpp
  OrthancServer/Internals/FindScp.cpp
  OrthancServer/Internals/MoveScp.cpp
  OrthancServer/Internals/StoreScp.cpp
  OrthancServer/OrthancInitialization.cpp
  OrthancServer/OrthancRestApi.cpp
  OrthancServer/ServerIndex.cpp
  OrthancServer/ToDcmtkBridge.cpp
  )

# Ensure autogenerated code is built before building ServerLibrary
add_dependencies(ServerLibrary CoreLibrary)

add_executable(Orthanc
  OrthancServer/main.cpp
  )

add_executable(UnitTests
  ${GTEST_SOURCES}
  UnitTests/main.cpp
  UnitTests/SQLite.cpp
  UnitTests/SQLiteChromium.cpp
  UnitTests/Versions.cpp
  UnitTests/Zip.cpp
  )

TARGET_LINK_LIBRARIES(Orthanc ServerLibrary CoreLibrary)
TARGET_LINK_LIBRARIES(UnitTests ServerLibrary CoreLibrary)

find_package(Doxygen)
if (DOXYGEN_FOUND)
  configure_file(
    ${CMAKE_SOURCE_DIR}/Resources/Orthanc.doxygen
    ${CMAKE_CURRENT_BINARY_DIR}/Orthanc.doxygen
    @ONLY)
  add_custom_target(doc
    ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Orthanc.doxygen
    WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
    COMMENT "Generating API documentation with Doxygen" VERBATIM
    )
endif(DOXYGEN_FOUND)