1 # Ceres Solver - A fast non-linear least squares minimizer
2 # Copyright 2015 Google Inc. All rights reserved.
3 # http://ceres-solver.org/
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions are met:
8 # * Redistributions of source code must retain the above copyright notice,
9 # this list of conditions and the following disclaimer.
10 # * Redistributions in binary form must reproduce the above copyright notice,
11 # this list of conditions and the following disclaimer in the documentation
12 # and/or other materials provided with the distribution.
13 # * Neither the name of Google Inc. nor the names of its contributors may be
14 # used to endorse or promote products derived from this software without
15 # specific prior written permission.
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 # POSSIBILITY OF SUCH DAMAGE.
29 # Author: sergey.vfx@gmail.com (Sergey Sharybin)
32 # FindSharedPtr.cmake - Find shared pointer header and namespace.
34 # This module defines the following variables:
36 # SHARED_PTR_FOUND: TRUE if shared_ptr found.
37 # SHARED_PTR_TR1_MEMORY_HEADER: True if <tr1/memory> header is to be used
38 # for the shared_ptr object, otherwise use <memory>.
39 # SHARED_PTR_TR1_NAMESPACE: TRUE if shared_ptr is defined in std::tr1 namespace,
40 # otherwise it's assumed to be defined in std namespace.
42 macro(FIND_SHARED_PTR)
43 # To support CXX11 option, clear the results of all check_xxx() functions
44 # s/t we always perform the checks each time, otherwise CMake fails to
45 # detect that the tests should be performed again after CXX11 is toggled.
46 unset(HAVE_STD_MEMORY_HEADER CACHE)
47 unset(HAVE_SHARED_PTR_IN_STD_NAMESPACE CACHE)
48 unset(HAVE_SHARED_PTR_IN_TR1_NAMESPACE CACHE)
49 unset(HAVE_TR1_MEMORY_HEADER CACHE)
50 unset(HAVE_SHARED_PTR_IN_TR1_NAMESPACE_FROM_TR1_MEMORY_HEADER CACHE)
52 set(SHARED_PTR_FOUND FALSE)
53 check_include_file_cxx(memory HAVE_STD_MEMORY_HEADER)
54 if (HAVE_STD_MEMORY_HEADER)
55 # Finding the memory header doesn't mean that shared_ptr is in std
58 # In particular, MSVC 2008 has shared_ptr declared in std::tr1. In
59 # order to support this, we do an extra check to see which namespace
61 include(CheckCXXSourceCompiles)
62 check_cxx_source_compiles("#include <memory>
64 std::shared_ptr<int> int_ptr;
67 HAVE_SHARED_PTR_IN_STD_NAMESPACE)
69 if (HAVE_SHARED_PTR_IN_STD_NAMESPACE)
70 message("-- Found shared_ptr in std namespace using <memory> header.")
71 set(SHARED_PTR_FOUND TRUE)
72 else (HAVE_SHARED_PTR_IN_STD_NAMESPACE)
73 check_cxx_source_compiles("#include <memory>
75 std::tr1::shared_ptr<int> int_ptr;
78 HAVE_SHARED_PTR_IN_TR1_NAMESPACE)
79 if (HAVE_SHARED_PTR_IN_TR1_NAMESPACE)
80 message("-- Found shared_ptr in std::tr1 namespace using <memory> header.")
81 set(SHARED_PTR_TR1_NAMESPACE TRUE)
82 set(SHARED_PTR_FOUND TRUE)
83 endif (HAVE_SHARED_PTR_IN_TR1_NAMESPACE)
84 endif (HAVE_SHARED_PTR_IN_STD_NAMESPACE)
85 endif (HAVE_STD_MEMORY_HEADER)
87 if (NOT SHARED_PTR_FOUND)
88 # Further, gcc defines shared_ptr in std::tr1 namespace and
89 # <tr1/memory> is to be included for this. And what makes things
90 # even more tricky is that gcc does have <memory> header, so
91 # all the checks above wouldn't find shared_ptr.
92 check_include_file_cxx("tr1/memory" HAVE_TR1_MEMORY_HEADER)
93 if (HAVE_TR1_MEMORY_HEADER)
94 check_cxx_source_compiles("#include <tr1/memory>
96 std::tr1::shared_ptr<int> int_ptr;
99 HAVE_SHARED_PTR_IN_TR1_NAMESPACE_FROM_TR1_MEMORY_HEADER)
100 if (HAVE_SHARED_PTR_IN_TR1_NAMESPACE_FROM_TR1_MEMORY_HEADER)
101 message("-- Found shared_ptr in std::tr1 namespace using <tr1/memory> header.")
102 set(SHARED_PTR_TR1_MEMORY_HEADER TRUE)
103 set(SHARED_PTR_TR1_NAMESPACE TRUE)
104 set(SHARED_PTR_FOUND TRUE)
105 endif (HAVE_SHARED_PTR_IN_TR1_NAMESPACE_FROM_TR1_MEMORY_HEADER)
106 endif (HAVE_TR1_MEMORY_HEADER)
107 endif (NOT SHARED_PTR_FOUND)
108 endmacro(FIND_SHARED_PTR)