git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Philip Oakley <philipoakley@iee.email>
To: Matt Rogers <mattr94@gmail.com>
Cc: Sibi Siddharthan <sibisiddharthan.github@gmail.com>,
	Git List <git@vger.kernel.org>,
	Johannes Schindelin <johannes.schindelin@gmx.de>,
	Danh Doan <congdanhqx@gmail.com>
Subject: Re: [RFH] CMake: detect if being run via Visual Studio, independent of build generator?
Date: Mon, 31 May 2021 18:12:21 +0100	[thread overview]
Message-ID: <ead4ff2a-dfc0-ef8c-e2c5-477197ddded6@iee.email> (raw)
In-Reply-To: <CAOjrSZusMSvs7AS-ZDsV8aQUgsF2ZA754vSDjgFKMRgi_oZAWw@mail.gmail.com>

On 31/05/2021 01:01, Matt Rogers wrote:

Thanks for the reply. Just hoping we aren't talking at cross purposes
here, filling out details where I can...
>>> 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.  

However, Visual Studio default install makes that decision for you (any
such user), and has changed that default in the last couple of years
(from Visual Studio generator to Ninja generator).

> As a consumer of the CMakeLists.txt it's on you to tell
> CMake what
> your tool needs

Here (this discussion), there are two different 'tools' being considered.
1) the Git for Windows build instructions for those hoping to build &
browse the code (using VS).
2) my hope that I can add Sourcetrail to that browse capability.

It's (1) that has broken at some point 'recently'.
(Our build detected MSVC as an indicator of being on Visual Studio, etc.
There is now no indicator for CMake, of being on Visual Studio, that
works across all releases)

I'm trying to un-break (1), and hopefully enable (2) while at it.

> , 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 

Noting: CMakePresets.json files are supported in Visual Studio 2019
version 16.10 or later. [1]

I'm not sure when Ninja became the default generator in Visual Studio
(esp. Community Ed).
A quick search didn't locate that info. I'm expecting there to be a gap
between the Ninja change and the CmakePresets support, that will need
documenting/advising for users hoping to browse the GfW code, so they
can ensure they have a recent enough version 'out of the box'.

> 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'm targetting the user who will start from Visual Studio defaults and
open the git folder, rather than be in a terminal, so perhaps a bit of
divergence of approach here.

>
> 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

True

> 2. Visual Studio is no longer creating the .sln files, which some of
> your external tools
> were relying on.

It would/has but it's catch22 -- I had already installed the vcpkg files
in the past so that step didn't need to happen. I also, I think maybe
had an old VS version (it gets confused here), I tried various things,,
during which the (hidden folder) .vs/git.sln file was generated (Yay).

From then on I could use Sourcetrails integration extension, but I
wanted to go back and re-verify that a basic user could build, from
scratch, GfW as per instructions. So I unistalled Visual Studio and
CMake I's also installed, re-installed just 'Microsoft Visual Studio
Community 2019 Version 16.9.4' and tried the File->Open->Git directory
step, wherein CMakeLists.txt is detected, and run, and fails... sigh.
Starts digging holes.

>
> 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.

Knobs are difficult..

I'd agree, with the extra point that the instructions need to tell users
to inspect their VS version (>=16.10), and either, maybe fiddle with the
GfW CMakeLists.txt to switch generators to VS/MSVC (relative to the main
Git Cmake), or instruct users to run/rerun the build with additional
options (though more potential for finger trouble errors).

>
> 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.

True, and it can't ask for user input.

> 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.

True.
Philip
>
[1]
https://docs.microsoft.com/en-us/cpp/build/cmake-presets-vs?view=msvc-160

      reply	other threads:[~2021-05-31 17:14 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-29 15:00 [RFH] CMake: detect if being run via Visual Studio, independent of build generator? Philip Oakley
2021-05-29 15:49 ` Matt Rogers
2021-05-29 16:25   ` Philip Oakley
2021-05-29 18:33     ` Sibi Siddharthan
2021-05-29 20:31       ` Philip Oakley
2021-05-29 22:14         ` Sibi Siddharthan
2021-05-30  0:14           ` Matt Rogers
2021-05-30 10:52             ` Philip Oakley
2021-05-30 13:22               ` Matt Rogers
2021-05-30 14:29                 ` Sibi Siddharthan
2021-05-30 15:24                   ` Philip Oakley
2021-05-30 22:26                     ` Philip Oakley
2021-05-31  0:01                       ` Matt Rogers
2021-05-31 17:12                         ` Philip Oakley [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ead4ff2a-dfc0-ef8c-e2c5-477197ddded6@iee.email \
    --to=philipoakley@iee.email \
    --cc=congdanhqx@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=johannes.schindelin@gmx.de \
    --cc=mattr94@gmail.com \
    --cc=sibisiddharthan.github@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).