From 4ec829b05405113bc33a62f55f1aec6729f363e2 Mon Sep 17 00:00:00 2001 From: Keith Smiley Date: Tue, 27 Aug 2019 10:29:19 -0700 Subject: [PATCH] Add support for libtool over ar On macOS libtool is preferred for creating static archives over ar. If libtool is set as the static linker, we need to pass different flags. --- tools/build_defs/cmake_script.bzl | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tools/build_defs/cmake_script.bzl b/tools/build_defs/cmake_script.bzl index bb004c158..b642cf72a 100644 --- a/tools/build_defs/cmake_script.bzl +++ b/tools/build_defs/cmake_script.bzl @@ -104,6 +104,8 @@ _CMAKE_CACHE_ENTRIES_CROSSTOOL = { "CMAKE_SYSTEM_NAME": struct(value = "CMAKE_SYSTEM_NAME", replace = True), "CMAKE_AR": struct(value = "CMAKE_AR", replace = True), "CMAKE_RANLIB": struct(value = "CMAKE_RANLIB", replace = True), + "CMAKE_C_ARCHIVE_CREATE": struct(value = "CMAKE_C_ARCHIVE_CREATE", replace = False), + "CMAKE_CXX_ARCHIVE_CREATE": struct(value = "CMAKE_CXX_ARCHIVE_CREATE", replace = False), "CMAKE_CXX_LINK_EXECUTABLE": struct(value = "CMAKE_CXX_LINK_EXECUTABLE", replace = True), "CMAKE_C_FLAGS": struct(value = "CMAKE_C_FLAGS_INIT", replace = False), "CMAKE_CXX_FLAGS": struct(value = "CMAKE_CXX_FLAGS_INIT", replace = False), @@ -233,6 +235,9 @@ def _fill_crossfile_from_toolchain(workspace_name, target_os, tools, flags): if tools.cxx_linker_static: dict["CMAKE_AR"] = _absolutize(workspace_name, tools.cxx_linker_static, True) + if tools.cxx_linker_static.endswith("/libtool"): + dict["CMAKE_C_ARCHIVE_CREATE"] = " -static -o " + dict["CMAKE_CXX_ARCHIVE_CREATE"] = " -static -o " if tools.cxx_linker_executable and tools.cxx_linker_executable != tools.cxx: normalized_path = _absolutize(workspace_name, tools.cxx_linker_executable)