From 566b98e5cb94a584c2f25f26ce59e39c0d71b20c Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Tue, 17 Jan 2017 21:28:04 +1100 Subject: [PATCH] nc_cxx: make stdc++fs discovery more robust --- nc_cxx.cmake | 19 +++++++++++++++---- nc_cxx_stdcxxfs.cpp | 11 +++++++++++ 2 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 nc_cxx_stdcxxfs.cpp diff --git a/nc_cxx.cmake b/nc_cxx.cmake index 395ad77..99642f1 100644 --- a/nc_cxx.cmake +++ b/nc_cxx.cmake @@ -8,10 +8,21 @@ append_compile_flag (-std=c++1z) ############################################################################### # find the gcc experimental filesystem library and append to libs if needed -find_library(STDCXXFS NAMES stdc++fs) -if (STDCXXFS) - set(LIBS ${LIBS} ${STDCXXFS}) -endif (STDCXXFS) +# +# note, we specifically _cannot_ use find_library because it just makes wild +# hardcoded guess and doesn't respect _all_ the system paths; specifically +# something like /usr/lib/gcc/x86_64-pc-linux-gnu/6.3.0/libstdc++.so won't get +# discovered. +foreach(lib "" stdc++fs) + if (NOT __nc_cxx_stdcxxfs) + try_compile(__nc_cxx_stdcxxfs ${CMAKE_CURRENT_BINARY_DIR} + SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/cmake/nc_cxx_stdcxxfs.cpp + LINK_LIBRARIES ${lib}) + if (__nc_cxx_stdcxxfs) + list (APPEND LIBS ${lib}) + endif () + endif () +endforeach() ############################################################################### diff --git a/nc_cxx_stdcxxfs.cpp b/nc_cxx_stdcxxfs.cpp new file mode 100644 index 0000000..cdca65a --- /dev/null +++ b/nc_cxx_stdcxxfs.cpp @@ -0,0 +1,11 @@ +#include + +int +main (int argc, char **argv) +{ + (void)argc; + (void)argv; + + std::experimental::filesystem::path p { "foo" }; + return 0; +}