meson.build 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. project('tinc', 'c',
  2. version: '1.1pre18',
  3. license: 'GPL-2.0-or-later',
  4. meson_version: '>=0.51',
  5. default_options: [
  6. 'c_std=c11',
  7. 'warning_level=3',
  8. 'buildtype=debugoptimized',
  9. ],
  10. )
  11. dir_run_state = get_option('runstatedir')
  12. opt_crypto = get_option('crypto')
  13. opt_curses = get_option('curses')
  14. opt_debug = get_option('debug')
  15. opt_docs = get_option('docs')
  16. opt_harden = get_option('hardening')
  17. opt_jumbograms = get_option('jumbograms')
  18. opt_lz4 = get_option('lz4')
  19. opt_lzo = get_option('lzo')
  20. opt_miniupnpc = get_option('miniupnpc')
  21. opt_readline = get_option('readline')
  22. opt_sandbox = get_option('sandbox')
  23. opt_static = get_option('static')
  24. opt_systemd = get_option('systemd')
  25. opt_tests = get_option('tests')
  26. opt_tunemu = get_option('tunemu')
  27. opt_uml = get_option('uml')
  28. opt_vde = get_option('vde')
  29. opt_zlib = get_option('zlib')
  30. meson_version = meson.version()
  31. cc = meson.get_compiler('c')
  32. os_name = host_machine.system()
  33. cpu_family = host_machine.cpu_family()
  34. cc_name = cc.get_id()
  35. python = find_program('python3', required: false)
  36. if python.found()
  37. if meson_version.version_compare('>=0.55')
  38. python_path = python.full_path()
  39. else
  40. python_path = python.path()
  41. endif
  42. else
  43. python_path = ''
  44. endif
  45. cc_defs = ['-D_GNU_SOURCE']
  46. if os_name == 'sunos'
  47. cc_defs += '-D__EXTENSIONS__'
  48. endif
  49. cc_flags = [cc_defs]
  50. ld_flags = []
  51. if cc_name != 'msvc'
  52. cc_flags += [
  53. '-Wbad-function-cast',
  54. '-Wduplicated-branches',
  55. '-Wduplicated-cond',
  56. '-Wformat-overflow=2',
  57. '-Wformat-truncation=1', # 2 prints too much noise
  58. '-Wformat=2',
  59. '-Wlogical-op',
  60. '-Wmissing-declarations',
  61. '-Wmissing-noreturn',
  62. '-Wmissing-prototypes',
  63. '-Wno-embedded-directive',
  64. '-Wold-style-definition',
  65. '-Wredundant-decls',
  66. '-Wreturn-type',
  67. '-Wstrict-prototypes',
  68. '-Wswitch-enum',
  69. '-Wtrampolines', # may require executable stack which is disabled
  70. '-Wvla', # VLAs are not supported by MSVC
  71. '-Wwrite-strings',
  72. '-fdiagnostics-show-option',
  73. '-fno-strict-overflow',
  74. '-fstrict-aliasing',
  75. ]
  76. endif
  77. if opt_static.auto()
  78. static = os_name == 'windows'
  79. else
  80. static = opt_static.enabled()
  81. endif
  82. if static and cc_name != 'msvc'
  83. ld_flags += '-static'
  84. endif
  85. if opt_harden
  86. if cc_name == 'msvc'
  87. # Most of these flags are already ON by default in the latest version of MSVC.
  88. # Add anyway in case someone is building using an old toolchain.
  89. cc_flags += ['/guard:cf', '/GS']
  90. ld_flags += [
  91. '/guard:cf',
  92. '/NXCOMPAT',
  93. '/DYNAMICBASE',
  94. cpu_family.endswith('64') ? '/HIGHENTROPYVA' : '/SAFESEH',
  95. ]
  96. else
  97. cc_flags += [
  98. '-D_FORTIFY_SOURCE=2',
  99. '-fcf-protection=full',
  100. '-fstack-protector-strong',
  101. ]
  102. ld_flags += ['-Wl,-z,relro', '-Wl,-z,now', '-Wl,-z,noexecstack']
  103. if os_name == 'windows'
  104. ld_flags += ['-Wl,--dynamicbase', '-Wl,--nxcompat']
  105. else
  106. # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90458
  107. cc_flags += '-fstack-clash-protection'
  108. endif
  109. endif
  110. endif
  111. cc_flags = cc.get_supported_arguments(cc_flags)
  112. ld_flags = cc.get_supported_link_arguments(ld_flags)
  113. add_project_arguments(cc_flags, language: 'c')
  114. add_project_link_arguments(ld_flags, language: 'c')
  115. build_root = meson.current_build_dir()
  116. src_root = meson.current_source_dir()
  117. prefix = get_option('prefix')
  118. dir_bin = prefix / get_option('bindir')
  119. dir_data = prefix / get_option('datadir')
  120. dir_info = prefix / get_option('infodir')
  121. dir_lib = prefix / get_option('libdir')
  122. dir_local_state = prefix / get_option('localstatedir')
  123. dir_locale = prefix / get_option('localedir')
  124. dir_man = prefix / get_option('mandir')
  125. dir_sbin = prefix / get_option('sbindir')
  126. dir_sysconf = prefix / get_option('sysconfdir')
  127. if dir_run_state == ''
  128. dir_run_state = dir_local_state / 'run'
  129. endif
  130. if not opt_docs.disabled()
  131. subdir('doc')
  132. endif
  133. subdir('src')
  134. if not opt_tests.disabled()
  135. subdir('test')
  136. endif
  137. subdir('bash_completion.d')
  138. if os_name == 'linux' and not opt_systemd.disabled()
  139. subdir('systemd')
  140. endif
  141. if python.found()
  142. run_target('reformat', command: [
  143. python,
  144. '@SOURCE_ROOT@/lint.py',
  145. '--fix',
  146. ])
  147. run_target('lint', command: [
  148. python,
  149. '@SOURCE_ROOT@/lint.py',
  150. ])
  151. endif
  152. if meson_version.version_compare('>=0.53')
  153. summary({
  154. 'prefix': prefix,
  155. 'sandbox': cdata.has('HAVE_SANDBOX'),
  156. 'watchdog': cdata.has('HAVE_WATCHDOG'),
  157. }, bool_yn: true, section: 'System')
  158. endif