git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFH] CMake: detect if being run via Visual Studio, independent of build generator?
@ 2021-05-29 15:00 Philip Oakley
  2021-05-29 15:49 ` Matt Rogers
  0 siblings, 1 reply; 14+ messages in thread
From: Philip Oakley @ 2021-05-29 15:00 UTC (permalink / raw)
  To: Git List; +Cc: Sibi Siddharthan, Johannes Schindelin, Danh Doan

Hi,
cc'ing those who've been involved with the CMake tool recently.

I've been looking at part of the Git-for-Windows (GfW) Visual Studio
build process that uses the CMakeLists.txt approach [A,B], which is
based on the git.git version. In part it's now, for an uninformed user,
broken, in an awkward way, hence the subject line question.

An uniformed user is expected to clone git, download Visual Studio, and
file-open the /git directory. Visual Studio will then find the
CMakeLists.txt and create a hidden .sln/.vcproj project ready to build.

In recent times Visual Studio has added the Ninja build generator, in
addition to it's historic visual studio generator, and made Ninja the
default (unless specifically configured otherwise e.g. [1]). This change
of generator breaks the detection of being in Visual Studio (using Win32
and MSVC flags). We used these flags as a cue to pre-load the vcpkg
libraries, but no longer. Also note Visual Studio embeds its own CMake
version.


One issue for creating an update is that the CMake file is meant to be
OS independent, and the Ninja generator is also OS independent, so
shouldn't be used as the indicator of working with Visual Studio.
Likewise using the Win32 CMake flag isn't appropriate for those not
using Visual Studio. So the issue, as best I see it, is how to decide
when to pre-load the vcpkg libraries needed for the build.

The CI for the git.git test of CMake preloads it's essential
pre-requites (as an informed user;-) so avoids those Visual Studio
changes to it's defaults.

The ultimate aim is to make it as simple as possible for GfW users to
browse the Git code, without feeling that they have taken the
developer/contributor commitment step, which appears to scare off some
users.

Part of that simple usage is that existing Visual Studio support tools
can expect  .sln/.vcproj files to be available to 'just work' out of the
box. In particular (for me) Sourcetrail [2,3], with it's easy graphic
visualisation and tracing through the code, is one target. Sourcetrail
isn't quite there yet but..[4]

This issue is tricky to test as it (pretend to be that inexperienced
user) expects a clean VS install and no vcpkg prior install.

I could be totally confused (I am feeling rather dumb on this one), but
I'd be grateful of any help in clarifying a way out for detecting if the
conditions are right to pre-load the vcpkg libraries. I've also raised
an issue at [5]

--
Philip
earlier discussions at
https://github.com/git-for-windows/git/discussions/3176

[A]
https://github.com/git/git/blob/master/contrib/buildsystems/CMakeLists.txt
[B]
https://github.com/git-for-windows/git/blob/main/contrib/buildsystems/CMakeLists.txt
[1] https://github.com/microsoft/vscode-cmake-tools/issues/1084
[2] https://github.com/CoatiSoftware/Sourcetrail
[3]
https://github.com/git-for-windows/git/wiki/Sourcetrail-code-viewer-and-linkage-to-Visual-Studio,-for-Git
[4] https://github.com/CoatiSoftware/Sourcetrail/issues/1179
[5] https://github.com/MicrosoftDocs/cpp-docs/issues/3167

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [RFH] CMake: detect if being run via Visual Studio, independent of build generator?
  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
  0 siblings, 1 reply; 14+ messages in thread
From: Matt Rogers @ 2021-05-29 15:49 UTC (permalink / raw)
  To: Philip Oakley; +Cc: Git List, Sibi Siddharthan, Johannes Schindelin, Danh Doan

I have some experience at my job with CMake, but some quick testing
has found that adding a check like:

message("MSVC = ${MSVC} , WIN32 = ${WIN32})

shows that the MSVC is uninitialized and WIN322 is initialized.  so the
issue is that the MSVC variable isn't being set which is causing
vcpkg_install.bat to not run, rather than the WIN32 variable.

The msvc variable is intended to be set whenever the compiler is a Visual C/C++
compiler [1].  And it seems like visual studio should be setting that itself
either via a toolchain or some other mechanism.  As you noted the
Ninja generator
is os-agnostic and doesn't imply a compiler unlike the Visual Studio family of
generators.

running CMake with -DMSVC=1 should resolve the issue (Assuming you're
actually using
an MSVC based compiler).  If the CMake is intended to support non-MSVC
compilers like
clang, etc. and vcpkg is required to do that build then the MSVC
portion of the check
should be removed, otherwise I am not sure if it's a Visual Studio
issue for not correctly
configuring with MSVC=1 when using an MSVC-based compiler or on the
CMakeList.txt file
for not correctly specifying when vcpk_install.bat needs to be
installed.  I don't really
know what vcpkg does in the build to be sure though.

1: https://cmake.org/cmake/help/latest/variable/MSVC.html

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [RFH] CMake: detect if being run via Visual Studio, independent of build generator?
  2021-05-29 15:49 ` Matt Rogers
@ 2021-05-29 16:25   ` Philip Oakley
  2021-05-29 18:33     ` Sibi Siddharthan
  0 siblings, 1 reply; 14+ messages in thread
From: Philip Oakley @ 2021-05-29 16:25 UTC (permalink / raw)
  To: Matt Rogers; +Cc: Git List, Sibi Siddharthan, Johannes Schindelin, Danh Doan

On 29/05/2021 16:49, Matt Rogers wrote:
> I have some experience at my job with CMake, but some quick testing
> has found that adding a check like:
>
> message("MSVC = ${MSVC} , WIN32 = ${WIN32})
>
> shows that the MSVC is uninitialized and WIN322 is initialized.  so the
> issue is that the MSVC variable isn't being set which is causing
> vcpkg_install.bat to not run, rather than the WIN32 variable.

Thanks for confirming what I'm seeing. It's good to have.
>
> The msvc variable is intended to be set whenever the compiler is a Visual C/C++
> compiler [1].  And it seems like visual studio should be setting that itself
> either via a toolchain or some other mechanism.

That is what VS used to do (as best I understand it)

>   As you noted the
> Ninja generator
> is os-agnostic and doesn't imply a compiler unlike the Visual Studio family of
> generators.

Which (Ninja) is the new VS default - classic latest and greatest
breaking backward compatible ;-)

>
> running CMake with -DMSVC=1 should resolve the issue (Assuming you're
> actually using
> an MSVC based compiler).

The CMake is being run automatically by VS when it opens the folder,
fails to find the .sln, so searches for the CMakeList.txt file, so can't
add in the flag (with the current approach)..

>   If the CMake is intended to support non-MSVC
> compilers like
> clang, etc. and vcpkg is required to do that build then the MSVC
> portion of the check
> should be removed, 
Id agree about removal, but I'm not sure what should be in it's place to
ensure we have localised to being built within VS..
> otherwise I am not sure if it's a Visual Studio
> issue for not correctly
> configuring with MSVC=1 when using an MSVC-based compiler or on the
> CMakeList.txt file
> for not correctly specifying when vcpk_install.bat needs to be
> installed.  
It's sort of both. It's that change of default generator that's tripped
up everything.

I think I may need to look into Ninja to see if there is anything there
that will help.

Ultimately the goal is to get the .sln to support other [Sourcetrail]
tools (which needs an actual build)

> I don't really
> know what vcpkg does in the build to be sure though.
Basically, the .bat file gets all our library dependencies in a nice
packaged manner  (~Visual C Packager - vcpkg)
>
> 1: https://cmake.org/cmake/help/latest/variable/MSVC.html
Philip

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [RFH] CMake: detect if being run via Visual Studio, independent of build generator?
  2021-05-29 16:25   ` Philip Oakley
@ 2021-05-29 18:33     ` Sibi Siddharthan
  2021-05-29 20:31       ` Philip Oakley
  0 siblings, 1 reply; 14+ messages in thread
From: Sibi Siddharthan @ 2021-05-29 18:33 UTC (permalink / raw)
  To: Philip Oakley; +Cc: Matt Rogers, Git List, Johannes Schindelin, Danh Doan

On Sat, May 29, 2021 at 9:55 PM Philip Oakley <philipoakley@iee.email> wrote:
>
> On 29/05/2021 16:49, Matt Rogers wrote:
> > I have some experience at my job with CMake, but some quick testing
> > has found that adding a check like:
> >
> > message("MSVC = ${MSVC} , WIN32 = ${WIN32})
> >
> > shows that the MSVC is uninitialized and WIN322 is initialized.  so the
> > issue is that the MSVC variable isn't being set which is causing
> > vcpkg_install.bat to not run, rather than the WIN32 variable.
>
> Thanks for confirming what I'm seeing. It's good to have.
> >
> > The msvc variable is intended to be set whenever the compiler is a Visual C/C++
> > compiler [1].  And it seems like visual studio should be setting that itself
> > either via a toolchain or some other mechanism.
>

CMake sets this variable.
Please see {CMAKE_INSTALLATION}/share/cmake-<version>/modules/Platform/Windows-MSVC.cmake.
This happens after CMake is required to find a compiler.
This happens in line:93 where we enable the C language.

To fix this I would suggest to change line:53

-  if(MSVC AND NOT EXISTS ${VCPKG_DIR})
+ if(CMAKE_GENERATOR MATCHES "Visual Studio" AND NOT EXISTS ${VCPKG_DIR})

and
add CMakeSettings.json to force Visual Studio to use MSBuild.
Please see https://docs.microsoft.com/en-us/cpp/build/cmakesettings-reference?view=msvc-160



Thank You,
Sibi Siddharthan

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [RFH] CMake: detect if being run via Visual Studio, independent of build generator?
  2021-05-29 18:33     ` Sibi Siddharthan
@ 2021-05-29 20:31       ` Philip Oakley
  2021-05-29 22:14         ` Sibi Siddharthan
  0 siblings, 1 reply; 14+ messages in thread
From: Philip Oakley @ 2021-05-29 20:31 UTC (permalink / raw)
  To: Sibi Siddharthan; +Cc: Matt Rogers, Git List, Johannes Schindelin, Danh Doan

On 29/05/2021 19:33, Sibi Siddharthan wrote:
> On Sat, May 29, 2021 at 9:55 PM Philip Oakley <philipoakley@iee.email> wrote:
>> On 29/05/2021 16:49, Matt Rogers wrote:
>>> I have some experience at my job with CMake, but some quick testing
>>> has found that adding a check like:
>>>
>>> message("MSVC = ${MSVC} , WIN32 = ${WIN32})
>>>
>>> shows that the MSVC is uninitialized and WIN322 is initialized.  so the
>>> issue is that the MSVC variable isn't being set which is causing
>>> vcpkg_install.bat to not run, rather than the WIN32 variable.
>> Thanks for confirming what I'm seeing. It's good to have.
>>> The msvc variable is intended to be set whenever the compiler is a Visual C/C++
>>> compiler [1].  And it seems like visual studio should be setting that itself
>>> either via a toolchain or some other mechanism.
> CMake sets this variable.
> Please see {CMAKE_INSTALLATION}/share/cmake-<version>/modules/Platform/Windows-MSVC.cmake.
> This happens after CMake is required to find a compiler.
> This happens in line:93 where we enable the C language.

Ahh, so it (MSVC) would be unset at that point no matter what at that
early point in the code, yes?

>
> To fix this I would suggest to change line:53
>
> -  if(MSVC AND NOT EXISTS ${VCPKG_DIR})
> + if(CMAKE_GENERATOR MATCHES "Visual Studio" AND NOT EXISTS ${VCPKG_DIR})

I'd seen this one recommended on a few StackOverflow answers but it no
longer works (for a new install of Visual Studio) because
CMAKE_GENERATOR is now set to "Ninja" as default (sigh).

Simply dropping the MSVC test may be one option - we are already guarded
by the earlier WIN32 test so were aren't on another OS, though I expect
there could be some who want to not use VS, and already have options..
> and

> add CMakeSettings.json to force Visual Studio to use MSBuild.

I was trying to avoid requiring VS users do any extra set up steps. Too
many steps often puts off new users, and forcing a change could be
annoying for established users - hence the caution.

> Please see https://docs.microsoft.com/en-us/cpp/build/cmakesettings-reference?view=msvc-160

I'll have a look.

Thanks.

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [RFH] CMake: detect if being run via Visual Studio, independent of build generator?
  2021-05-29 20:31       ` Philip Oakley
@ 2021-05-29 22:14         ` Sibi Siddharthan
  2021-05-30  0:14           ` Matt Rogers
  0 siblings, 1 reply; 14+ messages in thread
From: Sibi Siddharthan @ 2021-05-29 22:14 UTC (permalink / raw)
  To: Philip Oakley; +Cc: Matt Rogers, Git List, Johannes Schindelin, Danh Doan

> Ahh, so it (MSVC) would be unset at that point no matter what at that
> early point in the code, yes?
>

yes

> >
> > To fix this I would suggest to change line:53
> >
> > -  if(MSVC AND NOT EXISTS ${VCPKG_DIR})
> > + if(CMAKE_GENERATOR MATCHES "Visual Studio" AND NOT EXISTS ${VCPKG_DIR})
>
> I'd seen this one recommended on a few StackOverflow answers but it no
> longer works (for a new install of Visual Studio) because
> CMAKE_GENERATOR is now set to "Ninja" as default (sigh).
>
> Simply dropping the MSVC test may be one option - we are already guarded
> by the earlier WIN32 test so were aren't on another OS, though I expect
> there could be some who want to not use VS, and already have options..

I am one of them, I use clang and MSVC with Ninja.

> > and
>
> > add CMakeSettings.json to force Visual Studio to use MSBuild.
>
> I was trying to avoid requiring VS users do any extra set up steps. Too
> many steps often puts off new users, and forcing a change could be
> annoying for established users - hence the caution.
>

Yeah, I agree.

Right now, I seriously think that we need to revert
958a5f5dfe4dda4fd59af30c1d58abe43ff19d6e.
This patch also hurts command line users like me.

A more complete solution would involve adding an explicit option to use vcpkg.
This can cater to people who prefer using vcpkg and to people who
prefer using their
own packages (like me).
But this means that you have to generate the solution file using the command
line. Some people might be put off due to this extra  'single' step.

I am afraid this is a situation where you cannot make everyone happy.

Thank You,
Sibi Siddharthan



.

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [RFH] CMake: detect if being run via Visual Studio, independent of build generator?
  2021-05-29 22:14         ` Sibi Siddharthan
@ 2021-05-30  0:14           ` Matt Rogers
  2021-05-30 10:52             ` Philip Oakley
  0 siblings, 1 reply; 14+ messages in thread
From: Matt Rogers @ 2021-05-30  0:14 UTC (permalink / raw)
  To: Sibi Siddharthan; +Cc: Philip Oakley, Git List, Johannes Schindelin, Danh Doan

(resending because client reconfigured to not use plaintext)

Reading through the documentation, Visual Studio seems to support
CmakePresets.json [1] for handling configuration of cmake options.  It
might be worth it to keep the defaults as is. But provide a variable
for forcing vcpkg and a CMakePresets.json for Visual Studio
(and other such tools) to use.

This is nice since Visual Studio users wouldn't need to rely on the
slower Visual Studio * generators to run their builds, while leaving
non Visual Studio users still able to easily run builds.  So maybe there's
a way for everyone to be happy?

1: https://devblogs.microsoft.com/cppblog/cmake-presets-integration-in-visual-studio-and-visual-studio-code/

-- 
Matthew Rogers

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [RFH] CMake: detect if being run via Visual Studio, independent of build generator?
  2021-05-30  0:14           ` Matt Rogers
@ 2021-05-30 10:52             ` Philip Oakley
  2021-05-30 13:22               ` Matt Rogers
  0 siblings, 1 reply; 14+ messages in thread
From: Philip Oakley @ 2021-05-30 10:52 UTC (permalink / raw)
  To: Matt Rogers, Sibi Siddharthan; +Cc: Git List, Johannes Schindelin, Danh Doan

quick thoughts..
On 30/05/2021 01:14, Matt Rogers wrote:
> (resending because client reconfigured to not use plaintext)
;-)
>
> Reading through the documentation, Visual Studio seems to support
> CmakePresets.json [1]
Is that stored with the project, or with the VS installation (still to
read [1] beyond a v quick scan..)
>  for handling configuration of cmake options.  It
> might be worth it to keep the defaults as is.

Given that it's just changed, do you mean ' keep it as new - Ninja' or
'keep it as old - VS generator'..

>  But provide a variable
> for forcing vcpkg and a CMakePresets.json for Visual Studio
> (and other such tools) to use.
>
> This is nice since Visual Studio users wouldn't need to rely on the
> slower Visual Studio * generators to run their builds, 
[implies, keep as Ninja, I think ?]
> while leaving
> non Visual Studio users still able to easily run builds.  So maybe there's
> a way for everyone to be happy?
I'm hoping to ensure the project builds 'straight out of the tin' [mixed
metaphor 2,3], for those who are cross disciplinary (such as myself;-)

I'll have a good look at [1], thanks.

Philip

>
> 1: https://devblogs.microsoft.com/cppblog/cmake-presets-integration-in-visual-studio-and-visual-studio-code/
>
[2] https://en.wikipedia.org/wiki/Out_of_the_box_(feature)
[3] https://www.ronseal.com/the-ronseal-phrase/ (UK)

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [RFH] CMake: detect if being run via Visual Studio, independent of build generator?
  2021-05-30 10:52             ` Philip Oakley
@ 2021-05-30 13:22               ` Matt Rogers
  2021-05-30 14:29                 ` Sibi Siddharthan
  0 siblings, 1 reply; 14+ messages in thread
From: Matt Rogers @ 2021-05-30 13:22 UTC (permalink / raw)
  To: Philip Oakley; +Cc: Sibi Siddharthan, Git List, Johannes Schindelin, Danh Doan

On Sun, May 30, 2021 at 6:52 AM Philip Oakley <philipoakley@iee.email> wrote:
>
> quick thoughts..
> On 30/05/2021 01:14, Matt Rogers wrote:
> > (resending because client reconfigured to not use plaintext)
> ;-)
> >
> > Reading through the documentation, Visual Studio seems to support
> > CmakePresets.json [1]
> Is that stored with the project, or with the VS installation (still to
> read [1] beyond a v quick scan..)

This file would live in our source tree next to our CMakeLists.txt.  It's kind
of cmakes answer to the problem CMakeSettings.json was trying to solve.

> >  for handling configuration of cmake options.  It
> > might be worth it to keep the defaults as is.
>
> Given that it's just changed, do you mean ' keep it as new - Ninja' or
> 'keep it as old - VS generator'..
>

Users should be free to use arbitrary generators and have them work
out of the box for normal use cases (here I'm thinking of IDE integrations
as well as just running builds).  So you should have the option to use
either Visual Studio with Ninja or with the Visual Studio 2019 generator.
I personally prefer Ninja, but maybe somebody is stuck using an older version,
or would prefer to have a .sln file for other reasons.

Personally, I think that most users not knowing anything would go in
thinking that arbitrary generators are equally supported with perhaps
a small number of knobs.

By default Visual Studio 2019 is probably doing an invocation something
like:

mkdir out && cd out && cmake -G Ninja ..

Which would ideally just work automagically.  But if for example you wanted
to support using vcpkg as a package source, we're pretty much forced to
provide a knob here (what if I wanted to use Visual Studio as my IDE but
not want to use vcpkg to manage those dependencies for example).

I think the best middle of the line solution would be to just provide a manual
knob for turning vcpkg support on/off here and offer configurations in
CMakePresets.json for both situations.  The only downside here is that I believe
a lot of IDE's are aggressive about running the cmake configuration step and may
try to install vcpkg even if it is unnecessary.  But automatic
generation can generally
be turned off by users I guess.


-- 
Matthew Rogers

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [RFH] CMake: detect if being run via Visual Studio, independent of build generator?
  2021-05-30 13:22               ` Matt Rogers
@ 2021-05-30 14:29                 ` Sibi Siddharthan
  2021-05-30 15:24                   ` Philip Oakley
  0 siblings, 1 reply; 14+ messages in thread
From: Sibi Siddharthan @ 2021-05-30 14:29 UTC (permalink / raw)
  To: Matt Rogers; +Cc: Philip Oakley, Git List, Johannes Schindelin, Danh Doan

On Sun, May 30, 2021 at 6:52 PM Matt Rogers <mattr94@gmail.com> wrote:

>
> I think the best middle of the line solution would be to just provide a manual
> knob for turning vcpkg support on/off here and offer configurations in
> CMakePresets.json for both situations.  The only downside here is that I believe
> a lot of IDE's are aggressive about running the cmake configuration step and may
> try to install vcpkg even if it is unnecessary.  But automatic
> generation can generally
> be turned off by users I guess.

I agree. I would suggest vcpkg should be used by default for Windows platforms.
This way IDE's won't complain and command line users can straight up
disable this behaviour.

Thank You,
Sibi Siddharthan

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [RFH] CMake: detect if being run via Visual Studio, independent of build generator?
  2021-05-30 14:29                 ` Sibi Siddharthan
@ 2021-05-30 15:24                   ` Philip Oakley
  2021-05-30 22:26                     ` Philip Oakley
  0 siblings, 1 reply; 14+ messages in thread
From: Philip Oakley @ 2021-05-30 15:24 UTC (permalink / raw)
  To: Sibi Siddharthan, Matt Rogers; +Cc: Git List, Johannes Schindelin, Danh Doan

On 30/05/2021 15:29, Sibi Siddharthan wrote:
> On Sun, May 30, 2021 at 6:52 PM Matt Rogers <mattr94@gmail.com> wrote:
>
>> I think the best middle of the line solution would be to just provide a manual
>> knob for turning vcpkg support on/off here and offer configurations in
>> CMakePresets.json for both situations.  The only downside here is that I believe
>> a lot of IDE's are aggressive about running the cmake configuration step and may
>> try to install vcpkg even if it is unnecessary.  But automatic
>> generation can generally
>> be turned off by users I guess.
> I agree. I would suggest vcpkg should be used by default for Windows platforms.
> This way IDE's won't complain and command line users can straight up
> disable this behaviour.
>
> Thank You,
> Sibi Siddharthan
I think so as well.

I'd started writing (draft) in reply to Matt

"I'd agree that knowledgable users should be able to control the
settings, however I'm against forcing less knowledgable users being
required to add extra control option for knobs they don't yet
understand, hence the desire to ensure a consistent (though possible
old-fashioned/backward-compatible) settings 'that just work' that do not
set in stone those choices, which would be the worst of both worlds!

It maybe that in some ways we may have missed the boat as those project
based CMakePresets.json presets (setting back to old defaults) could
'annoy' the (potentially) experienced users who are simply using the new
defaults. This doesn't affect (*) truly experience users who are setting
their desired options directly as they would/should override the presets."

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

I'll have a go, though I'll be off-line for a while from ~Tuesday.

Philip

(*) - affect/effect?
https://www.londonschool.com/nordic/blogg/whats-difference-between-affect-and-effect-and-when-should-they-be-used/

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [RFH] CMake: detect if being run via Visual Studio, independent of build generator?
  2021-05-30 15:24                   ` Philip Oakley
@ 2021-05-30 22:26                     ` Philip Oakley
  2021-05-31  0:01                       ` Matt Rogers
  0 siblings, 1 reply; 14+ messages in thread
From: Philip Oakley @ 2021-05-30 22:26 UTC (permalink / raw)
  To: Sibi Siddharthan, Matt Rogers; +Cc: Git List, Johannes Schindelin, Danh Doan

On 30/05/2021 16:24, Philip Oakley wrote:
> On 30/05/2021 15:29, Sibi Siddharthan wrote:
>> On Sun, May 30, 2021 at 6:52 PM Matt Rogers <mattr94@gmail.com> wrote:
>>
>>> I think the best middle of the line solution would be to just provide a manual
>>> knob for turning vcpkg support on/off here and offer configurations in
>>> CMakePresets.json for both situations.  The only downside here is that I believe
>>> a lot of IDE's are aggressive about running the cmake configuration step and may
>>> try to install vcpkg even if it is unnecessary.  But automatic
>>> generation can generally
>>> be turned off by users I guess.
>> I agree. I would suggest vcpkg should be used by default for Windows platforms.
>> This way IDE's won't complain and command line users can straight up
>> disable this behaviour.
>>
>> Thank You,
>> Sibi Siddharthan
> I think so as well.
>
> I'd started writing (draft) in reply to Matt
>
> "I'd agree that knowledgable users should be able to control the
> settings, however I'm against forcing less knowledgable users being
> required to add extra control option for knobs they don't yet
> understand, hence the desire to ensure a consistent (though possible
> old-fashioned/backward-compatible) settings 'that just work' that do not
> set in stone those choices, which would be the worst of both worlds!
>
> It maybe that in some ways we may have missed the boat as those project
> based CMakePresets.json presets (setting back to old defaults) could
> 'annoy' the (potentially) experienced users who are simply using the new
> defaults. This doesn't affect (*) truly experience users who are setting
> their desired options directly as they would/should override the presets."
>
> 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...
>
> I'll have a go, 

I had a look at the previous link and others (below) but I think there
is a potential Catch-22 problem as it [see cppblog] also expects the
user to do some enabling of the use of presets (If I Read Correctly). My
initial use case is 'out of the box' usage;-)

This suggests I may need to fallback on ensuing we give instructions on
bypassing the potentially failing parts (e.g. run the vcpkg install one
self, other steps, ...)

I did find a recent video on the presets which was helpful:
   An Introduction to CMakePresets.json : the simple example
https://youtu.be/NFbnm1t6Mc4?t=251

It feels like having both the presets and the fallback instructions may
be the way to go to cover the range of use cases,

> though I'll be off-line for a while from ~Tuesday.
>
> Philip
>
> (*) - affect/effect?
> https://www.londonschool.com/nordic/blogg/whats-difference-between-affect-and-effect-and-when-should-they-be-used/


> Please see
https://docs.microsoft.com/en-us/cpp/build/cmakesettings-reference?view=msvc-160

Other links:
https://cmake.org/cmake/help/latest/manual/cmake-presets.7.html
https://devblogs.microsoft.com/cppblog/cmake-presets-integration-in-visual-studio-and-visual-studio-code/
https://docs.microsoft.com/en-us/cpp/build/cmake-presets-json-reference?view=msvc-160

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [RFH] CMake: detect if being run via Visual Studio, independent of build generator?
  2021-05-30 22:26                     ` Philip Oakley
@ 2021-05-31  0:01                       ` Matt Rogers
  2021-05-31 17:12                         ` Philip Oakley
  0 siblings, 1 reply; 14+ messages in thread
From: Matt Rogers @ 2021-05-31  0:01 UTC (permalink / raw)
  To: Philip Oakley; +Cc: Sibi Siddharthan, Git List, Johannes Schindelin, Danh Doan

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

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [RFH] CMake: detect if being run via Visual Studio, independent of build generator?
  2021-05-31  0:01                       ` Matt Rogers
@ 2021-05-31 17:12                         ` Philip Oakley
  0 siblings, 0 replies; 14+ messages in thread
From: Philip Oakley @ 2021-05-31 17:12 UTC (permalink / raw)
  To: Matt Rogers; +Cc: Sibi Siddharthan, Git List, Johannes Schindelin, Danh Doan

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

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2021-05-31 17:14 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 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).