conan-io / conan

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

[bug] Cmake's find_package fails even with requirements set #8357

Closed xahon closed 1 month ago

xahon commented 3 years ago

Environment Details (include every applicable attribute)

Steps to reproduce (Include if Applicable)

I'm trying to create a package for a third-party library that uses PulseAudio as a dependency. I've added that dependency into def requirements(self) from bincrafters repo. It fails to configure cmake with that output

... a bunch of stuff above ... Package 'libpng', required by 'freetype2', not found -- Found Fontconfig: /usr/lib64/libfontconfig.so
CMake Error at proj/cmake/platform_linux.cmake:139 (find_package): By not providing "FindPulseAudio.cmake" in CMAKE_MODULE_PATH this project has asked CMake to find a package configuration file provided by "PulseAudio", but CMake did not find one.

Could not find a package configuration file provided by "PulseAudio" with any of the following names:

PulseAudioConfig.cmake
pulseaudio-config.cmake

Add the installation prefix of "PulseAudio" to CMAKE_PREFIX_PATH or set "PulseAudio_DIR" to a directory containing one of the above files. If "PulseAudio" provides a separate development package or SDK, be sure it has been installed. Call Stack (most recent call first): CMakeLists.txt:29 (include)

-- Configuring incomplete, errors occurred! See also "/home/user/conan/Cinder/0.9.5///build/0ee6551d361945debc13c78a4ba71d22a111c8b3/CMakeFiles/CMakeOutput.log". Cinder/0.9.5: Cinder/0.9.5: ERROR: Package '0ee6551d361945debc13c78a4ba71d22a111c8b3' build failed Cinder/0.9.5: WARN: Build folder /home/user/conan/Cinder/0.9.5///build/0ee6551d361945debc13c78a4ba71d22a111c8b3 ERROR: Cinder/0.9.5: Error in build() method, line 45 cmake = self._configure_cmake() while calling '_configure_cmake', line 33 cmake.configure() ConanException: Error 1 while executing cd '/home/user/conan/Cinder/0.9.5//_/build/0ee6551d361945debc13c78a4ba71d22a111c8b3' && cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE="Debug" -DCONAN_IN_LOCAL_CACHE="ON" -DCONAN_COMPILER="clang" -DCONAN_COMPILER_VERSION="7.0" -DCONAN_CXX_FLAGS="-m64" -DCONAN_SHARED_LINKER_FLAGS="-m64" -DCONAN_C_FLAGS="-m64" -DCONAN_LIBCXX="libstdc++11" -DBUILD_SHARED_LIBS="OFF" -DCMAKE_INSTALLPREFIX="/home/user/conan/Cinder/0.9.5//_/package/0ee6551d361945debc13c78a4ba71d22a111c8b3" -DCMAKE_INSTALL_BINDIR="bin" -DCMAKE_INSTALL_SBINDIR="bin" -DCMAKE_INSTALL_LIBEXECDIR="bin" -DCMAKE_INSTALL_LIBDIR="lib" -DCMAKE_INSTALL_INCLUDEDIR="include" -DCMAKE_INSTALL_OLDINCLUDEDIR="include" -DCMAKE_INSTALL_DATAROOTDIR="share" -DCONAN_CMAKE_POSITION_INDEPENDENT_CODE="ON" -DCMAKE_EXPORT_NO_PACKAGE_REGISTRY="ON" -DCONANEXPORTED="1" -Wno-dev '/home/user/conan/Cinder/0.9.5//_/build/0ee6551d361945debc13c78a4ba71d22a111c8b3'

The recipe

from conans import ConanFile, CMake

class CinderConan(ConanFile):
    name = "Cinder"
    description = "Cinder is a community-developed, free and open source library for professional-quality creative coding in C++."
    topics = ["graphics", "3d", "2d", "image-processing"]
    url = "https://github.com/cinder/Cinder"
    homepage = "https://github.com/cinder/Cinder"
    license = "2-Clause BSD License"
    generators = "cmake"
    settings = "os", "arch", "compiler", "build_type"

    options = {
        "shared": [True, False],
        "fPIC": [True, False],
    }
    default_options = {
        "shared": False,
        "fPIC": True,
    }

    git_url = "file:///home/user/dev/m/cinder-conan/Source"
    source_folder = "_source"
    install_folder = "_source"

    def requirements(self):
        if self.settings.os == "Linux":
            self.requires("pulseaudio/13.0@bincrafters/stable")

    def _configure_cmake(self):
        _cmake = CMake(self)
        _cmake.configure()
        return _cmake

    def config_options(self):
        if self.settings.os == "Windows":
            self.options.fPIC = False

    def source(self):
        self.run("git clone --depth 1 %s %s" % (self.git_url, self.source_folder))
        self.run("cd %s" % self.source_folder)

    def build(self):
        cmake = self._configure_cmake()
        cmake.build()

    def package(self):
        cmake = self._configure_cmake()
        cmake.install()
        self.copy(pattern="COPYING", dst="licenses", src=self.source_folder)
memsharded commented 3 years ago

Hi @xahon

We would need to have a look at cinder CMakeLists.txt.

Using the cmake Conan generator won't automagically inject the dependency so find_package will find it. You have several alternatives:

You are also using and old recipe, not a modern one. The maintained ones are those in ConanCenter without user and channel: https://conan.io/center/pulseaudio (so use it with ``self.requires("pulseaudio/14.0")

memsharded commented 1 month ago

Closing as inactive and very outdated, using the legacy Conan 1.X integrations. Please check latest Conan 2.X integrations and file any new tickets if necessary, thanks for the feedback.