From 80a0e27d8cd34b3566b5b3eda8ea6fce9dc77f75 Mon Sep 17 00:00:00 2001 From: Dw9 Date: Sat, 29 Jan 2022 22:40:08 +0800 Subject: [PATCH] link atomic library automatic when compile on raspberrypi (#1405) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 增加检测atomic源文件 * 支持树莓派编译,自动检测atomic链接库 * 精简cmake操作 --- CMakeLists.txt | 12 ++++++++++++ cmake/checks/atomic_check.cpp | 12 ++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 cmake/checks/atomic_check.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 83479245..c4cc97e7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,6 +25,18 @@ if (CMAKE_SYSTEM_NAME MATCHES "Linux") SET(LIBRARY_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) + 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") + else() + set(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -latomic") + endif() + endif() elseif (CMAKE_SYSTEM_NAME MATCHES "Windows") if (CMAKE_CL_64) set(CL_32_64 64) diff --git a/cmake/checks/atomic_check.cpp b/cmake/checks/atomic_check.cpp new file mode 100644 index 00000000..f25e2d9f --- /dev/null +++ b/cmake/checks/atomic_check.cpp @@ -0,0 +1,12 @@ +#include + +static int test() +{ + std::atomic x; + return x; +} + +int main() +{ + return test(); +} \ No newline at end of file