Generates Visual Studio solutions and projects for meson projects
Project description
Tools for generating VisualStudio solution from meson introspection files.
The usecase is when you want to use the ninja backend,
but edit or debug the project using the VisualStudio IDE.
Requirements: you need a C or C++ meson project, with at least one configured build directory. You need meson 1.2.0 or higher.
Using the command line
A command line interface is provided through the vsgen command.
Generating project
The project command allows to generate one .vcxproj file from a configured
meson project:
vsgen project [--target TARGET] [--update] [--sourcedir SOURCEDIR] [--outputdir OUTPUTDIR] [--builddir [CONFIG:]BUILDDIR, ...] NAME
The NAME is the name of the generated .vcxproj. It can also be a full path.
By default, it will look for a target with the same name as the project,
unless --target option is provided. Project sources should be in current dir,
or specified with --sourcedir. Build directory must be provided using --builddir
option. It can be a path relative to SOURCEDIR. The config is deduced automatically,
but the config name to use can be specified using CONFIGNAME: prefix to the build dir
(e.g. --builddir debug:/path/to/debug/build).
Files are generated in --outputdir, unless a full path is provided for NAME.
By default, the OUTPUTDIR will be the current directory.
If --update option is provided, existing .vcxproj will be updated instead of
being rewritten. This is useful to add a new build config to an existing project.
Example:
vsgen project -t mylib -o vs -b build/debug -b build/release MyProject
will generate vs/MyProject.vcxproj, with configs for debug and release,
for the mylib build target.
Generating solution
The solution command allows to generate a .sln file that includes one or many projects.
vsgen solution [--project [TARGET:]PROJECT, ...] [--projectdir PROJECTDIR] [--update] [--sourcedir SOURCEDIR] [--outputdir OUTPUTDIR] [--builddir [CONFIG:]BUILDDIR, ...] NAME
The NAME is the name of the generated .sln file. It can also be a full path.
The --project option allows to specify the name or the path of a project to include.
It may be specified multiple times. If not specified, all projects from PROJECTDIR are
included. TARGET if the name of the build target to use, if different from PROJECT.
If not specified, projects for all build targets are generated.
If specified, PROJECTDIR will be a sudir of OUTPUTDIR containing the project files.
Other options are similar to those of the project command.
Using configuration file
The generate command allows the generation of complex solutions, using a .yaml
configuration file.
vsgen generate [--sourcedir SOURCEDIR] [--outputdir OUTPUTDIR] CONFIGFILE
CONFIGFILE is the path to the .yaml config file. Other options are similar
to those of project command.
The config file contains the following keys:
outputdir: (optional) Where to generate the solution files, if not specified on the command line. Default is to use current dir.projectdir: (optional) Name of a subdirectory where to write project files.case_insensitive_targets: (optional) If true, lower case targets match project names containing uppercase characters.only_relative_files: (optional) If true, do not add files outside target source dir (i.e. where target meson.build file is located) into the project.include_from_env: (optional) If true, will useINCLUDEenv var for system include path. If 'auto', will useINCLUDEif it is defined. If false (default), will no rewrite the include path. This is useful when using a different build tools version that the IDE.configs: map build directories to config names.archs: (optional) map cpu_family to arch name. If not specified, use the cpu_family as the arch name.projects: The projects to generate. See project specifications below for more details.solutions: The solutions to generate. See solution specifications below for more details.
Project specifications
For each project, the key is the name of the project to generate.
If the key is *, the settings apply to all unlisted projects,
and is used as default config.
If the value is a boolean, true means to generate the project with default settings,
and false means to not generate that project.
If the value is a map, the following keys are recognized:
target: the build target name.truemeans to use the project name as the target name. If target name begins withdep:, this is the name of an internal dependency object, used for a header only project. This project will not compile, but will display files from that dependency.allis used for a target that generates all targets.subdir: if specified, put the generated project into that subdir of the project dir.
Solution specifications
For each solution, the key is the name of the solution to generate.
Value is a map with the following keys:
projects: A list of projects to include into the solution. If the value is a string, this project is included (must be listed into theprojectssection). If the value is a map, it map a directory name with a list of projects. This allow to put projects into logical directories in the solution. The structure is recursive. If the value is*, it means to include all projects not referenced elsewhere in the solution. If the value is a map with a boolean value, the key is a project name, and it is included if the value istrue, and explicitly skipped if the value isfalse.build_solution: The value is the project (or a list of projects) invoked when building the solution.runsettings: (optional) Iftrue, generates runsettings for all executables. Otherwise, map a wildcard with runsettings options. This allow special configurations for running tests with Google Test Adapter.
Using the API
The Generator object
vsgen package can also be used as an API, from a python script:
from vsgen.api import Generator.
The generator object takes 3 arguments:
vspath: The path where to generate the solution and project files (absolute, or relative tobasedir)basedir: (optional) The base path for other paths. Default is current dir.projectdir: (optional) The subdir where to generate projects (relative tovapath)
You can also modify or override the cpu_arch dictionary,
mapping cpu_family to arch name for the solution and projects.
The next step is to call set_config. The method takes the following arguments:
builddir: meson build dir, absolute, or relative toself.basedir.name: (optional) config name to use (default is builddir name).use_include_from_env: (optional) IfTrue, will use theINCLUDEenv var as system include path.
The project method is used to create a VcxProj object. Arguments are:
name: The project name.target: (optional) The build target name. Default is project name.subdir: (optional) Subdir (relative to projectdir) where to write the project. IfTrue, the subdir is the project name. IfFalse, no subdir is used.update: (optional) IfTrue, update existing project instead of overwriting it. Default isTrue.only_relative_files: (optional) IfTrue, will not reference source files that are not relative to the project root.
The method returns a VcxProj object.
The solution method is used to create a SolutionFile object.
Arguments are:
name: The solution name.update: Whether to update existing files instead of overwriting them.
The ConfigFile object
This is a high-level interface to deal with complex solutions managed by a configuration file. See [Using configuration file] above for more details about the configuration file syntax.
from vsgen.configfile import ConfigFile
from pathlib import Path
cf = ConfigFile('path/to/config.yaml').load() # load config file
basepath = Path('project/basepath')
outputpath = Path('project/outputpath')
cf.analyse(basepath) # analyse project introspection data
cf.generate(basepath, outputpath, update=True) # generate project and solution files
The SolutionFile object
You usually create the SolutionFile object using the Generator.
Next step is to add projects to the solution:
sln.add_project(project, subdir, build_solution_target=False)
projectis aVcxProjobjectsubdiris an optional string if you want the project into a logical subdirectory in the solution.build_solution_target: ifTrue, this project is build when generating the whold solution. This is usually used for thealltarget only.
Finally, you can write the solution file:
sln.write()
The VcxProj object
To write the .vcxproj file: prj.write()/
The RunSettingsFile object
[https://learn.microsoft.com/en-us/visualstudio/test/configure-unit-tests-by-using-a-dot-runsettings-file?view=vs-2022]
This allow to configure and write a runsettings file.
from vsgen.runsettings import RunSettingsFile
from pathlib import Path
rsfile = RunSettingsFile(Path('path/to/runsettings/file'))
rsfile.add_solution_setting(name, value) # add a setting for whole solution
rsfile.add_project_setting(name, value, regex) # add a setting for projects
# matched by regex
rsfile.write()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file meson_vs_gen-0.7.0.tar.gz.
File metadata
- Download URL: meson_vs_gen-0.7.0.tar.gz
- Upload date:
- Size: 21.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.4 CPython/3.10.18 Linux/5.15.154+
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
25576df68f2fed9fbf8e680f1a6f33e7539a6096aed74ef0d1350e8ea143ccf9
|
|
| MD5 |
58a0f51c772b35e9a447ffeddcd605cf
|
|
| BLAKE2b-256 |
eda6a8e7a0067f93996a2aa52771edc3410aac91a86236ab69d04070efa8ad4e
|
File details
Details for the file meson_vs_gen-0.7.0-py3-none-any.whl.
File metadata
- Download URL: meson_vs_gen-0.7.0-py3-none-any.whl
- Upload date:
- Size: 24.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.4 CPython/3.10.18 Linux/5.15.154+
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eab54450c2c81564e936c1cc40e66d14c1e8fa4f2fd450c2162613df17443564
|
|
| MD5 |
37b624e81682e9deaa67d78a51aa6935
|
|
| BLAKE2b-256 |
4aed9b1db9264ed03b750bc41fe27ad5df260f77bb0e7ecc961cc43f0a868ac1
|