Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix unknown command error in CMake, when I using Conan?

I've got CMakeLists.txt file:

project(ip_filter LANGUAGES CXX)
cmake_minimum_required(VERSION 2.8)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()

add_executable(ip_filter ip_filter.cpp)
target_link_libraries(ip_filter ${CONAN_LIBS})

At the same folder, I've got a conanfile.txt:

[requires]
range-v3/0.9.1@ericniebler/stable

[generators]
cmake

When I tried to build it, using:

$ cmake CMakeLists.txt

I've got this output:

CMake Error at CMakeLists.txt:4 (include):
  include could not find load file:

    /home/bogdasar/Documents/C++_Programming/ip_filter/conanbuildinfo.cmake


CMake Error at CMakeLists.txt:5 (conan_basic_setup):
  Unknown CMake command "conan_basic_setup".


-- Configuring incomplete, errors occurred!
See also "/home/bogdasar/Documents/C++_Programming/ip_filter/CMakeFiles/CMakeOutput.log".
like image 779
Bogdasar Avatar asked Apr 01 '20 09:04

Bogdasar


1 Answers

I was stuck on the same issue for a while. After going through few threads I found the solution. Here I am summarizing the same.

Problem here is cmake is unable to find conanbuildinfo.cmake. This file should be generated when you call conan install.

If it is not getting generated then you should include cmake generator in conanfile.py. Like below:

generators = "virtualenv", "virtualrunenv", "cmake_find_package", "cmake"

or you can mention the same in your conan profile. Like below:

[generators]
cmake

Once this file is generated, cmake should be able to find it. And conan_basic_setup() step should pass.

like image 193
rakesh.sahu Avatar answered Sep 28 '22 13:09

rakesh.sahu