Handling Meson build options with multiple buildtypes
Having read the Meson site pages (which are generally high quality), I'm still unsure about the intended best practice to handle different options for different buildtypes.
So to specify a debug build:
meson [srcdir] --buildtype=debug
Or to specify a release build:
meson [srcdir] --buildtype=release
However, if I want to add b_sanitize=address
(or other arbitrary complex set of arguments) only for debug builds and b_ndebug=true
only for release builds, I would do:
meson [srcdir] --buildtype=debug -Db_sanitize=address ...
meson [srcdir] --buildtype=release -Db_ndebug=true ...
However, it's more of a pain to add a bunch of custom arguments on the command line, and to me it seems neater to put that in the meson.build file.
So I know I can set some built in options thusly:
project('myproject', ['cpp'],
default_options : ['cpp_std=c++14',
'b_ndebug=true'])
But they are unconditionally set.
So a condition would look something like this:
if get_option('buildtype').startswith('release')
add_project_arguments('-DNDEBUG', language : ['cpp'])
endif
Which is one way to do it, however, it would seem the b_ndebug=true
way would be preferred to add_project_arguments('-DNDEBUG')
, because it is portable.
How would the portable-style build options be conditionally set within the Meson script?
Additionally, b_sanitize=address
is set without any test whether the compiler supports it. I would prefer for it to check first if it is supported (because the library might be missing, for example):
if meson.get_compiler('cpp').has_link_argument('-fsanitize=address')
add_project_arguments('-fsanitize=address', language : ['cpp'])
add_project_link_arguments('-fsanitize=address', language : ['cpp'])
endif
Is it possible to have the built-in portable-style build options (such as b_sanitize
) have a check if they are supported?
c++ build meson-build
add a comment |
Having read the Meson site pages (which are generally high quality), I'm still unsure about the intended best practice to handle different options for different buildtypes.
So to specify a debug build:
meson [srcdir] --buildtype=debug
Or to specify a release build:
meson [srcdir] --buildtype=release
However, if I want to add b_sanitize=address
(or other arbitrary complex set of arguments) only for debug builds and b_ndebug=true
only for release builds, I would do:
meson [srcdir] --buildtype=debug -Db_sanitize=address ...
meson [srcdir] --buildtype=release -Db_ndebug=true ...
However, it's more of a pain to add a bunch of custom arguments on the command line, and to me it seems neater to put that in the meson.build file.
So I know I can set some built in options thusly:
project('myproject', ['cpp'],
default_options : ['cpp_std=c++14',
'b_ndebug=true'])
But they are unconditionally set.
So a condition would look something like this:
if get_option('buildtype').startswith('release')
add_project_arguments('-DNDEBUG', language : ['cpp'])
endif
Which is one way to do it, however, it would seem the b_ndebug=true
way would be preferred to add_project_arguments('-DNDEBUG')
, because it is portable.
How would the portable-style build options be conditionally set within the Meson script?
Additionally, b_sanitize=address
is set without any test whether the compiler supports it. I would prefer for it to check first if it is supported (because the library might be missing, for example):
if meson.get_compiler('cpp').has_link_argument('-fsanitize=address')
add_project_arguments('-fsanitize=address', language : ['cpp'])
add_project_link_arguments('-fsanitize=address', language : ['cpp'])
endif
Is it possible to have the built-in portable-style build options (such as b_sanitize
) have a check if they are supported?
c++ build meson-build
It turn outmeson -Dcpp_args=-ffoo
does not even work for cross-compiler situations, but the cpp_args can be specified within the cross compiler file, which adds a bit more complexity to the issue.
– Jetski S-type
Nov 29 '18 at 5:20
Is it possible to specify build type (debug/release) for executable or it has to be specified for project? (And if it possible to specify only for executable is the option applied on dependent libraries as well?)
– Nic30g
Jan 4 at 14:00
@Nic30g It would be preferred to have the build type for the whole project... but if you've got a solution for just an executable, I'd like to hear it too.
– Jetski S-type
Jan 6 at 22:32
add a comment |
Having read the Meson site pages (which are generally high quality), I'm still unsure about the intended best practice to handle different options for different buildtypes.
So to specify a debug build:
meson [srcdir] --buildtype=debug
Or to specify a release build:
meson [srcdir] --buildtype=release
However, if I want to add b_sanitize=address
(or other arbitrary complex set of arguments) only for debug builds and b_ndebug=true
only for release builds, I would do:
meson [srcdir] --buildtype=debug -Db_sanitize=address ...
meson [srcdir] --buildtype=release -Db_ndebug=true ...
However, it's more of a pain to add a bunch of custom arguments on the command line, and to me it seems neater to put that in the meson.build file.
So I know I can set some built in options thusly:
project('myproject', ['cpp'],
default_options : ['cpp_std=c++14',
'b_ndebug=true'])
But they are unconditionally set.
So a condition would look something like this:
if get_option('buildtype').startswith('release')
add_project_arguments('-DNDEBUG', language : ['cpp'])
endif
Which is one way to do it, however, it would seem the b_ndebug=true
way would be preferred to add_project_arguments('-DNDEBUG')
, because it is portable.
How would the portable-style build options be conditionally set within the Meson script?
Additionally, b_sanitize=address
is set without any test whether the compiler supports it. I would prefer for it to check first if it is supported (because the library might be missing, for example):
if meson.get_compiler('cpp').has_link_argument('-fsanitize=address')
add_project_arguments('-fsanitize=address', language : ['cpp'])
add_project_link_arguments('-fsanitize=address', language : ['cpp'])
endif
Is it possible to have the built-in portable-style build options (such as b_sanitize
) have a check if they are supported?
c++ build meson-build
Having read the Meson site pages (which are generally high quality), I'm still unsure about the intended best practice to handle different options for different buildtypes.
So to specify a debug build:
meson [srcdir] --buildtype=debug
Or to specify a release build:
meson [srcdir] --buildtype=release
However, if I want to add b_sanitize=address
(or other arbitrary complex set of arguments) only for debug builds and b_ndebug=true
only for release builds, I would do:
meson [srcdir] --buildtype=debug -Db_sanitize=address ...
meson [srcdir] --buildtype=release -Db_ndebug=true ...
However, it's more of a pain to add a bunch of custom arguments on the command line, and to me it seems neater to put that in the meson.build file.
So I know I can set some built in options thusly:
project('myproject', ['cpp'],
default_options : ['cpp_std=c++14',
'b_ndebug=true'])
But they are unconditionally set.
So a condition would look something like this:
if get_option('buildtype').startswith('release')
add_project_arguments('-DNDEBUG', language : ['cpp'])
endif
Which is one way to do it, however, it would seem the b_ndebug=true
way would be preferred to add_project_arguments('-DNDEBUG')
, because it is portable.
How would the portable-style build options be conditionally set within the Meson script?
Additionally, b_sanitize=address
is set without any test whether the compiler supports it. I would prefer for it to check first if it is supported (because the library might be missing, for example):
if meson.get_compiler('cpp').has_link_argument('-fsanitize=address')
add_project_arguments('-fsanitize=address', language : ['cpp'])
add_project_link_arguments('-fsanitize=address', language : ['cpp'])
endif
Is it possible to have the built-in portable-style build options (such as b_sanitize
) have a check if they are supported?
c++ build meson-build
c++ build meson-build
edited Nov 29 '18 at 4:45
Jetski S-type
asked Nov 22 '18 at 5:36
Jetski S-typeJetski S-type
4901621
4901621
It turn outmeson -Dcpp_args=-ffoo
does not even work for cross-compiler situations, but the cpp_args can be specified within the cross compiler file, which adds a bit more complexity to the issue.
– Jetski S-type
Nov 29 '18 at 5:20
Is it possible to specify build type (debug/release) for executable or it has to be specified for project? (And if it possible to specify only for executable is the option applied on dependent libraries as well?)
– Nic30g
Jan 4 at 14:00
@Nic30g It would be preferred to have the build type for the whole project... but if you've got a solution for just an executable, I'd like to hear it too.
– Jetski S-type
Jan 6 at 22:32
add a comment |
It turn outmeson -Dcpp_args=-ffoo
does not even work for cross-compiler situations, but the cpp_args can be specified within the cross compiler file, which adds a bit more complexity to the issue.
– Jetski S-type
Nov 29 '18 at 5:20
Is it possible to specify build type (debug/release) for executable or it has to be specified for project? (And if it possible to specify only for executable is the option applied on dependent libraries as well?)
– Nic30g
Jan 4 at 14:00
@Nic30g It would be preferred to have the build type for the whole project... but if you've got a solution for just an executable, I'd like to hear it too.
– Jetski S-type
Jan 6 at 22:32
It turn out
meson -Dcpp_args=-ffoo
does not even work for cross-compiler situations, but the cpp_args can be specified within the cross compiler file, which adds a bit more complexity to the issue.– Jetski S-type
Nov 29 '18 at 5:20
It turn out
meson -Dcpp_args=-ffoo
does not even work for cross-compiler situations, but the cpp_args can be specified within the cross compiler file, which adds a bit more complexity to the issue.– Jetski S-type
Nov 29 '18 at 5:20
Is it possible to specify build type (debug/release) for executable or it has to be specified for project? (And if it possible to specify only for executable is the option applied on dependent libraries as well?)
– Nic30g
Jan 4 at 14:00
Is it possible to specify build type (debug/release) for executable or it has to be specified for project? (And if it possible to specify only for executable is the option applied on dependent libraries as well?)
– Nic30g
Jan 4 at 14:00
@Nic30g It would be preferred to have the build type for the whole project... but if you've got a solution for just an executable, I'd like to hear it too.
– Jetski S-type
Jan 6 at 22:32
@Nic30g It would be preferred to have the build type for the whole project... but if you've got a solution for just an executable, I'd like to hear it too.
– Jetski S-type
Jan 6 at 22:32
add a comment |
1 Answer
1
active
oldest
votes
The project does not have to be the first line, so you can check the buildtype and generate a list of build options for your project. something like (untested):
if get_option('buildtype').startswith('release')
myopts = [ 'b_ndebug=true' ]
endif
project('myproj', ['cpp'], default_options : myopts)
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53424472%2fhandling-meson-build-options-with-multiple-buildtypes%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The project does not have to be the first line, so you can check the buildtype and generate a list of build options for your project. something like (untested):
if get_option('buildtype').startswith('release')
myopts = [ 'b_ndebug=true' ]
endif
project('myproj', ['cpp'], default_options : myopts)
add a comment |
The project does not have to be the first line, so you can check the buildtype and generate a list of build options for your project. something like (untested):
if get_option('buildtype').startswith('release')
myopts = [ 'b_ndebug=true' ]
endif
project('myproj', ['cpp'], default_options : myopts)
add a comment |
The project does not have to be the first line, so you can check the buildtype and generate a list of build options for your project. something like (untested):
if get_option('buildtype').startswith('release')
myopts = [ 'b_ndebug=true' ]
endif
project('myproj', ['cpp'], default_options : myopts)
The project does not have to be the first line, so you can check the buildtype and generate a list of build options for your project. something like (untested):
if get_option('buildtype').startswith('release')
myopts = [ 'b_ndebug=true' ]
endif
project('myproj', ['cpp'], default_options : myopts)
answered 2 days ago
mhhollomonmhhollomon
4257
4257
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53424472%2fhandling-meson-build-options-with-multiple-buildtypes%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
It turn out
meson -Dcpp_args=-ffoo
does not even work for cross-compiler situations, but the cpp_args can be specified within the cross compiler file, which adds a bit more complexity to the issue.– Jetski S-type
Nov 29 '18 at 5:20
Is it possible to specify build type (debug/release) for executable or it has to be specified for project? (And if it possible to specify only for executable is the option applied on dependent libraries as well?)
– Nic30g
Jan 4 at 14:00
@Nic30g It would be preferred to have the build type for the whole project... but if you've got a solution for just an executable, I'd like to hear it too.
– Jetski S-type
Jan 6 at 22:32