2016-09-23 23:10:37 +08:00
|
|
|
include(vcpkg_common_functions)
|
2017-05-11 03:29:10 +08:00
|
|
|
|
2017-09-01 19:42:51 +08:00
|
|
|
set(PROTOBUF_VERSION 3.4.0)
|
2017-05-11 03:29:10 +08:00
|
|
|
|
2016-09-23 23:10:37 +08:00
|
|
|
vcpkg_download_distfile(ARCHIVE_FILE
|
2017-05-11 03:29:10 +08:00
|
|
|
URLS "https://github.com/google/protobuf/releases/download/v${PROTOBUF_VERSION}/protobuf-cpp-${PROTOBUF_VERSION}.tar.gz"
|
|
|
|
FILENAME "protobuf-cpp-${PROTOBUF_VERSION}.tar.gz"
|
2017-09-01 19:42:51 +08:00
|
|
|
SHA512 ce9bd9bc818c4a8e8b08c83e8a4eba6fca008a64a5ad9d322b19683b1de2b5fa622ed99093323f3c9d0820ef23430f7ee07f6930f7f877d334e5d36df9b0be0e
|
2016-09-23 23:10:37 +08:00
|
|
|
)
|
|
|
|
vcpkg_download_distfile(TOOL_ARCHIVE_FILE
|
2017-05-11 03:29:10 +08:00
|
|
|
URLS "https://github.com/google/protobuf/releases/download/v${PROTOBUF_VERSION}/protoc-${PROTOBUF_VERSION}-win32.zip"
|
|
|
|
FILENAME "protoc-${PROTOBUF_VERSION}-win32.zip"
|
2017-09-01 19:42:51 +08:00
|
|
|
SHA512 b874c3f47b39ac78f5675e05220318683004a365c248bf47ba50d8c66c8ed7763432451bab30524e131e1185a2bdaa6e6071b389eb61ad58b1b95974cf39d41b
|
2016-09-23 23:10:37 +08:00
|
|
|
)
|
2017-05-11 03:29:10 +08:00
|
|
|
|
|
|
|
set(SOURCE_PATH ${CURRENT_BUILDTREES_DIR}/src/protobuf-${PROTOBUF_VERSION})
|
|
|
|
set(TOOL_PATH ${CURRENT_BUILDTREES_DIR}/src/protobuf-${PROTOBUF_VERSION}-win32)
|
|
|
|
|
2016-09-23 23:10:37 +08:00
|
|
|
vcpkg_extract_source_archive(${ARCHIVE_FILE})
|
2017-06-12 23:26:30 +08:00
|
|
|
|
2017-07-01 04:59:23 +08:00
|
|
|
# Add a flag that can be set to disable the protobuf compiler
|
2017-06-12 23:26:30 +08:00
|
|
|
vcpkg_apply_patches(
|
|
|
|
SOURCE_PATH ${CURRENT_BUILDTREES_DIR}/src/protobuf-${PROTOBUF_VERSION}
|
2017-09-01 19:42:51 +08:00
|
|
|
PATCHES "${CMAKE_CURRENT_LIST_DIR}/001-add-compiler-flag.patch"
|
2017-06-12 23:26:30 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2017-05-11 03:29:10 +08:00
|
|
|
vcpkg_extract_source_archive(${TOOL_ARCHIVE_FILE} ${TOOL_PATH})
|
|
|
|
|
2017-07-01 04:59:23 +08:00
|
|
|
# Disable the protobuf compiler when targeting UWP
|
|
|
|
if(VCPKG_CMAKE_SYSTEM_NAME STREQUAL WindowsStore)
|
|
|
|
set(protobuf_BUILD_COMPILER OFF)
|
|
|
|
else()
|
|
|
|
set(protobuf_BUILD_COMPILER ON)
|
|
|
|
endif()
|
|
|
|
|
2017-05-11 03:29:10 +08:00
|
|
|
if (VCPKG_LIBRARY_LINKAGE STREQUAL dynamic)
|
|
|
|
set(protobuf_BUILD_SHARED_LIBS ON)
|
|
|
|
else()
|
|
|
|
set(protobuf_BUILD_SHARED_LIBS OFF)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(VCPKG_CRT_LINKAGE STREQUAL static)
|
|
|
|
set(protobuf_MSVC_STATIC_RUNTIME ON)
|
|
|
|
else()
|
|
|
|
set(protobuf_MSVC_STATIC_RUNTIME OFF)
|
|
|
|
endif()
|
2016-09-23 23:10:37 +08:00
|
|
|
|
|
|
|
vcpkg_configure_cmake(
|
2017-05-11 03:29:10 +08:00
|
|
|
SOURCE_PATH ${SOURCE_PATH}/cmake
|
2016-09-23 23:10:37 +08:00
|
|
|
OPTIONS
|
2017-05-11 03:29:10 +08:00
|
|
|
-Dprotobuf_BUILD_SHARED_LIBS=${protobuf_BUILD_SHARED_LIBS}
|
|
|
|
-Dprotobuf_MSVC_STATIC_RUNTIME=${protobuf_MSVC_STATIC_RUNTIME}
|
2016-09-23 23:10:37 +08:00
|
|
|
-Dprotobuf_WITH_ZLIB=ON
|
|
|
|
-Dprotobuf_BUILD_TESTS=OFF
|
2017-07-01 04:59:23 +08:00
|
|
|
-Dprotobuf_BUILD_COMPILER=${protobuf_BUILD_COMPILER}
|
2016-09-23 23:10:37 +08:00
|
|
|
-DCMAKE_INSTALL_CMAKEDIR=share/protobuf
|
|
|
|
)
|
|
|
|
|
2017-01-17 10:36:47 +08:00
|
|
|
# Using 64-bit toolset to avoid occassional Linker Out-of-Memory issues.
|
|
|
|
vcpkg_install_cmake(MSVC_64_TOOLSET)
|
2016-09-23 23:10:37 +08:00
|
|
|
|
2017-01-17 10:36:47 +08:00
|
|
|
# It appears that at this point the build hasn't actually finished. There is probably
|
|
|
|
# a process spawned by the build, therefore we need to wait a bit.
|
|
|
|
|
|
|
|
function(protobuf_try_remove_recurse_wait PATH_TO_REMOVE)
|
|
|
|
file(REMOVE_RECURSE ${PATH_TO_REMOVE})
|
|
|
|
if (EXISTS "${PATH_TO_REMOVE}")
|
|
|
|
execute_process(COMMAND ${CMAKE_COMMAND} -E sleep 5)
|
|
|
|
file(REMOVE_RECURSE ${PATH_TO_REMOVE})
|
|
|
|
endif()
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
protobuf_try_remove_recurse_wait(${CURRENT_PACKAGES_DIR}/debug/include)
|
2016-09-23 23:10:37 +08:00
|
|
|
|
|
|
|
file(READ ${CURRENT_PACKAGES_DIR}/share/protobuf/protobuf-targets-release.cmake RELEASE_MODULE)
|
|
|
|
string(REPLACE "\${_IMPORT_PREFIX}/bin/protoc.exe" "\${_IMPORT_PREFIX}/tools/protoc.exe" RELEASE_MODULE "${RELEASE_MODULE}")
|
|
|
|
file(WRITE ${CURRENT_PACKAGES_DIR}/share/protobuf/protobuf-targets-release.cmake "${RELEASE_MODULE}")
|
|
|
|
|
|
|
|
file(READ ${CURRENT_PACKAGES_DIR}/debug/share/protobuf/protobuf-targets-debug.cmake DEBUG_MODULE)
|
|
|
|
string(REPLACE "\${_IMPORT_PREFIX}" "\${_IMPORT_PREFIX}/debug" DEBUG_MODULE "${DEBUG_MODULE}")
|
|
|
|
string(REPLACE "\${_IMPORT_PREFIX}/debug/bin/protoc.exe" "\${_IMPORT_PREFIX}/tools/protoc.exe" DEBUG_MODULE "${DEBUG_MODULE}")
|
|
|
|
file(WRITE ${CURRENT_PACKAGES_DIR}/share/protobuf/protobuf-targets-debug.cmake "${DEBUG_MODULE}")
|
|
|
|
|
2017-01-17 10:36:47 +08:00
|
|
|
protobuf_try_remove_recurse_wait(${CURRENT_PACKAGES_DIR}/debug/share)
|
2016-09-23 23:10:37 +08:00
|
|
|
|
2017-05-11 03:29:10 +08:00
|
|
|
if (VCPKG_LIBRARY_LINKAGE STREQUAL static)
|
|
|
|
protobuf_try_remove_recurse_wait(${CURRENT_PACKAGES_DIR}/bin)
|
|
|
|
protobuf_try_remove_recurse_wait(${CURRENT_PACKAGES_DIR}/debug/bin)
|
|
|
|
else()
|
|
|
|
protobuf_try_remove_recurse_wait(${CURRENT_PACKAGES_DIR}/bin/protoc.exe)
|
|
|
|
protobuf_try_remove_recurse_wait(${CURRENT_PACKAGES_DIR}/debug/bin/protoc.exe)
|
|
|
|
endif()
|
|
|
|
|
2017-09-07 19:52:59 +08:00
|
|
|
foreach(FILE ${CURRENT_PACKAGES_DIR}/include/google/protobuf/stubs/platform_macros.h)
|
2017-07-08 08:51:59 +08:00
|
|
|
file(READ ${FILE} _contents)
|
|
|
|
if(VCPKG_LIBRARY_LINKAGE STREQUAL dynamic)
|
2017-09-07 19:52:59 +08:00
|
|
|
string(REPLACE "\#endif // GOOGLE_PROTOBUF_PLATFORM_MACROS_H_" "\#define PROTOBUF_USE_DLLS 1\n\#endif // GOOGLE_PROTOBUF_PLATFORM_MACROS_H_" _contents "${_contents}")
|
2017-07-08 08:51:59 +08:00
|
|
|
else()
|
2017-09-07 19:52:59 +08:00
|
|
|
string(REPLACE "\#endif // GOOGLE_PROTOBUF_PLATFORM_MACROS_H_" "\#define PROTOBUF_USE_DLLS 0\n\#endif // GOOGLE_PROTOBUF_PLATFORM_MACROS_H_" _contents "${_contents}")
|
2017-07-08 08:51:59 +08:00
|
|
|
endif()
|
2017-07-08 13:41:34 +08:00
|
|
|
file(WRITE ${FILE} "${_contents}")
|
2017-07-08 08:51:59 +08:00
|
|
|
endforeach()
|
|
|
|
|
2017-05-11 03:29:10 +08:00
|
|
|
file(INSTALL ${SOURCE_PATH}/LICENSE DESTINATION ${CURRENT_PACKAGES_DIR}/share/protobuf RENAME copyright)
|
|
|
|
file(INSTALL ${TOOL_PATH}/bin/protoc.exe DESTINATION ${CURRENT_PACKAGES_DIR}/tools)
|
2016-09-23 23:10:37 +08:00
|
|
|
vcpkg_copy_pdbs()
|