blender/build_files/scons/tools/unordered_map.py
Lukas Tönne bbfcb0b1e4 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
2014-03-25 09:25:00 +01:00

33 lines
1.4 KiB
Python

def test_unordered_map(conf):
"""
Detect unordered_map availability
Returns (True/False, namespace, include prefix)
"""
if conf.CheckCXXHeader("unordered_map"):
# 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.
if conf.CheckType('std::unordered_map<int, int>', language = 'CXX', includes="#include <unordered_map>"):
print("-- Found unordered_map/set in std namespace.")
return True, 'std', ''
elif conf.CheckType('std::tr1::unordered_map<int, int>', language = 'CXX', includes="#include <unordered_map>"):
print("-- Found unordered_map/set in std::tr1 namespace.")
return True, 'std::tr1', ''
else:
print("-- Found <unordered_map> but can not find neither std::unordered_map nor std::tr1::unordered_map.")
return False, '', ''
elif conf.CheckCXXHeader("tr1/unordered_map"):
print("-- Found unordered_map/set in std::tr1 namespace.")
return True, 'std::tr1', 'tr1/'
else:
print("-- Unable to find <unordered_map> or <tr1/unordered_map>. ")
return False, '', ''