summaryrefslogtreecommitdiff
path: root/mesonbuild/modules/cmake.py
AgeCommit message (Collapse)Author
2025-11-19compilers: Remove Environment parameter from Compiler.sizeofDylan Baker
This also fixes the `_cross_sizeof` helper
2025-10-20interpreter: fix more default_options annotationsDylan Baker
2025-10-20interpreter: port dependency include_type to typed_kargsDylan Baker
The cleanup this allows lower down points out that we don't properly validate the value passed to `as_system()`. I have no idea what happens if you pass a non-valid value, but it's a bug and I've simply made it a hard error. We can re-assess if necessary.
2025-09-25mypy: enable allow-redefinition-new and fix falloutEli Schwartz
Reduces 3 errors that show up in newer mypy versions than pinned in CI. It is new since 1.16 and a likely future default for mypy 2.0. It allows things like: ``` for i in ['one', 'two', 'three']: frob_a(i) for i in [1, 2, 3]: frob_b(i) ``` since "i" is obviously used as a loop holder and its type can be freely reinvented. Note: allow-redefinition-new isn't actually about this at all, it has greater scope than loop holders and allows redefining "unannotated variables" of all kinds. No granularity in what to accept redefinition of. :P To enable this, we must also opt in to local-partial-types, which has some overlap with None-safety. Specifically: > the most common cases for partial types are variables initialized > using None, but without explicit X | None annotations. By default, mypy > won’t check partial types spanning module top level or class top level. > This flag changes the behavior to only allow partial types at local > level, therefore it disallows inferring variable type for None from two > assignments in different scopes. So with this, we also fix a couple of actual type errors this revealed. Where possible, stop None-initializing at all -- it's not strictly needed for global variables, anyway, and it's a coding error if it is possible to hit these variables without defining them first. Bug: https://github.com/python/mypy/issues/19280
2025-05-05cmake: include_directories() returns an arrayPaolo Bonzini
See the way that it is created: dir_node = assign(dir_var, function(include_directories, tgt.includes)) sys_node = assign(sys_var, function(include_directories, tgt.sys_includes, {is_system: True})) inc_node = assign(inc_var, array([id_node(dir_var), id_node(sys_var)])) Due to incorrect documentation, commit 1f4bb3737 ("modules/cmake: Make fully type safe", 2025-04-02) added an incorrect assertion. Fix both. Fixes: #14530 Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-04-02modules/cmake: Make fully type safeDylan Baker
Mostly this was just adding a few asserts for options, and one bug fix from the option refactor
2025-03-10coredata: replace get_option with optstore.get_value_forDylan Baker
This is an old method, that is now just a wrapper around the OptionStore method, that doesn't add any value. It's also an option related method attached to the CoreData instead of the OptionStore, so useless and a layering violation.
2024-10-01modules/cmake: use typed_kwargs instead of permittedKwargsDylan Baker
2024-10-01modules/cmake: use typed_kwargs for subproject.dependencyDylan Baker
2024-10-01modules/cmake: simplify _args_to_infoDylan Baker
We don't need to pass a list, and we don't need to check length or type
2024-10-01modules/cmake: use typed_pos_args for remaining subproject methodsDylan Baker
Since these are all more-or-less the same
2024-10-01modules/cmake: use typed_pos_args for subproject.dependencyDylan Baker
2024-10-01modules/cmake: use typed_pos_args for subproject.get_variableDylan Baker
2024-07-11Move OptionKey in the option source file.Jussi Pakkanen
2024-04-22add an error message for targets that are not dependenciesMomtchil Momtchev
2024-03-18cmake: fix incorrect decorator for append_link_argsStephan Lachnit
Signed-off-by: Stephan Lachnit <stephanlachnit@debian.org>
2023-12-13Use SPDX-License-Identifier consistentlyDylan Baker
This replaces all of the Apache blurbs at the start of each file with an `# SPDX-License-Identifier: Apache-2.0` string. It also fixes existing uses to be consistent in capitalization, and to be placed above any copyright notices. This removes nearly 3000 lines of boilerplate from the project (only python files), which no developer cares to look at. SPDX is in common use, particularly in the Linux kernel, and is the recommended format for Meson's own `project(license: )` field
2023-09-22Allow to fallback to cmake subprojectXavier Claessens
The method can be overridden by setting the `method` key in the wrap file and always defaults to 'meson'. cmake.subproject() is still needed in case specific cmake options need to be passed. This also makes it easier to extend to other methods in the future e.g. cargo.
2023-08-11treewide: automatic rewriting of all comment-style type annotationsEli Schwartz
Performed using https://github.com/ilevkivskyi/com2ann This has no actual effect on the codebase as type checkers (still) support both and negligible effect on runtime performance since __future__ annotations ameliorates that. Technically, the bytecode would be bigger for non function-local annotations, of which we have many either way. So if it doesn't really matter, why do a large-scale refactor? Simple: because people keep wanting to, but it's getting nickle-and-dimed. If we're going to do this we might as well do it consistently in one shot, using tooling that guarantees repeatability and correctness. Repeat with: ``` com2ann mesonbuild/ ```
2023-07-13cmake: fix directory separators in generated packageConfig.cmake filesMatthieu Rogez
On windows, meson would mix posix and windows dir separators in the computed PACKAGE_RELATIVE_PATH. Here we force posix directory separator even on Windows. This matches the CMake behavior and fixes interpretation of the resulting path. Fixes #6955 Fixes #9702
2023-06-20interpreter: allow default_options and override_options as a dictDylan Baker
2023-05-03cmake module: fix many typing issuesEli Schwartz
In #11761 it turned out that we failed to correctly handle all compiler.sizeof API changes in an old commit, breaking use of the module. And mypy could have caught this for us, except that the module is neither typed nor checked in CI. Partially solve this by adding lots of type annotations, greatly reducing the number of mypy errors in this file from 35 down to 12.
2023-05-03cmake module: make configured file correctly handle the do_conf_file APIEli Schwartz
This doesn't accept a dict, only an actual ConfigurationData object. Due to the way we poke at it, a dict can sort of work anyway, but might not if the internal layout isn't exactly correct. This is evidenced by the way we make the dict values be hard-to-read tuples containing emptiness, because that's how ConfigurationData objects handle descriptions. Simplify and make the seed dictionary readable, then actually convert it into a real ConfigurationData. Bonus: this now passes type checking.
2023-05-03cmake module: use more typed_pos_args for consistencyEli Schwartz
It's shorter and more descriptive. Although we always enforce the same rules either way, a unified decorator is one less line of code for each location, and also tells you how many "too few" arguments you *did* pass.
2023-05-02fix regression in precomputing CMAKE_SIZEOF_VOID_PMaxHearnden
In commit 808d5934dd6c6a6c16f66e9dc51dae6e83e02cef, compiler.sizeof was refactored to introduce caching, but cmake subprojects did not adapt to that API change and ended up embedding the python repr of a tuple as a cmake variable.
2022-10-04pylint: enable use-a-generatorDylan Baker
This catches some optimization problems, mostly in the use of `all()` and `any()`. Basically writing `any([x == 5 for x in f])` vs `any(x == 5 for x in f)` reduces the performance because the entire concrete list must first be created, then iterated over, while in the second f is iterated and checked element by element.
2022-08-31modules/cmake: Fix typoaleksander
2022-08-17modules: use module level information about new and deprecationDylan Baker
Instead of using FeatureNew/FeatureDeprecated in the module. The goal here is to be able to handle information about modules in a single place, instead of having to handle it separately. Each module simply defines some metadata, and then the interpreter handles the rest.
2022-06-01interpreter: use a shared KwargInfo for install_dirDylan Baker
CustomTarget allows multiple install dirs, while basically everything else allows only one. So this provides a shared instance for that.
2022-05-23move various imports into TYPE_CHECKING blocks for neatnessEli Schwartz
2022-03-03interpreter: replace build_def_files with OrderedSetDylan Baker
We do a bunch of backbending to make sure we don't have duplicates, let's just use the right datastructure to begin with.
2022-03-03interpreter: add cm_interpreter to SubprojectHolderDylan Baker
This is used in the cmake module, as an extra attribute we just tack on. Instead, let's actually define and type it.
2022-03-03interpreter: use typed_kwargs for subproject()Dylan Baker
2022-03-03modules/cmake: add type annotations for subproject methodDylan Baker
This will be used to handle the interpreter subproject as well
2022-02-27cmake: configure_package_config_file can now take a dictAndrea Pappacoda
2022-02-27cmake: typed_kwargs for configure_package_config_fileAndrea Pappacoda
2022-02-01cmake: add arch_independent kwargAndrea Pappacoda
CMake's write_basic_package_version_file has supported since version 3.14 an ARCH_INDEPENDENT option that makes it skip its architecture check in the Version file. With this patch Meson now supports it as well, and the change is also compatible with older CMake versions, as they will simply ignore the option. This also slightly changes the contents of the generated Version file when arch_independent is not set: previously, the if() needed to skip the arch check was always filled with an empty string, while CMake puts "FALSE" (or "TRUE") in it. Now, that if() will always be filled with either "False" or "True", better matching CMake's behaviour.
2022-02-01cmake: typed_kwargs for write_basic_package_version_fileAndrea Pappacoda
2022-01-18interpreter: replace ConfigurationDataObject with ConfigurationDataHolderDylan Baker
This is much cleaner, and more in line with the way we handle interpreter objects in modern meson practice
2021-12-31add FeatureNew decorators for various modules that were lacking themEli Schwartz
Going back to 0.38, though some of them are far older. The original implementation of FeatureNew only added backdated feature checks that far, anyway.
2021-12-21modules: use find_program implementation to find programsEli Schwartz
Do not use ExternalProgram as that is too low-level and doesn't handle e.g. machine file overrides. Fixes #9733
2021-11-21Make the generated reproducible .cmake files reproducible.Chris Lamb
Whilst working on the Reproducible Builds effort [0], I noticed that meson did not generate reproducible .cmake files: they include the full path name. This commit not only makes the build reproducible, but it also matches CMake's own behaviour. Specifically, CMakePackageConfigHelpers.cmake does the equivalent transformation using: get_filename_component(inputFileName "${_inputFile}" NAME) I originally filed this in Debian as bug #1000327 [1]. [0] https://reproducible-builds.org/ [1] https://bugs.debian.org/1000327
2021-10-27do not repeat magic regexes for cmake define replacementsEli Schwartz
We already have this magic string in mesonlib, and this should always have used the cmake@ format which is identical to the meson format other than the regex.
2021-10-04f-stringsEli Schwartz
2021-10-03cmake module: if cmake cannot be found, do not tracebackEli Schwartz
We ended up passing a NoneType as the program binary, which is a very awkward way to communicate an error when failing to write a basic package version file.
2021-09-06mintro: add installed_planFilipe Laíns
Signed-off-by: Filipe Laíns <lains@riseup.net>
2021-08-31pylint: turn on superflous-parensDylan Baker
We have a lot of these. Some of them are harmless, if unidiomatic, such as `if (condition)`, others are potentially dangerous `assert(...)`, as `assert(condtion)` works as expected, but `assert(condition, message)` will result in an assertion that never triggers, as what you're actually asserting is `bool(tuple[2])`, which will always be true.
2021-07-05cmake: Improved error message for using dependency for executablesDaniel Mensinger
fixes #8893
2021-06-29fix: Always explicitly set encoding for text files (fixes #8263)Daniel Mensinger
2021-06-18holders: remove unholderDaniel Mensinger