comparison OrthancFramework/Resources/CMake/ProtobufConfiguration.cmake @ 5807:8279eaab0d1d attach-custom-data

merged default -> attach-custom-data
author Alain Mazy <am@orthanc.team>
date Tue, 24 Sep 2024 11:39:52 +0200
parents f7adfb22e20e
children
comparison
equal deleted inserted replaced
5085:79f98ee4f04b 5807:8279eaab0d1d
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) 2024-2024 Orthanc Team SRL, Belgium
6 # Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
7 #
8 # This program is free software: you can redistribute it and/or
9 # modify it under the terms of the GNU Lesser General Public License
10 # as published by the Free Software Foundation, either version 3 of
11 # the License, or (at your option) any later version.
12 #
13 # This program is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 # Lesser General Public License for more details.
17 #
18 # You should have received a copy of the GNU Lesser General Public
19 # License along with this program. If not, see
20 # <http://www.gnu.org/licenses/>.
21
22
23 if (STATIC_BUILD OR NOT USE_SYSTEM_PROTOBUF)
24 if (ENABLE_PROTOBUF_COMPILER)
25 include(ExternalProject)
26 externalproject_add(ProtobufCompiler
27 SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/../ProtocolBuffers"
28 BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/ProtobufCompiler-build"
29 # this helps triggering build when changing the external project
30 BUILD_ALWAYS 1
31 CMAKE_ARGS
32 -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
33 -DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR}
34 )
35
36 # The "protoc" compiler is built using "externalproject_add",
37 # which builds for the host platform, not for the target platform
38 if (CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
39 set(Suffix ".exe")
40 else()
41 set(Suffix "")
42 endif()
43
44 set(PROTOC_EXECUTABLE ${CMAKE_CURRENT_BINARY_DIR}/protoc${Suffix})
45 endif()
46
47 include(${CMAKE_CURRENT_LIST_DIR}/../ProtocolBuffers/ProtobufLibrary.cmake)
48 source_group(ThirdParty\\Protobuf REGULAR_EXPRESSION ${PROTOBUF_SOURCE_DIR}/.*)
49
50 else()
51 if (CMAKE_CROSSCOMPILING)
52 message(FATAL_ERROR "If cross-compiling, the static version of Protocol Buffers should be used to avoid version mismatch")
53 endif()
54
55 if (ENABLE_PROTOBUF_COMPILER)
56 find_program(PROTOC_EXECUTABLE protoc)
57 if (${PROTOC_EXECUTABLE} MATCHES "PROTOC_EXECUTABLE-NOTFOUND")
58 message(FATAL_ERROR "Please install the 'protoc' compiler for Protocol Buffers (package 'protobuf-compiler' on Debian/Ubuntu)")
59 endif()
60 add_custom_target(ProtobufCompiler)
61 endif()
62
63 check_include_file_cxx(google/protobuf/any.h HAVE_PROTOBUF_H)
64 if (NOT HAVE_PROTOBUF_H)
65 message(FATAL_ERROR "Please install the libprotobuf-dev package")
66 endif()
67
68 set(CMAKE_REQUIRED_LIBRARIES "protobuf")
69
70 include(CheckCXXSourceCompiles)
71 check_cxx_source_compiles(
72 "
73 #include <google/protobuf/descriptor.h>
74 int main()
75 {
76 google::protobuf::FieldDescriptor::TypeName(google::protobuf::FieldDescriptor::TYPE_FLOAT);
77 }
78 " HAVE_PROTOBUF_LIB)
79 if (NOT HAVE_PROTOBUF_LIB)
80 message(FATAL_ERROR "Cannot find the protobuf library")
81 endif()
82
83 unset(CMAKE_REQUIRED_LIBRARIES)
84
85 link_libraries(protobuf)
86 endif()