Update CMake configuration to add a dependency on Abseil (#9793)

* Proof of concept for CMake Abseil dependency

* Hooked up Abseil linking

* Adding test binaries

* Reverting absl::string view use added for testing.  This will still be broken for automake and bazel

* Adding new cmake config to dist list

* Whitespace fixes and an attempt at fix for Windows Python Release (CMake version < 3.13)

* Hook up LTS to windows cmake

* Fix 'git cd' typo

* Adding clarifying comment for fix

* Adding abseil dependency to protobuf-lite too

* Update submodules instead of cloning abseil-cpp

* Adding explicit pointer to abseil root directory

Co-authored-by: Jason Lunn <jason.lunn@gmail.com>
Co-authored-by: Jorg Brown <jorg.brown@gmail.com>
pull/9800/head
mkruskal-google 3 years ago committed by GitHub
parent 6f99f12a6b
commit e9246cd789
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      .bazelignore
  2. 4
      .gitmodules
  3. 13
      CMakeLists.txt
  4. 1
      Makefile.am
  5. 28
      cmake/abseil-cpp.cmake
  6. 3
      cmake/libprotobuf-lite.cmake
  7. 3
      cmake/libprotobuf.cmake
  8. 3
      cmake/libprotoc.cmake
  9. 1
      cmake/protobuf-config.cmake.in
  10. 6
      cmake/protoc.cmake
  11. 17
      cmake/tests.cmake
  12. 2
      kokoro/release/python/linux/build_artifacts.sh
  13. 2
      kokoro/release/python/macos/build_artifacts.sh
  14. 7
      kokoro/release/python/windows/build_artifacts.bat
  15. 2
      kokoro/release/python/windows/build_single_artifact.bat
  16. 1
      third_party/abseil-cpp

@ -1,4 +1,5 @@
# These are fetched as external repositories. # These are fetched as external repositories.
third_party/abseil-cpp
third_party/benchmark third_party/benchmark
third_party/googletest third_party/googletest
_build/ _build/

4
.gitmodules vendored

@ -5,3 +5,7 @@
path = third_party/googletest path = third_party/googletest
url = https://github.com/google/googletest.git url = https://github.com/google/googletest.git
ignore = dirty ignore = dirty
[submodule "third_party/abseil-cpp"]
path = third_party/abseil-cpp
url = https://github.com/abseil/abseil-cpp.git
branch = lts_2021_11_02

@ -162,6 +162,15 @@ file(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/cmaketest.map)
find_package(Threads REQUIRED) find_package(Threads REQUIRED)
# We can install dependencies from submodules if we're running
# CMake v3.13 or newer.
if(CMAKE_VERSION VERSION_LESS 3.13)
set(_protobuf_INSTALL_SUPPORTED_FROM_MODULE OFF)
else()
set(_protobuf_INSTALL_SUPPORTED_FROM_MODULE ON)
endif()
set(_protobuf_FIND_ZLIB) set(_protobuf_FIND_ZLIB)
if (protobuf_WITH_ZLIB) if (protobuf_WITH_ZLIB)
find_package(ZLIB) find_package(ZLIB)
@ -301,6 +310,10 @@ if (protobuf_UNICODE)
add_definitions(-DUNICODE -D_UNICODE) add_definitions(-DUNICODE -D_UNICODE)
endif (protobuf_UNICODE) endif (protobuf_UNICODE)
set(protobuf_ABSL_PROVIDER "module" CACHE STRING "Provider of absl library")
set_property(CACHE protobuf_ABSL_PROVIDER PROPERTY STRINGS "module" "package")
include(${protobuf_SOURCE_DIR}/cmake/abseil-cpp.cmake)
include(${protobuf_SOURCE_DIR}/cmake/libprotobuf-lite.cmake) include(${protobuf_SOURCE_DIR}/cmake/libprotobuf-lite.cmake)
include(${protobuf_SOURCE_DIR}/cmake/libprotobuf.cmake) include(${protobuf_SOURCE_DIR}/cmake/libprotobuf.cmake)
if (protobuf_BUILD_LIBPROTOC) if (protobuf_BUILD_LIBPROTOC)

@ -1403,6 +1403,7 @@ EXTRA_DIST = $(@DIST_LANG@_EXTRA_DIST) \
BUILD \ BUILD \
WORKSPACE \ WORKSPACE \
CMakeLists.txt \ CMakeLists.txt \
cmake/abseil-cpp.cmake \
cmake/CMakeLists.txt \ cmake/CMakeLists.txt \
cmake/README.md \ cmake/README.md \
cmake/conformance.cmake \ cmake/conformance.cmake \

@ -0,0 +1,28 @@
if(protobuf_ABSL_PROVIDER STREQUAL "module")
if(NOT ABSL_ROOT_DIR)
set(ABSL_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/abseil-cpp)
endif()
if(EXISTS "${ABSL_ROOT_DIR}/CMakeLists.txt")
if(protobuf_INSTALL)
# When protobuf_INSTALL is enabled and Abseil will be built as a module,
# Abseil will be installed along with protobuf for convenience.
set(ABSL_ENABLE_INSTALL ON)
endif()
add_subdirectory(${ABSL_ROOT_DIR} third_party/abseil-cpp)
else()
message(WARNING "protobuf_ABSL_PROVIDER is \"module\" but ABSL_ROOT_DIR is wrong")
endif()
if(protobuf_INSTALL AND NOT _protobuf_INSTALL_SUPPORTED_FROM_MODULE)
message(WARNING "protobuf_INSTALL will be forced to FALSE because protobuf_ABSL_PROVIDER is \"module\" and CMake version (${CMAKE_VERSION}) is less than 3.13.")
set(protobuf_INSTALL FALSE)
endif()
elseif(protobuf_ABSL_PROVIDER STREQUAL "package")
# Use "CONFIG" as there is no built-in cmake module for absl.
find_package(absl REQUIRED CONFIG)
endif()
set(_protobuf_FIND_ABSL "if(NOT TARGET absl::strings)\n find_package(absl CONFIG)\nendif()")
set(protobuf_ABSL_USED_TARGETS
absl::strings
absl::strings_internal
)

@ -104,6 +104,9 @@ if(protobuf_HAVE_LD_VERSION_SCRIPT)
LINK_DEPENDS ${protobuf_SOURCE_DIR}/src/libprotobuf-lite.map) LINK_DEPENDS ${protobuf_SOURCE_DIR}/src/libprotobuf-lite.map)
endif() endif()
target_link_libraries(libprotobuf-lite PRIVATE ${CMAKE_THREAD_LIBS_INIT}) target_link_libraries(libprotobuf-lite PRIVATE ${CMAKE_THREAD_LIBS_INIT})
target_include_directories(libprotobuf-lite
PRIVATE ${ABSL_ROOT_DIR}
)
if(protobuf_LINK_LIBATOMIC) if(protobuf_LINK_LIBATOMIC)
target_link_libraries(libprotobuf-lite PRIVATE atomic) target_link_libraries(libprotobuf-lite PRIVATE atomic)
endif() endif()

@ -117,6 +117,9 @@ if(protobuf_HAVE_LD_VERSION_SCRIPT)
LINK_DEPENDS ${protobuf_SOURCE_DIR}/src/libprotobuf.map) LINK_DEPENDS ${protobuf_SOURCE_DIR}/src/libprotobuf.map)
endif() endif()
target_link_libraries(libprotobuf PRIVATE ${CMAKE_THREAD_LIBS_INIT}) target_link_libraries(libprotobuf PRIVATE ${CMAKE_THREAD_LIBS_INIT})
target_include_directories(libprotobuf
PRIVATE ${ABSL_ROOT_DIR}
)
if(protobuf_WITH_ZLIB) if(protobuf_WITH_ZLIB)
target_link_libraries(libprotobuf PRIVATE ${ZLIB_LIBRARIES}) target_link_libraries(libprotobuf PRIVATE ${ZLIB_LIBRARIES})
endif() endif()

@ -128,6 +128,9 @@ if(protobuf_HAVE_LD_VERSION_SCRIPT)
LINK_DEPENDS ${protobuf_SOURCE_DIR}/src/libprotoc.map) LINK_DEPENDS ${protobuf_SOURCE_DIR}/src/libprotoc.map)
endif() endif()
target_link_libraries(libprotoc PRIVATE libprotobuf) target_link_libraries(libprotoc PRIVATE libprotobuf)
target_include_directories(libprotoc
PRIVATE ${ABSL_ROOT_DIR}
)
if(protobuf_BUILD_SHARED_LIBS) if(protobuf_BUILD_SHARED_LIBS)
target_compile_definitions(libprotoc target_compile_definitions(libprotoc
PUBLIC PROTOBUF_USE_DLLS PUBLIC PROTOBUF_USE_DLLS

@ -3,6 +3,7 @@ include("${CMAKE_CURRENT_LIST_DIR}/protobuf-options.cmake")
# Depend packages # Depend packages
@_protobuf_FIND_ZLIB@ @_protobuf_FIND_ZLIB@
@_protobuf_FIND_ABSL@
# Imported targets # Imported targets
include("${CMAKE_CURRENT_LIST_DIR}/protobuf-targets.cmake") include("${CMAKE_CURRENT_LIST_DIR}/protobuf-targets.cmake")

@ -9,7 +9,11 @@ set(protoc_rc_files
endif() endif()
add_executable(protoc ${protoc_files} ${protoc_rc_files}) add_executable(protoc ${protoc_files} ${protoc_rc_files})
target_link_libraries(protoc libprotoc libprotobuf) target_link_libraries(protoc
libprotoc
libprotobuf
${protobuf_ABSL_USED_TARGETS}
)
add_executable(protobuf::protoc ALIAS protoc) add_executable(protobuf::protoc ALIAS protoc)
set_target_properties(protoc PROPERTIES set_target_properties(protoc PROPERTIES

@ -21,6 +21,7 @@ else()
set(googlemock_source_dir "${protobuf_SOURCE_DIR}/third_party/googletest/googlemock") set(googlemock_source_dir "${protobuf_SOURCE_DIR}/third_party/googletest/googlemock")
set(googletest_source_dir "${protobuf_SOURCE_DIR}/third_party/googletest/googletest") set(googletest_source_dir "${protobuf_SOURCE_DIR}/third_party/googletest/googletest")
include_directories( include_directories(
${ABSL_ROOT_DIR}
${googlemock_source_dir} ${googlemock_source_dir}
${googletest_source_dir} ${googletest_source_dir}
${googletest_source_dir}/include ${googletest_source_dir}/include
@ -257,7 +258,14 @@ if (MSVC)
/wd4146 # unary minus operator applied to unsigned type, result still unsigned /wd4146 # unary minus operator applied to unsigned type, result still unsigned
) )
endif() endif()
target_link_libraries(tests protobuf-lite-test-common protobuf-test-common libprotoc libprotobuf GTest::gmock_main) target_link_libraries(tests
protobuf-lite-test-common
protobuf-test-common
libprotoc
libprotobuf
GTest::gmock_main
${protobuf_ABSL_USED_TARGETS}
)
set(test_plugin_files set(test_plugin_files
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/mock_code_generator.cc ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/mock_code_generator.cc
@ -267,7 +275,12 @@ set(test_plugin_files
) )
add_executable(test_plugin ${test_plugin_files}) add_executable(test_plugin ${test_plugin_files})
target_link_libraries(test_plugin libprotoc libprotobuf GTest::gmock) target_link_libraries(test_plugin
libprotoc
libprotobuf
GTest::gmock
${protobuf_ABSL_USED_TARGETS}
)
set(lite_test_files set(lite_test_files
${protobuf_SOURCE_DIR}/src/google/protobuf/lite_unittest.cc ${protobuf_SOURCE_DIR}/src/google/protobuf/lite_unittest.cc

@ -30,7 +30,7 @@ git clone https://github.com/matthew-brett/multibuild.git
# silently creeping in (see https://github.com/protocolbuffers/protobuf/issues/9180). # silently creeping in (see https://github.com/protocolbuffers/protobuf/issues/9180).
# IMPORTANT: always pin multibuild at the same commit for: # IMPORTANT: always pin multibuild at the same commit for:
# - linux/build_artifacts.sh # - linux/build_artifacts.sh
# - linux/build_artifacts.sh # - macos/build_artifacts.sh
# - windows/build_artifacts.bat # - windows/build_artifacts.bat
(cd multibuild; git checkout b89bb903e94308be79abefa4f436bf123ebb1313) (cd multibuild; git checkout b89bb903e94308be79abefa4f436bf123ebb1313)
cp kokoro/release/python/linux/config.sh config.sh cp kokoro/release/python/linux/config.sh config.sh

@ -30,7 +30,7 @@ git clone https://github.com/matthew-brett/multibuild.git
# silently creeping in (see https://github.com/protocolbuffers/protobuf/issues/9180). # silently creeping in (see https://github.com/protocolbuffers/protobuf/issues/9180).
# IMPORTANT: always pin multibuild at the same commit for: # IMPORTANT: always pin multibuild at the same commit for:
# - linux/build_artifacts.sh # - linux/build_artifacts.sh
# - linux/build_artifacts.sh # - macos/build_artifacts.sh
# - windows/build_artifacts.bat # - windows/build_artifacts.bat
(cd multibuild; git checkout b89bb903e94308be79abefa4f436bf123ebb1313) (cd multibuild; git checkout b89bb903e94308be79abefa4f436bf123ebb1313)
cp kokoro/release/python/macos/config.sh config.sh cp kokoro/release/python/macos/config.sh config.sh

@ -18,7 +18,7 @@ REM Pin multibuild scripts at a known commit to avoid potentially unwanted futur
REM silently creeping in (see https://github.com/protocolbuffers/protobuf/issues/9180). REM silently creeping in (see https://github.com/protocolbuffers/protobuf/issues/9180).
REM IMPORTANT: always pin multibuild at the same commit for: REM IMPORTANT: always pin multibuild at the same commit for:
REM - linux/build_artifacts.sh REM - linux/build_artifacts.sh
REM - linux/build_artifacts.sh REM - macos/build_artifacts.sh
REM - windows/build_artifacts.bat REM - windows/build_artifacts.bat
cd multibuild cd multibuild
git checkout b89bb903e94308be79abefa4f436bf123ebb1313 git checkout b89bb903e94308be79abefa4f436bf123ebb1313
@ -34,6 +34,11 @@ SET ZLIB_ROOT=%cd%\zlib
del /Q zlib.zip del /Q zlib.zip
del /Q zlib-src.zip del /Q zlib-src.zip
REM Update Submodules
REM This is needed because this build uses CMake <3.13.
git submodule update --init --recursive
SET ABSL_ROOT_DIR=%cd%\third_party\abseil-cpp
REM Create directory for artifacts REM Create directory for artifacts
SET ARTIFACT_DIR=%cd%\artifacts SET ARTIFACT_DIR=%cd%\artifacts
mkdir %ARTIFACT_DIR% mkdir %ARTIFACT_DIR%

@ -49,7 +49,7 @@ mkdir src\.libs
mkdir vcprojects mkdir vcprojects
pushd vcprojects pushd vcprojects
cmake -G "%generator%" -Dprotobuf_BUILD_SHARED_LIBS=%BUILD_DLL% -Dprotobuf_UNICODE=%UNICODE% -Dprotobuf_BUILD_TESTS=OFF ../cmake || goto :error cmake -G "%generator%" -Dprotobuf_BUILD_SHARED_LIBS=%BUILD_DLL% -Dprotobuf_UNICODE=%UNICODE% -Dprotobuf_BUILD_TESTS=OFF -DABSL_ROOT_DIR=%ABSL_ROOT_DIR% ../cmake || goto :error
msbuild protobuf.sln /p:Platform=%vcplatform% /p:Configuration=Release || goto :error msbuild protobuf.sln /p:Platform=%vcplatform% /p:Configuration=Release || goto :error
dir /s /b dir /s /b
popd popd

@ -0,0 +1 @@
Subproject commit 8c6e53ef3adb1227fffa442c50349dab134a54bc
Loading…
Cancel
Save