conan_cmake_run fails when conan is installed locally (not system-wide)
CMake:
if(NOT EXISTS "${CMAKE_BINARY_DIR}/conan.cmake")
message(STATUS "Downloading conan.cmake from https://github.com/memsharded/cmake-conan")
file(DOWNLOAD "https://raw.githubusercontent.com/conan-io/cmake-conan/master/conan.cmake"
"${CMAKE_BINARY_DIR}/conan.cmake")
endif()
include(${CMAKE_BINARY_DIR}/conan.cmake)
conan_cmake_run(CONANFILE conanfile.txt # or relative build/conanfile.txt
BASIC_SETUP CMAKE_TARGETS
BUILD missing)
Output:
-- Conan ** WARNING** : This detection of settings from cmake is experimental and incomplete. Please check 'conan.cmake' and contribute
-- Conan executing: conan install -f=/home/sztomi/Projects/MyCoolProject/conanfile.txt -g cmake -s build_type=Debug -s os=Linux -s compiler=gcc -s compiler.version=6.3 -s compiler.libcxx=libstdc++11 --build=missing
CMake Error at cmake-build-debug/conan.cmake:221 (message):
Conan install failed='No such file or directory'
Call Stack (most recent call first):
cmake-build-debug/conan.cmake:298 (conan_cmake_install)
CMakeLists.txt:14 (conan_cmake_run)
However, when I run the same command from the command line, it works. Tried CMake 3.7 (bundled) and 3.8 with the same result.
Interestingly, it fails the same way in KDevelop. My guess is that the conan executable is not found because I don't have it system-wide installed (I installed via pip install conan --user, so it lives in ~/.local/bin)
Yep, after symlinking conan to /usr/bin, it works without a hitch.
I think cmake-conan has a configurable CONAN_COMMAND where you could provide the full path to conan executable. Is there any other suggestion of anything we could fix? Not sure what we could do to improve this issue.
Sorry I wasn't very explicit about this, but ~/.local/bin is in my $PATH (set in .bashrc), so I would expect the default conan command to work (without an absolute path). As mentioned, if I copy the logged command line to my terminal it works; and I think it should from cmake invoked via an IDE as well.
Thanks for clarifying! But the thing is that the IDE might not be using your .bashrc to set the $PATH, so from the IDE point of view it isn't there. Could this be the issue?
Yes, I think that's the issue. It's probably solvable by detecting the user's shell and loading the path from there. I assume there are more urgent issues on the backlog, but I'd appreciate if this could be kept open, maybe someone has valuable input on it. After all, this is (from a user point of view) a simple setup. I installed conan via pip and this cmake script can't invoke it via execute_process (I really don't want to install it system-wide because it tends to mess with my package manager).
Here's a related post on SO: http://stackoverflow.com/a/37663546/2515282
I've never used CLion myself, but it looks like a clean solution to add your ~/.local/bin to CLion's PATH.
Yeah, lets leave this open until we review the CLion flow too. Though it seems that the possible solution could be what @sixten-hilborn is pointing, because trying to detect the user's shell and loading the path from there, could be too complex and fragile, specially if we want to achieve that multi-OS. But we will have a look. Thanks everyone!
a note about clion: i was not able to modify PATH inside clion without breaking other things (even if it worked, you would have to do it for each build type...).
for linux, assuming you have conan installed via pip, the simplest solution is to launch clion from a shell (where ~/.local/bin is already in the path). clion is a bit hidden: ~/.local/share/JetBrains/Toolbox/apps/CLion/ch-0/173.4548.31/bin/clion.sh
a cleaner solution would be to setup CONAN_COMMAND and pass it to conan_cmake_run but then we would need to handle all possible conan locations inside our cmake scripts...
Thanks for the feedback @mistafunk
Unfortunately I can't think of any way to improve your issues from this cmake-conan project. A better integration with CLion will help, and it is something that is under consideration right now.
Just FYI this is also a problem in Qt Creator. It can be worked around with sudo ln -s ~/.local/bin/conan /usr/local/bin/conan. I haven't yet investigated if it could be fixed in other way.
Yep, after symlinking conan to /usr/bin, it works without a hitch.
Thank you! Had the same issue with yuzu emulator. Fixed with symlink:
sudo ln -s ~/.local/bin/conan /usr/bin/conan
Yep, after symlinking conan to /usr/bin, it works without a hitch.
Thank you! Had the same issue with yuzu emulator. Fixed with symlink:
sudo ln -s ~/.local/bin/conan /usr/bin/conan
Thanks, this worked for me to compile Yuzu.
Many years later we ran into the same problem (just not with conan). I don't think that symlinking is the right solution, it's more of a bandaid. Our solution was using find_program and passing ~/.local/bin as a hint. Then, CMake was able to find the binary and now we could execute it with the full path.
Yeah similarly:
find_program(CONAN_BIN NAMES conan PATHS $ENV{HOME}/.local/bin)
conan_cmake_run(CONANFILE "conanfile.py"
BUILD missing
# specify conan installed from the user local directory
CONAN_COMMAND "${CONAN_BIN}")
Works for us.
~~I was using this but it required I alter the existing conan.cmake.~~
find_program(CONAN_BIN NAMES conan PATHS $ENV{HOME}/.local/bin)
This I found was more useful in the long run. Thanks for the help.
sudo ln -s ~/.local/bin/conan /usr/bin/conan
You shouldn't need to edit conan.cmake for that to work, just place it in your projects root cmake file.
On Tue, May 24, 2022, 10:49 AM Robert Russell @.***> wrote:
I was using this but it required I alter the existing conan.cmake.
find_program(CONAN_BIN NAMES conan PATHS $ENV{HOME}/.local/bin) This I found was more useful in the long run. Thanks for the help. sudo ln -s ~/.local/bin/conan /usr/bin/conan
— Reply to this email directly, view it on GitHub https://github.com/conan-io/cmake-conan/issues/32#issuecomment-1136029485, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAOBAS2LBMSJ5P3DMS2NHWDVLTUAJANCNFSM4DLJTL3A . You are receiving this because you commented.Message ID: @.***>
~I was using this but it required I alter the existing conan.cmake.~
find_program(CONAN_BIN NAMES conan PATHS $ENV{HOME}/.local/bin)
This I found was more useful in the long run. Thanks for the help.
sudo ln -s ~/.local/bin/conan /usr/bin/conan
Sorry, which one do you use? find_program or ln -s. Because, in my case, I need to use the ln -s.
I ended up using sudo ln -s ~/.local/bin/conan /usr/bin/conan both methods work I didn't know I could use the find_program outside the conan.cmake. I had a custom conan.cmake for a while where I was doing that.