Mercurial > hg > orthanc
changeset 3242:5d78df37c62f
automating compilation if icu is used
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Sat, 16 Feb 2019 09:17:50 +0100 |
parents | 32596919d729 |
children | cf0ad1fb2bb7 |
files | Resources/CMake/DownloadPackage.cmake Resources/CMake/LibIcuConfiguration.cmake Resources/CMake/OrthancFrameworkParameters.cmake Resources/LinuxStandardBaseToolchain.cmake Resources/ThirdParty/icu/CMakeLists.txt Resources/ThirdParty/icu/README.txt Resources/ThirdParty/icu/Version.cmake |
diffstat | 7 files changed, 179 insertions(+), 60 deletions(-) [+] |
line wrap: on
line diff
--- a/Resources/CMake/DownloadPackage.cmake Sat Feb 16 00:31:35 2019 +0100 +++ b/Resources/CMake/DownloadPackage.cmake Sat Feb 16 09:17:50 2019 +0100 @@ -57,45 +57,64 @@ if (${TAR_EXECUTABLE} MATCHES "TAR_EXECUTABLE-NOTFOUND") message(FATAL_ERROR "Please install the 'tar' package") endif() + + find_program(GUNZIP_EXECUTABLE gunzip) + if (${GUNZIP_EXECUTABLE} MATCHES "GUNZIP_EXECUTABLE-NOTFOUND") + message(FATAL_ERROR "Please install the 'gzip' package") + endif() endif() +macro(DownloadFile MD5 Url) + GetUrlFilename(TMP_FILENAME "${Url}") + + 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() + + if ("${MD5}" STREQUAL "no-check") + message(WARNING "Not checking the MD5 of: ${Url}") + file(DOWNLOAD "${Url}" "${TMP_PATH}" + SHOW_PROGRESS TIMEOUT 300 INACTIVITY_TIMEOUT 60 + STATUS Failure) + else() + file(DOWNLOAD "${Url}" "${TMP_PATH}" + SHOW_PROGRESS TIMEOUT 300 INACTIVITY_TIMEOUT 60 + EXPECTED_MD5 "${MD5}" STATUS Failure) + endif() + + list(GET Failure 0 Status) + if (NOT Status EQUAL 0) + message(FATAL_ERROR "Cannot download file: ${Url}") + endif() + + else() + message("Using local copy of ${Url}") + + if ("${MD5}" STREQUAL "no-check") + message(WARNING "Not checking the MD5 of: ${Url}") + else() + file(MD5 ${TMP_PATH} ActualMD5) + if (NOT "${ActualMD5}" STREQUAL "${MD5}") + message(FATAL_ERROR "The MD5 hash of a previously download file is invalid: ${TMP_PATH}") + endif() + endif() + endif() +endmacro() + + macro(DownloadPackage MD5 Url TargetDirectory) if (NOT IS_DIRECTORY "${TargetDirectory}") - GetUrlFilename(TMP_FILENAME "${Url}") - - 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() - - if ("${MD5}" STREQUAL "no-check") - message(WARNING "Not checking the MD5 of: ${Url}") - file(DOWNLOAD "${Url}" "${TMP_PATH}" SHOW_PROGRESS TIMEOUT 300 INACTIVITY_TIMEOUT 60) - else() - file(DOWNLOAD "${Url}" "${TMP_PATH}" SHOW_PROGRESS TIMEOUT 300 INACTIVITY_TIMEOUT 60 EXPECTED_MD5 "${MD5}") - endif() - - else() - message("Using local copy of ${Url}") - - if ("${MD5}" STREQUAL "no-check") - message(WARNING "Not checking the MD5 of: ${Url}") - else() - file(MD5 ${TMP_PATH} ActualMD5) - if (NOT "${ActualMD5}" STREQUAL "${MD5}") - message(FATAL_ERROR "The MD5 hash of a previously download file is invalid: ${TMP_PATH}") - endif() - endif() - endif() - + DownloadFile("${MD5}" "${Url}") + GetUrlExtension(TMP_EXTENSION "${Url}") #message(${TMP_EXTENSION}) message("Uncompressing ${TMP_FILENAME}") @@ -140,7 +159,7 @@ OUTPUT_QUIET ) else() - message(FATAL_ERROR "Support your platform here") + message(FATAL_ERROR "Unsupported package extension: ${TMP_EXTENSION}") endif() else() @@ -170,7 +189,7 @@ RESULT_VARIABLE Failure ) else() - message(FATAL_ERROR "Unknown package format.") + message(FATAL_ERROR "Unsupported package extension: ${TMP_EXTENSION}") endif() endif() @@ -183,3 +202,58 @@ endif() endif() endmacro() + + + +macro(DownloadCompressedFile MD5 Url TargetFile) + message(${MD5}) + message(${Url}) + message(${TargetFile}) + if (NOT EXISTS "${TargetFile}") + DownloadFile("${MD5}" "${Url}") + + GetUrlExtension(TMP_EXTENSION "${Url}") + #message(${TMP_EXTENSION}) + message("Uncompressing ${TMP_FILENAME}") + + if ("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Windows") + # How to silently extract files using 7-zip + # http://superuser.com/questions/331148/7zip-command-line-extract-silently-quietly + + if ("${TMP_EXTENSION}" STREQUAL "gz") + execute_process( + COMMAND ${ZIP_EXECUTABLE} e -y ${TMP_PATH} + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + RESULT_VARIABLE Failure + OUTPUT_QUIET + ) + + if (Failure) + message(FATAL_ERROR "Error while running the uncompression tool") + endif() + + else() + message(FATAL_ERROR "Unsupported file extension: ${TMP_EXTENSION}") + endif() + + else() + if ("${TMP_EXTENSION}" STREQUAL "gz") + execute_process( + COMMAND sh -c "${GUNZIP_EXECUTABLE} -c ${TMP_PATH}" + OUTPUT_FILE "${TargetFile}" + RESULT_VARIABLE Failure + ) + else() + message(FATAL_ERROR "Unsupported file extension: ${TMP_EXTENSION}") + endif() + endif() + + if (Failure) + message(FATAL_ERROR "Error while running the uncompression tool") + endif() + + if (NOT EXISTS "${TargetFile}") + message(FATAL_ERROR "The file was not uncompressed at the proper location. Check the CMake instructions.") + endif() + endif() +endmacro()
--- a/Resources/CMake/LibIcuConfiguration.cmake Sat Feb 16 00:31:35 2019 +0100 +++ b/Resources/CMake/LibIcuConfiguration.cmake Sat Feb 16 09:17:50 2019 +0100 @@ -1,3 +1,5 @@ + +# Check out: ../ThirdParty/icu/README.txt # http://userguide.icu-project.org/packaging # http://userguide.icu-project.org/howtouseicu @@ -7,15 +9,15 @@ if (STATIC_BUILD OR NOT USE_SYSTEM_LIBICU) include(${CMAKE_CURRENT_LIST_DIR}/../ThirdParty/icu/Version.cmake) DownloadPackage(${LIBICU_MD5} ${LIBICU_URL} "${LIBICU_SOURCES_DIR}") - #DownloadPackage("2e12e17ae89e04768cfdc531aae4a5fb" "http://localhost/icudt63l_dat.c.gz" "icudt63l_dat.c") - + DownloadCompressedFile(${LIBICU_DATA_MD5} ${LIBICU_DATA_URL} ${LIBICU_DATA}) + include_directories(BEFORE ${LIBICU_SOURCES_DIR}/source/common ${LIBICU_SOURCES_DIR}/source/i18n ) set(LIBICU_SOURCES - /home/jodogne/Subversion/orthanc/ThirdPartyDownloads/${LIBICU_DATA} + ${CMAKE_BINARY_DIR}/${LIBICU_DATA} ) aux_source_directory(${LIBICU_SOURCES_DIR}/source/common LIBICU_SOURCES) @@ -38,7 +40,7 @@ ) set_source_files_properties( - /home/jodogne/Subversion/orthanc/ThirdPartyDownloads/${LIBICU_DATA} + ${CMAKE_BINARY_DIR}/${LIBICU_DATA} PROPERTIES COMPILE_DEFINITIONS "char16_t=uint16_t" )
--- a/Resources/CMake/OrthancFrameworkParameters.cmake Sat Feb 16 00:31:35 2019 +0100 +++ b/Resources/CMake/OrthancFrameworkParameters.cmake Sat Feb 16 09:17:50 2019 +0100 @@ -76,7 +76,6 @@ mark_as_advanced(SYSTEM_MONGOOSE_USE_CALLBACKS) mark_as_advanced(BOOST_LOCALE_BACKEND) mark_as_advanced(USE_PUGIXML) -mark_as_advanced(USE_LEGACY_JSONCPP) #####################################################################
--- a/Resources/LinuxStandardBaseToolchain.cmake Sat Feb 16 00:31:35 2019 +0100 +++ b/Resources/LinuxStandardBaseToolchain.cmake Sat Feb 16 09:17:50 2019 +0100 @@ -1,4 +1,4 @@ -# LSB_CC=gcc-4.8 LSB_CXX=g++-4.8 cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=../Resources/LinuxStandardBaseToolchain.cmake -DUSE_LEGACY_JSONCPP=ON -DBOOST_LOCALE_BACKEND=gcc +# LSB_CC=gcc-4.8 LSB_CXX=g++-4.8 cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=../Resources/LinuxStandardBaseToolchain.cmake -DUSE_LEGACY_JSONCPP=ON -DUSE_LEGACY_LIBICU=ON -DBOOST_LOCALE_BACKEND=icu INCLUDE(CMakeForceCompiler)
--- a/Resources/ThirdParty/icu/CMakeLists.txt Sat Feb 16 00:31:35 2019 +0100 +++ b/Resources/ThirdParty/icu/CMakeLists.txt Sat Feb 16 09:17:50 2019 +0100 @@ -1,9 +1,3 @@ -# Legacy version using LSB: -# LSB_CC=gcc-4.8 LSB_CXX=g++-4.8 cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=../../../LinuxStandardBaseToolchain.cmake -DUSE_LEGACY_LIBICU=ON -G Ninja && ninja - -# Newest release of icu: -# cmake .. -DCMAKE_BUILD_TYPE=Debug -G Ninja && ninja - cmake_minimum_required(VERSION 2.8) project(IcuCodeGeneration) @@ -17,6 +11,9 @@ include(${CMAKE_SOURCE_DIR}/../../CMake/DownloadPackage.cmake) include(Version.cmake) +set(SOURCE_DATA + "${LIBICU_SOURCES_DIR}/source/data/in/${LIBICU_DATA_VERSION}${LIBICU_SUFFIX}.dat") + set(ALLOW_DOWNLOADS ON) DownloadPackage(${LIBICU_MD5} ${LIBICU_URL} "${LIBICU_SOURCES_DIR}") @@ -51,19 +48,25 @@ ${LIBICU_SOURCES} ) +configure_file(${SOURCE_DATA} + ${CMAKE_BINARY_DIR}/${LIBICU_DATA_VERSION}.dat + COPYONLY) + add_custom_command( - OUTPUT ${LIBICU_DATA} - COMMAND IcuCodeGeneration ${LIBICU_SOURCE_DATA} + OUTPUT ${CMAKE_BINARY_DIR}/${LIBICU_DATA} + COMMAND IcuCodeGeneration ${CMAKE_BINARY_DIR}/${LIBICU_DATA_VERSION}.dat DEPENDS IcuCodeGeneration ) +message(${LIBICU_DATA}.gz) + add_custom_command( - OUTPUT ${LIBICU_DATA}.gz - COMMAND gzip -f ${LIBICU_DATA} + OUTPUT ${CMAKE_BINARY_DIR}/${LIBICU_DATA}.gz + COMMAND gzip ${CMAKE_BINARY_DIR}/${LIBICU_DATA_VERSION}_dat.c -c > ${CMAKE_BINARY_DIR}/${LIBICU_DATA}.gz DEPENDS ${LIBICU_DATA} ) -add_custom_target(Final ALL DEPENDS ${LIBICU_DATA}.gz) +add_custom_target(Final ALL DEPENDS ${CMAKE_BINARY_DIR}/${LIBICU_DATA}.gz) install( FILES ${CMAKE_BINARY_DIR}/${LIBICU_DATA}.gz
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Resources/ThirdParty/icu/README.txt Sat Feb 16 09:17:50 2019 +0100 @@ -0,0 +1,37 @@ +Generating ICU data file +======================== + +This folder generates the "icudtXXX_dat.c" file that contains the +resources internal to ICU. + +IMPORTANT: Since ICU 59, C++11 is mandatory, making it incompatible +with Linux Standard Base (LSB) SDK. The option +"-DUSE_LEGACY_LIBICU=ON" will use the latest version of ICU that does +not use C++11 (58-2). + + + +Usage +----- + +Newest release of icu: + +$ cmake .. -G Ninja && ninja install + +Legacy version for LSB: + +$ cmake .. -G Ninja -DUSE_LEGACY_LIBICU=ON && ninja install + +Legacy version using LSB: + +$ LSB_CC=gcc-4.8 LSB_CXX=g++-4.8 cmake .. -G Ninja \ + -DCMAKE_TOOLCHAIN_FILE=../../../LinuxStandardBaseToolchain.cmake \ + -DUSE_LEGACY_LIBICU=ON +$ ninja install + + +Result +------ + +The resulting files are placed in the "ThirdPartyDownloads" folder at +the root of the Orthanc repository (next to the main "CMakeLists.txt").
--- a/Resources/ThirdParty/icu/Version.cmake Sat Feb 16 00:31:35 2019 +0100 +++ b/Resources/ThirdParty/icu/Version.cmake Sat Feb 16 09:17:50 2019 +0100 @@ -11,18 +11,22 @@ set(LIBICU_SUFFIX "l") endif() -set(LIBICU_SOURCES_DIR ${CMAKE_BINARY_DIR}/icu) +set(LIBICU_BASE_URL "http://orthanc.osimis.io/ThirdPartyDownloads") if (USE_LEGACY_LIBICU) # This is the last version of icu that compiles with C++11 # support. It can be used for Linux Standard Base and Visual Studio 2008. - set(LIBICU_URL "http://orthanc.osimis.io/ThirdPartyDownloads/icu4c-58_2-src.tgz") + set(LIBICU_URL "${LIBICU_BASE_URL}/icu4c-58_2-src.tgz") set(LIBICU_MD5 "fac212b32b7ec7ab007a12dff1f3aea1") - set(LIBICU_DATA "icudt58${LIBICU_SUFFIX}_dat.c") - set(LIBICU_SOURCE_DATA "${LIBICU_SOURCES_DIR}/source/data/in/icudt58l.dat") + set(LIBICU_DATA_VERSION "icudt58") + set(LIBICU_DATA_MD5 "7761ce2c00d2dda5800f375f878c4a88") else() - set(LIBICU_URL "http://orthanc.osimis.io/ThirdPartyDownloads/icu4c-63_1-src.tgz") + set(LIBICU_URL "${LIBICU_BASE_URL}/icu4c-63_1-src.tgz") set(LIBICU_MD5 "9e40f6055294284df958200e308bce50") - set(LIBICU_DATA "icudt63${LIBICU_SUFFIX}_dat.c") - set(LIBICU_SOURCE_DATA "${LIBICU_SOURCES_DIR}/source/data/in/icudt63l.dat") + set(LIBICU_DATA_VERSION "icudt63") + set(LIBICU_DATA_MD5 "dc2f015e886f53e19cec3a44b971afba") endif() + +set(LIBICU_SOURCES_DIR ${CMAKE_BINARY_DIR}/icu) +set(LIBICU_DATA "${LIBICU_DATA_VERSION}${LIBICU_SUFFIX}_dat.c") +set(LIBICU_DATA_URL "${LIBICU_BASE_URL}/${LIBICU_DATA}.gz")