summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOrgad Shaneh <orgad.shaneh@audiocodes.com>2022-10-22 13:48:25 +0300
committerGitHub <noreply@github.com>2022-10-22 12:48:25 +0200
commite63107523915be883025836426fcdd96b97c22fa (patch)
tree80e0651381051bbb434ab90ce121ad535bdabac7
parentb53afeb556d55576ed3683fef6566361464393d5 (diff)
downloadccache-e63107523915be883025836426fcdd96b97c22fa.tar.gz
build: Support compilation with GCC 8 (#1190)
See https://discourse.cmake.org/t/correct-way-to-link-std-filesystem-with-gcc-8/4121
-rw-r--r--cmake/StandardSettings.cmake1
-rw-r--r--cmake/StdFilesystem.cmake26
2 files changed, 27 insertions, 0 deletions
diff --git a/cmake/StandardSettings.cmake b/cmake/StandardSettings.cmake
index 83871af8..9e09ea67 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 00000000..ca451ce7
--- /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 <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()