annotate OrthancFramework/Resources/CMake/ProtobufConfiguration.cmake @ 5188:4c6f0211caaf db-protobuf

compiling the protobuf compiler
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sun, 26 Mar 2023 21:09:13 +0200
parents 9466c95f70c8
children c0f6c6fe1c47
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5187
9466c95f70c8 integrating Protobuf library into Orthanc server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 # Orthanc - A Lightweight, RESTful DICOM Store
9466c95f70c8 integrating Protobuf library into Orthanc server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 # Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
9466c95f70c8 integrating Protobuf library into Orthanc server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 # Department, University Hospital of Liege, Belgium
9466c95f70c8 integrating Protobuf library into Orthanc server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 # Copyright (C) 2017-2023 Osimis S.A., Belgium
9466c95f70c8 integrating Protobuf library into Orthanc server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 # Copyright (C) 2021-2023 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
9466c95f70c8 integrating Protobuf library into Orthanc server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 #
9466c95f70c8 integrating Protobuf library into Orthanc server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 # This program is free software: you can redistribute it and/or
9466c95f70c8 integrating Protobuf library into Orthanc server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 # modify it under the terms of the GNU Lesser General Public License
9466c95f70c8 integrating Protobuf library into Orthanc server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 # as published by the Free Software Foundation, either version 3 of
9466c95f70c8 integrating Protobuf library into Orthanc server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 # the License, or (at your option) any later version.
9466c95f70c8 integrating Protobuf library into Orthanc server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 #
9466c95f70c8 integrating Protobuf library into Orthanc server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 # This program is distributed in the hope that it will be useful, but
9466c95f70c8 integrating Protobuf library into Orthanc server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
9466c95f70c8 integrating Protobuf library into Orthanc server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9466c95f70c8 integrating Protobuf library into Orthanc server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 # Lesser General Public License for more details.
9466c95f70c8 integrating Protobuf library into Orthanc server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 #
9466c95f70c8 integrating Protobuf library into Orthanc server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 # You should have received a copy of the GNU Lesser General Public
9466c95f70c8 integrating Protobuf library into Orthanc server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 # License along with this program. If not, see
9466c95f70c8 integrating Protobuf library into Orthanc server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 # <http://www.gnu.org/licenses/>.
9466c95f70c8 integrating Protobuf library into Orthanc server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20
9466c95f70c8 integrating Protobuf library into Orthanc server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
9466c95f70c8 integrating Protobuf library into Orthanc server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 if (STATIC_BUILD OR NOT USE_SYSTEM_PROTOBUF)
5188
4c6f0211caaf compiling the protobuf compiler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5187
diff changeset
23 if (ENABLE_PROTOBUF_COMPILER)
4c6f0211caaf compiling the protobuf compiler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5187
diff changeset
24 include(ExternalProject)
4c6f0211caaf compiling the protobuf compiler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5187
diff changeset
25 externalproject_add(ProtobufCompiler
4c6f0211caaf compiling the protobuf compiler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5187
diff changeset
26 SOURCE_DIR "${CMAKE_SOURCE_DIR}/../OrthancFramework/Resources/ProtocolBuffers"
4c6f0211caaf compiling the protobuf compiler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5187
diff changeset
27 BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/ProtobufCompiler-build"
4c6f0211caaf compiling the protobuf compiler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5187
diff changeset
28 # this helps triggering build when changing the external project
4c6f0211caaf compiling the protobuf compiler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5187
diff changeset
29 BUILD_ALWAYS 1
4c6f0211caaf compiling the protobuf compiler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5187
diff changeset
30 CMAKE_ARGS
4c6f0211caaf compiling the protobuf compiler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5187
diff changeset
31 -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
4c6f0211caaf compiling the protobuf compiler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5187
diff changeset
32 -DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR}
4c6f0211caaf compiling the protobuf compiler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5187
diff changeset
33 INSTALL_COMMAND ""
4c6f0211caaf compiling the protobuf compiler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5187
diff changeset
34 )
4c6f0211caaf compiling the protobuf compiler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5187
diff changeset
35 set(PROTOC_EXECUTABLE ${CMAKE_CURRENT_BINARY_DIR}/ProtobufCompiler-build/protoc)
4c6f0211caaf compiling the protobuf compiler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5187
diff changeset
36 endif()
4c6f0211caaf compiling the protobuf compiler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5187
diff changeset
37
5187
9466c95f70c8 integrating Protobuf library into Orthanc server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 include(${CMAKE_CURRENT_LIST_DIR}/../ProtocolBuffers/ProtobufLibrary.cmake)
9466c95f70c8 integrating Protobuf library into Orthanc server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 source_group(ThirdParty\\Protobuf REGULAR_EXPRESSION ${PROTOBUF_SOURCE_DIR}/.*)
9466c95f70c8 integrating Protobuf library into Orthanc server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40
9466c95f70c8 integrating Protobuf library into Orthanc server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 else()
5188
4c6f0211caaf compiling the protobuf compiler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5187
diff changeset
42 if (CMAKE_CROSSCOMPILING)
4c6f0211caaf compiling the protobuf compiler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5187
diff changeset
43 message(FATAL_ERROR "If cross-compiling, the static version of Protocol Buffers should be used to avoid version mismatch")
4c6f0211caaf compiling the protobuf compiler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5187
diff changeset
44 endif()
4c6f0211caaf compiling the protobuf compiler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5187
diff changeset
45
4c6f0211caaf compiling the protobuf compiler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5187
diff changeset
46 if (ENABLE_PROTOBUF_COMPILER)
4c6f0211caaf compiling the protobuf compiler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5187
diff changeset
47 find_program(PROTOC_EXECUTABLE protoc)
4c6f0211caaf compiling the protobuf compiler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5187
diff changeset
48 if (${PROTOC_EXECUTABLE} MATCHES "PROTOC_EXECUTABLE-NOTFOUND")
4c6f0211caaf compiling the protobuf compiler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5187
diff changeset
49 message(FATAL_ERROR "Please install the 'protoc' compiler for Protocol Buffers (package 'protobuf-compiler' on Debian/Ubuntu)")
4c6f0211caaf compiling the protobuf compiler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5187
diff changeset
50 endif()
4c6f0211caaf compiling the protobuf compiler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5187
diff changeset
51 add_custom_target(ProtobufCompiler)
5187
9466c95f70c8 integrating Protobuf library into Orthanc server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 endif()
9466c95f70c8 integrating Protobuf library into Orthanc server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53
9466c95f70c8 integrating Protobuf library into Orthanc server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 check_include_file_cxx(google/protobuf/any.h HAVE_PROTOBUF_H)
9466c95f70c8 integrating Protobuf library into Orthanc server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 if (NOT HAVE_PROTOBUF_H)
9466c95f70c8 integrating Protobuf library into Orthanc server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 message(FATAL_ERROR "Please install the libprotobuf-dev package")
9466c95f70c8 integrating Protobuf library into Orthanc server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 endif()
9466c95f70c8 integrating Protobuf library into Orthanc server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58
9466c95f70c8 integrating Protobuf library into Orthanc server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 set(CMAKE_REQUIRED_LIBRARIES "protobuf")
9466c95f70c8 integrating Protobuf library into Orthanc server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60
9466c95f70c8 integrating Protobuf library into Orthanc server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 include(CheckCXXSourceCompiles)
9466c95f70c8 integrating Protobuf library into Orthanc server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 check_cxx_source_compiles(
9466c95f70c8 integrating Protobuf library into Orthanc server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 "
9466c95f70c8 integrating Protobuf library into Orthanc server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 #include <google/protobuf/descriptor.h>
9466c95f70c8 integrating Protobuf library into Orthanc server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 int main()
9466c95f70c8 integrating Protobuf library into Orthanc server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 {
9466c95f70c8 integrating Protobuf library into Orthanc server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 google::protobuf::FieldDescriptor::TypeName(google::protobuf::FieldDescriptor::TYPE_FLOAT);
9466c95f70c8 integrating Protobuf library into Orthanc server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 }
9466c95f70c8 integrating Protobuf library into Orthanc server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 " HAVE_PROTOBUF_LIB)
9466c95f70c8 integrating Protobuf library into Orthanc server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 if (NOT HAVE_PROTOBUF_LIB)
9466c95f70c8 integrating Protobuf library into Orthanc server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 message(FATAL_ERROR "Cannot find the protobuf library")
9466c95f70c8 integrating Protobuf library into Orthanc server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 endif()
9466c95f70c8 integrating Protobuf library into Orthanc server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73
9466c95f70c8 integrating Protobuf library into Orthanc server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 unset(CMAKE_REQUIRED_LIBRARIES)
9466c95f70c8 integrating Protobuf library into Orthanc server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75
9466c95f70c8 integrating Protobuf library into Orthanc server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 link_libraries(protobuf)
9466c95f70c8 integrating Protobuf library into Orthanc server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 endif()