Mercurial > hg > orthanc
changeset 134:bdc60d16cc98
improved cmake
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 09 Oct 2012 11:58:22 +0200 |
parents | 1969ff16457c |
children | a2dbb5024fdf |
files | CMakeLists.txt NEWS Resources/CMake/Compiler.cmake Resources/CMake/GoogleLogConfiguration.cmake Resources/CMake/GoogleTestConfiguration.cmake |
diffstat | 5 files changed, 141 insertions(+), 128 deletions(-) [+] |
line wrap: on
line diff
--- a/CMakeLists.txt Mon Oct 08 13:27:49 2012 +0200 +++ b/CMakeLists.txt Tue Oct 09 11:58:22 2012 +0200 @@ -1,36 +1,55 @@ cmake_minimum_required(VERSION 2.8) project(Orthanc) -include(${CMAKE_SOURCE_DIR}/Resources/CMake/AutoGeneratedCode.cmake) -include(${CMAKE_SOURCE_DIR}/Resources/CMake/DownloadPackage.cmake) + +# Parameters of the build +SET(STATIC_BUILD ON CACHE BOOL "Static build of the third-party libraries (necessary for Windows)") +SET(STANDALONE_BUILD OFF CACHE BOOL "Standalone build (all the resources are embedded, necessary for releases)") +SET(ENABLE_SSL ON CACHE BOOL "Include support for SSL") +SET(BUILD_UNIT_TESTS ON CACHE BOOL "Build the unit tests") +SET(DEBIAN_FORCE_HARDENING OFF CACHE BOOL "Force the injection of Debian hardening flags (unrecommended)") +SET(USE_DYNAMIC_JSONCPP OFF CACHE BOOL "Use the dynamic version of JsonCpp (only for Debian sid)") +SET(USE_DYNAMIC_GOOGLE_LOG ON CACHE BOOL "Use the dynamic version of Google Log") +SET(USE_DYNAMIC_GOOGLE_TEST ON CACHE BOOL "Use the dynamic version of Google Test (not for Debian sid)") +SET(USE_STATIC_DEBIAN_GOOGLE_TEST OFF CACHE BOOL "Use the sources of Google Test shipped with libgtest-dev (only for Debian sid)") + +# Version of the build, should always be "mainline" except in release branches +add_definitions( + -DORTHANC_VERSION="mainline" + ) + +# Some basic inclusions include(CheckIncludeFiles) include(CheckIncludeFileCXX) - -add_definitions(-DORTHANC_VERSION="mainline") +include(${CMAKE_SOURCE_DIR}/Resources/CMake/AutoGeneratedCode.cmake) +include(${CMAKE_SOURCE_DIR}/Resources/CMake/DownloadPackage.cmake) +include(${CMAKE_SOURCE_DIR}/Resources/CMake/Compiler.cmake) -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(BUILD_UNIT_TESTS ON CACHE BOOL "Build the unit tests") -SET(DEBIAN_HARDENING OFF CACHE BOOL "Use Debian hardening flags") -SET(USE_DYNAMIC_JSONCPP OFF CACHE BOOL "Use the dynamic version of JsonCpp, only for Debian Unstable") -SET(USE_DYNAMIC_GOOGLE_LOG ON CACHE BOOL "Use the dynamic version of Google Log") - +# Configuration of the standalone builds if (${CMAKE_CROSSCOMPILING}) + # Cross-compilation implies the standalone build SET(STANDALONE_BUILD ON) endif() -if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows") - CHECK_INCLUDE_FILES(rpc.h HAVE_UUID_H) +if (${STANDALONE_BUILD}) + # We embed all the resources in the binaries for standalone builds + add_definitions(-DORTHANC_STANDALONE=1) + EmbedResources( + PREPARE_DATABASE OrthancServer/PrepareDatabase.sql + ORTHANC_EXPLORER OrthancExplorer + ) 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") + add_definitions( + -DORTHANC_STANDALONE=0 + -DORTHANC_PATH=\"${CMAKE_SOURCE_DIR}\" + ) + EmbedResources( + PREPARE_DATABASE OrthancServer/PrepareDatabase.sql + ) endif() +# Prepare the third-party dependencies SET(THIRD_PARTY_SOURCES ${CMAKE_SOURCE_DIR}/Resources/md5/md5.c ${CMAKE_SOURCE_DIR}/Resources/base64/base64.cpp @@ -55,106 +74,7 @@ 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() - - +# The main instructions to build the Orthanc binaries add_library(CoreLibrary STATIC ${AUTOGENERATED_SOURCES} @@ -212,9 +132,10 @@ OrthancServer/main.cpp ) -TARGET_LINK_LIBRARIES(Orthanc ServerLibrary CoreLibrary) +target_link_libraries(Orthanc ServerLibrary CoreLibrary) +# Build the unit tests if required if (BUILD_UNIT_TESTS) include(${CMAKE_SOURCE_DIR}/Resources/CMake/GoogleTestConfiguration.cmake) add_executable(UnitTests @@ -225,10 +146,11 @@ UnitTests/Versions.cpp UnitTests/Zip.cpp ) - TARGET_LINK_LIBRARIES(UnitTests ServerLibrary CoreLibrary) + target_link_libraries(UnitTests ServerLibrary CoreLibrary) endif() +# Generate the Doxygen documentation if Doxygen is present find_package(Doxygen) if (DOXYGEN_FOUND) configure_file( @@ -240,4 +162,4 @@ WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMENT "Generating API documentation with Doxygen" VERBATIM ) -endif(DOXYGEN_FOUND) +endif()
--- a/NEWS Mon Oct 08 13:27:49 2012 +0200 +++ b/NEWS Tue Oct 09 11:58:22 2012 +0200 @@ -1,6 +1,8 @@ Pending changes in the mainline =============================== +* Help on the command line +* Possibility of dynamic linking against jsoncpp, sqlite, boost and dmctk Version 0.2.2 (2012/10/04) @@ -10,7 +12,6 @@ * Fixes to Debian packaging - Version 0.2.1 (2012/09/28) ========================== @@ -19,7 +20,6 @@ * Ready for Debian packaging - Version 0.2.0 (2012/09/16) ========================== @@ -41,7 +41,6 @@ * Standalone build for cross-compilation - Version 0.1.1 (2012/07/20) ========================== @@ -50,7 +49,6 @@ * Add path to storage in Configuration.json - Version 0.1.0 (2012/07/19) ==========================
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Resources/CMake/Compiler.cmake Tue Oct 09 11:58:22 2012 +0200 @@ -0,0 +1,90 @@ +# This file sets all the compiler-related flags + +if (${CMAKE_COMPILER_IS_GNUCXX}) + set(CMAKE_C_FLAGS "${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 "${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_FORCE_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 "${CMAKE_EXE_LINKER_FLAGS} -Wl,--as-needed ${DEBIAN_LD_FLAGS}") + set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--no-undefined ${DEBIAN_LD_FLAGS}") + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined ${DEBIAN_LD_FLAGS}") + + # Remove the "-rdynamic" option + # 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 (${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() + +if (${STATIC_BUILD}) + add_definitions(-DORTHANC_STATIC=1) +else() + add_definitions(-DORTHANC_STATIC=0) +endif()
--- a/Resources/CMake/GoogleLogConfiguration.cmake Mon Oct 08 13:27:49 2012 +0200 +++ b/Resources/CMake/GoogleLogConfiguration.cmake Tue Oct 09 11:58:22 2012 +0200 @@ -1,4 +1,4 @@ -if (${STATIC_BUILD} OR NOT ${USE_DYNAMIC_GOOGLE_LOG}) +if (STATIC_BUILD OR NOT USE_DYNAMIC_GOOGLE_LOG) SET(GOOGLE_LOG_SOURCES_DIR ${CMAKE_BINARY_DIR}/glog-0.3.2) DownloadPackage("http://google-glog.googlecode.com/files/glog-0.3.2.tar.gz" "${GOOGLE_LOG_SOURCES_DIR}" "" "")
--- a/Resources/CMake/GoogleTestConfiguration.cmake Mon Oct 08 13:27:49 2012 +0200 +++ b/Resources/CMake/GoogleTestConfiguration.cmake Tue Oct 09 11:58:22 2012 +0200 @@ -1,4 +1,7 @@ -if (${STATIC_BUILD}) +if (USE_STATIC_DEBIAN_GOOGLE_TEST) + message(FATAL_ERROR "todo") + +elseif (STATIC_BUILD OR NOT USE_DYNAMIC_GOOGLE_TEST) SET(GTEST_SOURCES_DIR ${CMAKE_BINARY_DIR}/gtest-1.6.0) DownloadPackage("http://googletest.googlecode.com/files/gtest-1.6.0.zip" "${GTEST_SOURCES_DIR}" "" "")