conan-io / conan

Conan - The open-source C and C++ package manager
https://conan.io
MIT License
8.25k stars 980 forks source link

Could not find toolchain file when calling CMake after installing the GDAL package #17209

Open amine-aboufirass opened 1 week ago

amine-aboufirass commented 1 week ago

I would like to write some code which has GDAL as a dependency. Here's what I came up with so far:

profile

[settings]
arch=x86_64
build_type=Debug
compiler=msvc
compiler.cppstd=17
compiler.runtime=dynamic
compiler.version=194
os=Windows

conanfile.txt

[requires]
gdal/3.8.3
[generators]
CMakeDeps
CMakeToolchain
[layout]
cmake_layout

CMakeLists.txt

cmake_minimum_required(VERSION 3.15)
project(TestGdal)

find_package(GDAL REQUIRED)

add_executable(${PROJECT_NAME} src/main.cpp)
target_link_libraries(${PROJECT_NAME} GDAL::GDAL)

CMakeUserPresets.json

{
    "version": 4,
    "vendor": {
        "conan": {}
    },
    "include": [
        "build\\build\\generators\\CMakePresets.json"
    ]
}

I followed the Getting Started portion of the Conan docs as closely as was necessary. It does so happen that I would like to debug the code, so I am focusing on creating a debug configuration. The following install command took a WHILE, but appears to have run successfully:

conan install . --output-folder=build --build=missing --profile=profile

I then cd to my build directory and run the following:

cmake .. -DCMAKE_TOOLCHAIN_FILE="conan_toolchain.cmake"

This unfortunately fails with an error:

CMake Error at C:/Program Files/CMake/share/cmake-3.31/Modules/CMakeDetermineSystem.cmake:152 (message): Could not find toolchain file: conan_toolchain.cmake Call Stack (most recent call first): CMakeLists.txt:2 (project)

-- Configuring incomplete, errors occurred! MSBuild version 17.11.9+a69bbaaf5 for .NET Framework MSBUILD : error MSB1009: Project file does not exist. Switch: ALL_BUILD.vcxproj

What could I possibly be doing wrong here?

amine-aboufirass commented 1 week ago

I also notice that a directory called p has been created in $HOME/.conan2 which weighs over 10GB. Not sure what that's doing there....

memsharded commented 1 week ago

Hi @amine-aboufirass

Thanks for your question

conan install . --output-folder=build

It seems this is an issue with the paths. If your conanfile has cmake_layout, this is typically no longer necessary. Then please check the output, when you run conan install in the output messages you will see the real location of the different generated files. The conan toolchain will be somewhere more like:

$ cmake . -DCMAKE_TOOLCHAIN_FILE=build/generators/conan_toolchain.cmake

Also, in many cases and if using CMake>=3.23, it is more convenient to just use the generated presets, so

$ cmake --preset conan-default
$ cmake --build --preset conan-debug

I also notice that a directory called p has been created in $HOME/.conan2 which weighs over 10GB. Not sure what that's doing there....

Yes, that is the Conan cache, where the actual packages are installed, and yes, the C++ packages can be large, 10Gb sounds a bit too much unless you are installing a ton of dependencies. It also depends on different factors, for example Debug packages use way more space than Release packages

memsharded commented 10 hours ago

Hi @amine-aboufirass

Any further question or issue here? If not maybe we can close the ticket? Thanks for your feedback.