From 72ac596e19ddb37636e107635b52ee78888460e7 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Fri, 2 May 2014 05:52:56 +0600 Subject: Update Ceres to latest upstream version Brings new bounds limiting and also prepares build system for the changes in the upstream. Namely shared_ptr header and namespace is now being detected by a build system rather than by hacks in the code. This commit includes some changes to auto-detection flags in SCons, presumably adding more consistency there. This is main changes which are suppoed to be reviewed here. Reviewers: campbellbarton Differential Revision: https://developer.blender.org/D581 --- build_files/cmake/macros.cmake | 72 ++++++++++++++++++++++++++ build_files/scons/Modules/FindPython.py | 50 ++++++++++++++++++ build_files/scons/Modules/FindSharedPtr.py | 42 +++++++++++++++ build_files/scons/Modules/FindUnorderedMap.py | 38 ++++++++++++++ build_files/scons/Modules/__init__.py | 0 build_files/scons/config/Modules/FindPython.py | 50 ------------------ build_files/scons/config/Modules/__init__.py | 0 build_files/scons/config/linux-config.py | 2 +- build_files/scons/tools/unordered_map.py | 32 ------------ 9 files changed, 203 insertions(+), 83 deletions(-) create mode 100644 build_files/scons/Modules/FindPython.py create mode 100644 build_files/scons/Modules/FindSharedPtr.py create mode 100644 build_files/scons/Modules/FindUnorderedMap.py create mode 100644 build_files/scons/Modules/__init__.py delete mode 100644 build_files/scons/config/Modules/FindPython.py delete mode 100644 build_files/scons/config/Modules/__init__.py delete mode 100644 build_files/scons/tools/unordered_map.py (limited to 'build_files') diff --git a/build_files/cmake/macros.cmake b/build_files/cmake/macros.cmake index c6caef4d3d1..bfd1cf61df0 100644 --- a/build_files/cmake/macros.cmake +++ b/build_files/cmake/macros.cmake @@ -791,6 +791,78 @@ macro(TEST_UNORDERED_MAP_SUPPORT) endif() endmacro() +macro(TEST_SHARED_PTR_SUPPORT) + # This check are coming from Ceres library. + # + # Find shared pointer header and namespace. + # + # This module defines the following variables: + # + # SHARED_PTR_FOUND: TRUE if shared_ptr found. + # SHARED_PTR_TR1_MEMORY_HEADER: True if header is to be used + # for the shared_ptr object, otherwise use . + # SHARED_PTR_TR1_NAMESPACE: TRUE if shared_ptr is defined in std::tr1 namespace, + # otherwise it's assumed to be defined in std namespace. + + include(CheckIncludeFileCXX) + set(SHARED_PTR_FOUND FALSE) + CHECK_INCLUDE_FILE_CXX(memory HAVE_STD_MEMORY_HEADER) + if(HAVE_STD_MEMORY_HEADER) + # Finding the memory header doesn't mean that shared_ptr is in std + # namespace. + # + # In particular, MSVC 2008 has shared_ptr declared in std::tr1. In + # order to support this, we do an extra check to see which namespace + # should be used. + include(CheckCXXSourceCompiles) + CHECK_CXX_SOURCE_COMPILES("#include + int main() { + std::shared_ptr int_ptr; + return 0; + }" + HAVE_SHARED_PTR_IN_STD_NAMESPACE) + + if(HAVE_SHARED_PTR_IN_STD_NAMESPACE) + message("-- Found shared_ptr in std namespace using header.") + set(SHARED_PTR_FOUND TRUE) + else() + CHECK_CXX_SOURCE_COMPILES("#include + int main() { + std::tr1::shared_ptr int_ptr; + return 0; + }" + HAVE_SHARED_PTR_IN_TR1_NAMESPACE) + if(HAVE_SHARED_PTR_IN_TR1_NAMESPACE) + message("-- Found shared_ptr in std::tr1 namespace using header.") + set(SHARED_PTR_TR1_NAMESPACE TRUE) + set(SHARED_PTR_FOUND TRUE) + endif() + endif() + endif() + + if(NOT SHARED_PTR_FOUND) + # Further, gcc defines shared_ptr in std::tr1 namespace and + # is to be included for this. And what makes things + # even more tricky is that gcc does have header, so + # all the checks above wouldn't find shared_ptr. + CHECK_INCLUDE_FILE_CXX("tr1/memory" HAVE_TR1_MEMORY_HEADER) + if(HAVE_TR1_MEMORY_HEADER) + CHECK_CXX_SOURCE_COMPILES("#include + int main() { + std::tr1::shared_ptr int_ptr; + return 0; + }" + HAVE_SHARED_PTR_IN_TR1_NAMESPACE_FROM_TR1_MEMORY_HEADER) + if(HAVE_SHARED_PTR_IN_TR1_NAMESPACE_FROM_TR1_MEMORY_HEADER) + message("-- Found shared_ptr in std::tr1 namespace using header.") + set(SHARED_PTR_TR1_MEMORY_HEADER TRUE) + set(SHARED_PTR_TR1_NAMESPACE TRUE) + set(SHARED_PTR_FOUND TRUE) + endif() + endif() + endif() +endmacro() + # when we have warnings as errors applied globally this # needs to be removed for some external libs which we dont maintain. diff --git a/build_files/scons/Modules/FindPython.py b/build_files/scons/Modules/FindPython.py new file mode 100644 index 00000000000..a0ead88ebb4 --- /dev/null +++ b/build_files/scons/Modules/FindPython.py @@ -0,0 +1,50 @@ +import os +import platform + +def FindPython(): + all_abi_flags = ['m', 'mu', ''] + + python = "/usr" + abi_flags = "m" # Most common for linux distros + version = "3.4" + + _arch = platform.uname()[4] + "-linux-gnu" + + # Determine ABI flags used on this system + include = os.path.join(python, "include") + for cur_flags in all_abi_flags: + inc = os.path.join(include, "python" + version + cur_flags, "Python.h") + if os.path.exists(inc): + abi_flags = cur_flags + break + + # Find config.h. In some distros, such as ubuntu 12.10 they are not in standard include dir. + incconf = os.path.join(include, _arch, "python" + version + cur_flags) + if not os.path.exists(os.path.join(incconf, "pyconfig.h")): + incconf = '' + + # Determine whether python is in /usr/lib or /usr/lib64 + lib32 = os.path.join(python, "lib", "python" + version, "sysconfig.py") + lib64 = os.path.join(python, "lib64", "python" + version, "sysconfig.py") + if os.path.exists(lib32): + libpath = "${BF_PYTHON}/lib" + elif os.path.exists(lib64): + libpath = "${BF_PYTHON}/lib64" + else: + # roll back to default value + libpath = "${BF_PYTHON}/lib" + + libpath_arch = libpath + _libpath_arch = os.path.join(python, "lib", _arch) # No lib64 stuff with recent deb-like distro afaik... + _libs = ["libpython" + version + abi_flags + ext for ext in (".so", ".a")] + for l in _libs: + if not os.path.exists(os.path.join(libpath, l)) and os.path.exists(os.path.join(_libpath_arch, l)): + libpath_arch = os.path.join(libpath, _arch) + break + + return {"PYTHON": python, + "VERSION": version, + "LIBPATH": libpath, + "LIBPATH_ARCH": libpath_arch, + "ABI_FLAGS": abi_flags, + "CONFIG": incconf} diff --git a/build_files/scons/Modules/FindSharedPtr.py b/build_files/scons/Modules/FindSharedPtr.py new file mode 100644 index 00000000000..848431f8271 --- /dev/null +++ b/build_files/scons/Modules/FindSharedPtr.py @@ -0,0 +1,42 @@ +def FindSharedPtr(conf): + """ + Detect shared_ptr availability + """ + + found = False + namespace = None + header = None + + if conf.CheckCXXHeader("memory"): + # Finding the memory header doesn't mean that shared_ptr is in std + # namespace. + # + # In particular, MSVC 2008 has shared_ptr declared in std::tr1. In + # order to support this, we do an extra check to see which namespace + # should be used. + + if conf.CheckType('std::shared_ptr', language = 'CXX', includes="#include "): + print("-- Found shared_ptr in std namespace using header.") + namespace = 'std' + header = 'memory' + elif conf.CheckType('std::tr1::shared_ptr', language = 'CXX', includes="#include "): + print("-- Found shared_ptr in std::tr1 namespace using header..") + namespace = 'std::tr1' + header = 'memory' + + if not namespace and conf.CheckCXXHeader("tr1/memory"): + # Further, gcc defines shared_ptr in std::tr1 namespace and + # is to be included for this. And what makes things + # even more tricky is that gcc does have header, so + # all the checks above wouldn't find shared_ptr. + if conf.CheckType('std::tr1::shared_ptr', language = 'CXX', includes="#include "): + print("-- Found shared_ptr in std::tr1 namespace using header..") + namespace = 'std::tr1' + header = 'tr1/memory' + + if not namespace: + print("-- Unable to find shared_ptrred_map>.") + + conf.env['WITH_SHARED_PTR_SUPPORT'] = namespace and header + conf.env['SHARED_PTR_NAMESPACE'] = namespace + conf.env['SHARED_PTR_HEADER'] = header diff --git a/build_files/scons/Modules/FindUnorderedMap.py b/build_files/scons/Modules/FindUnorderedMap.py new file mode 100644 index 00000000000..34073c1b0b9 --- /dev/null +++ b/build_files/scons/Modules/FindUnorderedMap.py @@ -0,0 +1,38 @@ +def FindUnorderedMap(conf): + """ + Detect unordered_map availability + """ + + namespace = None + header = None + + 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', language = 'CXX', includes="#include "): + print("-- Found unordered_map/set in std namespace.") + namespace = 'std' + header = 'unordered_map' + elif conf.CheckType('std::tr1::unordered_map', language = 'CXX', includes="#include "): + print("-- Found unordered_map/set in std::tr1 namespace.") + namespace = 'std::tr1' + header = 'unordered_map' + else: + print("-- Found but can not find neither std::unordered_map nor std::tr1::unordered_map.") + elif conf.CheckCXXHeader("tr1/unordered_map"): + print("-- Found unordered_map/set in std::tr1 namespace.") + namespace = 'std::tr1' + header = 'tr1/unordered_map' + else: + print("-- Unable to find or . ") + + conf.env['WITH_UNORDERED_MAP_SUPPORT'] = namespace and header + conf.env['UNORDERED_MAP_NAMESPACE'] = namespace + conf.env['UNORDERED_MAP_HEADER'] = header diff --git a/build_files/scons/Modules/__init__.py b/build_files/scons/Modules/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/build_files/scons/config/Modules/FindPython.py b/build_files/scons/config/Modules/FindPython.py deleted file mode 100644 index a0ead88ebb4..00000000000 --- a/build_files/scons/config/Modules/FindPython.py +++ /dev/null @@ -1,50 +0,0 @@ -import os -import platform - -def FindPython(): - all_abi_flags = ['m', 'mu', ''] - - python = "/usr" - abi_flags = "m" # Most common for linux distros - version = "3.4" - - _arch = platform.uname()[4] + "-linux-gnu" - - # Determine ABI flags used on this system - include = os.path.join(python, "include") - for cur_flags in all_abi_flags: - inc = os.path.join(include, "python" + version + cur_flags, "Python.h") - if os.path.exists(inc): - abi_flags = cur_flags - break - - # Find config.h. In some distros, such as ubuntu 12.10 they are not in standard include dir. - incconf = os.path.join(include, _arch, "python" + version + cur_flags) - if not os.path.exists(os.path.join(incconf, "pyconfig.h")): - incconf = '' - - # Determine whether python is in /usr/lib or /usr/lib64 - lib32 = os.path.join(python, "lib", "python" + version, "sysconfig.py") - lib64 = os.path.join(python, "lib64", "python" + version, "sysconfig.py") - if os.path.exists(lib32): - libpath = "${BF_PYTHON}/lib" - elif os.path.exists(lib64): - libpath = "${BF_PYTHON}/lib64" - else: - # roll back to default value - libpath = "${BF_PYTHON}/lib" - - libpath_arch = libpath - _libpath_arch = os.path.join(python, "lib", _arch) # No lib64 stuff with recent deb-like distro afaik... - _libs = ["libpython" + version + abi_flags + ext for ext in (".so", ".a")] - for l in _libs: - if not os.path.exists(os.path.join(libpath, l)) and os.path.exists(os.path.join(_libpath_arch, l)): - libpath_arch = os.path.join(libpath, _arch) - break - - return {"PYTHON": python, - "VERSION": version, - "LIBPATH": libpath, - "LIBPATH_ARCH": libpath_arch, - "ABI_FLAGS": abi_flags, - "CONFIG": incconf} diff --git a/build_files/scons/config/Modules/__init__.py b/build_files/scons/config/Modules/__init__.py deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/build_files/scons/config/linux-config.py b/build_files/scons/config/linux-config.py index 8f2c5ca30f4..0c76aecfc4b 100644 --- a/build_files/scons/config/linux-config.py +++ b/build_files/scons/config/linux-config.py @@ -1,4 +1,4 @@ -from Modules.FindPython import FindPython +from FindPython import FindPython py = FindPython() diff --git a/build_files/scons/tools/unordered_map.py b/build_files/scons/tools/unordered_map.py deleted file mode 100644 index d314a777b0c..00000000000 --- a/build_files/scons/tools/unordered_map.py +++ /dev/null @@ -1,32 +0,0 @@ -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', language = 'CXX', includes="#include "): - print("-- Found unordered_map/set in std namespace.") - return True, 'std', '' - elif conf.CheckType('std::tr1::unordered_map', language = 'CXX', includes="#include "): - print("-- Found unordered_map/set in std::tr1 namespace.") - return True, 'std::tr1', '' - else: - print("-- Found 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 or . ") - return False, '', '' -- cgit v1.2.3