Mercurial > hg > orthanc
changeset 634:d775a3cb5a06
refactoring of CMake scripts
author | jodogne |
---|---|
date | Tue, 29 Oct 2013 10:31:02 +0100 |
parents | e207b33216db |
children | cd3b60f6e7d4 |
files | CMakeLists.txt INSTALL LinuxCompilation.txt Resources/CMake/DownloadPackage.cmake Resources/CMake/GoogleLogConfiguration.cmake Resources/CMake/GoogleTestConfiguration.cmake Resources/CMake/JsonCppConfiguration.cmake Resources/CMake/LibCurlConfiguration.cmake Resources/CMake/LibPngConfiguration.cmake Resources/CMake/LuaConfiguration.cmake Resources/CMake/MongooseConfiguration.cmake Resources/CMake/OpenSslConfiguration.cmake Resources/CMake/SQLiteConfiguration.cmake |
diffstat | 13 files changed, 166 insertions(+), 101 deletions(-) [+] |
line wrap: on
line diff
--- a/CMakeLists.txt Tue Oct 29 09:04:25 2013 +0100 +++ b/CMakeLists.txt Tue Oct 29 10:31:02 2013 +0100 @@ -11,29 +11,28 @@ ##################################################################### # Parameters of the build -SET(STATIC_BUILD ON CACHE BOOL "Static build of the third-party libraries (necessary for Windows)") +SET(STATIC_BUILD OFF CACHE BOOL "Static build of the third-party libraries (necessary for Windows)") SET(STANDALONE_BUILD ON 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(BUILD_CLIENT_LIBRARY ON CACHE BOOL "Build the client library") -SET(DCMTK_DICTIONARY_DIR "/usr/share/dcmtk" CACHE PATH "Directory containing the DCMTK dictionaries \"dicom.dic\" and \"private.dic\" (ignored in standalone builds)") +SET(DCMTK_DICTIONARY_DIR "/usr/share/dcmtk" CACHE PATH "Directory containing the DCMTK dictionaries \"dicom.dic\" and \"private.dic\" (only when using system version of DCMTK)") +SET(ALLOW_DOWNLOADS OFF CACHE BOOL "Allow CMake to download packages") # Advanced parameters to fine-tune linking against system libraries -SET(USE_DYNAMIC_JSONCPP OFF CACHE BOOL "Use the dynamic version of JsonCpp") -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") -SET(USE_DYNAMIC_SQLITE ON CACHE BOOL "Use the dynamic version of SQLite") -SET(USE_DYNAMIC_MONGOOSE OFF CACHE BOOL "Use the dynamic version of Mongoose") -SET(USE_DYNAMIC_LUA OFF CACHE BOOL "Use the dynamic version of Lua") +SET(USE_SYSTEM_JSONCPP ON CACHE BOOL "Use the system version of JsonCpp") +SET(USE_SYSTEM_GOOGLE_LOG ON CACHE BOOL "Use the system version of Google Log") +SET(USE_SYSTEM_GOOGLE_TEST ON CACHE BOOL "Use the system version of Google Test") +SET(USE_SYSTEM_SQLITE ON CACHE BOOL "Use the system version of SQLite") +SET(USE_SYSTEM_MONGOOSE ON CACHE BOOL "Use the system version of Mongoose") +SET(USE_SYSTEM_LUA ON CACHE BOOL "Use the system version of Lua") SET(USE_SYSTEM_DCMTK ON CACHE BOOL "Use the system version of DCMTK") SET(USE_SYSTEM_BOOST ON CACHE BOOL "Use the system version of Boost") -SET(DEBIAN_USE_GTEST_SOURCE_PACKAGE OFF CACHE BOOL "Use the sources of Google Test shipped with libgtest-dev (Debian only)") +SET(USE_SYSTEM_LIBPNG ON CACHE BOOL "Use the system version of LibPng") +SET(USE_SYSTEM_CURL ON CACHE BOOL "Use the system version of LibCurl") -mark_as_advanced(USE_DYNAMIC_JSONCPP) -mark_as_advanced(USE_DYNAMIC_GOOGLE_LOG) -mark_as_advanced(USE_DYNAMIC_GOOGLE_TEST) -mark_as_advanced(USE_DYNAMIC_SQLITE) -mark_as_advanced(DEBIAN_USE_GTEST_SOURCE_PACKAGE) +# Distribution-specific settings +SET(USE_GTEST_DEBIAN_PACKAGE OFF CACHE BOOL "Use the sources of Google Test shipped with libgtest-dev (Debian only)") +mark_as_advanced(USE_GTEST_DEBIAN_PACKAGE) # Some basic inclusions include(CheckIncludeFiles) @@ -239,28 +238,25 @@ ## Build the unit tests if required ##################################################################### -if (BUILD_UNIT_TESTS) - add_definitions(-DORTHANC_BUILD_UNIT_TESTS=1) - include(${CMAKE_SOURCE_DIR}/Resources/CMake/GoogleTestConfiguration.cmake) - add_executable(UnitTests - ${GTEST_SOURCES} - UnitTestsSources/FileStorage.cpp - UnitTestsSources/MemoryCache.cpp - UnitTestsSources/Png.cpp - UnitTestsSources/RestApi.cpp - UnitTestsSources/SQLite.cpp - UnitTestsSources/SQLiteChromium.cpp - UnitTestsSources/ServerIndex.cpp - UnitTestsSources/Versions.cpp - UnitTestsSources/Zip.cpp - UnitTestsSources/Lua.cpp - UnitTestsSources/main.cpp - ) - target_link_libraries(UnitTests ServerLibrary CoreLibrary) +include(${CMAKE_SOURCE_DIR}/Resources/CMake/GoogleTestConfiguration.cmake) +add_executable(UnitTests + ${GTEST_SOURCES} + UnitTestsSources/FileStorage.cpp + UnitTestsSources/MemoryCache.cpp + UnitTestsSources/Png.cpp + UnitTestsSources/RestApi.cpp + UnitTestsSources/SQLite.cpp + UnitTestsSources/SQLiteChromium.cpp + UnitTestsSources/ServerIndex.cpp + UnitTestsSources/Versions.cpp + UnitTestsSources/Zip.cpp + UnitTestsSources/Lua.cpp + UnitTestsSources/main.cpp + ) +target_link_libraries(UnitTests ServerLibrary CoreLibrary) - if (${OPENSSL_SOURCES_LENGTH} GREATER 0) - target_link_libraries(UnitTests OpenSSL) - endif() +if (${OPENSSL_SOURCES_LENGTH} GREATER 0) + target_link_libraries(UnitTests OpenSSL) endif()
--- a/INSTALL Tue Oct 29 09:04:25 2013 +0100 +++ b/INSTALL Tue Oct 29 10:31:02 2013 +0100 @@ -43,29 +43,7 @@ Native Linux Compilation ------------------------ -To build binaries with debug information: - -# cd ~/OrthancBuild -# cmake -DSTATIC_BUILD=ON -DCMAKE_BUILD_TYPE=Debug ~/Orthanc -# make -# make doc - - -To build a release version: - -# cd ~/OrthancBuild -# cmake -DSTATIC_BUILD=ON -DCMAKE_BUILD_TYPE=Release ~/Orthanc -# make -# make doc - - -Under Linux, you have the possibility to dynamically link Orthanc -against the shared libraries of your system, provided their version is -recent enough. This greatly speeds up the compilation: - -# cd ~/OrthancBuild -# cmake -DSTATIC_BUILD=OFF -DCMAKE_BUILD_TYPE=Debug ~/Orthanc -# make +See the file "LinuxCompilation.txt". @@ -104,23 +82,3 @@ # cd [...]\OrthancBuild # cmake -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Debug [...]\Orthanc # mingw32-make - - - -Using ccache ------------- - -Under Linux, you have the opportunity to use "ccache" to dramatically -decrease the compilation time when rebuilding Orthanc. This is -especially useful for developers. Under Debian/Ubuntu, you would use: - -# CC="ccache gcc" CXX="ccache g++" cmake "-DDCMTK_LIBRARIES=wrap;oflog" \ - -DSTATIC_BUILD=OFF -DCMAKE_BUILD_TYPE=Debug ~/Orthanc - - - -Troubleshooting ---------------- - -The build instructions for specific Linux distributions are available at the following place: -https://code.google.com/p/orthanc/wiki/FAQ#I_use_the_Linux_distribution_XXX,_how_can_I_build_Orthanc?
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LinuxCompilation.txt Tue Oct 29 10:31:02 2013 +0100 @@ -0,0 +1,102 @@ +This file is a complement to "INSTALL", which contains instructions +that are specific to Linux. + + +Static linking for Linux +======================== + +The most simple way of building Orthanc under Linux consists in +statically linking against all the third-party dependencies. In this +case, the system-wide libraries will not be used. The build tool +(CMake) will download the sources of all the required packages and +automatically compile them. This process should work on all the Linux +distributions. + + +To build binaries with debug information: + +# cd ~/OrthancBuild +# cmake -DSTATIC_BUILD=ON -DCMAKE_BUILD_TYPE=Debug ~/Orthanc +# make +# make doc + + +To build a release version: + +# cd ~/OrthancBuild +# cmake -DSTATIC_BUILD=ON -DCMAKE_BUILD_TYPE=Release ~/Orthanc +# make +# make doc + + +Note: When the "STATIC_BUILD" option is set to "ON", the build tool +will not ask you the permission to download packages from the +Internet. + + +Use system-wide libraries under Linux +===================================== + +Under Linux, by default, Orthanc links against the shared libraries of +your system (the "STATIC_BUILD" option is set to "OFF"). This greatly +speeds up the compilation. This is also required when building +packages for Linux distributions. Because using system libraries is +the default behavior, you just have to use: + +# cd ~/OrthancBuild +# cmake -DCMAKE_BUILD_TYPE=Debug ~/Orthanc +# make + + +However, on some Linux distributions, it is still required to download +and static link against some third-party dependencies, e.g. when the +system-wide library is not shipped or is outdated. Because of +difference in the packaging of the various Linux distribution, it is +also sometimes required to fine-tune some options. + +You will find below build instructions for specific Linux +distributions. Distributions tagged by "SUPPORTED" are tested by +Sébastien Jodogne. Distributions tagged by "CONTRIBUTED" come from +Orthanc users. + + +SUPPORTED - Debian Squeeze (6.0) +-------------------------------- + +# sudo apt-get install build-essential unzip cmake mercurial \ + uuid-dev libcurl4-gnutls-dev liblua5.1-0-dev + +# cmake -DALLOW_DOWNLOADS=ON \ + -DUSE_SYSTEM_BOOST=OFF \ + -DUSE_SYSTEM_DCMTK=OFF \ + -DUSE_SYSTEM_MONGOOSE=OFF \ + -DUSE_SYSTEM_JSONCPP=OFF \ + ~/Orthanc + + + +Other Linux distributions? +-------------------------- + +Please send us your build instructions (by a mail to +s.jodogne@gmail.com)! + +You can find build instructions for Orthanc up to 0.7.0 on the +following Wiki page: +https://code.google.com/p/orthanc/wiki/LinuxCompilationUpTo070 + +These instructions will not work as such beyond Orthanc 0.7.0, but +they might give indications. + + + + +Using ccache +============ + +Under Linux, you also have the opportunity to use "ccache" to +dramatically decrease the compilation time when rebuilding +Orthanc. This is especially useful for developers. To this end, you +would use: + +# CC="ccache gcc" CXX="ccache g++" cmake ~/Orthanc [Options]
--- a/Resources/CMake/DownloadPackage.cmake Tue Oct 29 09:04:25 2013 +0100 +++ b/Resources/CMake/DownloadPackage.cmake Tue Oct 29 10:31:02 2013 +0100 @@ -40,6 +40,15 @@ set(TMP_PATH "${CMAKE_SOURCE_DIR}/ThirdPartyDownloads/${TMP_FILENAME}") if (NOT EXISTS "${TMP_PATH}") message("Downloading ${Url}") + + # This fixes issue 6: "I think cmake shouldn't download the + # packages which are not in the system, it should stop and let + # user know." + # https://code.google.com/p/orthanc/issues/detail?id=6 + if (NOT STATIC_BUILD AND NOT ALLOW_DOWNLOADS) + message(FATAL_ERROR "CMake is not allowed to download from Internet. Please set the ALLOW_DOWNLOADS option to ON") + endif() + file(DOWNLOAD "${Url}" "${TMP_PATH}" SHOW_PROGRESS EXPECTED_MD5 "${MD5}") else() message("Using local copy of ${Url}")
--- a/Resources/CMake/GoogleLogConfiguration.cmake Tue Oct 29 09:04:25 2013 +0100 +++ b/Resources/CMake/GoogleLogConfiguration.cmake Tue Oct 29 10:31:02 2013 +0100 @@ -1,4 +1,4 @@ -if (STATIC_BUILD OR NOT USE_DYNAMIC_GOOGLE_LOG) +if (STATIC_BUILD OR NOT USE_SYSTEM_GOOGLE_LOG) SET(GOOGLE_LOG_SOURCES_DIR ${CMAKE_BINARY_DIR}/glog-0.3.2) DownloadPackage( "897fbff90d91ea2b6d6e78c8cea641cc"
--- a/Resources/CMake/GoogleTestConfiguration.cmake Tue Oct 29 09:04:25 2013 +0100 +++ b/Resources/CMake/GoogleTestConfiguration.cmake Tue Oct 29 10:31:02 2013 +0100 @@ -1,4 +1,4 @@ -if (DEBIAN_USE_GTEST_SOURCE_PACKAGE) +if (USE_GTEST_DEBIAN_PACKAGE) set(GTEST_SOURCES /usr/src/gtest/src/gtest-all.cc) include_directories(/usr/src/gtest) @@ -7,7 +7,7 @@ message(FATAL_ERROR "Please install the libgtest-dev package") endif() -elseif (STATIC_BUILD OR NOT USE_DYNAMIC_GOOGLE_TEST) +elseif (STATIC_BUILD OR NOT USE_SYSTEM_GOOGLE_TEST) SET(GTEST_SOURCES_DIR ${CMAKE_BINARY_DIR}/gtest-1.6.0) DownloadPackage( "4577b49f2973c90bf9ba69aa8166b786"
--- a/Resources/CMake/JsonCppConfiguration.cmake Tue Oct 29 09:04:25 2013 +0100 +++ b/Resources/CMake/JsonCppConfiguration.cmake Tue Oct 29 10:31:02 2013 +0100 @@ -1,14 +1,5 @@ -if (USE_DYNAMIC_JSONCPP) - CHECK_INCLUDE_FILE_CXX(jsoncpp/json/reader.h HAVE_JSONCPP_H) - if (NOT HAVE_JSONCPP_H) - message(FATAL_ERROR "Please install the libjsoncpp-dev package") - endif() - - include_directories(/usr/include/jsoncpp) - link_libraries(jsoncpp) - -else() - SET(JSONCPP_SOURCES_DIR ${CMAKE_BINARY_DIR}/jsoncpp-src-0.6.0-rc2) +if (STATIC_BUILD OR NOT USE_SYSTEM_JSONCPP) + set(JSONCPP_SOURCES_DIR ${CMAKE_BINARY_DIR}/jsoncpp-src-0.6.0-rc2) DownloadPackage( "363e2f4cbd3aeb63bf4e571f377400fb" "http://www.montefiore.ulg.ac.be/~jodogne/Orthanc/ThirdPartyDownloads/jsoncpp-src-0.6.0-rc2.tar.gz" @@ -25,5 +16,14 @@ ) source_group(ThirdParty\\JsonCpp REGULAR_EXPRESSION ${JSONCPP_SOURCES_DIR}/.*) + +else() + CHECK_INCLUDE_FILE_CXX(jsoncpp/json/reader.h HAVE_JSONCPP_H) + if (NOT HAVE_JSONCPP_H) + message(FATAL_ERROR "Please install the libjsoncpp-dev package") + endif() + + include_directories(/usr/include/jsoncpp) + link_libraries(jsoncpp) + endif() -
--- a/Resources/CMake/LibCurlConfiguration.cmake Tue Oct 29 09:04:25 2013 +0100 +++ b/Resources/CMake/LibCurlConfiguration.cmake Tue Oct 29 10:31:02 2013 +0100 @@ -1,4 +1,4 @@ -if (${STATIC_BUILD}) +if (STATIC_BUILD OR NOT USE_SYSTEM_CURL) SET(CURL_SOURCES_DIR ${CMAKE_BINARY_DIR}/curl-7.26.0) DownloadPackage( "3fa4d5236f2a36ca5c3af6715e837691"
--- a/Resources/CMake/LibPngConfiguration.cmake Tue Oct 29 09:04:25 2013 +0100 +++ b/Resources/CMake/LibPngConfiguration.cmake Tue Oct 29 10:31:02 2013 +0100 @@ -1,4 +1,4 @@ -if (${STATIC_BUILD}) +if (STATIC_BUILD OR NOT USE_SYSTEM_LIBPNG) SET(LIBPNG_SOURCES_DIR ${CMAKE_BINARY_DIR}/libpng-1.5.12) DownloadPackage( "8ea7f60347a306c5faf70b977fa80e28"
--- a/Resources/CMake/LuaConfiguration.cmake Tue Oct 29 09:04:25 2013 +0100 +++ b/Resources/CMake/LuaConfiguration.cmake Tue Oct 29 10:31:02 2013 +0100 @@ -1,4 +1,4 @@ -if (STATIC_BUILD OR NOT USE_DYNAMIC_LUA) +if (STATIC_BUILD OR NOT USE_SYSTEM_LUA) SET(LUA_SOURCES_DIR ${CMAKE_BINARY_DIR}/lua-5.1.5) DownloadPackage( "2e115fe26e435e33b0d5c022e4490567"
--- a/Resources/CMake/MongooseConfiguration.cmake Tue Oct 29 09:04:25 2013 +0100 +++ b/Resources/CMake/MongooseConfiguration.cmake Tue Oct 29 10:31:02 2013 +0100 @@ -1,4 +1,4 @@ -if (STATIC_BUILD OR NOT USE_DYNAMIC_MONGOOSE) +if (STATIC_BUILD OR NOT USE_SYSTEM_MONGOOSE) SET(MONGOOSE_SOURCES_DIR ${CMAKE_BINARY_DIR}/mongoose) DownloadPackage( "e718fc287b4eb1bd523be3fa00942bb0"
--- a/Resources/CMake/OpenSslConfiguration.cmake Tue Oct 29 09:04:25 2013 +0100 +++ b/Resources/CMake/OpenSslConfiguration.cmake Tue Oct 29 10:31:02 2013 +0100 @@ -1,4 +1,4 @@ -if (${STATIC_BUILD}) +if (STATIC_BUILD) SET(OPENSSL_SOURCES_DIR ${CMAKE_BINARY_DIR}/openssl-1.0.1c) DownloadPackage( "ae412727c8c15b67880aef7bd2999b2e"
--- a/Resources/CMake/SQLiteConfiguration.cmake Tue Oct 29 09:04:25 2013 +0100 +++ b/Resources/CMake/SQLiteConfiguration.cmake Tue Oct 29 10:31:02 2013 +0100 @@ -1,4 +1,4 @@ -if (STATIC_BUILD OR NOT USE_DYNAMIC_SQLITE) +if (STATIC_BUILD OR NOT USE_SYSTEM_SQLITE) SET(SQLITE_SOURCES_DIR ${CMAKE_BINARY_DIR}/sqlite-amalgamation-3071300) DownloadPackage( "5fbeff9645ab035a1f580e90b279a16d" @@ -36,7 +36,7 @@ IF (${SQLITE_VERSION_NUMBER} LESS 3007000) # "sqlite3_create_function_v2" is not defined in SQLite < 3.7.0 - message(FATAL_ERROR "SQLite version must be above 3.7.0. Please set the CMake variable USE_DYNAMIC_SQLITE to OFF.") + message(FATAL_ERROR "SQLite version must be above 3.7.0. Please set the CMake variable USE_SYSTEM_SQLITE to OFF.") ENDIF() link_libraries(sqlite3)