conan create fails with can't find conanbuildinfo.cmake
See original GitHub issueI have been trying to use conan_cmake_run
in my CMakeLists.txt
files to allow conan to be run in the cmake configure step, such that I can build a project or subproject with (from the source directory) cd build && cmake -DCMAKE_BUILD_TYPE=Debug .. && cmake --build .
This all works nicely.
However, when I now try to package up my project by running, from the source directory, conan create .
, I get errors originating from conan.cmake
that it cannot find conanbuildinfo.cmake
.
I have an example below that I’ve tried my best to make minimal, to demonstrate the problem.
Directory structure:
- bla
- CMakeLists.txt
- conanfile.py
- bla.cpp
bla/CMakeLists.txt
cmake_minimum_required(VERSION 3.14)
project(bla)
set(CMAKE_VERBOSE_MAKEFILE TRUE)
if(NOT EXISTS "${CMAKE_BINARY_DIR}/conan.cmake")
file(DOWNLOAD "https://github.com/conan-io/cmake-conan/raw/v0.15/conan.cmake" "${CMAKE_BINARY_DIR}/conan.cmake")
endif()
include(${CMAKE_BINARY_DIR}/conan.cmake)
conan_cmake_run(CONANFILE conanfile.py BASIC_SETUP CMAKE_TARGETS BUILD missing)
add_executable(${PROJECT_NAME} bla.cpp)
target_link_libraries(${PROJECT_NAME} PUBLIC CONAN_PKG::range-v3)
bla/conanfile.py
from conans import ConanFile, CMake, tools
import shutil
class BlaConan(ConanFile):
name = "bla"
version = "0.1"
settings = "os", "compiler", "build_type", "arch"
options = {"shared": [True, False]}
default_options = {"shared": False}
generators = "cmake"
requires = "range-v3/0.10.0"
_cmake = None
def _configure_cmake(self):
if self._cmake:
return self._cmake
self._cmake = CMake(self)
self._cmake.configure(source_folder = "source_folder", build_folder = "build_folder")
return self._cmake
def source(self):
shutil.copytree("/absolute/path/to/bla", "source_folder")
def build(self):
cmake = self._configure_cmake()
cmake.build()
bla/bla.cpp
#include <iostream>
#include <range/v3/all.hpp>
int main() { std::cout << "Hello world" << "\n"; }
The example code as presented will fail when calling conan create .
from bla
. The important bit of the error message from cmake as reported by conan:
...
CMake Error at /home/justin/.conan/data/bla/0.1/_/_/build/6e41abfb5a7d95fbe289321565b7c1d2f35255f2/build_folder/conan.cmake:461 (message):
conanbuildinfo.cmake doesn't exist in
/home/justin/.conan/data/bla/0.1/_/_/build/6e41abfb5a7d95fbe289321565b7c1d2f35255f2/build_folder
Call Stack (most recent call first):
/home/justin/.conan/data/bla/0.1/_/_/build/6e41abfb5a7d95fbe289321565b7c1d2f35255f2/build_folder/conan.cmake:502 (conan_load_buildinfo)
CMakeLists.txt:8 (conan_cmake_run)
...
conan cmake
is complaining that at the path /home/justin/.conan/data/bla/0.1/_/_/build/6e41abfb5a7d95fbe289321565b7c1d2f35255f2/build_folder
there is no file conanbuildinfo.cmake
. And it’s right, there isn’t.
However, that file is present, one directory up, at /home/justin/.conan/data/bla/0.1/_/_/build/6e41abfb5a7d95fbe289321565b7c1d2f35255f2/
?
This very simple example will work if you remove the build_folder = "build_folder"
in the conanfile.py
’s cmake.configure call, although this seems more like a coincidence.
My actual use case is more complex and involves nested calls of cmake’s add_subdirectory
, where those subfolders also can’t find conanbuildinfo.cmake
and look in the wrong place - they fail with the same kind of error, not being able to find conanbuildinfo.cmake
. I have omitted a more complex example (with subdirectories) here as this post is long enough, and I hope if someone can show me a fix for this those may be fixed too.
Ideally a solution would allow me the ability, as I have now, to build my project from the parent or a subproject (each resolving their own conan dependencies) with cd build && cmake -DCMAKE_BUILD_TYPE=Debug .. && cmake --build .
or similar, and additionally allow conan create .
from the parent project directory to work.
I would like to ask:
- How can I fix this, what am I doing wrong?
- Is this a poor way to structure a project? If so, what is the alternative? I am presuming what I want is possible but I’m ignorant and perhaps am going about this the wrong way?
Cheers if you’ve read till here, I realise this is a bit long and appreciate your time.
Ubuntu, x64, Conan 1.26.0, cmake-conan release 0.15, cmake 3.17
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:10 (5 by maintainers)
Top GitHub Comments
Hi @Arghnews , If you want to use the same
CMakeLists.txt
for both consuming you should differentiate when you are running in the local cache and when in your local folder doing something like this:That’s probably what’s causing your problems. Hope this helps, please check and tell me if it solves your problems.
As this issue seems solved, I’ll close it. Please reopen if you have more questions.