nc_cxx: make stdc++fs discovery more robust

This commit is contained in:
Danny Robson 2017-01-17 21:28:04 +11:00
parent e9eedc72c2
commit 566b98e5cb
2 changed files with 26 additions and 4 deletions

View File

@ -8,10 +8,21 @@ append_compile_flag (-std=c++1z)
############################################################################### ###############################################################################
# find the gcc experimental filesystem library and append to libs if needed # find the gcc experimental filesystem library and append to libs if needed
find_library(STDCXXFS NAMES stdc++fs) #
if (STDCXXFS) # note, we specifically _cannot_ use find_library because it just makes wild
set(LIBS ${LIBS} ${STDCXXFS}) # hardcoded guess and doesn't respect _all_ the system paths; specifically
endif (STDCXXFS) # 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()
############################################################################### ###############################################################################

11
nc_cxx_stdcxxfs.cpp Normal file
View File

@ -0,0 +1,11 @@
#include <experimental/filesystem>
int
main (int argc, char **argv)
{
(void)argc;
(void)argv;
std::experimental::filesystem::path p { "foo" };
return 0;
}