conan-io / conan

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

[question] Can't find package configuration file for pre-build binary package #17148

Closed dwswingle closed 1 month ago

dwswingle commented 1 month ago

What is your question?

Hello,

I am trying to create a pre-built binary package and have it be consumed by a C++ CMake project. I'm currently getting the following error:

CMake Error at CMakeLists.txt:15 (find_package): Could not find a package configuration file provided by testme" with any of the following names: testmeConfig.cmake testme-config.cmake Add the installation prefix of "testme" to CMAKE_PREFIX_PATH or set "testme_DIR" to a directory containing one of the above files. If "testme" provides a separate development package or SDK, be sure it has been installed.

Here is my current conanfile.py below. What am I missing? I'm not sure how to add the CMake generation items in this:

import_ os
from conan.tools.files import get, copy
from conan import ConanFile

class helloRecipe(ConanFile):
    name = "testme"
    settings = "os", "arch"

    def set_version(self):
        self.version = os.environ['generated_version_tag']

    def build(self):
        get(self, "https://artifactory.test.com/artifactory/generic-sandbox/testme/testme-Linux_2.6_x86_64_gcc85-Release.tgz")        

    def package(self):
        copy(self, "*.h*", self.build_folder, os.path.join(self.package_folder, "include"))
        copy(self, "*.a", self.build_folder, os.path.join(self.package_folder, "lib"))
        copy(self, "*.so*", self.build_folder, os.path.join(self.package_folder, "lib"))
        copy(self, "*.lic", self.build_folder, os.path.join(self.package_folder, "licenses"))

    def package_info(self):
        self.cpp_info.libs = ["testme_cf",
                "testme_cxx",
                "testme_xml",
                "testme_provider",
                "testme_dyntype",
                "testme_dyntype_xml" ]
        self.cpp_info.includedirs = [ "include/testme/target/include",
                "include/testme/target/include/dds_cxx" ]
        self.cpp_info.libdirs = [ "lib/testme/target/Linux_2.6_x86_64_gcc85/lib" ]

Have you read the CONTRIBUTING guide?

memsharded commented 1 month ago

Hi @dwswingle

Thanks for your question.

The usage from the consumer side is as important as having the right recipe: which generators are you using, which commands... If you can please report:

That might help to understand what could be missing.

Some extra tips:

dwswingle commented 1 month ago

conanfile I'm using to consume the package:

from conan import ConanFile
from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout, CMakeDeps
from conan.tools.build import check_min_cppstd
from os import environ, path

class CoreRecipe(ConanFile):
    name = "core"
    package_type = "shared-library"
    exports_sources = "cmake/*", "example/*", "interface_builder/*", "cyclone_interface/*", "CMakeLists.txt"

    settings = "os", "compiler", "build_type", "arch"

    def requirements(self):
        self.requires("cyclonedds/0.10.4", transitive_libs=True, transitive_headers=True)
        self.requires("cyclonedds-cxx/0.10.4", transitive_libs=True, transitive_headers=True)
        self.requires("testme/v0.0.1")

        self.tool_requires("ninja/1.12.1")
        self.tool_requires("cmake/3.29.5")

    def set_version(self):
        self.version = environ['generated_version_tag']

    def validate(self):
        check_min_cppstd(self, "17")

    def layout(self):
        cmake_layout(self, generator="Ninja")

    def generate(self):
        deps = CMakeDeps(self)
        deps.generate()
        tc = CMakeToolchain(self, generator="Ninja")
        tc.variables["USING_CONAN"] = True
        tc.user_presets_path = 'ConanPresets.json'
        tc.generate()

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

    def package(self):
        cmake = CMake(self)
        cmake.install()

    def package_info(self):

        cmake_modules = list()
        cmake_modules.append(path.join("cmake/modules", "generated_dds_dependencies.cmake"))
        cmake_modules.append(path.join("cmake/modules", "generated_dds_interface.cmake"))
        cmake_modules.append(path.join("cmake/modules", "idl_rules.cmake"))
        self.cpp_info.set_property("cmake_build_modules", cmake_modules)

        self.cpp_info.components["CMakeScripts"].includedirs= ["cmake/modules"]
        self.cpp_info.components["InterfaceBuilder"].includedirs= ["scripts/InterfaceBuilder"]

commands executing:

conan install . -pr:b default-abi11 -pr:h default-abi11 -b missing -s build_type=Release
source build/Release/generators/conanbuild.sh
cmake --preset conan-Release
cmake --build --preset conan-Release
conan export-pkg . -pr:b default-abi11 -pr:h default-abi11 -s build_type=Release

fails on the build step:

CMake Error at example/CMakeLists.txt:15 (find_package):
  Could not find a package configuration file provided by "testme" with
  any of the following names:

    testmeConfig.cmake
    testme-config.cmake

  Add the installation prefix of "testme" to CMAKE_PREFIX_PATH or set
  "testme_DIR" to a directory containing one of the above files.  If
  "testme" provides a separate development package or SDK, be sure it
  has been installed.

-- Configuring incomplete, errors occurred!

I do have a test package that passes, but maybe I implemented it incorrect. Let me review that. Will also review the additional tips. thank you!

memsharded commented 1 month ago

Thanks for sharing those details!

fails on the build step:

It seems you are using your own presets that include the Conan generated ones. Can you post the full output of the cmake --preset conan-Release command?

One thing that could be related, though I am not sure if it would fix, is that you package (the exported-pkg one, not the consumer one) is missing a package_type. If it is a shared library, it should probably be package_type = "shared-library".

memsharded commented 1 month ago

Hi @dwswingle

Did the package_type hint help to solve the issue? If not, please share the output of that cmake command. Any further question or issue here? thanks for the feedback.

dwswingle commented 1 month ago

I’m trying it out this morning and will respond back

dwswingle commented 1 month ago

I think I just realized that my "test_package" folder isn't being called when I run "conan create". I have no top level CMakeLists.txt because the repo is pulling remote binaries. what is best practice to invoke it? something in conanfile.py? Should I create a top level CMakeList for the sake of calling the test package? thanks

dwswingle commented 1 month ago

I stand corrected. test_package is running when I run "conan create", but I still can't consume the package with the added package_type

memsharded commented 1 month ago

I have been reviewing the details above, and there might be some small detail that we are missing.

It would be necessary to have more information. Ideally to have a fully reproducible example, these cases can be typically reduced to a simple "minimal reproducible case" removing lots of things.

If not, the exact commands used and the full output of those commands (with an update of the conanfile.py, test_package/conanfile.py, test_package/CMakeLists.txt). Or if using a consuming project instead of the test_package one, updated conanfile and CMakeLists.txt would help.

Thanks for your feedback.

dwswingle commented 1 month ago

I have been reviewing the details above, and there might be some small detail that we are missing.

It would be necessary to have more information. Ideally to have a fully reproducible example, these cases can be typically reduced to a simple "minimal reproducible case" removing lots of things.

If not, the exact commands used and the full output of those commands (with an update of the conanfile.py, test_package/conanfile.py, test_package/CMakeLists.txt). Or if using a consuming project instead of the test_package one, updated conanfile and CMakeLists.txt would help.

Thanks for your feedback.

copy, will provide

dwswingle commented 1 month ago

conanfile.py

import os
from conan.tools.files import get, copy
from conan import ConanFile

class CoreDXRecipe(ConanFile):
    name = "coredx5.19.0"
    package_type = "shared-library"    
    settings = "os", "arch"

    def set_version(self):
        self.version = os.environ['generated_version_tag']

    def build(self):
        get(self, "https://artifactory.test.com/artifactory/generic-sandbox/CoreDX/coredx-5.19.0-Linux_2.6_x86_64_gcc85-Release.tgz")        

    def package(self):
        copy(self, "*.h*", self.build_folder, os.path.join(self.package_folder, "include"))
        copy(self, "*.a", self.build_folder, os.path.join(self.package_folder, "lib"))
        copy(self, "*.so*", self.build_folder, os.path.join(self.package_folder, "lib"))
        copy(self, "*.lic", self.build_folder, os.path.join(self.package_folder, "licenses"))

    def package_info(self):
        self.cpp_info.libs = ["dds_cf",
                "dds_cxx",
                "dds_xml",
                "dds_qos_provider",
                "dds_dyntype",
                "dds_dyntype_xml" ]
        self.cpp_info.includedirs = [ "include/coredx-5.19.0/target/include",
                "include/coredx-5.19.0/target/include/dds_cxx" ]
        self.cpp_info.libdirs = [ "lib/coredx-5.19.0/target/Linux_2.6_x86_64_gcc85/lib" ]

test_package/conanfile.py

import os

from conan import ConanFile
from conan.tools.cmake import CMake, cmake_layout
from conan.tools.build import can_run

class CoreDXTestConan(ConanFile):
    settings = "os", "compiler", "build_type", "arch"
    package_type = "shared-library"
    generators = "CMakeDeps", "CMakeToolchain"

    def requirements(self):
        self.requires(self.tested_reference_str)
        self.tool_requires("ninja/1.12.1")
        self.tool_requires("cmake/3.30.5")

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

    def layout(self):
        cmake_layout(self)

    def test(self):
        if can_run(self):
            cmd = os.path.join(self.cpp.build.bindir, "example")
            self.run(cmd, env="conanrun")

test_package/CMakeLists.txt

cmake_minimum_required(VERSION 3.15)
project( PackageTest )

find_package( coredx5.19.0 CONFIG REQUIRED  )

add_executable( example src/example.cpp )
target_link_libraries( example coredx5.19.0::coredx5.19.0 )

running

conan install . -pr:b abi11 -pr:h abi11 -s build_type=Debug
conan create . -pr:b abi11 -pr:h abi11 -s build_type=Debug

from what I can tell, this is all working/passing

dwswingle commented 1 month ago

the separate repo that I'm trying to consume it with:

conanfile.py

from conan import ConanFile
from conan.tools.files import load, save, copy
from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout, CMakeDeps
from conan.tools.build import check_max_cppstd, check_min_cppstd
from pathlib import Path
from os import environ, path

class HermesRecipe(ConanFile):
    name = "test_repo"
    package_type = "shared-library"
    exports_sources = "cmake/*", "interface_builder/*", "interface_factory/*", "integer_definition/*", "shared_memory_utils/*", "example/*", "CMakeLists.txt", "logging/*"

    settings = "os", "compiler", "build_type", "arch"

    def requirements(self):
        self.tool_requires("ninja/1.12.1")
        self.tool_requires("cmake/3.29.5")

        self.requires("coredx5.19.0/v4.4.4")

    def set_version(self):
        self.version = environ['generated_version_tag']

    def validate(self):
        check_min_cppstd(self, "17")

    def layout(self):
        cmake_layout(self, generator="Ninja")

    def generate(self):
        deps = CMakeDeps(self)
        deps.generate()
        tc = CMakeToolchain(self, generator="Ninja")
        tc.variables["USING_CONAN"] = True
        tc.user_presets_path = 'ConanPresets.json'
        tc.generate()

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

    def package(self):
        cmake = CMake(self)
        cmake.install()

    def package_info(self):
        cmake_modules = list()

CMakeLists.txt

cmake_minimum_required (VERSION 3.26.3)

project(test_repo CXX)

find_package(coredx 5.19.0 CONFIG REQUIRED)

add_executable( test_repo main.cpp)
target_compile_features( test_repo PUBLIC cxx_std_17)
target_link_libraries( test_repo  PRIVATE coredx5.19.0::coredx5.19.0 )

output of

conan create . -pr:b abi11 -pr:h abi11 -s build_type=Debug

WARN: Profile [system_tools] is deprecated, please use [platform_tool_requires]
WARN: Profile [system_tools] is deprecated, please use [platform_tool_requires]

======== Exporting recipe to the cache ========
test_repo/v1.2.3: Exporting package recipe: /home/caeuser/Repos/test_repo/conanfile.py
test_repo/v1.2.3: Copied 1 '.py' file: conanfile.py
test_repo/v1.2.3: Copied 1 '.txt' file: CMakeLists.txt
test_repo/v1.2.3: Exported to cache folder: /home/caeuser/.conan2/p/test_49010ea2a266f/e
test_repo/v1.2.3: Exported: test_repo/v1.2.3#9f9461f5ef91e5cec7ce77d441fee278 (2024-10-18 19:51:39 UTC)

======== Input profiles ========
Profile host:
[settings]
arch=x86_64
build_type=Debug
compiler=gcc
compiler.cppstd=17
compiler.libcxx=libstdc++11
compiler.version=8
os=Linux
[platform_tool_requires]
cmake/[>=3.23.0]
[conf]
tools.cmake.cmaketoolchain:generator=Ninja

Profile build:
[settings]
arch=x86_64
build_type=Release
compiler=gcc
compiler.cppstd=17
compiler.libcxx=libstdc++11
compiler.version=8
os=Linux
[platform_tool_requires]
cmake/[>=3.23.0]
[conf]
tools.cmake.cmaketoolchain:generator=Ninja

======== Computing dependency graph ========
Graph root
    cli
Requirements
    coredx5.19.0/v4.4.4#fb71aeb7f2c3752cb776fbdc63586ff9 - Cache
    test_repo/v1.2.3#9f9461f5ef91e5cec7ce77d441fee278 - Cache
Build requirements
    cmake/3.29.5#56dbff3ff8af6bcd4b9c170fbd4da068 - Cache
    ninja/1.12.1#fd583651bf0c6a901943495d49878803 - Cache

======== Computing necessary packages ========
test_repo/v1.2.3: Forced build from source
Requirements
    coredx5.19.0/v4.4.4#fb71aeb7f2c3752cb776fbdc63586ff9:63fead0844576fc02943e16909f08fcdddd6f44b#92dcb719fc9cf0cd306551c6198b6cd0 - Cache
    test_repo/v1.2.3#9f9461f5ef91e5cec7ce77d441fee278:5ddc71d8d459633908a7aaf990928accd796b740 - Build
Build requirements
    cmake/3.29.5#56dbff3ff8af6bcd4b9c170fbd4da068:63fead0844576fc02943e16909f08fcdddd6f44b#96b8ea57ee8ae3516c1ffc387ef340f7 - Cache
    ninja/1.12.1#fd583651bf0c6a901943495d49878803:3593751651824fb813502c69c971267624ced41a#a46e32b2b79add597b73d8b42c415ed1 - Cache

======== Installing packages ========
cmake/3.29.5: Already installed! (1 of 4)
cmake/3.29.5: Appending PATH environment variable: /home/caeuser/.conan2/p/cmake33f87d8fd6850/p/bin
coredx5.19.0/v4.4.4: Already installed! (2 of 4)
ninja/1.12.1: Already installed! (3 of 4)

-------- Installing package test_repo/v1.2.3 (4 of 4) --------
test_repo/v1.2.3: Building from source
test_repo/v1.2.3: Package test_repo/v1.2.3:5ddc71d8d459633908a7aaf990928accd796b740
test_repo/v1.2.3: Copying sources to build folder
test_repo/v1.2.3: Building your package in /home/caeuser/.conan2/p/b/test_28632a8acf8db/b
test_repo/v1.2.3: Calling generate()
test_repo/v1.2.3: Generators folder: /home/caeuser/.conan2/p/b/test_28632a8acf8db/b/build/Debug/generators
test_repo/v1.2.3: CMakeDeps necessary find_package() and targets for your CMakeLists.txt
    find_package(coredx5.19.0)
    target_link_libraries(... coredx5.19.0::coredx5.19.0)
test_repo/v1.2.3: CMakeToolchain generated: conan_toolchain.cmake
test_repo/v1.2.3: CMakeToolchain generated: /home/caeuser/.conan2/p/b/test_28632a8acf8db/b/build/Debug/generators/CMakePresets.json
test_repo/v1.2.3: CMakeToolchain generated: /home/caeuser/.conan2/p/b/test_28632a8acf8db/b/ConanPresets.json
test_repo/v1.2.3: Generating aggregated env files
test_repo/v1.2.3: Generated aggregated env files: ['conanbuild.sh', 'conanrun.sh']
test_repo/v1.2.3: Calling build()
test_repo/v1.2.3: Running CMake.configure()
test_repo/v1.2.3: RUN: cmake -G "Ninja" -DCMAKE_TOOLCHAIN_FILE="generators/conan_toolchain.cmake" -DCMAKE_INSTALL_PREFIX="/home/caeuser/.conan2/p/b/test_28632a8acf8db/p" -DCMAKE_POLICY_DEFAULT_CMP0091="NEW" -DCMAKE_BUILD_TYPE="Debug" "/home/caeuser/.conan2/p/b/test_28632a8acf8db/b"
-- Using Conan toolchain: /home/caeuser/.conan2/p/b/test_28632a8acf8db/b/build/Debug/generators/conan_toolchain.cmake
-- Conan toolchain: Defining architecture flag: -m64
-- Conan toolchain: C++ Standard 17 with extensions OFF
-- The CXX compiler identification is GNU 8.5.0
-- 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
CMake Error at CMakeLists.txt:15 (find_package):
  Could not find a package configuration file provided by "coredx" (requested
  version 5.19.0) with any of the following names:

    coredxConfig.cmake
    coredx-config.cmake

  Add the installation prefix of "coredx" to CMAKE_PREFIX_PATH or set
  "coredx_DIR" to a directory containing one of the above files.  If "coredx"
  provides a separate development package or SDK, be sure it has been
  installed.

-- Configuring incomplete, errors occurred!

test_repo/v1.2.3: ERROR: 
Package '5ddc71d8d459633908a7aaf990928accd796b740' build failed
test_repo/v1.2.3: WARN: Build folder /home/caeuser/.conan2/p/b/test_28632a8acf8db/b/build/Debug
ERROR: test_repo/v1.2.3: Error in build() method, line 50
    cmake.configure()
    ConanException: Error 1 while executing
memsharded commented 1 month ago

Thanks for the feedback, I think it is really useful.

It seems the difference is:

find_package( coredx5.19.0 CONFIG REQUIRED  )

Inside the test_package works

But your project has instead:

find_package( coredx 5.19.0 CONFIG REQUIRED  )

Which fails, because it is not matching the package name (note the space). Please fix that and try again.

dwswingle commented 1 month ago

wow I thought I was going crazy thank you

memsharded commented 1 month ago

Those details are often difficult to spot :) Happy to help!