conan: [bug] Conan 1.48.0 breaks CMakeDeps / CMakeToolchain

Environment Details

  • Operating System+version: Ubuntu 20.04
  • Compiler+version: GCC 9
  • Conan version: 1.48.0
  • Python version: 3.8.10
  • CMake version: 3.22.2

Steps to reproduce

conanfile.txt:

[requires]
fmt/8.1.1

[generators]
CMakeDeps
CMakeToolchain

CMakeLists.txt:

cmake_minimum_required(VERSION 3.16)
project(reproduction)

find_package(fmt REQUIRED)

add_executable(reproduction)
target_link_libraries(reproduction PRIVATE fmt::fmt)
target_sources(reproduction PRIVATE main.cpp)

main.cpp:

#include <fmt/format.h>

int main() {}

Logs (Executed commands with output)

$ mkdir build && cd build
$ conan install .. -pr:b=default
Configuration (profile_host):
[settings]
arch=x86_64
arch_build=x86_64
build_type=Debug
compiler=gcc
compiler.libcxx=libstdc++11
compiler.version=9
os=Linux
os_build=Linux
[options]
*:fPIC=True
*:shared=False
[build_requires]
[env]

Configuration (profile_build):
[settings]
arch=x86_64
arch_build=x86_64
build_type=Debug
compiler=gcc
compiler.libcxx=libstdc++11
compiler.version=9
os=Linux
os_build=Linux
[options]
*:fPIC=True
*:shared=False
[build_requires]
[env]

conanfile.txt: Installing package
Requirements
    fmt/8.1.1 from 'conan-center' - Cache
Packages
    fmt/8.1.1:4eb2d280e3273c9ab04b4c51b456b2a272ff6fc3 - Cache

Installing (downloading, building) binaries...
fmt/8.1.1: Already installed!
conanfile.txt: Generator 'CMakeToolchain' calling 'generate()'
conanfile.txt: Generator txt created conanbuildinfo.txt
conanfile.txt: Generator 'CMakeDeps' calling 'generate()'
conanfile.txt: Aggregating env generators
conanfile.txt: Generated conaninfo.txt
conanfile.txt: Generated graphinfo
$ cmake .. --toolchain=conan_toolchain.cmake
-- Using Conan toolchain: /root/repro/build/conan_toolchain.cmake
-- The C compiler identification is GNU 9.3.0
-- The CXX compiler identification is GNU 9.3.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Conan: Target declared 'fmt::fmt'
-- Configuring done
-- Generating done
-- Build files have been written to: /root/repro/build
$ VERBOSE=1 make
/usr/local/lib/python3.8/dist-packages/cmake/data/bin/cmake -S/root/repro -B/root/repro/build --check-build-system CMakeFiles/Makefile.cmake 0
/usr/local/lib/python3.8/dist-packages/cmake/data/bin/cmake -E cmake_progress_start /root/repro/build/CMakeFiles /root/repro/build//CMakeFiles/progress.marks
make  -f CMakeFiles/Makefile2 all
make[1]: Entering directory '/root/repro/build'
make  -f CMakeFiles/reproduction.dir/build.make CMakeFiles/reproduction.dir/depend
make[2]: Entering directory '/root/repro/build'
cd /root/repro/build && /usr/local/lib/python3.8/dist-packages/cmake/data/bin/cmake -E cmake_depends "Unix Makefiles" /root/repro /root/repro /root/repro/build /root/repro/build /root/repro/build/CMakeFiles/reproduction.dir/DependInfo.cmake --color=
make[2]: Leaving directory '/root/repro/build'
make  -f CMakeFiles/reproduction.dir/build.make CMakeFiles/reproduction.dir/build
make[2]: Entering directory '/root/repro/build'
[ 50%] Building CXX object CMakeFiles/reproduction.dir/main.cpp.o
/usr/bin/c++   -m64 -MD -MT CMakeFiles/reproduction.dir/main.cpp.o -MF CMakeFiles/reproduction.dir/main.cpp.o.d -o CMakeFiles/reproduction.dir/main.cpp.o -c /root/repro/main.cpp
/root/repro/main.cpp:2:10: fatal error: fmt/format.h: No such file or directory
    2 | #include <fmt/format.h>
      |          ^~~~~~~~~~~~~~
compilation terminated.
make[2]: *** [CMakeFiles/reproduction.dir/build.make:76: CMakeFiles/reproduction.dir/main.cpp.o] Error 1
make[2]: Leaving directory '/root/repro/build'
make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/reproduction.dir/all] Error 2
make[1]: Leaving directory '/root/repro/build'
make: *** [Makefile:91: all] Error 2

Other

It can be seen that the include path to the package is not added to the build command.

Can be reproduced with other packages (I also tried nlohmann_json/3.10.5).

The issue is not present with conan 1.47.0

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 16 (9 by maintainers)

Most upvoted comments

@memsharded Do we also have to enforce CMAKE_BUILD_TYPE when CMake is called with CMakeToolchain + CMake helper? In source code, CMake helper comments claim that only --config Release is passed for multi-config generators, but what about single-config generators?

In single-config generators, CMake is passing -DCMAKE_BUILD_TYPE, extracted from the CMakePresets.json file. It is more idiomatic than having it defined in the toolchain.cmake file.

@memsharded Thanks for helping me out! I really appreciate it. Good luck!