annotate OrthancFramework/Resources/CMake/ProtobufConfiguration.cmake @ 5190:c0f6c6fe1c47 db-protobuf

fix windows builds
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 27 Mar 2023 07:44:50 +0200
parents 4c6f0211caaf
children fb96f1ffd020
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 )
5190
c0f6c6fe1c47 fix windows builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5188
diff changeset
35
c0f6c6fe1c47 fix windows builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5188
diff changeset
36 # The "protoc" compiler is built using "externalproject_add",
c0f6c6fe1c47 fix windows builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5188
diff changeset
37 # which builds for the host platform, not for the target platform
c0f6c6fe1c47 fix windows builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5188
diff changeset
38 if (CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
c0f6c6fe1c47 fix windows builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5188
diff changeset
39 set(Suffix ".exe")
c0f6c6fe1c47 fix windows builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5188
diff changeset
40 else()
c0f6c6fe1c47 fix windows builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5188
diff changeset
41 set(Suffix "")
c0f6c6fe1c47 fix windows builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5188
diff changeset
42 endif()
c0f6c6fe1c47 fix windows builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5188
diff changeset
43
c0f6c6fe1c47 fix windows builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5188
diff changeset
44 set(PROTOC_EXECUTABLE ${CMAKE_CURRENT_BINARY_DIR}/ProtobufCompiler-build/protoc${Suffix})
5188
4c6f0211caaf compiling the protobuf compiler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5187
diff changeset
45 endif()
4c6f0211caaf compiling the protobuf compiler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5187
diff changeset
46
5187
9466c95f70c8 integrating Protobuf library into Orthanc server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 include(${CMAKE_CURRENT_LIST_DIR}/../ProtocolBuffers/ProtobufLibrary.cmake)
9466c95f70c8 integrating Protobuf library into Orthanc server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 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
49
9466c95f70c8 integrating Protobuf library into Orthanc server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 else()
5188
4c6f0211caaf compiling the protobuf compiler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5187
diff changeset
51 if (CMAKE_CROSSCOMPILING)
4c6f0211caaf compiling the protobuf compiler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5187
diff changeset
52 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
53 endif()
4c6f0211caaf compiling the protobuf compiler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5187
diff changeset
54
4c6f0211caaf compiling the protobuf compiler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5187
diff changeset
55 if (ENABLE_PROTOBUF_COMPILER)
4c6f0211caaf compiling the protobuf compiler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5187
diff changeset
56 find_program(PROTOC_EXECUTABLE protoc)
4c6f0211caaf compiling the protobuf compiler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5187
diff changeset
57 if (${PROTOC_EXECUTABLE} MATCHES "PROTOC_EXECUTABLE-NOTFOUND")
4c6f0211caaf compiling the protobuf compiler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5187
diff changeset
58 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
59 endif()
4c6f0211caaf compiling the protobuf compiler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5187
diff changeset
60 add_custom_target(ProtobufCompiler)
5187
9466c95f70c8 integrating Protobuf library into Orthanc server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 endif()
9466c95f70c8 integrating Protobuf library into Orthanc server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62
9466c95f70c8 integrating Protobuf library into Orthanc server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 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
64 if (NOT HAVE_PROTOBUF_H)
9466c95f70c8 integrating Protobuf library into Orthanc server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 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
66 endif()
9466c95f70c8 integrating Protobuf library into Orthanc server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67
9466c95f70c8 integrating Protobuf library into Orthanc server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 set(CMAKE_REQUIRED_LIBRARIES "protobuf")
9466c95f70c8 integrating Protobuf library into Orthanc server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69
9466c95f70c8 integrating Protobuf library into Orthanc server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 include(CheckCXXSourceCompiles)
9466c95f70c8 integrating Protobuf library into Orthanc server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 check_cxx_source_compiles(
9466c95f70c8 integrating Protobuf library into Orthanc server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 "
9466c95f70c8 integrating Protobuf library into Orthanc server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 #include <google/protobuf/descriptor.h>
9466c95f70c8 integrating Protobuf library into Orthanc server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 int main()
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 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
77 }
9466c95f70c8 integrating Protobuf library into Orthanc server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 " HAVE_PROTOBUF_LIB)
9466c95f70c8 integrating Protobuf library into Orthanc server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 if (NOT HAVE_PROTOBUF_LIB)
9466c95f70c8 integrating Protobuf library into Orthanc server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 message(FATAL_ERROR "Cannot find the protobuf library")
9466c95f70c8 integrating Protobuf library into Orthanc server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 endif()
9466c95f70c8 integrating Protobuf library into Orthanc server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82
9466c95f70c8 integrating Protobuf library into Orthanc server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 unset(CMAKE_REQUIRED_LIBRARIES)
9466c95f70c8 integrating Protobuf library into Orthanc server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84
9466c95f70c8 integrating Protobuf library into Orthanc server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 link_libraries(protobuf)
9466c95f70c8 integrating Protobuf library into Orthanc server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 endif()