Martin Mocko
Martin Mocko

Reputation: 33

How to detect Visual Studio LLVM toolset in CMakeLists?

How can I detect in CMakeLists.txt, that Visual Studio Clang toolset is used, as opposed to clang on Linux? When Visual Studio Clang toolset is used, I need to specify extra flags specific to Visual Studio headers (such as _CRT_SECURE_NO_WARNINGS).

Further info:

The toolset is Visual Studio Community 2019 Preview, version 16.10.0 Preview 3.0 (with C++ Clang Tools for Windows 10.0.0).

To build I am using Visual Studio Codium 1.56.2 with plugins CMake 0.0.17 and CMake Tools 1.7.2.

The VSCode CMake plugin autodetects Visual Studio Clang toolset, and when I select it, it builds with following command:

D:\dev_tools\cmake\bin\cmake.EXE --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE "-DCMAKE_C_COMPILER:FILEPATH=C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\Llvm\x64\bin\clang.exe" "-DCMAKE_CXX_COMPILER:FILEPATH=C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\Llvm\x64\bin\clang.exe" -Hd:/dev/exemine -Bd:/dev/exemine/build -G Ninja

The build works correctly. I just need to detect when this toolset is used from CMakeLists.txt and specify few extra options.

Upvotes: 0

Views: 279

Answers (1)

Martin Mocko
Martin Mocko

Reputation: 33

Note: As a workaround, I am using following code:

if(MSVC OR (CMAKE_CXX_COMPILER MATCHES "clang.exe$"))
  add_compile_definitions(WIN32)
  ...

Upvotes: 0

Related Questions