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