]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
build: Support compilation with GCC 8 (#1190)
authorOrgad Shaneh <orgad.shaneh@audiocodes.com>
Sat, 22 Oct 2022 10:48:25 +0000 (13:48 +0300)
committerGitHub <noreply@github.com>
Sat, 22 Oct 2022 10:48:25 +0000 (12:48 +0200)
See https://discourse.cmake.org/t/correct-way-to-link-std-filesystem-with-gcc-8/4121

cmake/StandardSettings.cmake
cmake/StdFilesystem.cmake [new file with mode: 0644]

index 83871af82e2e465d98e8bcbb55aaa77e4236d7e5..9e09ea67e8df92c3e9016763259ea5c02be77769 100644 (file)
@@ -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 (file)
index 0000000..ca451ce
--- /dev/null
@@ -0,0 +1,26 @@
+# Check if std::filesystem needs -lstdc++fs
+
+include(CheckCXXSourceCompiles)
+
+set(
+  check_std_filesystem_source_code
+  [=[
+    #include <filesystem>
+    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()