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 29, 2021, 15:49 UTC
Message-ID
<CAOjrSZtWVEUNEuJFw8WGPAW0YNccN9LWyuHZ28aKecdjd6dp=A@mail.gmail.com>
In-Reply-To
<013f42a4-19f4-a935-7068-db3f7ff40446@iee.email>

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
Previous: Philip OakleyNext: Philip Oakley
Message 2 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.