cmake-conan icon indicating copy to clipboard operation
cmake-conan copied to clipboard

How can you pass conan command line options when using CLion's conan plugin?

Open rturrado opened this issue 1 year ago • 6 comments

Hi all,

Sorry if this question doesn't belong here. I believe the CLion's conan plugin uses cmake-conan (as stated here), but this may well be more an issue of the plugin than of cmake-conan.

Let's say I have a conan command line such as:

conan build . -s:h compiler.cppstd=20 -s:h libqasm/*:build_type=Debug -o libqasm/*:build_tests=True -b missing

Is there a way to pass all or some of those options to the plugin?

At the moment, I can only think of setting them directly as CMake flags. One of the problems with that is that, for example, if I'm requiring gtest in the conanfile.py depending on the command line option build_tests, that check will always be false.

Thanks!

rturrado avatar Sep 19 '23 23:09 rturrado

Hi @rturrado

We have pending the "customization" feature for cmake-conan. It will work mostly by allowing to inject custom profiles to the build, @jcar87 will be contributing it soon, please keep tuned

memsharded avatar Sep 20 '23 07:09 memsharded

Hi @rturrado - thanks for your questions.

We have recently merged: https://github.com/conan-io/cmake-conan/pull/567 with documentation here: https://github.com/conan-io/cmake-conan/tree/develop2#customizing-conan-profiles

Which allows you to customise the Conan profiles. While this does not let you customize the command line invocation, most of the settings/options you have in your example:

-s:h compiler.cppstd=20 -s:h libqasm/*:build_type=Debug -o libqasm/*:build_tests=True

can be set in a profile file (with the exception of the --build flag, which currently is set to --build=missing in CMake-Conan).
The new option supports profile composition, so you could have a profile file somewhere with the following contents:

[settings]
 libqasm/*:build_type=Debug
[options]
 libqasm/*:build_tests=True

if this file is saved in /path/to/my_overrides then you could pass -DCONAN_HOST_PROFILE=default;auto-cmake;/path/to/my_overrides, to achieve the result you want.

Please let us know if this helps!

jcar87 avatar Sep 25 '23 08:09 jcar87

Hi @jcar87,

Many thanks to you for your great work and support!

A couple of questions:

  1. Can I also set compiler.cppstd=20 as a setting in my custom Conan profile?
  2. Do you know when will this change be available for the CLion's plugin? I am using version 2.0.2 of the plugin and it seems it is the latest.

Many thanks!

rturrado avatar Sep 25 '23 09:09 rturrado

Hi @rturrado -

  1. Yes, you should be able to set this as well. Bear in mind that this is currently autodetected based on whether CMAKE_CXX_STANDARD is defined (if you define it and set it to 20, it will have the same effect).

  2. In the CLion plugin you can refresh to pull the latest version of cmake-conan: image

jcar87 avatar Sep 25 '23 10:09 jcar87

Wow! Many thanks for your answer!

  1. Knowing this is highly valuable. I was using at the moment target_compile_features(<target> PUBLIC cxx_std_<YY>), but I'll definitely set CMAKE_CXX_STANDARD as well in order to avoid passing one extra argument to conan.
  2. Beautiful, easy!

Again, great work and support, guys!

rturrado avatar Sep 26 '23 08:09 rturrado

Hi guys,

I have tried this today, and:

  1. In my case, setting CMAKE_CXX_STANDARD in the CMakeLists.txt file is not enough. I need to explicitly use compiler.cppstd=<YY>.
  2. Using -DCONAN_HOST_PROFILE="default;auto-cmake;/path/to/libqasm/conan/profiles/tests-debug" didn't work for me either. I can see the options in the CMake output (Input profiles, Profile host section), but then they seem not to be passed to the build (e.g. tests are not built). I am using the version 2.0.2 of the Conan's CLion plugin.

It may well be that something is wrong with my system. I work on WSL 2 and it's a bit of a headache everyday (root user, permission errors from within CLion until you reboot WSL...). But this is my real current feedback anyway.

Thanks!

rturrado avatar Sep 27 '23 00:09 rturrado