Closed rdong8 closed 6 months ago
Hi @rdong8
Thanks for your report. First, some quick feedback:
conanfile.py
the conanfile.txt
is unnecessary, probably duplicated information. You can (and it is recommended) to use the same conanfile.py
also for consumption and conan install .
where the dot "." will be able to use the conanfile.py
without ambiguitybuild_type="Debug"
, which is typically not useful. The tool_requires
in the "build" context can be perfectly be built with gcc and can be in Release mode. Maybe some of this can be explained by the following: This is not completely clear:
I am using the Jetbrains extension. Here is my profile:
Do you mean, the Conan-CLion plugin? This works with the cmake-conan
extension, so it is driven from CMake, and in most cases the profile is unnecessary. Are you providing your own custom profile via variables to CLion? Or is that the automatically detected profile? Have you updated to the latest plugin and updated the CMake-conan integration?
If you provide your own profile, then the important point is the following:
Conan profile [settings]
is a declaration of the "active" configuration that will be used to build, to compute the package_id
of the package binaries. But it is not a configuration of the environment, nor it will try to automatically setup your environment to activate the clang
compiler. If you want to do that, there are typically some steps to do:
[buildenv]
:
[buildenv]
CC=(path)/path/to/your/clang
CXX=(path)/.....
The (path)
might not be strictly necessary for this use case.
Conan also listens to the conf (https://docs.conan.io/2/reference/tools/cmake/cmaketoolchain.html#conan-cmake-toolchain-conf):
[conf]
tools.build:compiler_executables={"cpp": "/path/to/your/clang ...
Hi, thank you for the feedback, I've gotten rid of the conanfile.txt
. I am indeed using the Conan-CLion plugin and I think I'm just letting it automatically detect the profile. When I try to generate the CMake config which CLion is doing using this command:
/home/rd8/.local/share/JetBrains/Toolbox/apps/clion-nova/bin/cmake/linux/x64/bin/cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_MAKE_PROGRAM=ninja -DCMAKE_CXX_COMPILER=clang++ -G Ninja -S /home/rd8/CLionProjects/clcp_test -B /home/rd8/CLionProjects/clcp_test/cmake-build-debug
I end up getting this error:
-- The C compiler identification is GNU 13.2.1
-- The CXX compiler identification is Clang 17.0.6
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/clang++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at CMakeLists.txt:9 (find_package):
By not providing "Findspdlog.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "spdlog", but
CMake did not find one.
Could not find a package configuration file provided by "spdlog" with any
of the following names:
spdlogConfig.cmake
spdlog-config.cmake
Add the installation prefix of "spdlog" to CMAKE_PREFIX_PATH or set
"spdlog_DIR" to a directory containing one of the above files. If "spdlog"
provides a separate development package or SDK, be sure it has been
installed.
I see in the tutorials that -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake
is usually added as well, but when I try to add this it complains that it can't find the file:
CMake Error at /home/rd8/.local/share/JetBrains/Toolbox/apps/clion-nova/bin/cmake/linux/x64/share/cmake-3.27/Modules/CMakeDetermineSystem.cmake:154 (message):
Could not find toolchain file: conan_toolchain.cmake
Call Stack (most recent call first):
CMakeLists.txt:2 (project)
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
I see the CLion Conan plugin generates a file called conan_provider.cmake
, is that the same thing as conan_toolchain.cmake
? Is that file generated automatically by the plugin when I add a package to the project or do I need to manually run conan install
for it?
Thanks for the feedback.
I see some potential issue in:
-- The C compiler identification is GNU 13.2.1
-- The CXX compiler identification is Clang 17.0.6
As you can see the compiler is different. There will be dependencies that will need the C compiler too, so it is extremely recommended to make sure that clang
is also defined in your CLion as C compiler, it seems it is not.
Then, the conan_toolchain.cmake
cannot be used within the cmake-conan
integration that CLion uses. Basically because if the driver is CMake, not conan, CMake is already running, and it is not possible to inject a toolchain generated by conan into it, it is too late. This shouldn't be a problem, the cmake-conan
integration should take care of the equivalent functionality. The conan_provider.cmake
should be automatically injected by CLion, this is the code that is launching the installation of Conan dependencies, so if you saw output of conan dependencies being installed, the provider was successfully used.
As the error trace above was failing in another place (dependencies installation), but that part seems to be already working, could you please post the full output, not only the build part? Trying to see if there could be something there I am missing. Many thanks!
I have set clang to be both my C and C++ compilers. Here is a demo where I create a new project, set up Conan, install spdlog
and then add it to my CMake and attempt to build.
This is the log at the end:
/home/rd8/.local/share/JetBrains/Toolbox/apps/clion-nova/bin/cmake/linux/x64/bin/cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_MAKE_PROGRAM=ninja -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_PROJECT_TOP_LEVEL_INCLUDES=conan_provider.cmake -G Ninja -S /home/rd8/CLionProjects/untitled -B /home/rd8/CLionProjects/untitled/cmake-build-debug
CMake Error at conan_provider.cmake:494 (find_program):
Could not find CONAN_COMMAND using the following names: conan
Call Stack (most recent call first):
CMakeLists.txt:8 (find_package)
CMake Error at CMakeLists.txt:8 (find_package):
By not providing "Findspdlog.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "spdlog", but
CMake did not find one.
Could not find a package configuration file provided by "spdlog" with any
of the following names:
spdlogConfig.cmake
spdlog-config.cmake
Add the installation prefix of "spdlog" to CMAKE_PREFIX_PATH or set
"spdlog_DIR" to a directory containing one of the above files. If "spdlog"
provides a separate development package or SDK, be sure it has been
installed.
Here's what was generated at the end:
$ tree
.
├── cmake-build-debug
│ ├── build.ninja
│ ├── CMakeCache.txt
│ ├── CMakeFiles
│ │ ├── 3.27.8
│ │ │ ├── CMakeCCompiler.cmake
│ │ │ ├── CMakeCXXCompiler.cmake
│ │ │ ├── CMakeDetermineCompilerABI_C.bin
│ │ │ ├── CMakeDetermineCompilerABI_CXX.bin
│ │ │ ├── CMakeSystem.cmake
│ │ │ ├── CompilerIdC
│ │ │ │ ├── a.out
│ │ │ │ ├── CMakeCCompilerId.c
│ │ │ │ └── tmp
│ │ │ └── CompilerIdCXX
│ │ │ ├── a.out
│ │ │ ├── CMakeCXXCompilerId.cpp
│ │ │ └── tmp
│ │ ├── clion-Debug-log.txt
│ │ ├── clion-environment.txt
│ │ ├── cmake.check_cache
│ │ ├── CMakeConfigureLog.yaml
│ │ ├── pkgRedirects
│ │ ├── rules.ninja
│ │ ├── TargetDirectories.txt
│ │ └── untitled.dir
│ ├── cmake_install.cmake
│ └── Testing
│ └── Temporary
│ └── LastTest.log
├── CMakeLists.txt
├── conandata.yml
├── conanfile.py
├── conan_provider.cmake
└── main.cpp
12 directories, 24 files
CMakeLists.txt:
cmake_minimum_required(VERSION 3.27)
project(untitled)
set(CMAKE_CXX_STANDARD 23)
add_executable(untitled main.cpp)
find_package(spdlog REQUIRED)
target_link_libraries(untitled PRIVATE spdlog::spdlog)
conandata.yml:
# This file is managed by Conan, contents will be overwritten.
# To keep your changes, remove these comment lines, but the plugin won't be able to modify your requirements
requirements:
- "spdlog/1.12.0"
conanfile.py:
# This file is managed by Conan, contents will be overwritten.
# To keep your changes, remove these comment lines, but the plugin won't be able to modify your requirements
from conan import ConanFile
from conan.tools.cmake import cmake_layout, CMakeToolchain
class ConanApplication(ConanFile):
package_type = "application"
settings = "os", "compiler", "build_type", "arch"
generators = "CMakeDeps"
def layout(self):
cmake_layout(self)
def generate(self):
tc = CMakeToolchain(self)
tc.user_presets_path = False
tc.generate()
def requirements(self):
requirements = self.conan_data.get('requirements', [])
for requirement in requirements:
self.requires(requirement)
Ok, I think I got it. If you carefully read the log messages, in the first lines it will display an error that reads something like:
CMake error. find_program() couldn't find conan
This means that Conan is not installed in your system, and consequently it couldn't install the dependencies. I am a bit confused, because in the first logs we could clearly see:
======== Computing necessary packages ========
So Conan was installing packages. But for some reason, now it cannot be found anymore, so this seems a different problem than before. I am moving this ticket to the CLion
plugin repo, as this doesnt seem a Conan issue (client issue), but a CLion plugin one. Thanks for all the feedback!
If you provide your own profile, then the important point is the following:
Conan profile
[settings]
is a declaration of the "active" configuration that will be used to build, to compute thepackage_id
of the package binaries. But it is not a configuration of the environment, nor it will try to automatically setup your environment to activate theclang
compiler. If you want to do that, there are typically some steps to do:* You can define the CC and CXX environment variables in profile `[buildenv]`:
[buildenv] CC=(path)/path/to/your/clang CXX=(path)/.....
Hey I'm still not really sure what this means. I just want to use clang++ and libc++ in my code, what needs to be done on the Conan side? Do I also need to make conan use clang and libc++ for my conan dependencies?
Hey I'm still not really sure what this means. I just want to use clang++ and libc++ in my code, what needs to be done on the Conan side? Do I also need to make conan use clang and libc++ for my conan dependencies?
Not because of using Conan, but in general, to link with third party dependencies, these dependencies must be built to be binary compatible. That means building with the same libc++
for example, and using the same compiler and compiler verison can also be necessary in most cases. So yes, the dependencies should use the same Conan settings as the current project.
The cmake-conan
integration is the one being used by the CLion plugin, it should take care of most of it, and obtain the Conan settings from the current compiler configuration. But then you said above:
Here is my profile: .... compiler.libcxx=libstdc++
So it is not clear if you wrote your own profile or it was automatically detected by cmake-conan
.
Furthermore, above there are different issues that it is not clear if they have been resolved:
conanfile.py
and a conanfile.txt
, and this is not necessary as commented above.So it would be great if you could do an update, make sure you use the latest update of the plugin, and make sure to update the cmake-conan integration with the plugin and summarize from scratch:
conanfile
you are usingCMakeLists.txt
you are usingThanks very much.
So I ended up not using the CLion plugin since it doesn't work with the newest version of CLion Nova I am using. I am trying to get it to work in the CLI.
I can get it to work when both my Conan build_type
and CMake --config
(via Ninja multi-config) are set to Debug, but when I try have my Conan build_type
set to Release and my CMake config set to Debug, it doesn't work.
Just to clarify, do the two always need to be the same?
conanfile.py
:
from conan import ConanFile
from conan.tools.cmake import cmake_layout, CMakeToolchain
class ConanApplication(ConanFile):
package_type = "application"
settings = "os", "compiler", "build_type", "arch"
generators = "CMakeDeps"
def layout(self):
cmake_layout(self)
def generate(self):
tc = CMakeToolchain(self)
tc.user_presets_path = False
tc.generate()
def requirements(self):
requirements = self.conan_data.get('requirements', [])
for requirement in requirements:
self.requires(requirement)
conandata.yml
:
requirements:
- "boost/1.83.0"
- "catch2/3.5.0"
- "spdlog/1.12.0"
My CMake is here, it's a template I'm building for future projects so apologies for the complexity.
Conan profile:
[buildenv]
CC=clang
CXX=clang++
[settings]
arch=x86_64
build_type=Release
compiler=clang
compiler.cppstd=23
compiler.libcxx=libc++
compiler.version=17
os=Linux
Here are the logs for when I have a my Conan build type set to Release and my CMake build type set to Debug.
I can get it to work when both my Conan build_type and CMake --config (via Ninja multi-config) are set to Debug, but when I try have my Conan build_type set to Release and my CMake config set to Debug, it doesn't work.
No, they don't necessarily need to be the same in all cases (In Windows, msvc, it is almost mandatory, for example, but in other compilers it isnt). Just Conan needs to be aware of the build types that are being used both for dependencies and the current project if they are different. This can be done with per-package settings. Something like this is possible:
conan install . -s build_type=Release -s mypkg/*:build_type=Debug
That uses Release for all packages except for "mypkg" This syntax can also be used with a placeholder that indicates the current "consumer":
conan install . -s build_type=Release -s &:build_type=Debug
This means that you want the dependencies in Release, but your current project build will be a Debug one.
Please try that and let us know.
The second command causes issues on linux since the &
means to send the current command to the background, so it actually tries to run conan install . -s build_type=Release -s
in the background and then :build_type=Debug
which is not a valid command. I tried quoting it like this:
conan install . -b missing -s build_type=Release -s "&:build_type=Debug"
But now I still get the same error as before. It seems to continue to build everything in Debug, and then CMake configure fails since it can't find the file that I pass to the command -DCMAKE_TOOLCHAIN_FILE=build/Release/generators/conan_toolchain.cmake
. Only the Debug one is generated.
If you want to generate both:
conan install . -b missing -s build_type=Release -s "&:build_type=Release"
conan install . -b missing -s build_type=Release -s "&:build_type=Debug"
Every configuration uses one conan install
Is this what you meant?
Ah sorry, I thought the subdirectory where the conan toolchain file is in was going to be named after the build type used for the Conan packages (Release) not what I planned to build my code with (Debug). I changed it to -DCMAKE_TOOLCHAIN_FILE=build/Debug/generators/conan_toolchain.cmake
and it works.
One last question - is there a way to tell Conan what the build directory will be called or does it have to be under ./build/
.
One last question - is there a way to tell Conan what the build directory will be called or does it have to be under
Sure, the full layout of the current project is fully customizable with the layout()
method, please have a look to:
Environment details
Steps to reproduce
I am using the Jetbrains extension. Here is my profile:
conanfile.py:
conanfile.txt:
conandata.yml:
Then I just run:
Logs