summaryrefslogtreecommitdiff
path: root/cmake
diff options
context:
space:
mode:
authorJoel Rosdahl <joel@rosdahl.net>2020-11-12 20:40:08 +0100
committerGitHub <noreply@github.com>2020-11-12 20:40:08 +0100
commitac13fb9a0ef7aabcf94ef7fdba1fc92f8e31c0a0 (patch)
tree818501518144d2871fb669b369c2e72247e5d304 /cmake
parent53519446d5b1b93531d5ddc69b531bb714cee6d2 (diff)
downloadccache-ac13fb9a0ef7aabcf94ef7fdba1fc92f8e31c0a0.tar.gz
Link with libatomic when needed (#723)
Linking with libatomic is apparently needed when using <atomic> functionality with GCC on ARM and PowerPC.
Diffstat (limited to 'cmake')
-rw-r--r--cmake/StandardSettings.cmake2
-rw-r--r--cmake/StdAtomic.cmake31
2 files changed, 33 insertions, 0 deletions
diff --git a/cmake/StandardSettings.cmake b/cmake/StandardSettings.cmake
index 88d8dff0..a0f0189c 100644
--- a/cmake/StandardSettings.cmake
+++ b/cmake/StandardSettings.cmake
@@ -47,6 +47,8 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "^GNU|(Apple)?Clang$")
INTERFACE -fsanitize=${SANITIZER})
endforeach()
+ include(StdAtomic)
+
elseif(MSVC)
target_compile_options(standard_settings INTERFACE /std:c++latest /Zc:preprocessor /Zc:__cplusplus /D_CRT_SECURE_NO_WARNINGS)
endif()
diff --git a/cmake/StdAtomic.cmake b/cmake/StdAtomic.cmake
new file mode 100644
index 00000000..aa3bb4bf
--- /dev/null
+++ b/cmake/StdAtomic.cmake
@@ -0,0 +1,31 @@
+# Check if std::atomic needs -latomic
+
+include(CheckCXXSourceCompiles)
+
+set(CMAKE_REQUIRED_FLAGS ${CMAKE_CXX11_STANDARD_COMPILE_OPTION})
+set(
+ check_std_atomic_source_code
+ [=[
+ #include <atomic>
+ int main()
+ {
+ std::atomic<long long> x;
+ (void)x.load();
+ return 0;
+ }
+ ]=])
+
+check_cxx_source_compiles("${check_std_atomic_source_code}" std_atomic_without_libatomic)
+
+if(NOT std_atomic_without_libatomic)
+ set(CMAKE_REQUIRED_LIBRARIES atomic)
+ check_cxx_source_compiles("${check_std_atomic_source_code}" std_atomic_with_libatomic)
+ set(CMAKE_REQUIRED_LIBRARIES)
+ if(NOT std_atomic_with_libatomic)
+ message(FATAL_ERROR "Toolchain doesn't support std::atomic with nor without -latomic")
+ else()
+ target_link_libraries(standard_settings INTERFACE atomic)
+ endif()
+endif()
+
+set(CMAKE_REQUIRED_FLAGS)