CMAKE_REQUIRED_FLAGS is not appropriate for libraries.
They are added before object files to the compiler command line arguments.
Depending on compiler settings it might decide that the library is not
actually needed because at that point it hasn't seen any object file
using a symbol from the library.
See "-Wl,--as-needed"
The checks are valid, the "atomic" is added to CMAKE_REQUIRED_LIBRARIES,
but it fails during linking with undefined reference to __atomic_store_8
error.
"-latomic" needs to be added to CMAKE_CXX_LINK_FLAGS to fix that.
It's no sense to repeat an already failed check.
Looks like a copy-paste bug as the HAVE_CXX_LIBATOMICS64_2ARGS test
runs again the very same check as the HAVE_LIBATOMIC_2ARGS.
Without this change the check obviously fails:
-- Performing Test HAVE_LIBATOMIC_2ARGS
-- Performing Test HAVE_LIBATOMIC_2ARGS - Failed
-- Performing Test HAVE_CXX_ATOMICS64_WITHOUT_LIB
-- Performing Test HAVE_CXX_ATOMICS64_WITHOUT_LIB - Failed
-- Looking for __atomic_load_8 in atomic
-- Looking for __atomic_load_8 in atomic - not found
-- Performing Test HAVE_CXX_LIBATOMICS64_2ARGS
-- Performing Test HAVE_CXX_LIBATOMICS64_2ARGS - Failed
CMake Error at cmake/CheckAtomic.cmake:146 (message):
Host compiler appears to require libatomic, but cannot find it.
Call Stack (most recent call first):
CMakeLists.txt:80 (include)
With this change the test HAVE_CXX_LIBATOMICS64_2ARGS succeeds:
-- Performing Test HAVE_LIBATOMIC_2ARGS
-- Performing Test HAVE_LIBATOMIC_2ARGS - Failed
-- Performing Test HAVE_CXX_ATOMICS64_WITHOUT_LIB
-- Performing Test HAVE_CXX_ATOMICS64_WITHOUT_LIB - Failed
-- Looking for __atomic_load_8 in atomic
-- Looking for __atomic_load_8 in atomic - not found
-- Performing Test HAVE_CXX_LIBATOMICS64_2ARGS
-- Performing Test HAVE_CXX_LIBATOMICS64_2ARGS - Success
-- Performing Test HAVE_CXX_ATOMICS64_WITH_LIB
-- Performing Test HAVE_CXX_ATOMICS64_WITH_LIB - Success
Use 'long long' in the check_working_cxx_atomics check.
Without it the check succeed but fails during linking:
-- Performing Test HAVE_CXX_ATOMICS_WITHOUT_LIB
-- Performing Test HAVE_CXX_ATOMICS_WITHOUT_LIB - Success
Tested with the following toolchains with OpenWrt:
* toolchain-aarch64_cortex-a72_gcc-8.3.0_musl
* toolchain-arm_cortex-a7+neon-vfpv4_gcc-8.3.0_musl_eabi
* toolchain-i386_pentium_gcc-8.3.0_musl
* toolchain-mips_24kc_gcc-8.3.0_musl
* toolchain-mipsel_24kc_gcc-8.3.0_musl