Comments (3)
This is expected behavior since you told the compiler to use an actual argument with zero length.
An array of length one, content ''
is not the same as an array of length zero, no content. There are valid use cases for both, e.g. the value to a flag can be set to empty and this produces different results compared to not passing the flag at all.
Is there a reason you wanted to pass a blank string as a positive component of the compiler command line?
from meson.
@eli-schwartz, thanks for the reply, I thought that the behavior of meson
will automatically remove the quotes, and then pass it to the compiler. There is a deviation between my understanding and the meson
feature.
But in retrospect, this incident surprised me. My original meson.build
was to use meson_options.txt
to control the macro definition -DC2
: diff-1 (bad).
project('test', 'fortran')
-test_lib = static_library('test1', 'src/kinds.F90', fortran_args: ['']) # This is the problem: `fortran_args: ['']`
+C2 = get_option('C2')
+if C2
+ C2_macro = '-DC2'
+else
+ C2_macro = ''
+endif
+
+test_lib = static_library('test1', 'src/kinds.F90', fortran_args: [C2_macro]) # This is the problem: `fortran_args: ['']`
exe = executable('test2', 'src/main.f90',
link_with: [test_lib])
+option('C2', type: 'boolean', value: false, description: 'use C2 macros')
+option('C4', type: 'boolean', value: true, description: 'use C4 macros')
I didn't mean to pass the empty string [""]
to the compiler, when C2 == False
, I just pass the compiler parameter []
. meson <=1.2.3
, my meson project works fine, and after updating the version to 1.4.0
, the project failed to build, which surprised me, but no hints.
Now I know I should define macros like this diff-2 (good):
diff --git a/meson.build b/meson.build
index b594880..b3a3783 100644
--- a/meson.build
+++ b/meson.build
@@ -1,13 +1,11 @@
project('test', 'fortran')
-C2 = get_option('C2')
-if C2
- C2_macro = '-DC2'
-else
- C2_macro = ''
+fortran_args = []
+if get_option('C2')
+ fortran_args += '-DC2'
endif
-test_lib = static_library('test1', 'src/kinds.F90', fortran_args: [C2_macro]) # This is the problem: `fortran_args: ['']`
+test_lib = static_library('test1', 'src/kinds.F90', fortran_args: [fortran_args])
exe = executable('test2', 'src/main.f90',
link_with: [test_lib])
Crude idea, maybe meson
can detect the existence of ""
, after all, ""
will cause the compilation to fail, and the user side is not easy to find the root reason, because there is no obvious hint; or maybe it is not necessary to do this, because at least the latest meson 1.4.0
will throw a compilation error (this is a expected behavior, compared to meson <=1.2.3
), but the user like me may not be good to detect the cause of failure.
diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py
index 28f5d532f..6684a9697 100644
--- a/mesonbuild/backend/ninjabackend.py
+++ b/mesonbuild/backend/ninjabackend.py
@@ -2891,7 +2891,13 @@ https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47485'''))
commands += compiler.get_include_args(d, i.is_system)
# Add per-target compile args, f.ex, `c_args : ['-DFOO']`. We set these
# near the end since these are supposed to override everything else.
- commands += self.escape_extra_args(target.get_extra_args(compiler.get_language()))
+ commands += [
+ s
+ for s in self.escape_extra_args(
+ target.get_extra_args(compiler.get_language())
+ )
+ if s != ""
+ ]
# D specific additional flags
if compiler.language == 'd':
from meson.
@eli-schwartz, thanks for the reply, I thought that the behavior of
meson
will automatically remove the quotes, and then pass it to the compiler. There is a deviation between my understanding and themeson
feature.
Meson doesn't remove quotes. Quotes are syntax, not data. ''
isn't a pair of empty quotes, it is a meson array containing one string. It gets forwarded to the compiler using bash, and bash also uses quotes as syntax to denote strings (in this case, not always. Bash requires quotes for ambiguous cases that cannot be word-split obviously otherwise, and a blank string is one of those cases where bash needs those quotes.)
I didn't mean to pass the empty string
[""]
to the compiler, whenC2 == False
, I just pass the compiler parameter[]
.meson <=1.2.3
, my meson project works fine, and after updating the version to1.4.0
, the project failed to build, which surprised me, but no hints.
In my testing, both meson 1.2.3 and meson 1.4.0 fail in the same way. You would need to use []
in both cases.
from meson.
Related Issues (20)
- Cython support issue with generated pyx when touching cimported pxd: ninja needs to be run twice to fully build the project? HOT 3
- [cmake] Generator expression test during configure doesn't work.
- meson and NVIDIA HPC SDK HOT 4
- Passing sys_root to the --sysroot compiler argument
- Linker detection fails for wr-cc (VxWorks) without a file input
- install_symlink pointing_to does not observe prefix
- Add checks for files in POTFILES.in / POTFILES.skip
- binaries in toolchain file are wrongly handled
- Rust bindgen with output_inline_wrapper create c file with incorrect include path if build directory is not inside source directory HOT 1
- Meson Failing with FLTK HOT 1
- `meson rewrite kwargs delete project / <option>` raises unhandled exception unless a dummy second value is passed
- CI failure in rust / Windows
- Build failure in gst-plugins-rs Subproject with meson 0.61.2-1 on Intel N100 CPU HOT 1
- 'cuda' compile find_library() always returns found
- Unable to find CUPTI module in CUDA runfile installation
- `meson format` crashes in `add_nl_after` HOT 1
- Generated pkg-config file for Qt6 includes has incorrect file separator
- Support getting library file path from compiler for preloading purposes
- Why the library compiled on Apple's M2 machine,but have x86_64 architecture
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from meson.