When I run the conan install command, as specified below, I expect to generate conan_toolchain.cmake
and a conan_deps.cmake
files in my output folder. But only conan_toolchain.cmake
is present. And from the conan_deps.cmake
, I expect the ${CONAN_INCLUDE_DIRS}
to correctly add the directories of the build sources. Also note, this code worked fine with conan 1.x, using cmake
as the generator, conan_basic_setup() in the cmakelist, and using the conanbuildinfo.cmake
file previously generated.
When I run the following... `
(.env) user@mercury:~/dev/myapp$ conan install . --output-folder=cmake-build-debug -g CMakeToolchain -g CMakeDeps
I expect to generate ${CMAKE_BINARY_DIR}/conan_deps.cmake
. I've searched through the conan documentation, but they all say to expect the file.
Top level CMakeList.txt
make_minimum_required (VERSION 3.10)
set (CMAKE_CXX_STANDARD 17)
project (Ares)
include(${CMAKE_BINARY_DIR}/conan_toolchain.cmake)
include(${CMAKE_BINARY_DIR}/conan_deps.cmake) # this is not found
#conan_basic_setup()
message(STATUS "Conan Include Dirs: ${CONAN_INCLUDE_DIRS}") ## this is returning empthy
message(STATUS "Binary Dirs: ${CMAKE_BINARY_DIR}")
include(${CMAKE_BINARY_DIR}/conan_deps.cmake)
get_cmake_property(_variableNames VARIABLES)
list (SORT _variableNames)
foreach (_variableName ${_variableNames})
message(STATUS "${_variableName}=${${_variableName}}")
endforeach()
unset(BUILD_TEST CACHE)
option(BUILD_TEST "Build the unit tests" ON)
if(BUILD_TEST)
enable_testing()
message(STATUS "Building Unit Tests")
endif()
if(NOT (UNIX AND CMAKE_COMPILER_IS_GNUCXX))
message(FATAL_ERROR "Must compile on UNIX with GCC" )
endif()
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-march=native" COMPILER_SUPPORTS_MARCH_NATIVE)
if(COMPILER_SUPPORTS_MARCH_NATIVE)
message(STATUS "Using Native Architecture Flag")
add_compile_options("-march=native")
endif()
# Add warnings
add_compile_options("-Wall" "-Wextra" "-Wno-unknown-pragmas" "-Wno-int-in-bool-context" "-Wno-unused-parameter" "-Werror=switch" "-Wno-empty-body")
# Use -03 optimizations if in release
add_compile_options("$<$<CONFIG:RELEASE>:-O3>")
add_compile_options("$<$<CONFIG:DEBUG>:--coverage>")
link_libraries("$<$<CONFIG:DEBUG>:--coverage>")
if(NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
message(WARNING "You are using an unsupported compiler! Compilation has only been tested with GCC.")
endif()
add_definitions(-DSBE_HAVE_CMATH)
#add_definitions(-DSBE_NO_BOUNDS_CHECK)
add_definitions(-DHFFIX_NO_BOOST_DATETIME)
#add_definitions(-DQL_USE_STD_SHARED_PTR)
include( modules/VersionFromGit.cmake )
add_subdirectory (schemas)
add_subdirectory (platform)
Here is the summary of the output...
======== Finalizing install (deploy, generators) ========
conanfile.txt: Writing generators to /home/user/dev/myapp/cmake-build-debug
conanfile.txt: Generator 'CMakeDeps' calling 'generate()'
conanfile.txt: Generator 'CMakeToolchain' calling 'generate()'
conanfile.txt: CMakeToolchain generated: conan_toolchain.cmake
conanfile.txt: Preset 'conan-release' added to CMakePresets.json. Invoke it manually using 'cmake --preset conan-release' if using CMake>=3.23
conanfile.txt: If your CMake version is not compatible with CMakePresets (<3.23) call cmake like: 'cmake <path> -G "Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=/home/user/dev/myapp/cmake-build-debug/conan_toolchain.cmake -DCMAKE_POLICY_DEFAULT_CMP0091=NEW -DCMAKE_BUILD_TYPE=Release'
conanfile.txt: CMakeToolchain generated: CMakePresets.json
conanfile.txt: CMakeToolchain generated: ../CMakeUserPresets.json
conanfile.txt: Generating aggregated env files
conanfile.txt: Generated aggregated env files: ['conanbuild.sh', 'conanrun.sh']
Install finished successfully
In Conan 1.X the cmake
legacy generator created a conanbuildinfo.cmake
file that could be included in the CMakeLists.txt
with include(.../conanbuildinfo.cmake)
This generator was superseded some time ago, already in Conan 1.X (this is not specific of Conan 2.0) by the CMakeToolchain
and CMakeDeps
, that implements a full transparent integration, that means, they can be used without modifying at all the CMakeLists.txt
in any way that is specific to Conan, and they can be fully agnostic. This is achieved by:
CMakeToolchain
generates a toolchain file that can be passed in -DCMAKE_TOOLCHAIN_FILE=...
argument in command line (or defined in CMakePresets, also generated by Conan, so just calling cmake --preset ...
works)CMakeDeps
generates different xxx-config.cmake
files, one per dependency, so the CMakeLists.txt
can use them just with the standard and CMake-blessed way of doing find_package(pkgname)
and then linked with target_link_libraries(... pkg::pkg)