From ba5ce157bd06479753f44b4414247495848c23d0 Mon Sep 17 00:00:00 2001 From: "Adam C. Emerson" Date: Fri, 9 Feb 2018 16:16:43 -0500 Subject: [PATCH] build: Use the right experimental library Test whether we're building with libstdc++ or libc++. Use stdc++filesystem if the former and c++experimental if the later. Signed-off-by: Adam C. Emerson --- CMakeLists.txt | 15 ++++++++++++++- librarytest.sh | 17 +++++++++++++++++ src/test/CMakeLists.txt | 4 ++-- 3 files changed, 33 insertions(+), 3 deletions(-) create mode 100755 librarytest.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index f748bc6c21520..c8f5d20d041e5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -96,7 +96,7 @@ CHECK_FUNCTION_EXISTS(getgrouplist HAVE_GETGROUPLIST) if(NOT APPLE) CHECK_FUNCTION_EXISTS(fdatasync HAVE_FDATASYNC) endif() -CHECK_FUNCTION_EXISTS(strerror_r HAVE_STRERROR_R) +CHECK_FUNCTION_EXISTS(strerror_r HAVE_Strerror_R) CHECK_FUNCTION_EXISTS(name_to_handle_at HAVE_NAME_TO_HANDLE_AT) CHECK_FUNCTION_EXISTS(pipe2 HAVE_PIPE2) set(CMAKE_REQUIRED_LIBRARIES pthread) @@ -594,6 +594,19 @@ include_directories(SYSTEM ${PROJECT_BINARY_DIR}/include) find_package(Threads REQUIRED) +execute_process( + COMMAND ./librarytest.sh ${CMAKE_CXX_COMPILER} ${CMAKE_CXX_FLAGS} + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE CXX_STDLIB + ) + +if(CXX_STDLIB STREQUAL "libstdc++" OR CXX_STDLIB STREQUAL "libc++") + message(STATUS "We are using ${CXX_STDLIB}.") +else() + message(FATAL_ERROR + "Unable to determine C++ standard library, got ${CXX_STDLIB}.") +endif() + option(WITH_SELINUX "build SELinux policy" OFF) if(WITH_SELINUX) find_file(SELINUX_MAKEFILE selinux/devel/Makefile diff --git a/librarytest.sh b/librarytest.sh new file mode 100755 index 0000000000000..12bc8c3cca9f6 --- /dev/null +++ b/librarytest.sh @@ -0,0 +1,17 @@ +#!/bin/sh + +CXX=$1 + +shift + +echo "#include +#if defined(_LIBCPP_VERSION) +#define MYRESULT libc++ +#elif defined(__GLIBCXX__) +#define MYRESULT libstdc++ +#else +#define MYRESULT unknown +#endif + +HelloFriendsTheAnsWerIs MYRESULT" | ${CXX} -E -xc++ $* - | \ + grep "HelloFriendsTheAnsWerIs" | cut -f 2 -d ' ' | tr -d '\n' diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt index 3d97be7c81cce..f2f12956dfa9d 100644 --- a/src/test/CMakeLists.txt +++ b/src/test/CMakeLists.txt @@ -508,10 +508,10 @@ add_executable(ceph_test_admin_socket_output ) target_link_libraries(ceph_test_admin_socket_output ceph-common) -if(CMAKE_CXX_COMPILER_ID STREQUAL GNU) +if(CXX_STDLIB STREQUAL "libstdc++") target_link_libraries(ceph_test_admin_socket_output -lstdc++fs) -elseif(CMAKE_CXX_COMPILER_ID STREQUAL Clang) +elseif(CXX_STDLIB STREQUAL "libc++") target_link_libraries(ceph_test_admin_socket_output -lc++experimental) endif() -- 2.39.5