git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [RFH] CMake: detect if being run via Visual Studio, independent of build generator?

From
Matt Rogers <mattr94@gmail.com>
Date
May 31, 2021, 00:01 UTC
Message-ID
<CAOjrSZusMSvs7AS-ZDsV8aQUgsF2ZA754vSDjgFKMRgi_oZAWw@mail.gmail.com>
In-Reply-To
<580d858d-dcd3-9d62-ec97-2daa9d9e0f45@iee.email>
Show 5 quoted lines
> > My other consideration is that the build process should generate enough
> > of the right artefacts (e.g. a .sln etc). This is so that other typical
> > tools and extensions e.g. Sourcetrail which expects the .sln, but maybe
> > they'll also cope with Ninja/Cmake builds soon...
> >

Something to keep in mind is that the generator is what decides what artifacts get produced. As a consumer of the CMakeLists.txt it's on you to tell CMake what your tool needs, i.e. if it needs a compile_commands.json to run clang-tidy or a .sln file or a ninja.build that would be on the user to generate. I think that's acceptable, if there are common tools in use that require a more complicated cmake invocation to get that generation, then it might pay to define a preset in our CMakePresets.json so that users can get those artifacts with a straightforward invocation like:

cd contrib/buildsystems mkdir build cd build cmake --preset sourcetrail ..

which I would still consider pretty "batteries included".

I do think however is that there are a few problems you're encountering in this case:

1. Visual Studio build breaks because we don't install vcpkg here when we should
2. Visual Studio is no longer creating the .sln files, which some of
your external tools
were relying on.

I think that the solution to 1. would be to add a knob for vcpkg installation, and either have that knob "on" by default and/or provide a configuration in a CMakePresets.json that Visual Studio (and other IDE's/tools) could use to build.

I think the problem with 2. is that CMake is a build file generator rather than an actual build system itself, so it needs a user to tell it what kind of files that their tools expect. And I don't think there's any way to make it guess what kind of files the user expects cmake to generate. Depending on the complexity of the configuration it may be worth providing a CMakePresets.json file to make it easier to use, but I guess it would depend on what exactly you need it to do.

-- 
Matthew Rogers
Previous: Philip OakleyNext: Philip Oakley
Message 13 of 14 in “[RFH] CMake: detect if being run via Visual Studio, independent of build generator?”
  1. Philip OakleyMay 29, 2021
  2. Matt RogersMay 29, 2021
  3. Philip OakleyMay 29, 2021
  4. Sibi SiddharthanMay 29, 2021
  5. Philip OakleyMay 29, 2021
  6. Sibi SiddharthanMay 29, 2021
  7. Matt RogersMay 30, 2021
  8. Philip OakleyMay 30, 2021
  9. Matt RogersMay 30, 2021
  10. Sibi SiddharthanMay 30, 2021
  11. Philip OakleyMay 30, 2021
  12. Philip OakleyMay 30, 2021
  13. Matt RogersMay 31, 2021
  14. Philip OakleyMay 31, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.