aboutsummaryrefslogtreecommitdiffstats
path: root/CheckCXX11SharedPtr.cmake
blob: 0dc328190663f949a564f6a3b000e1553cb0f07c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
cmake_minimum_required(VERSION 2.8.3)

if (ENTITYX_USE_CPP11_STDLIB)
    add_definitions(-DGTEST_USE_OWN_TR1_TUPLE=1)
    set(OLD_CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
    check_cxx_source_compiles(
    "
    #include <memory>

    int main() {
        std::shared_ptr<int>();
    }
    "
    ENTITYX_HAVE_CXX11_STDLIB
    )

    if (NOT ENTITYX_HAVE_CXX11_STDLIB)
        message("-- Not using -stdlib=libc++ (test failed to build)")
        set(CMAKE_CXX_FLAGS "${OLD_CMAKE_CXX_FLAGS}")
    else ()
        message("-- Using -stdlib=libc++")
    endif ()
else ()
    message("-- Using default stdlib (try -DENTITYX_USE_CPP11_STDLIB=1 to use -stdlib=libc++)")
endif ()

check_cxx_source_compiles(
"
#include <memory>

int main() { std::shared_ptr<int>(); }
"
ENTITYX_HAVE_STD_SHARED_PTR
)

check_cxx_source_compiles(
"
#include <boost/shared_ptr.hpp>

int main() { boost::shared_ptr<int>(); }
"
ENTITYX_HAVE_BOOST_SHARED_PTR
)

if (ENTITYX_HAVE_STD_SHARED_PTR AND ENTITYX_USE_STD_SHARED_PTR)
    message("-- Using std::shared_ptr<T>")
else()
    if (ENTITYX_USE_STD_SHARED_PTR)
        message("-- Using boost::shared_ptr<T> (std::shared_ptr<T> could not be used)")
    else()
        message("-- Using boost::shared_ptr<T> (try -DENTITYX_USE_STD_SHARED_PTR=1 to use std::shared_ptr<T>)")
    endif()
endif()