tls_configure.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. from __future__ import print_function
  2. def supported(result):
  3. return 'supported' if result else 'not supported'
  4. def check_cxx11_thread_local(conf):
  5. print('Checking for `thread_local` support...', end=" ")
  6. result = conf.TryCompile('thread_local int foo = 0; int main() { return foo; }', '.cpp')
  7. print(supported(result))
  8. return bool(result)
  9. def check_declspec_thread(conf):
  10. print('Checking for `__declspec(thread)` support...', end=" ")
  11. result = conf.TryCompile('__declspec(thread) int foo = 0; int main() { return foo; }', '.cpp')
  12. print(supported(result))
  13. return bool(result)
  14. def check_gcc___thread(conf):
  15. print('Checking for `__thread` support...', end=" ")
  16. result = conf.TryCompile('__thread int foo = 0; int main() { return foo; }', '.cpp')
  17. print(supported(result))
  18. return bool(result)
  19. def configure(conf):
  20. if check_cxx11_thread_local(conf):
  21. conf.env.Append(CPPDEFINES=['HAVE_CXX11_THREAD_LOCAL'])
  22. else:
  23. if conf.env.msvc:
  24. if check_declspec_thread(conf):
  25. conf.env.Append(CPPDEFINES=['HAVE_DECLSPEC_THREAD'])
  26. elif check_gcc___thread(conf):
  27. conf.env.Append(CPPDEFINES=['HAVE_GCC___THREAD'])