Skip to content

Commit 53f6a8c

Browse files
committed
Meson build: Better detection of MSVC-like compilers
Treat all compilers with MSVC-like argument syntax the same. Use cpp_compiler.get_define('_MSC_VER') instead of cpp_compiler.version() to check compiler version. Suggested by Tim-Philipp Müller and Chun-wei Fan. See https://gitlab.freedesktop.org/cairo/cairomm/-/merge_requests/30
1 parent c581b5b commit 53f6a8c

File tree

2 files changed

+17
-18
lines changed

2 files changed

+17
-18
lines changed

meson.build

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,12 @@ project_build_root = meson.project_build_root()
3939

4040
cpp_compiler = meson.get_compiler('cpp')
4141
cpp_compiler_id = cpp_compiler.get_id()
42-
is_msvc = cpp_compiler_id == 'msvc' or cpp_compiler_id.endswith('-cl')
43-
is_cl_impersonator = is_msvc and cpp_compiler_id != 'msvc'
42+
is_msvc_style = cpp_compiler.get_argument_syntax() == 'msvc'
4443
python3 = find_program('python3', version: '>=3.7')
4544

46-
# MSVC: We currently do not support shared and static builds at the,
47-
# same time, since we need different defines/cflags for proper
48-
# linking.
49-
if is_msvc
45+
# MSVC: We currently do not support shared and static builds at the same time,
46+
# since we need different defines/cflags for proper linking.
47+
if is_msvc_style
5048
if get_option('default_library') == 'both'
5149
error('-Ddefault_library=both is currently not supported for Visual Studio')
5250
endif
@@ -119,11 +117,11 @@ benchmark_dep = dependency('boost', modules: ['system', 'timer'],
119117
version: '>=1.20.0', required: do_benchmark)
120118
can_benchmark = benchmark_dep.found()
121119

122-
if is_msvc and not is_cl_impersonator
120+
if is_msvc_style
123121
# We must have Visual Studio 2017 15.7 or later...
124-
assert(cpp_compiler.version().split('.')[0].to_int() >= 19 and \
125-
cpp_compiler.version().split('.')[1].to_int() >= 15,
126-
'Visual Studio 2017 15.7 or later is required')
122+
mscver = cpp_compiler.get_define('_MSC_VER')
123+
assert(mscver == '' or mscver.version_compare('>=1914'),
124+
'Visual Studio 2017 15.7 or later or compatible is required')
127125
endif
128126

129127
# Some dependencies are required only in maintainer mode and/or
@@ -184,17 +182,17 @@ endif
184182
warning_flags = []
185183
if cpp_warnings == 'min'
186184
if warning_level == 0
187-
warning_flags = is_msvc ? ['/W2'] : ['-Wall']
188-
endif
185+
warning_flags = is_msvc_style ? ['/W2'] : ['-Wall']
186+
endif
189187
elif cpp_warnings == 'max' or cpp_warnings == 'fatal'
190188
if warning_level < 3
191-
warning_flags = is_msvc ? ['/W4'] : ['-pedantic', '-Wall', '-Wextra']
189+
warning_flags = is_msvc_style ? ['/W4'] : ['-pedantic', '-Wall', '-Wextra']
192190
endif
193-
if not is_msvc
191+
if not is_msvc_style
194192
warning_flags += '-Wsuggest-override -Wshadow -Wzero-as-null-pointer-constant -Wformat-security'.split()
195193
endif
196194
if cpp_warnings == 'fatal' and not werror
197-
warning_flags += is_msvc ? ['/WX'] : ['-Werror']
195+
warning_flags += is_msvc_style ? ['/WX'] : ['-Werror']
198196
endif
199197
endif
200198

@@ -205,7 +203,7 @@ add_project_arguments(warning_flags, language: 'cpp')
205203
# that should not be overlooked stand out.
206204
static_cxxflag = '-DLIBSIGCXX_STATIC'
207205
msvc_static_cxxflag = is_msvc_static ? static_cxxflag : ''
208-
if is_msvc
206+
if is_msvc_style
209207
disable_warnings_list = [
210208
'/EHsc', # avoid warnings caused by exception handling model used
211209
]

sigc++/meson.build

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# sigc++
22

33
# Input: sigcxx_build_dep, sigcxx_pcname, sigcxx_libversion, sigcxx_api_version,
4-
# darwin_versions, install_includedir, sig_rc, msvc_static_cxxflag
4+
# darwin_versions, install_includedir, sig_rc, msvc_static_cxxflag,
5+
# is_msvc_style
56
# Output: source_h_files, sigcxx_own_dep
67

78
# There are no built source files in libsigc++-3.0.
@@ -76,7 +77,7 @@ extra_sigc_cppflags = []
7677
extra_sigc_objects = []
7778

7879
# Make sure we are exporting the symbols from the DLL
79-
if is_msvc
80+
if is_msvc_style
8081
extra_sigc_cppflags += ['-DSIGC_BUILD']
8182
endif
8283

0 commit comments

Comments
 (0)