From bbfcb0b1e44636b73b8c46f1cb800fa53dda5277 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20T=C3=B6nne?= Date: Tue, 25 Mar 2014 09:21:30 +0100 Subject: Build file macro for testing unordered_map C++ container support. Using unordered_map and unordered_set C++ container types currently requires careful testing or usage of boost, due to the various confusing C++ version differences in include paths and namespaces. Libmv defines tests for these cases in cmake and scons, such that ceres can use any available implementation, or fall back too std::map/std::set if none can be found. This patch generalizes this buildfile code by providing a Blender macro. * cmake: defines both the variables used by libmv at them moment as well as 2 variables UNORDERED_MAP_INCLUDE_PREFIX and UNORDERED_MAP_NAMESPACE, which can later be used in other C++ parts for convenience. * scons: adds a tool script returning the include prefix and namespace. Libmv checks these to define the appropriate definitions for ceres. Differential Revision: https://developer.blender.org/D425 --- build_files/cmake/macros.cmake | 71 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) (limited to 'build_files/cmake') diff --git a/build_files/cmake/macros.cmake b/build_files/cmake/macros.cmake index 28af1c1486c..772ff6d7596 100644 --- a/build_files/cmake/macros.cmake +++ b/build_files/cmake/macros.cmake @@ -483,6 +483,77 @@ macro(TEST_STDBOOL_SUPPORT) HAVE_STDBOOL_H) endmacro() +macro(TEST_UNORDERED_MAP_SUPPORT) + # - Detect unordered_map availability + # Test if a valid implementation of unordered_map exists + # and define the include path + # This module defines + # HAVE_UNORDERED_MAP, whether unordered_map implementation was found + # + # HAVE_STD_UNORDERED_MAP_HEADER, was found + # HAVE_UNORDERED_MAP_IN_STD_NAMESPACE, unordered_map is in namespace std + # HAVE_UNORDERED_MAP_IN_TR1_NAMESPACE, unordered_map is in namespace std::tr1 + # + # UNORDERED_MAP_INCLUDE_PREFIX, include path prefix for unordered_map, if found + # UNORDERED_MAP_NAMESPACE, namespace for unordered_map, if found + + include(CheckIncludeFileCXX) + CHECK_INCLUDE_FILE_CXX("unordered_map" HAVE_STD_UNORDERED_MAP_HEADER) + if(HAVE_STD_UNORDERED_MAP_HEADER) + # Even so we've found unordered_map header file it doesn't + # mean unordered_map and unordered_set will be declared in + # std namespace. + # + # Namely, MSVC 2008 have unordered_map header which declares + # unordered_map class in std::tr1 namespace. In order to support + # this, we do extra check to see which exactly namespace is + # to be used. + + include(CheckCXXSourceCompiles) + CHECK_CXX_SOURCE_COMPILES("#include + int main() { + std::unordered_map map; + return 0; + }" + HAVE_UNORDERED_MAP_IN_STD_NAMESPACE) + if(HAVE_UNORDERED_MAP_IN_STD_NAMESPACE) + message(STATUS "Found unordered_map/set in std namespace.") + + set(HAVE_UNORDERED_MAP "TRUE") + set(UNORDERED_MAP_INCLUDE_PREFIX "") + set(UNORDERED_MAP_NAMESPACE "std") + else() + CHECK_CXX_SOURCE_COMPILES("#include + int main() { + std::tr1::unordered_map map; + return 0; + }" + HAVE_UNORDERED_MAP_IN_TR1_NAMESPACE) + if(HAVE_UNORDERED_MAP_IN_TR1_NAMESPACE) + message(STATUS "Found unordered_map/set in std::tr1 namespace.") + + set(HAVE_UNORDERED_MAP "TRUE") + set(UNORDERED_MAP_INCLUDE_PREFIX "") + set(UNORDERED_MAP_NAMESPACE "std::tr1") + else() + message(STATUS "Found but cannot find either std::unordered_map " + "or std::tr1::unordered_map.") + endif() + endif() + else() + CHECK_INCLUDE_FILE_CXX("tr1/unordered_map" HAVE_UNORDERED_MAP_IN_TR1_NAMESPACE) + if(HAVE_UNORDERED_MAP_IN_TR1_NAMESPACE) + message(STATUS "Found unordered_map/set in std::tr1 namespace.") + + set(HAVE_UNORDERED_MAP "TRUE") + set(UNORDERED_MAP_INCLUDE_PREFIX "tr1") + set(UNORDERED_MAP_NAMESPACE "std::tr1") + else() + message(STATUS "Unable to find or . ") + endif() + endif() +endmacro() + # when we have warnings as errors applied globally this # needs to be removed for some external libs which we dont maintain. -- cgit v1.2.3