question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using conan with clang-cl and CMake on Windows

See original GitHub issue

Clang provides the clang-cl binary, which is compatible with MSVC’s cl. It can also be used with the Ninja CMake generator, for example, the following way:

call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Auxiliary\Build\vcvarsall.bat" x64

set CC=clang-cl
set CXX=clang-cl
set CFLAGS=-m64 -fmsc-version=1910
set CXXFLAGS=-m64 -fmsc-version=1910
cmake ../ -GNinja

CMake’s internal scripts correctly detect the compiler to be cl-compatible and use the cl style command line parameters in this case.

Conan itself has no knowledge about this compiler, but I assumed that if I compile the dependencies with MSVC (which is the default), I should be able to use them in my CMake project.

While this approach mostly works, the conanbuildinfo.cmake script generated by conan detects the compiler as Clang instead of as MSVC, and displays an error, because of the following line:

if( (CONAN_COMPILER STREQUAL "Visual Studio" AND NOT CMAKE_CXX_COMPILER_ID MATCHES MSVC) OR

While the Ninja generator sets the compiler id to Clang, it also sets the MSVC variable to 1 and sets the MSVC_VERSION correctly to 1910.

I also know that ideally compilers shouldn’t be mixed, but I also assume that adding fully working clang/clang-cl support for conan on windows would be a significant work.

As a simpler solution, this check could be more permissive, for example:

  1. By changing that line to just if( (CONAN_COMPILER STREQUAL "Visual Studio" AND NOT MSVC)
  2. By changing the MSVC version checks to use MSVC_VERSION instead of the CMAKE_CXX_COMPILER_VERSION variable. (currently, this step isn’t necessary, because as I described in #1838, the MSVC version checks are incomplete and pass even when they shouldn’t)

This change would allow any compiler which claims to be compatible with the given MSVC version to be used. It would be also consistent with how most projects detect that they are compiled with MSVC.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:12
  • Comments:26 (13 by maintainers)

github_iconTop GitHub Comments

1reaction
dutowcommented, Feb 25, 2019

Re: GNU command line clang. I have a merge request for CMake to support it on windows - after that gets merged, both clang and clang-cl can be real use cases on windows. In the current version, CMake gets a new information variable (CMAKE_lang_COMPILER_FRONTEND_VARIANT) which lets users differentiate between these. (https://gitlab.kitware.com/cmake/cmake/merge_requests/2992)

0reactions
memshardedcommented, Sep 30, 2022

This PR https://github.com/conan-io/conan/pull/11492, merged for next 1.53 contains a few changes to better support clang in Windows, mainly for the new CMakeToolchain integration, but some minor changes for others too.

There are some other pending issues about the Windows subsystems environment management, we are also trying to improve them in https://github.com/conan-io/conan/pull/12178, so if you are using Clang in some subsystem and depend on the environment, you might want to track this PR too.

Closing this issue now, but we know that there might still be some gaps, so please try to update to the new integration (this is necessary for 2.0 anyway), and report what might still be failing against this new integration. The best starting point would be the tests in https://github.com/conan-io/conan/blob/develop/conans/test/functional/toolchains/cmake/test_cmake_toolchain_win_clang.py, or using any of the predefined templates conan new hello/0.1 -m=cmake_lib|autotools_lib|msbuild_lib|meson_lib, and open a new issue. Many thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Understanding the different flavors of Clang C and C++ ...
This section illustrates how to test the different Clang flavors using CMake and Conan, as it provides a good abstraction layer over them,...
Read more >
Using conan with clang-cl and CMake on Windows
Clang provides the clang-cl binary, which is compatible with MSVC's cl . It can also be used with the Ninja CMake generator, for...
Read more >
Conan Package Manager in Practice - GitHub Pages
compiler: apple-clang ... Exercise : Consume a Conan Package : Windows ... creates FindBoost.cmake (sets paths to Boost files in conan cache).
Read more >
Understanding the different flavors of Clang C and ... - Reddit
Conan should probably be installed inside cygwin and not require any ... Meanwhile, X runs on windows through wsl2, which is pretty neat....
Read more >
Increasing odds of using pre-built binaries with conan
Next, scan through the list of available binary packages, e.g., ... REMOTE conancenter GENERATORS cmake SETTINGS compiler=clang ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found