From: Orgad Shaneh Date: Sat, 22 Oct 2022 10:48:25 +0000 (+0300) Subject: build: Support compilation with GCC 8 (#1190) X-Git-Tag: v4.7.1~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e63107523915be883025836426fcdd96b97c22fa;p=thirdparty%2Fccache.git build: Support compilation with GCC 8 (#1190) See https://discourse.cmake.org/t/correct-way-to-link-std-filesystem-with-gcc-8/4121 --- diff --git a/cmake/StandardSettings.cmake b/cmake/StandardSettings.cmake index 83871af82..9e09ea67e 100644 --- a/cmake/StandardSettings.cmake +++ b/cmake/StandardSettings.cmake @@ -54,6 +54,7 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "^GNU|(Apple)?Clang$") endforeach() include(StdAtomic) + include(StdFilesystem) elseif(MSVC) target_compile_options( diff --git a/cmake/StdFilesystem.cmake b/cmake/StdFilesystem.cmake new file mode 100644 index 000000000..ca451ce78 --- /dev/null +++ b/cmake/StdFilesystem.cmake @@ -0,0 +1,26 @@ +# Check if std::filesystem needs -lstdc++fs + +include(CheckCXXSourceCompiles) + +set( + check_std_filesystem_source_code + [=[ + #include + int main(void) + { + return std::filesystem::is_regular_file(\"/\") ? 0 : 1; + } + ]=]) + +check_cxx_source_compiles("${check_std_filesystem_source_code}" std_filesystem_without_libfs) + +if(NOT std_filesystem_without_libfs) + set(CMAKE_REQUIRED_LIBRARIES stdc++fs) + check_cxx_source_compiles("${check_std_filesystem_source_code}" std_filesystem_with_libfs) + set(CMAKE_REQUIRED_LIBRARIES) + if(NOT std_filesystem_with_libfs) + message(FATAL_ERROR "Toolchain doesn't support std::filesystem with nor without -lstdc++fs") + else() + target_link_libraries(standard_settings INTERFACE stdc++fs) + endif() +endif()