link atomic library automatic when compile on raspberrypi (#1405)

* 增加检测atomic源文件

* 支持树莓派编译,自动检测atomic链接库

* 精简cmake操作
This commit is contained in:
Dw9 2022-01-29 22:40:08 +08:00 committed by GitHub
parent c97aa8483e
commit 80a0e27d8c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 0 deletions

View File

@ -25,6 +25,18 @@ if (CMAKE_SYSTEM_NAME MATCHES "Linux")
SET(LIBRARY_OUTPUT_PATH ${RELEASE_DIR}/linux/${CMAKE_BUILD_TYPE}) SET(LIBRARY_OUTPUT_PATH ${RELEASE_DIR}/linux/${CMAKE_BUILD_TYPE})
SET(EXECUTABLE_OUTPUT_PATH ${RELEASE_DIR}/linux/${CMAKE_BUILD_TYPE}) SET(EXECUTABLE_OUTPUT_PATH ${RELEASE_DIR}/linux/${CMAKE_BUILD_TYPE})
add_compile_options(-fPIC -Wall -Wno-unused-variable -Wno-unused-value) add_compile_options(-fPIC -Wall -Wno-unused-variable -Wno-unused-value)
INCLUDE(CheckCXXSourceCompiles)
file(READ ${CMAKE_CURRENT_SOURCE_DIR}/cmake/checks/atomic_check.cpp atomic_check_cpp)
CHECK_CXX_SOURCE_COMPILES("${atomic_check_cpp}" HAVE_CXX_ATOMICS_WITHOUT_LIB)
if(NOT HAVE_CXX_ATOMICS_WITHOUT_LIB)
list(APPEND CMAKE_REQUIRED_LIBRARIES "atomic")
CHECK_CXX_SOURCE_COMPILES("${atomic_check_cpp}" HAVE_CXX_ATOMICS_WITH_LIB)
if(NOT HAVE_CXX_ATOMICS_WITH_LIB)
message(WARNING "Compiler doesn't support std::atomic<long long>")
else()
set(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -latomic")
endif()
endif()
elseif (CMAKE_SYSTEM_NAME MATCHES "Windows") elseif (CMAKE_SYSTEM_NAME MATCHES "Windows")
if (CMAKE_CL_64) if (CMAKE_CL_64)
set(CL_32_64 64) set(CL_32_64 64)

View File

@ -0,0 +1,12 @@
#include <atomic>
static int test()
{
std::atomic<long long> x;
return x;
}
int main()
{
return test();
}