comparison Resources/Orthanc/CMake/JsonCppConfiguration.cmake @ 0:3ecef5782f2c

initial commit
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 18 Oct 2023 17:59:44 +0200
parents
children 1be232fa8f33
comparison
equal deleted inserted replaced
-1:000000000000 0:3ecef5782f2c
1 # Orthanc - A Lightweight, RESTful DICOM Store
2 # Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
3 # Department, University Hospital of Liege, Belgium
4 # Copyright (C) 2017-2023 Osimis S.A., Belgium
5 # Copyright (C) 2021-2023 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
6 #
7 # This program is free software: you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public License
9 # as published by the Free Software Foundation, either version 3 of
10 # the License, or (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # Lesser General Public License for more details.
16 #
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this program. If not, see
19 # <http://www.gnu.org/licenses/>.
20
21
22 set(JSONCPP_CXX11 OFF)
23
24 if (STATIC_BUILD OR NOT USE_SYSTEM_JSONCPP)
25 if (USE_LEGACY_JSONCPP)
26 set(JSONCPP_SOURCES_DIR ${CMAKE_BINARY_DIR}/jsoncpp-0.10.7)
27 set(JSONCPP_URL "https://orthanc.uclouvain.be/third-party-downloads/jsoncpp-0.10.7.tar.gz")
28 set(JSONCPP_MD5 "3a8072ca6a1fa9cbaf7715ae625f134f")
29 add_definitions(-DORTHANC_LEGACY_JSONCPP=1)
30 else()
31 set(JSONCPP_SOURCES_DIR ${CMAKE_BINARY_DIR}/jsoncpp-1.9.4)
32 set(JSONCPP_URL "https://orthanc.uclouvain.be/third-party-downloads/jsoncpp-1.9.4.tar.gz")
33 set(JSONCPP_MD5 "4757b26ec89798c5247fa638edfdc446")
34 add_definitions(-DORTHANC_LEGACY_JSONCPP=0)
35 set(JSONCPP_CXX11 ON)
36 endif()
37
38 DownloadPackage(${JSONCPP_MD5} ${JSONCPP_URL} "${JSONCPP_SOURCES_DIR}")
39
40 set(JSONCPP_SOURCES
41 ${JSONCPP_SOURCES_DIR}/src/lib_json/json_reader.cpp
42 ${JSONCPP_SOURCES_DIR}/src/lib_json/json_value.cpp
43 ${JSONCPP_SOURCES_DIR}/src/lib_json/json_writer.cpp
44 )
45
46 include_directories(
47 ${JSONCPP_SOURCES_DIR}/include
48 )
49
50 if (NOT ENABLE_LOCALE)
51 add_definitions(-DJSONCPP_NO_LOCALE_SUPPORT=1)
52 endif()
53
54 source_group(ThirdParty\\JsonCpp REGULAR_EXPRESSION ${JSONCPP_SOURCES_DIR}/.*)
55
56 else()
57 find_path(JSONCPP_INCLUDE_DIR json/reader.h
58 /usr/include/jsoncpp
59 /usr/local/include/jsoncpp
60 )
61
62 message("JsonCpp include dir: ${JSONCPP_INCLUDE_DIR}")
63 include_directories(${JSONCPP_INCLUDE_DIR})
64 link_libraries(jsoncpp)
65
66 CHECK_INCLUDE_FILE_CXX(${JSONCPP_INCLUDE_DIR}/json/reader.h HAVE_JSONCPP_H)
67 if (NOT HAVE_JSONCPP_H)
68 message(FATAL_ERROR "Please install the libjsoncpp-dev package")
69 endif()
70
71 # Detect if the version of JsonCpp is >= 1.0.0
72 if (EXISTS ${JSONCPP_INCLUDE_DIR}/json/version.h)
73 file(STRINGS
74 "${JSONCPP_INCLUDE_DIR}/json/version.h"
75 JSONCPP_VERSION_MAJOR1 REGEX
76 ".*define JSONCPP_VERSION_MAJOR.*")
77
78 if (NOT JSONCPP_VERSION_MAJOR1)
79 message(FATAL_ERROR "Unable to extract the major version of JsonCpp")
80 endif()
81
82 string(REGEX REPLACE
83 ".*JSONCPP_VERSION_MAJOR.*([0-9]+)$" "\\1"
84 JSONCPP_VERSION_MAJOR ${JSONCPP_VERSION_MAJOR1})
85 message("JsonCpp major version: ${JSONCPP_VERSION_MAJOR}")
86
87 if (JSONCPP_VERSION_MAJOR GREATER 0)
88 set(JSONCPP_CXX11 ON)
89 endif()
90 else()
91 message("Unable to detect the major version of JsonCpp, assuming < 1.0.0")
92 endif()
93 endif()
94
95
96 if (JSONCPP_CXX11)
97 # Osimis has encountered problems when this macro is left at its
98 # default value (1000), so we increase this limit
99 # https://gitlab.kitware.com/third-party/jsoncpp/commit/56df2068470241f9043b676bfae415ed62a0c172
100 add_definitions(-DJSONCPP_DEPRECATED_STACK_LIMIT=5000)
101
102 if (APPLE AND
103 "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
104 # Explicitly adding "-std=c++11" is needed on XCode
105 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
106 endif()
107 endif()