-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
In CMake, support declining items depending on the configuration used #13071
base: master
Are you sure you want to change the base?
In CMake, support declining items depending on the configuration used #13071
Conversation
61e14be
to
c42d2f9
Compare
fe9a4ce
to
7100b66
Compare
mlog.debug('CMake build type set from the meson build type') | ||
cmake_args += [f'-DCMAKE_BUILD_TYPE={self.build_type}'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't this set CMAKE_BUILD_TYPE
to "plain
" in case of an unsupported build type? self.build_type
falls back to the Meson build type if it isn't in the map.
Some CMake projects have a default build type they use in case no build type is provided. I don't think we should break that by setting some weird CMAKE_BUILD_TYPE
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Normally, with CMake
, the CMAKE_BUILD_TYPE
is considered mandatory according to their latest recommendations.
The default in CMake
, unless the project has defined something else, is an empty string, which can lead to all type of problems.
I can skip setting the build type if it is not in the buildtype_map
- but this would have an effect only for projects where the meson
project uses an unusual build type naming scheme. I do not know beforehand what is the CMake
naming scheme.
I wonder if I will be making more or less cases work if the default one is Debug
/Release
according to the meson
build type.
You can still set it to an empty string if you want to force the project's default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jpakkane determines the vision of Meson, but if it were me, I would greatly prefer to interfere as little as possible with external tools (i.e. CMake). I would trust the subproject developers in setting the appropriate defaults for their projects more than any blanket approach implemented in Meson. Put differently, I prefer Meson to implement the simplest logic possible to enable correct building (but not any simpler). The proposed build type logic feels both too invasive and too fragile to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a bunch of fixups for previous patches later in the series, those should be squashed back into the patch that introduced the issue. I also have a few inline comments for you
if any(arg.startswith('-DCMAKE_BUILD_TYPE=') for arg in cmake_args): | ||
# Allow to override the CMAKE_BUILD_TYPE environment variable | ||
mlog.debug('CMake build type explicitly set') | ||
cmake_build_type = next(arg for arg in cmake_args if arg.startswith('-DCMAKE_BUILD_TYPE=')).split('=')[1] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a helper in utils.universal
called first
that does the same thing, but is a little easier to read (IMHO), even though it is rather filter
like.
@@ -134,7 +134,7 @@ def target_file(arg: str) -> str: | |||
|
|||
# Configurations (Debug, Release...) | |||
# CMake is case-insensitive | |||
'CONFIG': lambda x: '1' if x.upper() == trace.env.coredata.get_option(OptionKey('buildtype')).upper() else '0' | |||
'CONFIG': lambda x: '1' if x.upper() == T.cast('str', trace.env.coredata.get_option(OptionKey('buildtype'))).upper() else '0' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you squash the first three patches together? They're one logical change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You do not intend to squash on merge?
mesonbuild/cmake/tracetargets.py
Outdated
@@ -54,7 +55,7 @@ def get_config_declined_property(target: CMakeTarget, | |||
cfg = trace.build_type.upper() if trace.build_type else None | |||
imported_cfgs: T.List[str] = [] | |||
if f'MAP_IMPORTED_CONFIG_{cfg}' in target.properties: | |||
cfg = target.properties[f'MAP_IMPORTED_CONFIG_{cfg}'].upper() | |||
cfg = target.properties[f'MAP_IMPORTED_CONFIG_{cfg}'][0].upper() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't seem like a mypy issue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it is not and I even added a unit test for this case in the next commit.
@@ -84,11 +84,12 @@ def __init__(self, name: str) -> None: | |||
self.working_dir: T.Optional[Path] = None | |||
|
|||
class CMakeTraceParser: | |||
def __init__(self, cmake_version: str, build_dir: Path, env: 'Environment', permissive: bool = True) -> None: | |||
def __init__(self, cmake_version: str, build_dir: Path, env: 'Environment', build_type: str = None, permissive: bool = True) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This breaks the strict-optional rule that we want to turn on later, so build_type: T.Optional[str] = None
mesonbuild/cmake/tracetargets.py
Outdated
cfg = trace.build_type.upper() if trace.build_type else None | ||
imported_cfgs: T.List[str] = [] | ||
if f'MAP_IMPORTED_CONFIG_{cfg}' in target.properties: | ||
cfg = target.properties[f'MAP_IMPORTED_CONFIG_{cfg}'].upper() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't this get changed to target.properties[...][0].upper()
in the last patch?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it should be [0]
, it is an array, there is a test for this case now
mesonbuild/cmake/tracetargets.py
Outdated
if cmake_is_debug(trace.env): | ||
if 'DEBUG' in imported_cfgs: | ||
cfg = 'DEBUG' | ||
elif 'RELEASE' in imported_cfgs: | ||
cfg = 'RELEASE' | ||
else: | ||
if 'RELEASE' in imported_cfgs: | ||
cfg = 'RELEASE' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can simplify this to:
if cmake_is_debug(trace.env) and 'DEBUG' in imported_cfgs:
cfg = 'DEBUG'
else:
cfg = 'RELEASE'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the previous author's version, I simplified it
mesonbuild/cmake/tracetargets.py
Outdated
@@ -12,7 +11,7 @@ | |||
import typing as T | |||
|
|||
if T.TYPE_CHECKING: | |||
from .traceparser import CMakeTraceParser | |||
from .traceparser import CMakeTraceParser, CMakeTarget |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be squashed into a previous patch?
This adds support for
conan
CMake
config files:it centralizes the deduction of
CMAKE_BUILD_TYPE
which is not written to the trace fileit adds support for config generator expressions:
it centralizes and fixes the handling of
IMPORTED_LOCATION_<CONFIG>
directives