Mercurial > hg > orthanc
changeset 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 | 50c4a18caa85 |
files | OrthancFramework/Resources/CMake/OrthancFrameworkParameters.cmake OrthancFramework/Resources/CMake/ProtobufConfiguration.cmake OrthancFramework/Resources/Patches/protobuf-3.5.1.patch OrthancFramework/Resources/ProtocolBuffers/ProtobufLibrary.cmake OrthancServer/CMakeLists.txt OrthancServer/Plugins/Include/orthanc/OrthancDatabasePlugin.proto |
diffstat | 6 files changed, 106 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/OrthancFramework/Resources/CMake/OrthancFrameworkParameters.cmake Sun Mar 26 11:59:03 2023 +0200 +++ b/OrthancFramework/Resources/CMake/OrthancFrameworkParameters.cmake Sun Mar 26 21:09:13 2023 +0200 @@ -124,7 +124,8 @@ set(ENABLE_LOCALE OFF CACHE INTERNAL "Enable support for locales (notably in Boost)") set(ENABLE_LUA OFF CACHE INTERNAL "Enable support of Lua scripting") set(ENABLE_PNG OFF CACHE INTERNAL "Enable support of PNG") -set(ENABLE_PROTOBUF OFF CACHE INTERNAL "Enable support for Google Protocol Buffers") +set(ENABLE_PROTOBUF OFF CACHE INTERNAL "Enable support for Google Protocol Buffers' library") +set(ENABLE_PROTOBUF_COMPILER OFF CACHE INTERNAL "Enable support for Google Protocol Buffers' compiler") set(ENABLE_PUGIXML OFF CACHE INTERNAL "Enable support of XML through Pugixml") set(ENABLE_SQLITE OFF CACHE INTERNAL "Enable support of SQLite databases") set(ENABLE_ZLIB OFF CACHE INTERNAL "Enable support of zlib")
--- a/OrthancFramework/Resources/CMake/ProtobufConfiguration.cmake Sun Mar 26 11:59:03 2023 +0200 +++ b/OrthancFramework/Resources/CMake/ProtobufConfiguration.cmake Sun Mar 26 21:09:13 2023 +0200 @@ -20,13 +20,35 @@ if (STATIC_BUILD OR NOT USE_SYSTEM_PROTOBUF) + if (ENABLE_PROTOBUF_COMPILER) + include(ExternalProject) + externalproject_add(ProtobufCompiler + SOURCE_DIR "${CMAKE_SOURCE_DIR}/../OrthancFramework/Resources/ProtocolBuffers" + BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/ProtobufCompiler-build" + # this helps triggering build when changing the external project + BUILD_ALWAYS 1 + CMAKE_ARGS + -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE} + -DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR} + INSTALL_COMMAND "" + ) + set(PROTOC_EXECUTABLE ${CMAKE_CURRENT_BINARY_DIR}/ProtobufCompiler-build/protoc) + endif() + include(${CMAKE_CURRENT_LIST_DIR}/../ProtocolBuffers/ProtobufLibrary.cmake) source_group(ThirdParty\\Protobuf REGULAR_EXPRESSION ${PROTOBUF_SOURCE_DIR}/.*) else() - find_program(PROTOC_EXECUTABLE protoc) - if (${PROTOC_EXECUTABLE} MATCHES "PROTOC_EXECUTABLE-NOTFOUND") - message(FATAL_ERROR "Please install the 'protoc' compiler for Protocol Buffers (package 'protobuf-compiler' on Debian/Ubuntu)") + if (CMAKE_CROSSCOMPILING) + message(FATAL_ERROR "If cross-compiling, the static version of Protocol Buffers should be used to avoid version mismatch") + endif() + + if (ENABLE_PROTOBUF_COMPILER) + find_program(PROTOC_EXECUTABLE protoc) + if (${PROTOC_EXECUTABLE} MATCHES "PROTOC_EXECUTABLE-NOTFOUND") + message(FATAL_ERROR "Please install the 'protoc' compiler for Protocol Buffers (package 'protobuf-compiler' on Debian/Ubuntu)") + endif() + add_custom_target(ProtobufCompiler) endif() check_include_file_cxx(google/protobuf/any.h HAVE_PROTOBUF_H)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/OrthancFramework/Resources/Patches/protobuf-3.5.1.patch Sun Mar 26 21:09:13 2023 +0200 @@ -0,0 +1,17 @@ +diff -urEb protobuf-3.5.1.orig/src/google/protobuf/stubs/io_win32.cc protobuf-3.5.1/src/google/protobuf/stubs/io_win32.cc +--- protobuf-3.5.1.orig/src/google/protobuf/stubs/io_win32.cc 2023-03-26 20:13:45.095021011 +0200 ++++ protobuf-3.5.1/src/google/protobuf/stubs/io_win32.cc 2023-03-26 20:19:19.932920102 +0200 +@@ -91,7 +91,12 @@ + + template <typename char_type> + bool null_or_empty(const char_type* s) { +- return s == nullptr || *s == 0; ++ /** ++ * "nullptr" is not known to Visual Studio 2008, because this is a ++ * C++11 construction, which shouldn't be present in protobuf 3.5.1 ++ * that is supposed to comply with C++98. ++ **/ ++ return s == NULL || *s == 0; + } + + // Returns true if the path starts with a drive letter, e.g. "c:".
--- a/OrthancFramework/Resources/ProtocolBuffers/ProtobufLibrary.cmake Sun Mar 26 11:59:03 2023 +0200 +++ b/OrthancFramework/Resources/ProtocolBuffers/ProtobufLibrary.cmake Sun Mar 26 21:09:13 2023 +0200 @@ -19,12 +19,32 @@ # <http://www.gnu.org/licenses/>. +set(PROTOBUF_SOURCE_DIR ${CMAKE_CURRENT_BINARY_DIR}/protobuf-3.5.1) + +if (IS_DIRECTORY "${PROTOBUF_SOURCE_DIR}") + set(FirstRun OFF) +else() + set(FirstRun ON) +endif() + DownloadPackage( "ca0d9b243e649d398a6b419acd35103a" "http://orthanc.uclouvain.be/third-party-downloads/protobuf-cpp-3.5.1.tar.gz" "${CMAKE_CURRENT_BINARY_DIR}/protobuf-3.5.1") -set(PROTOBUF_SOURCE_DIR ${CMAKE_CURRENT_BINARY_DIR}/protobuf-3.5.1) +if (FirstRun) + # Apply the patches + execute_process( + COMMAND ${PATCH_EXECUTABLE} -p0 -N -i + ${CMAKE_CURRENT_LIST_DIR}/../Patches/protobuf-3.5.1.patch + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + RESULT_VARIABLE Failure + ) + + if (Failure) + message(FATAL_ERROR "Error while patching a file") + endif() +endif() include_directories( ${PROTOBUF_SOURCE_DIR}/src
--- a/OrthancServer/CMakeLists.txt Sun Mar 26 11:59:03 2023 +0200 +++ b/OrthancServer/CMakeLists.txt Sun Mar 26 21:09:13 2023 +0200 @@ -42,6 +42,7 @@ set(ENABLE_OPENSSL_ENGINES ON) # OpenSSL engines are necessary for PKCS11 set(ENABLE_PNG ON) set(ENABLE_PROTOBUF ON) +set(ENABLE_PROTOBUF_COMPILER ON) set(ENABLE_PUGIXML ON) set(ENABLE_SQLITE ON) set(ENABLE_WEB_CLIENT ON) @@ -362,8 +363,13 @@ ## Build the core of Orthanc ##################################################################### +add_custom_target(AutogeneratedTarget + DEPENDS + ${AUTOGENERATED_SOURCES} + ) + # "CoreLibrary" contains all the third-party dependencies and the -# content of the "Core" folder +# content of the "OrthancFramework" folder add_library(CoreLibrary STATIC ${ORTHANC_CORE_PCH} @@ -372,6 +378,8 @@ ${AUTOGENERATED_SOURCES} ) +add_dependencies(CoreLibrary AutogeneratedTarget) + if (LIBICU_LIBRARIES) target_link_libraries(CoreLibrary ${LIBICU_LIBRARIES}) endif() @@ -381,6 +389,30 @@ ## Build the Orthanc server ##################################################################### +if (ENABLE_PLUGINS) + add_custom_command( + COMMAND + ${PROTOC_EXECUTABLE} ${CMAKE_SOURCE_DIR}/Plugins/Include/orthanc/OrthancDatabasePlugin.proto --cpp_out=${AUTOGENERATED_DIR} -I${CMAKE_SOURCE_DIR}/Plugins/Include/orthanc + DEPENDS + ProtobufCompiler + ${CMAKE_SOURCE_DIR}/Plugins/Include/orthanc/OrthancDatabasePlugin.proto + OUTPUT + ${AUTOGENERATED_DIR}/OrthancDatabasePlugin.pb.cc + ${AUTOGENERATED_DIR}/OrthancDatabasePlugin.pb.h + ) + + add_custom_target(OrthancDatabaseProtobuf + DEPENDS + ${AUTOGENERATED_DIR}/OrthancDatabasePlugin.pb.h + ) + + list(APPEND ORTHANC_SERVER_SOURCES + ${AUTOGENERATED_DIR}/OrthancDatabasePlugin.pb.cc + ) +else() + add_custom_target(OrthancDatabaseProtobuf) +endif() + add_library(ServerLibrary STATIC ${ORTHANC_SERVER_PCH} @@ -388,7 +420,7 @@ ) # Ensure autogenerated code is built before building ServerLibrary -add_dependencies(ServerLibrary CoreLibrary) +add_dependencies(ServerLibrary CoreLibrary OrthancDatabaseProtobuf) add_executable(Orthanc ${CMAKE_SOURCE_DIR}/Sources/main.cpp @@ -547,7 +579,6 @@ if (ENABLE_PLUGINS AND (BUILD_DELAYED_DELETION OR BUILD_CONNECTIVITY_CHECKS)) include(ExternalProject) - endif()