Thread (14 messages) flat view 14 messages, 3 authors, 2021-05-31

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

From: Matt Rogers <hidden>
Date: 2021-05-31 00:08:29

quoted
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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help