On Mon Jan 5, 2026 at 9:38 AM CET, Peter Eisentraut wrote:
Perhaps we should prefer to use the less ambiguous name "cxx" throughout.
Done
From d82337f6101e600bcd99b8a2714631d11c61711c Mon Sep 17 00:00:00 2001 From: Jelte Fennema-Nio <[email protected]> Date: Mon, 5 Jan 2026 09:49:43 +0100 Subject: [PATCH v7 1/2] meson: rename cpp variable to cxx Since CPP is also used to mean C PreProcessor in our meson.build files it's confusing to use it to also mean C PlusPlus. This uses the non-ambiguous cxx wherever possible. --- meson.build | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/meson.build b/meson.build index c3834a9dc8f..80dd51a0d4a 100644 --- a/meson.build +++ b/meson.build @@ -843,7 +843,7 @@ if add_languages('cpp', required: llvmopt, native: false) cdata.set('USE_LLVM', 1) - cpp = meson.get_compiler('cpp') + cxx = meson.get_compiler('cpp') llvm_binpath = llvm.get_variable(configtool: 'bindir') @@ -1917,10 +1917,10 @@ endforeach # We need to repeat the test for C++ because gcc and clang prefer different # format archetypes. if llvm.found() - attrib_error_args = cpp.get_supported_arguments('-Werror=format', '-Werror=ignored-attributes') + attrib_error_args = cxx.get_supported_arguments('-Werror=format', '-Werror=ignored-attributes') foreach a : printf_attributes - if cpp.compiles(testsrc.format(a), - args: attrib_error_args, name: 'cppformat ' + a) + if cxx.compiles(testsrc.format(a), + args: attrib_error_args, name: 'cxxformat ' + a) cdata.set('PG_CXX_PRINTF_ATTRIBUTE', a) break endif @@ -2084,7 +2084,7 @@ common_functional_flags = [ cflags += cc.get_supported_arguments(common_functional_flags) if llvm.found() - cxxflags += cpp.get_supported_arguments(common_functional_flags) + cxxflags += cxx.get_supported_arguments(common_functional_flags) endif vectorize_cflags = cc.get_supported_arguments(['-ftree-vectorize']) @@ -2108,7 +2108,7 @@ common_warning_flags = [ cflags_warn += cc.get_supported_arguments(common_warning_flags) if llvm.found() - cxxflags_warn += cpp.get_supported_arguments(common_warning_flags) + cxxflags_warn += cxx.get_supported_arguments(common_warning_flags) endif # A few places with imported code get a pass on -Wdeclaration-after-statement, remember @@ -2161,7 +2161,7 @@ foreach w : negative_warning_flags if cc.has_argument('-W' + w) cflags_warn += '-Wno-' + w endif - if llvm.found() and cpp.has_argument('-W' + w) + if llvm.found() and cxx.has_argument('-W' + w) cxxflags_warn += '-Wno-' + w endif endforeach @@ -2230,7 +2230,7 @@ endif cflags_builtin = cc.get_supported_arguments(common_builtin_flags) if llvm.found() - cxxflags_builtin = cpp.get_supported_arguments(common_builtin_flags) + cxxflags_builtin = cxx.get_supported_arguments(common_builtin_flags) endif @@ -3951,7 +3951,7 @@ summary( if llvm.found() summary( { - 'C++ compiler': '@0@ @1@'.format(cpp.get_id(), cpp.version()), + 'C++ compiler': '@0@ @1@'.format(cxx.get_id(), cxx.version()), }, section: 'Compiler', ) base-commit: 4c144e0452daa2508a008bb4cde520613bbd386d -- 2.52.0
From cce830ffdf911776f04179a2165a91a0a9f96da5 Mon Sep 17 00:00:00 2001 From: Tristan Partin <[email protected]> Date: Wed, 16 Apr 2025 20:25:21 -0500 Subject: [PATCH v7 2/2] Decouple C++ support in Meson's PGXS from LLVM enablement This is important for Postgres extensions that are written in C++, such as pg_duckdb, which uses PGXS as the build system currently. In the autotools build, C++ is not coupled to LLVM. If the autotools build is configured without --with-llvm, the C++ compiler and the various flags get persisted into the Makefile.global. Signed-off-by: Tristan Partin <[email protected]> --- meson.build | 29 ++++++++++++++++++----------- src/include/meson.build | 8 +++++++- src/makefiles/meson.build | 4 +--- 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/meson.build b/meson.build index 80dd51a0d4a..c1ea236103f 100644 --- a/meson.build +++ b/meson.build @@ -41,6 +41,10 @@ build_system = build_machine.system() host_cpu = host_machine.cpu_family() cc = meson.get_compiler('c') +have_cxx = add_languages('cpp', required: false, native: false) +if have_cxx + cxx = meson.get_compiler('cpp') +endif not_found_dep = dependency('', required: false) thread_dep = dependency('threads') @@ -836,15 +840,13 @@ endif llvmopt = get_option('llvm') llvm = not_found_dep -if add_languages('cpp', required: llvmopt, native: false) +if have_cxx llvm = dependency('llvm', version: '>=14', method: 'config-tool', required: llvmopt) if llvm.found() cdata.set('USE_LLVM', 1) - cxx = meson.get_compiler('cpp') - llvm_binpath = llvm.get_variable(configtool: 'bindir') ccache = find_program('ccache', native: true, required: false) @@ -853,8 +855,13 @@ if add_languages('cpp', required: llvmopt, native: false) # find via PATH, too. clang = find_program(llvm_binpath / 'clang', 'clang', required: true) endif -elif llvmopt.auto() - message('llvm requires a C++ compiler') +else + msg = 'llvm requires a C++ compiler' + if llvmopt.auto() + message(msg) + elif llvmopt.enabled() + error(msg) + endif endif @@ -1916,7 +1923,7 @@ endforeach # We need to repeat the test for C++ because gcc and clang prefer different # format archetypes. -if llvm.found() +if have_cxx attrib_error_args = cxx.get_supported_arguments('-Werror=format', '-Werror=ignored-attributes') foreach a : printf_attributes if cxx.compiles(testsrc.format(a), @@ -2083,7 +2090,7 @@ common_functional_flags = [ ] cflags += cc.get_supported_arguments(common_functional_flags) -if llvm.found() +if have_cxx cxxflags += cxx.get_supported_arguments(common_functional_flags) endif @@ -2107,7 +2114,7 @@ common_warning_flags = [ ] cflags_warn += cc.get_supported_arguments(common_warning_flags) -if llvm.found() +if have_cxx cxxflags_warn += cxx.get_supported_arguments(common_warning_flags) endif @@ -2161,7 +2168,7 @@ foreach w : negative_warning_flags if cc.has_argument('-W' + w) cflags_warn += '-Wno-' + w endif - if llvm.found() and cxx.has_argument('-W' + w) + if have_cxx and cxx.has_argument('-W' + w) cxxflags_warn += '-Wno-' + w endif endforeach @@ -2229,7 +2236,7 @@ elif optimization == 's' endif cflags_builtin = cc.get_supported_arguments(common_builtin_flags) -if llvm.found() +if have_cxx cxxflags_builtin = cxx.get_supported_arguments(common_builtin_flags) endif @@ -3948,7 +3955,7 @@ summary( section: 'Compiler Flags', ) -if llvm.found() +if have_cxx summary( { 'C++ compiler': '@0@ @1@'.format(cxx.get_id(), cxx.version()), diff --git a/src/include/meson.build b/src/include/meson.build index d9c7b709330..c8ac3e60291 100644 --- a/src/include/meson.build +++ b/src/include/meson.build @@ -36,9 +36,15 @@ config_paths_data.set_quoted('MANDIR', dir_prefix / dir_man) var_cc = ' '.join(cc.cmd_array()) var_cpp = ' '.join(cc.cmd_array() + ['-E']) var_cflags = ' '.join(cflags + cflags_builtin + cflags_warn + get_option('c_args')) -if llvm.found() +if have_cxx + var_cxx = ' '.join(cxx.cmd_array()) var_cxxflags = ' '.join(cxxflags + cxxflags_builtin + cxxflags_warn + get_option('cpp_args')) else + # Default to 'g++' so PGXS users get a clear "g++ not found" error when + # building C++ extensions. Otherwise they'd get a confusing error because no + # binary is specified in the build commands and the first flag would be + # interpreted as the program. + var_cxx = 'g++' var_cxxflags = '' endif var_cppflags = ' '.join(cppflags) diff --git a/src/makefiles/meson.build b/src/makefiles/meson.build index 124df2c8582..6f5072081da 100644 --- a/src/makefiles/meson.build +++ b/src/makefiles/meson.build @@ -31,7 +31,6 @@ if not working_strip strip_shared_cmd = [':'] endif - pgxs_kv = { 'PACKAGE_URL': pg_url, 'PACKAGE_VERSION': pg_version, @@ -86,6 +85,7 @@ pgxs_kv = { 'CC': var_cc, 'CPP': var_cpp, + 'CXX': var_cxx, 'GCC': cc.get_argument_syntax() == 'gcc' ? 'yes' : 'no', 'CPPFLAGS': var_cppflags, @@ -122,13 +122,11 @@ pgxs_kv = { if llvm.found() pgxs_kv += { 'CLANG': clang.full_path(), - 'CXX': ' '.join(cpp.cmd_array()), 'LLVM_BINPATH': llvm_binpath, } else pgxs_kv += { 'CLANG': '', - 'CXX': '', 'LLVM_BINPATH': '', } endif -- 2.52.0
