Blame cmake/FindSharedPtr.cmake

Packit ea1746
# Ceres Solver - A fast non-linear least squares minimizer
Packit ea1746
# Copyright 2015 Google Inc. All rights reserved.
Packit ea1746
# http://ceres-solver.org/
Packit ea1746
#
Packit ea1746
# Redistribution and use in source and binary forms, with or without
Packit ea1746
# modification, are permitted provided that the following conditions are met:
Packit ea1746
#
Packit ea1746
# * Redistributions of source code must retain the above copyright notice,
Packit ea1746
#   this list of conditions and the following disclaimer.
Packit ea1746
# * Redistributions in binary form must reproduce the above copyright notice,
Packit ea1746
#   this list of conditions and the following disclaimer in the documentation
Packit ea1746
#   and/or other materials provided with the distribution.
Packit ea1746
# * Neither the name of Google Inc. nor the names of its contributors may be
Packit ea1746
#   used to endorse or promote products derived from this software without
Packit ea1746
#   specific prior written permission.
Packit ea1746
#
Packit ea1746
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
Packit ea1746
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Packit ea1746
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
Packit ea1746
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
Packit ea1746
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
Packit ea1746
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
Packit ea1746
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
Packit ea1746
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
Packit ea1746
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
Packit ea1746
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
Packit ea1746
# POSSIBILITY OF SUCH DAMAGE.
Packit ea1746
#
Packit ea1746
# Author: sergey.vfx@gmail.com (Sergey Sharybin)
Packit ea1746
#
Packit ea1746
Packit ea1746
# FindSharedPtr.cmake - Find shared pointer header and namespace.
Packit ea1746
#
Packit ea1746
# This module defines the following variables:
Packit ea1746
#
Packit ea1746
# SHARED_PTR_FOUND: TRUE if shared_ptr found.
Packit ea1746
# SHARED_PTR_TR1_MEMORY_HEADER: True if <tr1/memory> header is to be used
Packit ea1746
# for the shared_ptr object, otherwise use <memory>.
Packit ea1746
# SHARED_PTR_TR1_NAMESPACE: TRUE if shared_ptr is defined in std::tr1 namespace,
Packit ea1746
# otherwise it's assumed to be defined in std namespace.
Packit ea1746
Packit ea1746
macro(FIND_SHARED_PTR)
Packit ea1746
  # To support CXX11 option, clear the results of all check_xxx() functions
Packit ea1746
  # s/t we always perform the checks each time, otherwise CMake fails to
Packit ea1746
  # detect that the tests should be performed again after CXX11 is toggled.
Packit ea1746
  unset(HAVE_STD_MEMORY_HEADER CACHE)
Packit ea1746
  unset(HAVE_SHARED_PTR_IN_STD_NAMESPACE CACHE)
Packit ea1746
  unset(HAVE_SHARED_PTR_IN_TR1_NAMESPACE CACHE)
Packit ea1746
  unset(HAVE_TR1_MEMORY_HEADER CACHE)
Packit ea1746
  unset(HAVE_SHARED_PTR_IN_TR1_NAMESPACE_FROM_TR1_MEMORY_HEADER CACHE)
Packit ea1746
Packit ea1746
  set(SHARED_PTR_FOUND FALSE)
Packit ea1746
  check_include_file_cxx(memory HAVE_STD_MEMORY_HEADER)
Packit ea1746
  if (HAVE_STD_MEMORY_HEADER)
Packit ea1746
    # Finding the memory header doesn't mean that shared_ptr is in std
Packit ea1746
    # namespace.
Packit ea1746
    #
Packit ea1746
    # In particular, MSVC 2008 has shared_ptr declared in std::tr1.  In
Packit ea1746
    # order to support this, we do an extra check to see which namespace
Packit ea1746
    # should be used.
Packit ea1746
    include(CheckCXXSourceCompiles)
Packit ea1746
    check_cxx_source_compiles("#include <memory>
Packit ea1746
                               int main() {
Packit ea1746
                                 std::shared_ptr<int> int_ptr;
Packit ea1746
                                 return 0;
Packit ea1746
                               }"
Packit ea1746
                              HAVE_SHARED_PTR_IN_STD_NAMESPACE)
Packit ea1746
Packit ea1746
    if (HAVE_SHARED_PTR_IN_STD_NAMESPACE)
Packit ea1746
      message("-- Found shared_ptr in std namespace using <memory> header.")
Packit ea1746
      set(SHARED_PTR_FOUND TRUE)
Packit ea1746
    else (HAVE_SHARED_PTR_IN_STD_NAMESPACE)
Packit ea1746
      check_cxx_source_compiles("#include <memory>
Packit ea1746
                                 int main() {
Packit ea1746
                                   std::tr1::shared_ptr<int> int_ptr;
Packit ea1746
                                   return 0;
Packit ea1746
                                 }"
Packit ea1746
                                HAVE_SHARED_PTR_IN_TR1_NAMESPACE)
Packit ea1746
      if (HAVE_SHARED_PTR_IN_TR1_NAMESPACE)
Packit ea1746
        message("-- Found shared_ptr in std::tr1 namespace using <memory> header.")
Packit ea1746
        set(SHARED_PTR_TR1_NAMESPACE TRUE)
Packit ea1746
        set(SHARED_PTR_FOUND TRUE)
Packit ea1746
      endif (HAVE_SHARED_PTR_IN_TR1_NAMESPACE)
Packit ea1746
    endif (HAVE_SHARED_PTR_IN_STD_NAMESPACE)
Packit ea1746
  endif (HAVE_STD_MEMORY_HEADER)
Packit ea1746
Packit ea1746
  if (NOT SHARED_PTR_FOUND)
Packit ea1746
    # Further, gcc defines shared_ptr in std::tr1 namespace and
Packit ea1746
    # <tr1/memory> is to be included for this. And what makes things
Packit ea1746
    # even more tricky is that gcc does have <memory> header, so
Packit ea1746
    # all the checks above wouldn't find shared_ptr.
Packit ea1746
    check_include_file_cxx("tr1/memory" HAVE_TR1_MEMORY_HEADER)
Packit ea1746
    if (HAVE_TR1_MEMORY_HEADER)
Packit ea1746
      check_cxx_source_compiles("#include <tr1/memory>
Packit ea1746
                                 int main() {
Packit ea1746
                                   std::tr1::shared_ptr<int> int_ptr;
Packit ea1746
                                   return 0;
Packit ea1746
                                 }"
Packit ea1746
                                HAVE_SHARED_PTR_IN_TR1_NAMESPACE_FROM_TR1_MEMORY_HEADER)
Packit ea1746
      if (HAVE_SHARED_PTR_IN_TR1_NAMESPACE_FROM_TR1_MEMORY_HEADER)
Packit ea1746
        message("-- Found shared_ptr in std::tr1 namespace using <tr1/memory> header.")
Packit ea1746
          set(SHARED_PTR_TR1_MEMORY_HEADER TRUE)
Packit ea1746
          set(SHARED_PTR_TR1_NAMESPACE TRUE)
Packit ea1746
        set(SHARED_PTR_FOUND TRUE)
Packit ea1746
      endif (HAVE_SHARED_PTR_IN_TR1_NAMESPACE_FROM_TR1_MEMORY_HEADER)
Packit ea1746
    endif (HAVE_TR1_MEMORY_HEADER)
Packit ea1746
  endif (NOT SHARED_PTR_FOUND)
Packit ea1746
endmacro(FIND_SHARED_PTR)