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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux