cmakeconan

Unable to build conan package dependencies [GTest] with tool_requires(cmake)


I have such simple package in conanfile.py in root of my project that looks like this:

from conan import ConanFile
from conan.tools.cmake import CMakeToolchain, CMakeDeps, CMake, cmake_layout


class APL(ConanFile):
    name    = "***"
    version = "1.0.0"

    # Binary configuration
    settings = "os", "compiler", "build_type", "arch"
    generators = "VirtualBuildEnv"

    def build_requirements(self):
        self.tool_requires("cmake/3.22.6")
        self.test_requires("gtest/1.16.0")

    def configure(self):
        return
    def layout(self):
        cmake_layout(self)

    def generate(self):
        deps = CMakeDeps(self)
        deps.generate()

        tc = CMakeToolchain(self)
        tc.cache_variables["CONAN_PROJECT_VERSION"] = self.version
        tc.cache_variables["CONAN_PROJECT_NAME"] = self.name
        tc.generate()

    def build(self):
        cmake = CMake(self)
        cmake.configure()
        cmake.build()

When running conan install . --build missing i get an error from gtest dependency after conan runs:

[gtest/1.16.0: RUN:] cmake -G "MinGW Makefiles" 
-DCMAKE_TOOLCHAIN_FILE="generators/conan_toolchain.cmake" 
-DCMAKE_INSTALL_PREFIX="A:/Conan/p/b/gtest113aa6315e3a4/p" 
-DCMAKE_SH="CMAKE_SH-NOTFOUND" 
-DCMAKE_POLICY_DEFAULT_CMP0091="NEW" 
-DCMAKE_BUILD_TYPE="Debug"<br>  
"A:/Conan/p/b/gtest113aa6315e3a4/b/src"  

With such description:

'cmake' is not recognized as an internal or external command,
operable program or batch file.

While i don't have cmake installed system-wide (it is not mentioned in PATH) i expect gtest to catch it from

self.tool_requires("cmake/3.22.6")

but that doesn't happen. What am i doing wrong and how can i fix it?

Thanks for your help!

Full log of failure, inlcuding conan profile:

 conan install . -b missing

======== Input profiles ========
Profile host:
[settings]
arch=x86_64
build_type=Debug
compiler=gcc
compiler.cppstd=23
compiler.libcxx=libstdc++
compiler.version=14
os=Windows

Profile build:
[settings]
arch=x86_64
build_type=Debug
compiler=gcc
compiler.cppstd=23
compiler.libcxx=libstdc++
compiler.version=14
os=Windows


======== Computing dependency graph ========
Graph root
    conanfile.py (alarm-point-lib/1.0.0): G:\cpp\alarm-point-library\conanfile.py
Test requirements
    gtest/1.16.0#4fd8d9d80636ea9504de6a0ec1ab8686 - Cache
Build requirements
    cmake/3.22.6#32cced101c6df0fab43e8d00bd2483eb - Cache

======== Computing necessary packages ========
Connecting to remote 'conancenter' anonymously
Test requirements
    gtest/1.16.0#4fd8d9d80636ea9504de6a0ec1ab8686:36b58f8adc45de83a03da2d614722cbcac25bc82 - Build
Build requirements
    cmake/3.22.6#32cced101c6df0fab43e8d00bd2483eb:522dcea5982a3f8a5b624c16477e47195da2f84f#a9d024f459972755e5a815b775408fff - Cache

======== Installing packages ========
cmake/3.22.6: Already installed! (1 of 2)
cmake/3.22.6: Appending PATH environment variable: A:\Conan\p\cmake1927748c2604b\p\bin

-------- Installing package gtest/1.16.0 (2 of 2) --------
gtest/1.16.0: Building from source
gtest/1.16.0: Package gtest/1.16.0:36b58f8adc45de83a03da2d614722cbcac25bc82
gtest/1.16.0: Copying sources to build folder
gtest/1.16.0: Building your package in A:\Conan\p\b\gtest74bcb8da0522a\b
gtest/1.16.0: Calling generate()
gtest/1.16.0: Generators folder: A:\Conan\p\b\gtest74bcb8da0522a\b\build\Debug\generators
gtest/1.16.0: CMakeToolchain generated: conan_toolchain.cmake
gtest/1.16.0: CMakeToolchain generated: A:\Conan\p\b\gtest74bcb8da0522a\b\build\Debug\generators\CMakePresets.json
gtest/1.16.0: CMakeToolchain generated: A:\Conan\p\b\gtest74bcb8da0522a\b\src\CMakeUserPresets.json
gtest/1.16.0: Generating aggregated env files
gtest/1.16.0: Generated aggregated env files: ['conanbuild.bat', 'conanrun.bat']
gtest/1.16.0: Calling build()
gtest/1.16.0: apply_conandata_patches(): No patches defined in conandata
gtest/1.16.0: Running CMake.configure()
gtest/1.16.0: RUN: cmake -G "MinGW Makefiles" -DCMAKE_TOOLCHAIN_FILE="generators/conan_toolchain.cmake" -DCMAKE_INSTALL_PREFIX="A:/Conan/p/b/gtest74bcb8da0522a/p" -DCMAKE_SH="CMAKE_SH-NOTFOUND" -DCMAKE_POLICY_DEFAULT_CMP0091="NEW" -DCMAKE_BUILD_TYPE="Debug" "A:/Conan/p/b/gtest74bcb8da0522a/b/src"
'cmake' is not recognized as an internal or external command,
operable program or batch file.

gtest/1.16.0: ERROR:
Package '36b58f8adc45de83a03da2d614722cbcac25bc82' build failed
gtest/1.16.0: WARN: Build folder A:\Conan\p\b\gtest74bcb8da0522a\b\build\Debug
ERROR: gtest/1.16.0: Error in build() method, line 140
        cmake.configure()
        ConanException: Error 1 while executing

My environment: CLion 2025.1, Windows 10, MinGW build tools


Solution

  • I think you'll have to add cmake to your default profile.

    So something like:

    conan profile detect --force 
    conan profile show default
    

    That should tell you were your conan profile is located (probably ~/.conan2/profiles/default ). Open that file, and at the end add:

    [tool_requires] 
    cmake/3.22.6
    

    Finally, rebuild:

    conan install . --build=missing --profile=default