Skip to content

Commit 076fc27

Browse files
Vladislav Aranovgiulianobelinassi
authored andcommitted
Support building on RHEL 8.0
Those changes add support for building on RHEL 8.X while preserving compatibility with other build environments. Adds: - More advanced support for outside-of-system gcc installation - Links with proper runtime in case of gcc installation used for building is different from the system default one.
1 parent 1fcfc0a commit 076fc27

File tree

2 files changed

+43
-8
lines changed

2 files changed

+43
-8
lines changed

meson.build

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ add_project_arguments(
2828
], language: 'cpp'
2929
)
3030

31+
fs = import('fs')
32+
3133
# For debug builds, we want every debug info we can get plus addrsan.
3234
buildtype = get_option('buildtype')
3335
if buildtype == 'debug' or buildtype == 'debugoptimized'
@@ -48,22 +50,52 @@ gcc = find_program('gcc', version : '>=7.5.0')
4850
# building with the correct headers, otherwise we run the risk of building
4951
# clang-extract with different headers than libLLVM
5052
gcc_install_dir = ''
51-
gcc_output = run_command(gcc.full_path(), '-v', check: true).stderr().strip().split('\n')
52-
foreach line : gcc_output
53-
params = line.split('=')
54-
lhs = params.get(0)
55-
rhs = params.get(1, '')
53+
build_dir_absolute_path = meson.build_root()
54+
simple_program_file = configure_file(output: 'simple_program.c', input: 'simple_program.c.in', copy: true )
5655

57-
if lhs == 'COLLECT_LTO_WRAPPER'
58-
gcc_install_dir = run_command('dirname', rhs, check: true).stdout().strip()
59-
break
56+
gcc_output = run_command(gcc.full_path(), '-v', '-o', build_dir_absolute_path / 'simple_program.out',
57+
build_dir_absolute_path / 'simple_program.c', check: true).stderr().strip().split('\n')
58+
foreach line : gcc_output
59+
if line.contains('crtbegin.o')
60+
ilines = line.strip().split(' ')
61+
foreach iline : ilines
62+
if iline.contains('crtbegin.o')
63+
gcc_install_dir = fs.parent(iline)
64+
break
65+
endif
66+
endforeach
6067
endif
6168
endforeach
69+
if build_machine.system() == 'linux'
70+
rm = find_program('rm')
71+
run_command(rm.full_path(),'-f', build_dir_absolute_path / 'simple_program.out', check: false)
72+
endif
6273

6374
# Check if we got the gcc installation dir and add it to the project arguments.
6475
assert(gcc_install_dir != '', 'GCC headers dir not found. Check \'gcc -v\'')
6576
add_project_arguments('--gcc-install-dir=' + gcc_install_dir, language: 'cpp')
6677

78+
########## Dependency: additional clang includes ################
79+
llvm_config = find_program('llvm-config')
80+
if llvm_config.found()
81+
extra_args_line = run_command(llvm_config.full_path(), '--cxxflags').stdout().strip().split('\n')[0]
82+
extra_args = extra_args_line.split(' -')
83+
i = 0
84+
foreach arg : extra_args
85+
targ = arg
86+
if i > 0
87+
targ = '-' + arg
88+
endif
89+
if(not targ.startswith('-I'))
90+
i += 1
91+
continue
92+
endif
93+
message('Adding extra compilation flag: ' + targ)
94+
add_project_arguments(targ, language: 'cpp')
95+
i += 1
96+
endforeach
97+
endif
98+
6799
########## Dependency: clang libraries ################
68100
llvm_libdir = dependency('llvm', version : '>=16').get_variable(cmake : 'LLVM_LIBRARY_DIR', configtool: 'libdir')
69101

@@ -82,13 +114,15 @@ incdir = include_directories('libcextract')
82114
executable('ce-inline', 'Inline.cpp',
83115
include_directories : incdir,
84116
install : true,
117+
link_args : ['--gcc-install-dir=' + gcc_install_dir],
85118
link_with : libcextract_static,
86119
dependencies : [elf_dep, zlib_dep, zstd_dep]
87120
)
88121

89122
executable('clang-extract', 'Main.cpp',
90123
include_directories : incdir,
91124
install : true,
125+
link_args : ['--gcc-install-dir=' + gcc_install_dir],
92126
link_with : libcextract_static,
93127
dependencies : [elf_dep, clang_dep, zlib_dep, zstd_dep]
94128
)

simple_program.c.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
int main(){return 0;}

0 commit comments

Comments
 (0)