From b7cbc36071e30fada02af6562f27d63ef36ccc68 Mon Sep 17 00:00:00 2001 From: Christian Blichmann Date: Tue, 30 Jul 2019 06:48:16 -0700 Subject: [PATCH] Follow-up to 3c51348 fixing linker issues with gflags and glog The temporary solution for binaries/tests that fully statically linked is to link against `gflags` using `-Wl,--whole-archive`. This will no longer be necessary, once Abseil ships with logging. Then we can (finally) use Abseil flags and use a logging library that does not depend on a different flags library. PiperOrigin-RevId: 260705702 Change-Id: I8562faaff59f9c3e0e1d331186d2806d387438fb --- sandboxed_api/bazel/CMakeLists.txt | 1 + .../examples/stringop/lib/CMakeLists.txt | 3 +++ sandboxed_api/examples/sum/lib/CMakeLists.txt | 3 +++ sandboxed_api/sandbox2/CMakeLists.txt | 11 ++++++----- sandboxed_api/sandbox2/testcases/CMakeLists.txt | 11 ++++++++++- sandboxed_api/sandbox2/util/CMakeLists.txt | 15 ++++++++------- sandboxed_api/util/CMakeLists.txt | 14 +++++++------- 7 files changed, 38 insertions(+), 20 deletions(-) diff --git a/sandboxed_api/bazel/CMakeLists.txt b/sandboxed_api/bazel/CMakeLists.txt index 75b7649..d64abf2 100644 --- a/sandboxed_api/bazel/CMakeLists.txt +++ b/sandboxed_api/bazel/CMakeLists.txt @@ -42,6 +42,7 @@ if(SAPI_ENABLE_TESTS) sandbox2::file_helpers sandbox2::fileops sandbox2::testing + sapi::status_matchers sapi::test_main ) gtest_discover_tests(filewrapper_test PROPERTIES diff --git a/sandboxed_api/examples/stringop/lib/CMakeLists.txt b/sandboxed_api/examples/stringop/lib/CMakeLists.txt index 813105f..df75374 100644 --- a/sandboxed_api/examples/stringop/lib/CMakeLists.txt +++ b/sandboxed_api/examples/stringop/lib/CMakeLists.txt @@ -33,6 +33,9 @@ add_library(sapi_stringop STATIC stringop.cc ) add_library(sapi::stringop ALIAS sapi_stringop) +add_dependencies(sapi_stringop + sapi::stringop_params_proto +) target_link_libraries(sapi_stringop PRIVATE $ sapi::base diff --git a/sandboxed_api/examples/sum/lib/CMakeLists.txt b/sandboxed_api/examples/sum/lib/CMakeLists.txt index b02c152..b632117 100644 --- a/sandboxed_api/examples/sum/lib/CMakeLists.txt +++ b/sandboxed_api/examples/sum/lib/CMakeLists.txt @@ -34,6 +34,9 @@ add_library(sapi_sum STATIC sum_cpp.cc ) add_library(sapi::sum ALIAS sapi_sum) +add_dependencies(sapi_sum + sapi::sum_params_proto +) target_link_libraries(sapi_sum PRIVATE $ glog::glog diff --git a/sandboxed_api/sandbox2/CMakeLists.txt b/sandboxed_api/sandbox2/CMakeLists.txt index d0ddfb4..377ca70 100644 --- a/sandboxed_api/sandbox2/CMakeLists.txt +++ b/sandboxed_api/sandbox2/CMakeLists.txt @@ -57,7 +57,8 @@ target_link_libraries(sandbox2_syscall absl::strings sandbox2::util sapi::base - PUBLIC glog::glog + PUBLIC glog::glog + gflags::gflags ) # sandboxed_api/sandbox2:result @@ -637,9 +638,9 @@ if(SAPI_ENABLE_TESTS) ${_sandbox2_comms_test_pb_h} ) add_library(sandbox2::comms_test_proto ALIAS sandbox2_comms_test_proto) - target_link_libraries(sandbox2_comms_test_proto PRIVATE - protobuf::libprotobuf - sapi::base + target_link_libraries(sandbox2_comms_test_proto + PRIVATE sapi::base + PUBLIC protobuf::libprotobuf ) # sandboxed_api/sandbox2:comms_test @@ -650,7 +651,7 @@ if(SAPI_ENABLE_TESTS) absl::fixed_array absl::strings glog::glog - protobuf::libprotobuf + gflags::gflags sandbox2::comms sandbox2::comms_test_proto sapi::status_matchers diff --git a/sandboxed_api/sandbox2/testcases/CMakeLists.txt b/sandboxed_api/sandbox2/testcases/CMakeLists.txt index c3ee7c4..70c447d 100644 --- a/sandboxed_api/sandbox2/testcases/CMakeLists.txt +++ b/sandboxed_api/sandbox2/testcases/CMakeLists.txt @@ -71,6 +71,9 @@ add_executable(ipc add_executable(sandbox2::testcase_ipc ALIAS ipc) target_link_libraries(ipc PRIVATE absl::strings + -Wl,--whole-archive + gflags::gflags + -Wl,--no-whole-archive glog::glog sandbox2::client sandbox2::comms @@ -135,6 +138,9 @@ set_target_properties(pidcomms PROPERTIES ${_sandbox2_testcase_properties} ) target_link_libraries(pidcomms PRIVATE + -Wl,--whole-archive + gflags::gflags + -Wl,--no-whole-archive glog::glog sandbox2::client sandbox2::comms @@ -234,10 +240,13 @@ set_target_properties(tsync PROPERTIES ${_sandbox2_testcase_properties} ) target_link_libraries(tsync PRIVATE + -Wl,--whole-archive + gflags::gflags + -Wl,--no-whole-archive glog::glog - sapi::base sandbox2::client sandbox2::comms + sapi::base ${_sandbox2_fully_static_linkopts} ) diff --git a/sandboxed_api/sandbox2/util/CMakeLists.txt b/sandboxed_api/sandbox2/util/CMakeLists.txt index a2262b1..eb5d1f1 100644 --- a/sandboxed_api/sandbox2/util/CMakeLists.txt +++ b/sandboxed_api/sandbox2/util/CMakeLists.txt @@ -89,13 +89,13 @@ add_library(sandbox2_util_temp_file STATIC temp_file.h ) add_library(sandbox2::temp_file ALIAS sandbox2_util_temp_file) -target_link_libraries(sandbox2_util_temp_file PRIVATE - absl::strings - sandbox2::fileops - sandbox2::strerror - sapi::base - sapi::status - sapi::statusor +target_link_libraries(sandbox2_util_temp_file + PRIVATE absl::strings + sandbox2::fileops + sandbox2::strerror + sapi::base + PUBLIC sapi::status + sapi::statusor ) # sandboxed_api/sandbox2/util:maps_parser @@ -191,6 +191,7 @@ if(SAPI_ENABLE_TESTS) sandbox2::maps_parser sandbox2::minielf sandbox2::testing + sapi::status_matchers sapi::test_main ) gtest_discover_tests(minielf_test PROPERTIES diff --git a/sandboxed_api/util/CMakeLists.txt b/sandboxed_api/util/CMakeLists.txt index a50a488..ce42e1a 100644 --- a/sandboxed_api/util/CMakeLists.txt +++ b/sandboxed_api/util/CMakeLists.txt @@ -85,13 +85,13 @@ if(SAPI_ENABLE_TESTS) status_matchers.h ) add_library(sapi::status_matchers ALIAS sapi_util_status_matchers) - target_link_libraries(sapi_util_status_matchers PRIVATE - absl::optional - gmock - gtest - sapi::base - sapi::status - sapi::statusor + target_link_libraries(sapi_util_status_matchers + PRIVATE absl::optional + gmock + gtest + sapi::base + PUBLIC sapi::status + sapi::statusor ) # sandboxed_api/util:status_test