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.

[bug] CMakeToolchain behaviour is not always the same

See original GitHub issue

Environment Details (include every applicable attribute)

  • Operating System+version: Any (Windows 10 / Ubuntu 20.04)
  • Compiler+version: MSVC 16 / GCC 9
  • Conan version: 1.45.0
  • Python version: 3.9.10

When I add GLFW dependency (glfw/3.3.6), CMakeToolchain doesn’t produce the same content each time. Command: conan create . videoviewer/testing -pr:h=default -c tools.cmaketoolchain:generator=Ninja --build=missing

[Working time]

The content of glfw3Targets.cmake is

if(NOT TARGET glfw::glfw)
    add_library(glfw::glfw INTERFACE IMPORTED)
endif()

# Load the debug and release library finders
get_filename_component(_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
file(GLOB CONFIG_FILES "${_DIR}/glfw3Target-*.cmake")

foreach(f ${CONFIG_FILES})
    include(${f})
endforeach()

[Not working time]

The content of glfw3Targets.cmake is

# Load the debug and release variables
get_filename_component(_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
file(GLOB DATA_FILES "${_DIR}/glfw3-*-data.cmake")

foreach(f ${DATA_FILES})
    include(${f})
endforeach()

# Create the targets for all the components
foreach(_COMPONENT ${glfw_COMPONENT_NAMES} )
    if(NOT TARGET ${_COMPONENT})
        add_library(${_COMPONENT} INTERFACE IMPORTED)
        conan_message(STATUS "Conan: Component target declared '${_COMPONENT}'")
    endif()
endforeach()

if(NOT TARGET glfw)
    add_library(glfw INTERFACE IMPORTED)
    conan_message(STATUS "Conan: Target declared 'glfw'")
endif()
# Load the debug and release library finders
get_filename_component(_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
file(GLOB CONFIG_FILES "${_DIR}/glfw3-Target-*.cmake")

foreach(f ${CONFIG_FILES})
    include(${f})
endforeach()

Log is

PS C:\local\gitlab\cc\streaming\videoviewer> conan create . videoviewer/testing -pr:h=default -c tools.cmaketoolchain:generator=Ninja --build=missing
Exporting package recipe
videoviewer/0.1.0@videoviewer/testing exports_sources: Copied 4 '.txt' files: CMakeLists.txt, CMakeLists.txt, CMakeLists.txt, CMakeLists.txt
videoviewer/0.1.0@videoviewer/testing exports_sources: Copied 6 '.shader' files
videoviewer/0.1.0@videoviewer/testing exports_sources: Copied 8 '.h' files
videoviewer/0.1.0@videoviewer/testing exports_sources: Copied 1 '.in' file: version.h.in
videoviewer/0.1.0@videoviewer/testing exports_sources: Copied 1 '.rc' file: version.rc
videoviewer/0.1.0@videoviewer/testing exports_sources: Copied 5 '.cpp' files
videoviewer/0.1.0@videoviewer/testing exports_sources: Copied 4 files: .git, .gitignore, SConstruct, UNLICENSE
videoviewer/0.1.0@videoviewer/testing exports_sources: Copied 1 '.py' file: gl3w_gen.py
videoviewer/0.1.0@videoviewer/testing exports_sources: Copied 1 '.png' file: public-domain-mark.png
videoviewer/0.1.0@videoviewer/testing exports_sources: Copied 1 '.rst' file: README.rst
videoviewer/0.1.0@videoviewer/testing exports_sources: Copied 1 '.cmake' file: gl3w-config.cmake
videoviewer/0.1.0@videoviewer/testing exports_sources: Copied 3 '.c' files: gl3w.c, glfw_test.c, glut_test.c
videoviewer/0.1.0@videoviewer/testing: The stored package has not changed
videoviewer/0.1.0@videoviewer/testing: Exported revision: d61d3654f90ad4d2b79cffd8dd7c2a39
Configuration:
[settings]
arch=x86_64
arch_build=x86_64
build_type=Release
compiler=Visual Studio
compiler.cppstd=14
compiler.runtime=MD
compiler.version=16
os=Windows
os_build=Windows
[options]
[build_requires]
[env]
[conf]
tools.cmaketoolchain:generator=Ninja
videoviewer/0.1.0@videoviewer/testing: WARN: Package binary is corrupted, removing: 55dd02feed8e27b6b55bd1f360c729b88141ee92
videoviewer/0.1.0@videoviewer/testing (test package): Installing package
Requirements
    glfw/3.3.6 from 'conancenter' - Cache
    opengl/system from 'conancenter' - Cache
    videoviewer/0.1.0@videoviewer/testing from local cache - Cache
Packages
    glfw/3.3.6:d3cffeefc8c8bcb6be8abdd182cb1b56fc81bacc - Cache
    opengl/system:5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9 - Cache
    videoviewer/0.1.0@videoviewer/testing:55dd02feed8e27b6b55bd1f360c729b88141ee92 - Build

Installing (downloading, building) binaries...
opengl/system: Already installed!
glfw/3.3.6: Already installed!
videoviewer/0.1.0@videoviewer/testing: WARN: Build folder is dirty, removing it: C:\Users\ja\.conan\data\videoviewer\0.1.0\videoviewer\testing\build\55dd02feed8e27b6b55bd1f360c729b88141ee92
videoviewer/0.1.0@videoviewer/testing: Copying sources to build folder
videoviewer/0.1.0@videoviewer/testing: Building your package in C:\Users\ja\.conan\data\videoviewer\0.1.0\videoviewer\testing\build\55dd02feed8e27b6b55bd1f360c729b88141ee92
videoviewer/0.1.0@videoviewer/testing: Generator cmake_find_package_multi created glfw3-config-version.cmake
videoviewer/0.1.0@videoviewer/testing: Generator cmake_find_package_multi created glfw3-config.cmake
videoviewer/0.1.0@videoviewer/testing: Generator cmake_find_package_multi created glfw3Targets.cmake
videoviewer/0.1.0@videoviewer/testing: Generator cmake_find_package_multi created glfw3Target-release.cmake
videoviewer/0.1.0@videoviewer/testing: Generator cmake_find_package_multi created opengl_system-config-version.cmake
videoviewer/0.1.0@videoviewer/testing: Generator cmake_find_package_multi created opengl_system-config.cmake
videoviewer/0.1.0@videoviewer/testing: Generator cmake_find_package_multi created opengl_systemTargets.cmake
videoviewer/0.1.0@videoviewer/testing: Generator cmake_find_package_multi created opengl_systemTarget-release.cmake
videoviewer/0.1.0@videoviewer/testing: WARN: Using the new toolchains and generators without specifying a build profile (e.g: -pr:b=default) is discouraged and might cause failures and unexpected behavior
videoviewer/0.1.0@videoviewer/testing: Generator 'CMakeDeps' calling 'generate()'
videoviewer/0.1.0@videoviewer/testing: Calling generate()
videoviewer/0.1.0@videoviewer/testing: WARN: Using the new toolchains and generators without specifying a build profile (e.g: -pr:b=default) is discouraged and might cause failures and unexpected behavior
videoviewer/0.1.0@videoviewer/testing: Aggregating env generators
videoviewer/0.1.0@videoviewer/testing: CMake command: cmake -G "Visual Studio 16 2019" -DCMAKE_TOOLCHAIN_FILE="C:/Users/ja/.conan/data/videoviewer/0.1.0/videoviewer/testing/build/55dd02feed8e27b6b55bd1f360c729b88141ee92/conan_toolchain.cmake" -DCMAKE_INSTALL_PREFIX="C:/Users/ja/.conan/data/videoviewer/0.1.0/videoviewer/testing/package/55dd02feed8e27b6b55bd1f360c729b88141ee92" "C:\Users\ja\.conan\data\videoviewer\0.1.0\videoviewer\testing\build\55dd02feed8e27b6b55bd1f360c729b88141ee92"
Using Conan toolchain: C:/Users/ja/.conan/data/videoviewer/0.1.0/videoviewer/testing/build/55dd02feed8e27b6b55bd1f360c729b88141ee92/conan_toolchain.cmake.
-- Conan toolchain: C++ Standard 14 with extensions OFF
-- Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.19042.
-- The C compiler identification is MSVC 19.29.30139.0
-- The CXX compiler identification is MSVC 19.29.30139.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe - 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: C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Conan: Target declared 'opengl::opengl'
-- Found PythonInterp: C:/Program Files/WindowsApps/PythonSoftwareFoundation.Python.3.9_3.9.2800.0_x64__qbz5n2kfra8p0/python3.9.exe (found version "3.9.10")
-- Conan: Target declared 'glfw'
-- Library glfw3 found C:/Users/ja/.conan/data/glfw/3.3.6/_/_/package/d3cffeefc8c8bcb6be8abdd182cb1b56fc81bacc/lib/glfw3.lib
-- Found: C:/Users/ja/.conan/data/glfw/3.3.6/_/_/package/d3cffeefc8c8bcb6be8abdd182cb1b56fc81bacc/lib/glfw3.lib
CMake Error at glfw3-config.cmake:80 (set_property):
  set_property could not find TARGET glfw::glfw.  Perhaps it has not yet been
  created.
Call Stack (most recent call first):
  src/CMakeLists.txt:33 (find_package)


CMake Error at glfw3-config.cmake:90 (set_property):
  set_property could not find TARGET glfw::glfw.  Perhaps it has not yet been
  created.
Call Stack (most recent call first):
  src/CMakeLists.txt:33 (find_package)


CMake Error at glfw3-config.cmake:96 (set_property):
  set_property could not find TARGET glfw::glfw.  Perhaps it has not yet been
  created.
Call Stack (most recent call first):
  src/CMakeLists.txt:33 (find_package)


CMake Error at glfw3-config.cmake:102 (set_property):
  set_property could not find TARGET glfw::glfw.  Perhaps it has not yet been
  created.
Call Stack (most recent call first):
  src/CMakeLists.txt:33 (find_package)


-- Configuring incomplete, errors occurred!
See also "C:/Users/ja/.conan/data/videoviewer/0.1.0/videoviewer/testing/build/55dd02feed8e27b6b55bd1f360c729b88141ee92/CMakeFiles/CMakeOutput.log".
videoviewer/0.1.0@videoviewer/testing:
videoviewer/0.1.0@videoviewer/testing: ERROR: Package '55dd02feed8e27b6b55bd1f360c729b88141ee92' build failed
videoviewer/0.1.0@videoviewer/testing: WARN: Build folder C:\Users\ja\.conan\data\videoviewer\0.1.0\videoviewer\testing\build\55dd02feed8e27b6b55bd1f360c729b88141ee92
ERROR: videoviewer/0.1.0@videoviewer/testing: Error in build() method, line 62
        cmake.configure()
        ConanException: Error 1 while executing cmake -G "Visual Studio 16 2019" -DCMAKE_TOOLCHAIN_FILE="C:/Users/ja/.conan/data/videoviewer/0.1.0/videoviewer/testing/build/55dd02feed8e27b6b55bd1f360c729b88141ee92/conan_toolchain.cmake" -DCMAKE_INSTALL_PREFIX="C:/Users/ja/.conan/data/videoviewer/0.1.0/videoviewer/testing/package/55dd02feed8e27b6b55bd1f360c729b88141ee92" "C:\Users\ja\.conan\data\videoviewer\0.1.0\videoviewer\testing\build\55dd02feed8e27b6b55bd1f360c729b88141ee92"

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:15 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
memshardedcommented, Feb 15, 2022

No problem, it was our fault for that outdated docs! Thanks very much for reporting it, we will fix it asap 😃

0reactions
memshardedcommented, Feb 28, 2022

This was fixed like the day after, in https://github.com/conan-io/docs/pull/2398, the live docs don’t show that anymore, so I am closing this. Sorry for the trouble again and thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Conan / CMake Toolchain file defaulted to - Stack Overflow
The conan genrator I use is only the CMakeDeps generator (no CMakeToolchain generator). The build works fine on a build agent.
Read more >
CMAKE_CXX_FLAGS set by the toolchain file are not used ...
I may be missing something but I have the same behavior on current master (b3adccc8) and the CMakeLists.txt generated for the feature test ......
Read more >
Conan Documentation
Conan is a dependency and package manager for C and C++ languages. It is free and open-source, works in all platforms ( Windows,...
Read more >
Changelog
clang-tidy performs all the same checks by default, and scan-build was no longer working. See the bug for more details, but no user-side...
Read more >
cmake-toolchains(7) — CMake 3.25.1 Documentation
Some toolchain features have built-in handling in CMake, and do not require compile-tests. ... since it always has an unambiguous, predictable value.
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