cmake: add libatomic check

This commit is contained in:
Alexander Alekhin 2019-08-20 16:19:37 +03:00
parent 9612397aa2
commit 464972855e
4 changed files with 57 additions and 1 deletions

View File

@ -64,6 +64,10 @@ if(POLICY CMP0068)
cmake_policy(SET CMP0068 NEW) # CMake 3.9+: `RPATH` settings on macOS do not affect `install_name`.
endif()
if(POLICY CMP0075)
cmake_policy(SET CMP0075 NEW) # CMake 3.12+: Include file check macros honor `CMAKE_REQUIRED_LIBRARIES`
endif()
#
# Configure OpenCV CMake hooks

View File

@ -194,3 +194,21 @@ if(NOT HAVE_CXX11)
endif()
endif()
endif()
if((HAVE_CXX11
AND NOT MSVC
AND NOT (X86 OR X86_64)
AND NOT OPENCV_SKIP_LIBATOMIC_COMPILER_CHECK)
OR OPENCV_FORCE_LIBATOMIC_COMPILER_CHECK
)
ocv_check_compiler_flag(CXX "" HAVE_CXX_ATOMICS_WITHOUT_LIB "${OpenCV_SOURCE_DIR}/cmake/checks/atomic_check.cpp")
if(NOT HAVE_CXX_ATOMICS_WITHOUT_LIB)
list(APPEND CMAKE_REQUIRED_LIBRARIES atomic)
ocv_check_compiler_flag(CXX "" HAVE_CXX_ATOMICS_WITH_LIB "${OpenCV_SOURCE_DIR}/cmake/checks/atomic_check.cpp")
if(HAVE_CXX_ATOMICS_WITH_LIB)
list(APPEND OPENCV_LINKER_LIBS atomic)
else()
message(FATAL_ERROR "C++11 compiler must support std::atomic")
endif()
endif()
endif()

View File

@ -415,12 +415,34 @@ MACRO(ocv_check_compiler_flag LANG FLAG RESULT)
else()
set(__msg "")
endif()
if(CMAKE_REQUIRED_LIBRARIES)
set(__link_libs LINK_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
else()
set(__link_libs)
endif()
set(__cmake_flags "")
if(CMAKE_EXE_LINKER_FLAGS) # CMP0056 do this on new CMake
list(APPEND __cmake_flags "-DCMAKE_EXE_LINKER_FLAGS=${CMAKE_EXE_LINKER_FLAGS}")
endif()
# CMP0067 do this on new CMake
if(DEFINED CMAKE_CXX_STANDARD)
list(APPEND __cmake_flags "-DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}")
endif()
if(DEFINED CMAKE_CXX_STANDARD_REQUIRED)
list(APPEND __cmake_flags "-DCMAKE_CXX_STANDARD_REQUIRED=${CMAKE_CXX_STANDARD_REQUIRED}")
endif()
if(DEFINED CMAKE_CXX_EXTENSIONS)
list(APPEND __cmake_flags "-DCMAKE_CXX_EXTENSIONS=${CMAKE_CXX_EXTENSIONS}")
endif()
MESSAGE(STATUS "Performing Test ${RESULT}${__msg}")
TRY_COMPILE(${RESULT}
"${CMAKE_BINARY_DIR}"
"${_fname}"
CMAKE_FLAGS "-DCMAKE_EXE_LINKER_FLAGS=${CMAKE_EXE_LINKER_FLAGS}" # CMP0056 do this on new CMake
CMAKE_FLAGS ${__cmake_flags}
COMPILE_DEFINITIONS "${FLAG}"
${__link_libs}
OUTPUT_VARIABLE OUTPUT)
if(${RESULT})

View File

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