Skip to content

Commit

Permalink
meson: use meson.get_compiler() just once
Browse files Browse the repository at this point in the history
  • Loading branch information
ammen99 committed Feb 27, 2025
1 parent b34813d commit 2ad7d0c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
12 changes: 6 additions & 6 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ project(
],
)

cpp = meson.get_compiler('cpp')

version = '"@0@"'.format(meson.project_version())
add_project_arguments('-DWAYFIRE_VERSION=@0@'.format(version), language: 'cpp')

Expand All @@ -32,7 +34,7 @@ glm = dependency('glm', required: false)
libinput = dependency('libinput', version: '>=1.7.0')
pixman = dependency('pixman-1')
xkbcommon = dependency('xkbcommon')
libdl = meson.get_compiler('cpp').find_library('dl')
libdl = cpp.find_library('dl')
json = dependency('nlohmann_json', version: '>= 3.11.2')
udev = dependency('libudev')

Expand Down Expand Up @@ -106,11 +108,11 @@ elif get_option('use_system_wfconfig').auto()
endif
endif

if not glm.found() and not meson.get_compiler('cpp').check_header('glm/glm.hpp')
if not glm.found() and not cpp.check_header('glm/glm.hpp')
error('GLM not found, and directly using the header \'glm/glm.hpp\' is not possible.')
endif

backtrace = meson.get_compiler('cpp').find_library('execinfo', required: false)
backtrace = cpp.find_library('execinfo', required: false)

wfutils = subproject('wf-utils').get_variable('wfutils')
wftouch = subproject('wf-touch').get_variable('wftouch')
Expand All @@ -122,7 +124,7 @@ jpeg = dependency('libjpeg', required: false)
png = dependency('libpng', required: false)

# backtrace() is in a separate library on FreeBSD and Linux with musl
backtrace = meson.get_compiler('cpp').find_library('execinfo', required: false)
backtrace = cpp.find_library('execinfo', required: false)

conf_data = configuration_data()

Expand All @@ -140,8 +142,6 @@ else
conf_data.set('DEFAULT_CONFIG_BACKEND', get_option('default_config_backend'))
endif

cpp = meson.get_compiler('cpp')

# needed to dlopen() plugins
# -E is for RTTI/dynamic_cast across plugins
add_project_link_arguments(['-rdynamic', '-Wl,-E'], language: 'cpp')
Expand Down
9 changes: 4 additions & 5 deletions plugins/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ subdir('common')
if get_option('custom_pch')
# Add a workaround for https://github.com/mesonbuild/meson/issues/4350
# We create a PCH ourselves and manage it for all plugins.
cc = meson.get_compiler('cpp')
pch_file = meson.current_source_dir() / 'pch/plugin_pch.hpp'
custom_pch_flags = ['@INPUT@', '-c', '-o', '@OUTPUT@', '-MD', '-MF', '@DEPFILE@',
'-std=' + get_option('cpp_std'), '-pthread', '-fPIC'] + get_option('cpp_args')
Expand Down Expand Up @@ -32,18 +31,18 @@ if get_option('custom_pch')
input: pch_file,
output: 'plugin_pch.hpp.gch',
depfile: 'plugin_pch.hpp.d',
command: cc.cmd_array() + custom_pch_flags)
command: cpp.cmd_array() + custom_pch_flags)

fs = import('fs')
if cc.get_id() == 'clang'
if cpp.get_id() == 'clang'
# In clang, everything is simple, we just tell the compiler which PCH file to use
plugin_pch_arg = ['-include-pch', pch.full_path(), '-pthread']
elif cc.get_id() == 'gcc'
elif cpp.get_id() == 'gcc'
# GCC requires that the .gch and the .hpp file are in the same dir.
fs.copyfile(pch_file) # copy to build dir where .gch is found
plugin_pch_arg = ['-I' + fs.parent(pch.full_path()), '-include', fs.name(pch_file), '-pthread', '-fpch-preprocess']
else
error('Unsupported compiler for custom pch: ' + cc.get_id())
error('Unsupported compiler for custom pch: ' + cpp.get_id())
endif

plugin_pch_dep = declare_dependency(sources: pch, compile_args: plugin_pch_arg)
Expand Down

0 comments on commit 2ad7d0c

Please sign in to comment.