• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2018 Mike Dev
2# Copyright 2019 Peter Dimov
3# Copyright 2020 Andrey Semashev
4# Distributed under the Boost Software License, Version 1.0.
5# See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt
6
7cmake_minimum_required(VERSION 3.5...3.16)
8project(boost_atomic VERSION "${BOOST_SUPERPROJECT_VERSION}" LANGUAGES CXX)
9
10include(CheckCXXSourceCompiles)
11
12set(boost_atomic_sources src/lock_pool.cpp)
13
14set(CMAKE_REQUIRED_INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/../..")
15check_cxx_source_compiles("#include <${CMAKE_CURRENT_SOURCE_DIR}/../config/checks/architecture/x86.cpp>\nint main() {}" BOOST_ATOMIC_TARGET_X86)
16unset(CMAKE_REQUIRED_INCLUDES)
17
18if (BOOST_ATOMIC_TARGET_X86)
19    if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
20        if (CMAKE_SIZEOF_VOID_P EQUAL 4)
21            set(boost_atomic_sse2_cflags "/arch:SSE2")
22            set(boost_atomic_sse41_cflags "/arch:SSE2")
23        endif()
24    elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
25        if (WIN32)
26            set(boost_atomic_sse2_cflags "/QxSSE2")
27            set(boost_atomic_sse41_cflags "/QxSSE4.1")
28        else()
29            set(boost_atomic_sse2_cflags "-xSSE2")
30            set(boost_atomic_sse41_cflags "-xSSE4.1")
31        endif()
32    else()
33        set(boost_atomic_sse2_cflags "-msse -msse2")
34        set(boost_atomic_sse41_cflags "-msse -msse2 -msse3 -mssse3 -msse4.1")
35    endif()
36
37    set(CMAKE_REQUIRED_INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/../..")
38    set(CMAKE_REQUIRED_FLAGS "${boost_atomic_sse2_cflags}")
39    check_cxx_source_compiles("#include <${CMAKE_CURRENT_SOURCE_DIR}/config/has_sse2.cpp>" BOOST_ATOMIC_COMPILER_HAS_SSE2)
40    unset(CMAKE_REQUIRED_FLAGS)
41    unset(CMAKE_REQUIRED_INCLUDES)
42
43    set(CMAKE_REQUIRED_INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/../..")
44    set(CMAKE_REQUIRED_FLAGS "${boost_atomic_sse41_cflags}")
45    check_cxx_source_compiles("#include <${CMAKE_CURRENT_SOURCE_DIR}/config/has_sse41.cpp>" BOOST_ATOMIC_COMPILER_HAS_SSE41)
46    unset(CMAKE_REQUIRED_FLAGS)
47    unset(CMAKE_REQUIRED_INCLUDES)
48
49    if (BOOST_ATOMIC_COMPILER_HAS_SSE2)
50        set(boost_atomic_sources_sse2 src/find_address_sse2.cpp)
51        set_source_files_properties(${boost_atomic_sources_sse2} PROPERTIES COMPILE_FLAGS "${boost_atomic_sse2_cflags}")
52        set(boost_atomic_sources ${boost_atomic_sources} ${boost_atomic_sources_sse2})
53    endif()
54
55    if (BOOST_ATOMIC_COMPILER_HAS_SSE41)
56        set(boost_atomic_sources_sse41 src/find_address_sse41.cpp)
57        set_source_files_properties(${boost_atomic_sources_sse41} PROPERTIES COMPILE_FLAGS "${boost_atomic_sse41_cflags}")
58        set(boost_atomic_sources ${boost_atomic_sources} ${boost_atomic_sources_sse41})
59    endif()
60endif()
61
62if (WIN32)
63    set(boost_atomic_sources ${boost_atomic_sources} src/wait_ops_windows.cpp)
64endif()
65
66if (WIN32)
67    # Note: We can't use the Boost::library targets here as they may not yet be included by the superproject when this CMakeLists.txt is included.
68    set(CMAKE_REQUIRED_INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/../..")
69    set(CMAKE_REQUIRED_LIBRARIES synchronization)
70    check_cxx_source_compiles("#include <${CMAKE_CURRENT_SOURCE_DIR}/config/has_synchronization.cpp>" BOOST_ATOMIC_HAS_SYNCHRONIZATION)
71    unset(CMAKE_REQUIRED_LIBRARIES)
72    unset(CMAKE_REQUIRED_INCLUDES)
73endif()
74
75add_library(boost_atomic ${boost_atomic_sources})
76add_library(Boost::atomic ALIAS boost_atomic)
77
78target_include_directories(boost_atomic PUBLIC include)
79target_include_directories(boost_atomic PRIVATE src)
80
81target_link_libraries(boost_atomic
82    PUBLIC
83        Boost::assert
84        Boost::config
85        Boost::static_assert
86        Boost::type_traits
87    PRIVATE
88        Boost::align
89        Boost::predef
90        Boost::preprocessor
91)
92
93if (WIN32)
94    target_link_libraries(boost_atomic
95        PUBLIC
96            Boost::winapi
97    )
98
99    if (BOOST_ATOMIC_HAS_SYNCHRONIZATION)
100        target_link_libraries(boost_atomic PRIVATE synchronization)
101    endif()
102endif()
103
104target_compile_definitions(boost_atomic
105    PUBLIC
106        BOOST_ATOMIC_NO_LIB
107    PRIVATE
108        BOOST_ATOMIC_SOURCE
109)
110
111if (BUILD_SHARED_LIBS)
112    target_compile_definitions(boost_atomic PUBLIC BOOST_ATOMIC_DYN_LINK)
113else()
114    target_compile_definitions(boost_atomic PUBLIC BOOST_ATOMIC_STATIC_LINK)
115endif()
116
117if (BOOST_ATOMIC_COMPILER_HAS_SSE2)
118    target_compile_definitions(boost_atomic PRIVATE BOOST_ATOMIC_USE_SSE2)
119endif()
120if (BOOST_ATOMIC_COMPILER_HAS_SSE41)
121    target_compile_definitions(boost_atomic PRIVATE BOOST_ATOMIC_USE_SSE41)
122endif()
123