From df4da20058eb6587b942f331767548363d3086a4 Mon Sep 17 00:00:00 2001 From: Nikhil Benesch Date: Thu, 31 May 2018 16:17:19 -0400 Subject: [PATCH] Makefile: fix check-libroach with linux release toolchain The Linux release toolchain uses an ancient version of glibc that requires linking against -lrt. Teach CMake to link test binaries accordingly on Linux. The Linux release toolchain also uses a very recent version of libstdc++ that must be statically linked. Plumb the link flags down into CMake via the LDFLAGS variable. (Previously they were only passed down to links invoked by Go via the -extldflags flag in the LINKFLAGS variable.) Release note: None --- Makefile | 12 ++++++++---- c-deps/libroach/CMakeLists.txt | 4 ++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 60d55aa0698c..57a1178e18d0 100644 --- a/Makefile +++ b/Makefile @@ -148,19 +148,22 @@ else ifeq ($(TYPE),release-linux-gnu) # this toolchain's libstdc++ version is quite recent and must be statically # linked to avoid depending on the target's available libstdc++. XHOST_TRIPLE := x86_64-unknown-linux-gnu -override LINKFLAGS += -extldflags "-static-libgcc -static-libstdc++" +override LDFLAGS = -static-libgcc -static-libstdc++ +override LINKFLAGS += -extldflags "$(LDFLAGS)" override SUFFIX := $(SUFFIX)-linux-2.6.32-gnu-amd64 BUILD_TYPE := release else ifeq ($(TYPE),release-linux-musl) XHOST_TRIPLE := x86_64-unknown-linux-musl -override LINKFLAGS += -extldflags "-static" +override LDFLAGS = -static +override LINKFLAGS += -extldflags "$(LDFLAGS)" override SUFFIX := $(SUFFIX)-linux-2.6.32-musl-amd64 BUILD_TYPE := release else ifeq ($(TYPE),release-aarch64-linux) XGOARCH := arm64 export CGO_ENABLED := 1 XHOST_TRIPLE := aarch64-unknown-linux-gnueabi -override LINKFLAGS += -extldflags "-static-libgcc -static-libstdc++" +override LDFLAGS = -static-libgcc -static-libstdc++ +override LINKFLAGS += -extldflags "$(LDFLAGS)" override SUFFIX := $(SUFFIX)-linux-3.7.10-gnu-aarch64 BUILD_TYPE := release else ifeq ($(TYPE),release-darwin) @@ -174,7 +177,8 @@ XGOOS := windows export CGO_ENABLED := 1 XHOST_TRIPLE := x86_64-w64-mingw32 override SUFFIX := $(SUFFIX)-windows-6.2-amd64 -override LINKFLAGS += -extldflags "-static" +override LDFLAGS += -static +override LINKFLAGS += -extldflags "$(LDFLAGS)" BUILD_TYPE := release else $(error unknown build type $(TYPE)) diff --git a/c-deps/libroach/CMakeLists.txt b/c-deps/libroach/CMakeLists.txt index 0c5e0c5694e5..3e5ccef0f12f 100644 --- a/c-deps/libroach/CMakeLists.txt +++ b/c-deps/libroach/CMakeLists.txt @@ -152,6 +152,10 @@ foreach(tsrc ${tests}) ${SNAPPY_LIB} ) + if(${CMAKE_SYSTEM_NAME} MATCHES "Linux") + target_link_libraries(${tname} rt) + endif() + set_target_properties(${tname} PROPERTIES CXX_STANDARD 11 CXX_STANDARD_REQUIRED YES