comparison Resources/Orthanc/CMake/ProtobufConfiguration.cmake @ 409:e25f4500b531

fix linking against system-wide Orthanc framework
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sat, 15 Apr 2023 14:55:21 +0200
parents
children ecd0b719cff5
comparison
equal deleted inserted replaced
407:ca6dc9bb8b79 409:e25f4500b531
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 if (STATIC_BUILD OR NOT USE_SYSTEM_PROTOBUF)
23 if (ENABLE_PROTOBUF_COMPILER)
24 include(ExternalProject)
25 externalproject_add(ProtobufCompiler
26 SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/../ProtocolBuffers"
27 BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/ProtobufCompiler-build"
28 # this helps triggering build when changing the external project
29 BUILD_ALWAYS 1
30 CMAKE_ARGS
31 -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
32 -DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR}
33 )
34
35 # The "protoc" compiler is built using "externalproject_add",
36 # which builds for the host platform, not for the target platform
37 if (CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
38 set(Suffix ".exe")
39 else()
40 set(Suffix "")
41 endif()
42
43 set(PROTOC_EXECUTABLE ${CMAKE_CURRENT_BINARY_DIR}/protoc${Suffix})
44 endif()
45
46 include(${CMAKE_CURRENT_LIST_DIR}/../ProtocolBuffers/ProtobufLibrary.cmake)
47 source_group(ThirdParty\\Protobuf REGULAR_EXPRESSION ${PROTOBUF_SOURCE_DIR}/.*)
48
49 else()
50 if (CMAKE_CROSSCOMPILING)
51 message(FATAL_ERROR "If cross-compiling, the static version of Protocol Buffers should be used to avoid version mismatch")
52 endif()
53
54 if (ENABLE_PROTOBUF_COMPILER)
55 find_program(PROTOC_EXECUTABLE protoc)
56 if (${PROTOC_EXECUTABLE} MATCHES "PROTOC_EXECUTABLE-NOTFOUND")
57 message(FATAL_ERROR "Please install the 'protoc' compiler for Protocol Buffers (package 'protobuf-compiler' on Debian/Ubuntu)")
58 endif()
59 add_custom_target(ProtobufCompiler)
60 endif()
61
62 check_include_file_cxx(google/protobuf/any.h HAVE_PROTOBUF_H)
63 if (NOT HAVE_PROTOBUF_H)
64 message(FATAL_ERROR "Please install the libprotobuf-dev package")
65 endif()
66
67 set(CMAKE_REQUIRED_LIBRARIES "protobuf")
68
69 include(CheckCXXSourceCompiles)
70 check_cxx_source_compiles(
71 "
72 #include <google/protobuf/descriptor.h>
73 int main()
74 {
75 google::protobuf::FieldDescriptor::TypeName(google::protobuf::FieldDescriptor::TYPE_FLOAT);
76 }
77 " HAVE_PROTOBUF_LIB)
78 if (NOT HAVE_PROTOBUF_LIB)
79 message(FATAL_ERROR "Cannot find the protobuf library")
80 endif()
81
82 unset(CMAKE_REQUIRED_LIBRARIES)
83
84 link_libraries(protobuf)
85 endif()