gxx.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. #!/usr/bin/env python
  2. # encoding: utf-8
  3. # Thomas Nagy, 2006-2018 (ita)
  4. # Ralf Habacker, 2006 (rh)
  5. # Yinon Ehrlich, 2009
  6. """
  7. g++/llvm detection.
  8. """
  9. from waflib.Tools import ccroot, ar
  10. from waflib.Configure import conf
  11. @conf
  12. def find_gxx(conf):
  13. """
  14. Finds the program g++, and if present, try to detect its version number
  15. """
  16. cxx = conf.find_program(['g++', 'c++'], var='CXX')
  17. conf.get_cc_version(cxx, gcc=True)
  18. conf.env.CXX_NAME = 'gcc'
  19. @conf
  20. def gxx_common_flags(conf):
  21. """
  22. Common flags for g++ on nearly all platforms
  23. """
  24. v = conf.env
  25. v.CXX_SRC_F = []
  26. v.CXX_TGT_F = ['-c', '-o']
  27. if not v.LINK_CXX:
  28. v.LINK_CXX = v.CXX
  29. v.CXXLNK_SRC_F = []
  30. v.CXXLNK_TGT_F = ['-o']
  31. v.CPPPATH_ST = '-I%s'
  32. v.DEFINES_ST = '-D%s'
  33. v.LIB_ST = '-l%s' # template for adding libs
  34. v.LIBPATH_ST = '-L%s' # template for adding libpaths
  35. v.STLIB_ST = '-l%s'
  36. v.STLIBPATH_ST = '-L%s'
  37. v.RPATH_ST = '-Wl,-rpath,%s'
  38. v.SONAME_ST = '-Wl,-h,%s'
  39. v.SHLIB_MARKER = '-Wl,-Bdynamic'
  40. v.STLIB_MARKER = '-Wl,-Bstatic'
  41. v.cxxprogram_PATTERN = '%s'
  42. v.CXXFLAGS_cxxshlib = ['-fPIC']
  43. v.LINKFLAGS_cxxshlib = ['-shared']
  44. v.cxxshlib_PATTERN = 'lib%s.so'
  45. v.LINKFLAGS_cxxstlib = ['-Wl,-Bstatic']
  46. v.cxxstlib_PATTERN = 'lib%s.a'
  47. v.LINKFLAGS_MACBUNDLE = ['-bundle', '-undefined', 'dynamic_lookup']
  48. v.CXXFLAGS_MACBUNDLE = ['-fPIC']
  49. v.macbundle_PATTERN = '%s.bundle'
  50. @conf
  51. def gxx_modifier_win32(conf):
  52. """Configuration flags for executing gcc on Windows"""
  53. v = conf.env
  54. v.cxxprogram_PATTERN = '%s.exe'
  55. v.cxxshlib_PATTERN = '%s.dll'
  56. v.implib_PATTERN = '%s.dll.a'
  57. v.IMPLIB_ST = '-Wl,--out-implib,%s'
  58. v.CXXFLAGS_cxxshlib = []
  59. # Auto-import is enabled by default even without this option,
  60. # but enabling it explicitly has the nice effect of suppressing the rather boring, debug-level messages
  61. # that the linker emits otherwise.
  62. import sys
  63. if sys.platform != "cygwin":
  64. # disabled on cygwin as it breaks build with arm cross compiler
  65. v.append_value('LINKFLAGS', ['-Wl,--enable-auto-import'])
  66. @conf
  67. def gxx_modifier_cygwin(conf):
  68. """Configuration flags for executing g++ on Cygwin"""
  69. gxx_modifier_win32(conf)
  70. v = conf.env
  71. v.cxxshlib_PATTERN = 'cyg%s.dll'
  72. v.append_value('LINKFLAGS_cxxshlib', ['-Wl,--enable-auto-image-base'])
  73. v.CXXFLAGS_cxxshlib = []
  74. @conf
  75. def gxx_modifier_darwin(conf):
  76. """Configuration flags for executing g++ on MacOS"""
  77. v = conf.env
  78. v.CXXFLAGS_cxxshlib = ['-fPIC']
  79. v.LINKFLAGS_cxxshlib = ['-dynamiclib']
  80. v.cxxshlib_PATTERN = 'lib%s.dylib'
  81. v.FRAMEWORKPATH_ST = '-F%s'
  82. v.FRAMEWORK_ST = ['-framework']
  83. v.ARCH_ST = ['-arch']
  84. v.LINKFLAGS_cxxstlib = []
  85. v.SHLIB_MARKER = []
  86. v.STLIB_MARKER = []
  87. v.SONAME_ST = []
  88. @conf
  89. def gxx_modifier_aix(conf):
  90. """Configuration flags for executing g++ on AIX"""
  91. v = conf.env
  92. v.LINKFLAGS_cxxprogram= ['-Wl,-brtl']
  93. v.LINKFLAGS_cxxshlib = ['-shared', '-Wl,-brtl,-bexpfull']
  94. v.SHLIB_MARKER = []
  95. @conf
  96. def gxx_modifier_hpux(conf):
  97. v = conf.env
  98. v.SHLIB_MARKER = []
  99. v.STLIB_MARKER = []
  100. v.CFLAGS_cxxshlib = ['-fPIC','-DPIC']
  101. v.cxxshlib_PATTERN = 'lib%s.sl'
  102. @conf
  103. def gxx_modifier_openbsd(conf):
  104. conf.env.SONAME_ST = []
  105. @conf
  106. def gcc_modifier_osf1V(conf):
  107. v = conf.env
  108. v.SHLIB_MARKER = []
  109. v.STLIB_MARKER = []
  110. v.SONAME_ST = []
  111. @conf
  112. def gxx_modifier_platform(conf):
  113. """Execute platform-specific functions based on *gxx_modifier_+NAME*"""
  114. # * set configurations specific for a platform.
  115. # * the destination platform is detected automatically by looking at the macros the compiler predefines,
  116. # and if it's not recognised, it fallbacks to sys.platform.
  117. gxx_modifier_func = getattr(conf, 'gxx_modifier_' + conf.env.DEST_OS, None)
  118. if gxx_modifier_func:
  119. gxx_modifier_func()
  120. def configure(conf):
  121. """
  122. Configuration for g++
  123. """
  124. conf.find_gxx()
  125. conf.find_ar()
  126. conf.gxx_common_flags()
  127. conf.gxx_modifier_platform()
  128. conf.cxx_load_tools()
  129. conf.cxx_add_flags()
  130. conf.link_add_flags()
  131. conf.check_gcc_o_space('cxx')