From acf588f5a22eafd7d21de55b954e8641d4b06568 Mon Sep 17 00:00:00 2001 From: Benjamin Barenblat Date: Tue, 19 May 2020 11:55:11 -0400 Subject: Enable CMake support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Install Abseil’s CMake support files. Some of these files are autogenerated, and the generator produces files with a googletest dependency if Abseil is built with unit tests enabled; to prevent this, turn off unit tests. --- debian/control | 3 +- debian/libabsl-dev.install | 1 + debian/not-installed | 17 ----- debian/patches/series | 2 - debian/patches/use_local_gtest.diff | 130 ----------------------------------- debian/patches/use_local_gtest2.diff | 21 ------ debian/rules | 2 +- debian/tests/cmake | 45 ++++++++++++ debian/tests/control | 3 + 9 files changed, 51 insertions(+), 173 deletions(-) delete mode 100644 debian/not-installed delete mode 100644 debian/patches/use_local_gtest.diff delete mode 100644 debian/patches/use_local_gtest2.diff create mode 100755 debian/tests/cmake (limited to 'debian') diff --git a/debian/control b/debian/control index f43bd41a..202de055 100644 --- a/debian/control +++ b/debian/control @@ -18,7 +18,6 @@ Maintainer: Benjamin Barenblat Build-Depends: cmake (>= 3.5), debhelper-compat (= 12), - googletest, Standards-Version: 4.5.0 Section: libs Homepage: https://abseil.io/ @@ -90,7 +89,7 @@ Depends: libabsl-time20200225 (= ${binary:Version}), libabsl-time-zone20200225 (= ${binary:Version}), ${misc:Depends}, -Recommends: g++ (>= 4.7), libgmock-dev, libgtest-dev +Recommends: cmake (>= 2.6), g++ (>= 4.7) Description: ${source:Synopsis} (development files) ${source:Extended-Description} . diff --git a/debian/libabsl-dev.install b/debian/libabsl-dev.install index 43f80c3b..6a5120e6 100644 --- a/debian/libabsl-dev.install +++ b/debian/libabsl-dev.install @@ -14,3 +14,4 @@ usr/include/absl usr/lib/*/*.so +usr/lib/*/cmake diff --git a/debian/not-installed b/debian/not-installed deleted file mode 100644 index 01e24a96..00000000 --- a/debian/not-installed +++ /dev/null @@ -1,17 +0,0 @@ -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. - -usr/lib/x86_64-linux-gnu/cmake/absl/abslConfig.cmake -usr/lib/x86_64-linux-gnu/cmake/absl/abslTargets-none.cmake -usr/lib/x86_64-linux-gnu/cmake/absl/abslTargets.cmake diff --git a/debian/patches/series b/debian/patches/series index 0d0ecdd4..f99c8e0c 100644 --- a/debian/patches/series +++ b/debian/patches/series @@ -1,4 +1,2 @@ license.diff -use_local_gtest.diff -use_local_gtest2.diff configure.diff diff --git a/debian/patches/use_local_gtest.diff b/debian/patches/use_local_gtest.diff deleted file mode 100644 index 9ccd2316..00000000 --- a/debian/patches/use_local_gtest.diff +++ /dev/null @@ -1,130 +0,0 @@ -From: Benjamin Barenblat -Subject: Support testing with a local googletest checkout -Forwarded: yes -Applied-Upstream: https://github.com/abseil/abseil-cpp/commit/bcefbdcdf6ad85046ccacee0aeffba5404d3e528 - -Debian likes doing dependency management manually, so add support for -testing against a local googletest checkout rather than one downloaded -from GitHub. Add an ABSL_LOCAL_GOOGLETEST_DIR variable that can be used -in conjunction with -DABSL_RUN_TESTS=ON -DABSL_USE_GOOGLETEST_HEAD=OFF -to specify the googletest location manually, and do a bit of related -cleanup. - -This patch was originally submitted as -https://github.com/abseil/abseil-cpp/pull/628. Since the author works at -Google, upstream requested that he submit it internally. It was applied -as Piper revision 297677173 and exported to GitHub; the Applied-Upstream -URL above points to the exported commit. - ---- a/CMake/Googletest/CMakeLists.txt.in -+++ b/CMake/Googletest/CMakeLists.txt.in -@@ -1,15 +1,26 @@ - cmake_minimum_required(VERSION 2.8.2) - --project(googletest-download NONE) -+project(googletest-external NONE) - - include(ExternalProject) --ExternalProject_Add(googletest -- GIT_REPOSITORY https://github.com/google/googletest.git -- GIT_TAG master -- SOURCE_DIR "${CMAKE_BINARY_DIR}/googletest-src" -- BINARY_DIR "${CMAKE_BINARY_DIR}/googletest-build" -- CONFIGURE_COMMAND "" -- BUILD_COMMAND "" -- INSTALL_COMMAND "" -- TEST_COMMAND "" --) -\ No newline at end of file -+if(${ABSL_USE_GOOGLETEST_HEAD}) -+ ExternalProject_Add(googletest -+ GIT_REPOSITORY https://github.com/google/googletest.git -+ GIT_TAG master -+ SOURCE_DIR "${absl_gtest_src_dir}" -+ BINARY_DIR "${absl_gtest_build_dir}" -+ CONFIGURE_COMMAND "" -+ BUILD_COMMAND "" -+ INSTALL_COMMAND "" -+ TEST_COMMAND "" -+ ) -+else() -+ ExternalProject_Add(googletest -+ SOURCE_DIR "${absl_gtest_src_dir}" -+ BINARY_DIR "${absl_gtest_build_dir}" -+ CONFIGURE_COMMAND "" -+ BUILD_COMMAND "" -+ INSTALL_COMMAND "" -+ TEST_COMMAND "" -+ ) -+endif() -\ No newline at end of file ---- a/CMake/Googletest/DownloadGTest.cmake -+++ b/CMake/Googletest/DownloadGTest.cmake -@@ -1,10 +1,11 @@ --# Downloads and unpacks googletest at configure time. Based on the instructions --# at https://github.com/google/googletest/tree/master/googletest#incorporating-into-an-existing-cmake-project -+# Integrates googletest at configure time. Based on the instructions at -+# https://github.com/google/googletest/tree/master/googletest#incorporating-into-an-existing-cmake-project - --# Download the latest googletest from Github master -+# Set up the external googletest project, downloading the latest from Github -+# master if requested. - configure_file( - ${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt.in -- ${CMAKE_BINARY_DIR}/googletest-download/CMakeLists.txt -+ ${CMAKE_BINARY_DIR}/googletest-external/CMakeLists.txt - ) - - set(ABSL_SAVE_CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) -@@ -14,17 +15,17 @@ if (BUILD_SHARED_LIBS) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DGTEST_CREATE_SHARED_LIBRARY=1") - endif() - --# Configure and build the downloaded googletest source -+# Configure and build the googletest source. - execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . - RESULT_VARIABLE result -- WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download ) -+ WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-external ) - if(result) - message(FATAL_ERROR "CMake step for googletest failed: ${result}") - endif() - - execute_process(COMMAND ${CMAKE_COMMAND} --build . - RESULT_VARIABLE result -- WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download) -+ WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-external) - if(result) - message(FATAL_ERROR "Build step for googletest failed: ${result}") - endif() -diff --git a/CMakeLists.txt b/CMakeLists.txt -index fdfb2cf..74b5cd9 100644 ---- a/CMakeLists.txt -+++ b/CMakeLists.txt -@@ -84,6 +84,10 @@ - option(ABSL_USE_GOOGLETEST_HEAD - "If ON, abseil will download HEAD from googletest at config time." OFF) - -+set(ABSL_LOCAL_GOOGLETEST_DIR "/usr/src/googletest" CACHE PATH -+ "If ABSL_USE_GOOGLETEST_HEAD is OFF, specifies the directory of a local googletest checkout." -+ ) -+ - option(ABSL_RUN_TESTS "If ON, Abseil tests will be run." OFF) - - if(${ABSL_RUN_TESTS}) -@@ -96,11 +100,13 @@ - ## check targets - if(BUILD_TESTING) - -+ set(absl_gtest_build_dir ${CMAKE_BINARY_DIR}/googletest-build) - if(${ABSL_USE_GOOGLETEST_HEAD}) -- include(CMake/Googletest/DownloadGTest.cmake) - set(absl_gtest_src_dir ${CMAKE_BINARY_DIR}/googletest-src) -- set(absl_gtest_build_dir ${CMAKE_BINARY_DIR}/googletest-build) -+ else() -+ set(absl_gtest_src_dir ${ABSL_LOCAL_GOOGLETEST_DIR}) - endif() -+ include(CMake/Googletest/DownloadGTest.cmake) - - check_target(gtest) - check_target(gtest_main) diff --git a/debian/patches/use_local_gtest2.diff b/debian/patches/use_local_gtest2.diff deleted file mode 100644 index 37f3e7d0..00000000 --- a/debian/patches/use_local_gtest2.diff +++ /dev/null @@ -1,21 +0,0 @@ -From: Benjamin Barenblat -Subject: Support testing with a local googletest checkout, part 2 -Forwarded: yes -Applied-Upstream: https://github.com/abseil/abseil-cpp/commit/79e0dc11514df035a8d07a356f9ee1800fb2160c - -use_local_gtest.diff missed a necessary line; add it. - -The author works at Google. Upstream applied this patch as Piper revision -302947488 and exported it to GitHub; the Applied-Upstream URL above points to -the exported commit. - ---- a/CMake/Googletest/DownloadGTest.cmake -+++ b/CMake/Googletest/DownloadGTest.cmake -@@ -38,6 +38,4 @@ - - # Add googletest directly to our build. This defines the gtest and gtest_main - # targets. --add_subdirectory(${CMAKE_BINARY_DIR}/googletest-src -- ${CMAKE_BINARY_DIR}/googletest-build -- EXCLUDE_FROM_ALL) -+add_subdirectory(${absl_gtest_src_dir} ${absl_gtest_build_dir} EXCLUDE_FROM_ALL) diff --git a/debian/rules b/debian/rules index 79964920..4c276263 100755 --- a/debian/rules +++ b/debian/rules @@ -19,7 +19,7 @@ export DEB_BUILD_MAINT_OPTIONS = hardening=+bindnow dh $@ override_dh_auto_configure: - dh_auto_configure -- -DCMAKE_CXX_STANDARD=14 -DABSL_RUN_TESTS=ON -DABSL_USE_GOOGLETEST_HEAD=OFF -DBUILD_SHARED_LIBS=ON + dh_auto_configure -- -DCMAKE_CXX_STANDARD=14 -DBUILD_SHARED_LIBS=ON override_dh_auto_install: dh_auto_install diff --git a/debian/tests/cmake b/debian/tests/cmake new file mode 100755 index 00000000..1eb04de9 --- /dev/null +++ b/debian/tests/cmake @@ -0,0 +1,45 @@ +#!/bin/sh -eu +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may not +# use this file except in compliance with the License. You may obtain a copy of +# the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations under +# the License. + +readonly TMP="$(mktemp -d)" +trap "rm -rf \"$TMP\"" EXIT +cd "$TMP" + +cat >test.cc < + +int main(int argc, char* argv[]) { + int n; + if (!absl::SimpleAtoi(argv[1], &n)) { + return 1; + } + return n; +} +EOF + +cat >CMakeLists.txt <= 3.5), g++, make -- cgit v1.2.3