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.

conan create fails with can't find conanbuildinfo.cmake

See original GitHub issue

I 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:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
czoidocommented, Jun 17, 2020

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:

if(CONAN_EXPORTED) # in conan local cache
    include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
    conan_basic_setup(TARGETS)
else() # in user space
    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)
endif()

That’s probably what’s causing your problems. Hope this helps, please check and tell me if it solves your problems.

0reactions
czoidocommented, Dec 2, 2020

As this issue seems solved, I’ll close it. Please reopen if you have more questions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to fix unknown command error in CMake, when I using ...
Problem here is cmake is unable to find conanbuildinfo.cmake. This file should be generated when you call conan install.
Read more >
Using Visual Studio 2017 - CMake integration - Conan Docs
As expected, our CMakeLists.txt is using an include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) , and that file doesn't exist yet, because Conan has not yet ...
Read more >
Conan Integration — ApprovalTests.cpp documentation
cmake_minimum_required(VERSION 3.14 FATAL_ERROR) project(conan_cmake) # Conan's cmake generator creates a conanbuildinfo.cmake file, which we # need to ...
Read more >
Conan and resolving dependencies in a C++ project
Ideally that would be CMake, because that is our main build system. If a library doesn't have a project file, then it could...
Read more >
Cmake Conan - Github Mirror - GitLab - AIMMS
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) ... It will make the configure, auto-detect and install in one step so if you plan to use ...
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