Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[question] Header files are not found when downloading a package #17699

Closed
1 task done
omgronny opened this issue Feb 4, 2025 · 19 comments
Closed
1 task done

[question] Header files are not found when downloading a package #17699

omgronny opened this issue Feb 4, 2025 · 19 comments
Assignees

Comments

@omgronny
Copy link

omgronny commented Feb 4, 2025

What is your question?

Hello!

I migrate my project from conan1.x to conan2, and I have an issue when trying to use my uploaded package

I create a package using conan export-pkg conanfile.py --name <name> --version <version> using pre-built binaries and libs. And I get:

...
conanfile.py : package(): Packaged 242 '.a' files
conanfile.py : package(): Packaged 27 '.proto' files
conanfile.py : package(): Packaged 308 '.h' files
...

So I consider my header files packaged

After that, I run conan upload an it runs successfully.

But when I try to use my package in different project, I get an error fatal error: '<header>.h' file not found even after successful conan install

When I run conan cache path, and list the directory, I see that there is no header files:

$ ls ~/.conan2/p/data3d4e0adbbf673/e
conanfile.py  conanmanifest.txt

But how I can get the package with all the headers?
Can you please help me with that?

Have you read the CONTRIBUTING guide?

  • I've read the CONTRIBUTING guide
@memsharded memsharded self-assigned this Feb 4, 2025
@memsharded
Copy link
Member

Hi @omgronny

Thanks for your question.
I am not sure what would be happening, lets try to confirm step by step:

  • First do the conan export-pkg. Share the full output, I am specially interested in knowing the recipe-revision and package_id
  • After the conan export-pkg do the conan cache path and check the files are indeed there
  • Do the conan upload and share again the output, to double check about the uploaded revision
  • Do the conan remove to make sure it is cleaned from the cache
  • Do the conan install that downloads the package and share the output
  • Do the conan cache path after the download for the specific revision that was downloaded conan cache path pkg/version#recipe_revision

Thanks for the feedback!

@omgronny
Copy link
Author

omgronny commented Feb 4, 2025

Actually, headers are not there after the first step:

$ conan export-pkg conanfile_data.py --name data --version 123

======== Exporting recipe to the cache ========
data/123: Exporting package recipe: /home/roman_glinskikh/repo/conanfile_data.py
data/123: Calling export_sources()
data/123: Copied 11 '.py' files
data/123: Copied 14 '.cmake' files
data/123: Copied 39 '.txt' files
data/123: Copied 2 '.yml' files: .gitlab-ci.yml, settings.yml
data/123: Copied 1 '.yaml' file: .pre-commit-config.yaml
data/123: Copied 16 files
data/123: Copied 95 '.conf' files
data/123: Copied 150 '.json' files
data/123: Copied 75 '.cpp' files
data/123: Copied 9 '.proto' files
data/123: Copied 48 '.h' files
data/123: Copied 3 '.j2' files: transfer_rule.json.j2, supervisor_saver.conf.j2, supervisor_transfer_rule.conf.j2
data/123: Copied 1 '.service' file: metrics-proxy.service
data/123: Copied 9 '.sh' files
data/123: Copied 3 '.jinja' files: default_steps.json.jinja, steps.json.jinja, steps.json.jinja
data/123: Copied 12 '.sample' files
data/123: Copied 1 '.in' file: GetGitRevisionDescription.cmake.in
data/123: Copied 4 '.profile' files: clang17-sanitize.profile, clang18.profile, clang17.profile, clang17.profile
data/123: Exported to cache folder: /home/roman_glinskikh/.conan2/p/data3d4e0adbbf673/e
data/123: Exported: data/123#34ab297390cf15ef80ba3b8101ea90c0 (2025-02-04 19:50:35 UTC)

======== Computing dependency graph ========
Graph root
    conanfile_data.py (data/123): /home/roman_glinskikh/repo/conanfile_data.py

======== Computing necessary packages ========

======== Installing packages ========
conanfile_data.py (data/123): Writing generators to /home/roman_glinskikh/repo
conanfile_data.py (data/123): Generator 'CMakeDeps' calling 'generate()'
conanfile_data.py (data/123): Generating aggregated env files
conanfile_data.py (data/123): Generated aggregated env files: ['conanbuild.sh', 'conanrun.sh']

======== Exporting recipe and package to the cache ========
conanfile_data.py (data/123): Exporting binary from user folder to Conan cache
conanfile_data.py (data/123): Packaging to 062a827c1030df026f8987d16ecfe78764da7afe
conanfile_data.py (data/123): Generating the package
conanfile_data.py (data/123): Packaging in folder /home/roman_glinskikh/.conan2/p/b/data97024ecd6aae3/p
conanfile_data.py (data/123): Calling package()
lconanfile_data.py (data/123): package(): Packaged 242 '.a' files
conanfile_data.py (data/123): package(): Packaged 3 '.proto' files: data_source_type.proto, logs_processing_task.proto, processing_task.proto
conanfile_data.py (data/123): package(): Packaged 36 '.h' files
conanfile_data.py (data/123): Created package revision 1212ca7300ff9a0f318519046abd3fc9
conanfile_data.py (data/123): Package '062a827c1030df026f8987d16ecfe78764da7afe' created
conanfile_data.py (data/123): Full package reference: data/123#34ab297390cf15ef80ba3b8101ea90c0:062a827c1030df026f8987d16ecfe78764da7afe#1212ca7300ff9a0f318519046abd3fc9
conanfile_data.py (data/123): Package folder /home/roman_glinskikh/.conan2/p/b/data97024ecd6aae3/p
conanfile_data.py (data/123): Exported package binary
$ conan cache path data/123

/home/roman_glinskikh/.conan2/p/data3d4e0adbbf673/e
$ ls /home/roman_glinskikh/.conan2/p/data3d4e0adbbf673/e
conanfile.py  conanmanifest.txt

@memsharded
Copy link
Member

Great, thanks for the feedback.

Some quick feedback about your recipe: it has data/123: Calling export_sources() an export_sources method. This is incorrect for conan export-pkg command, as it works copying directly from user space to the final binary, not exporting sources, as that will unnecessarily duplicate the package size.

The $ conan cache path data/123 will only list the "recipe" path in the cache. You want to do conan cache path pkg/version:package_id to get the path to a specific binary. Sorry I didn't realize about this in your first comment, when I saw the conanfile.py inside the folder. That is part of the recipe. Package binaries should contain the conaninfo.txt, the conanmanifest.txt and then the files.

Recall that in any case the conan cache path command is mostly intended for debugging. For consuming packages installed with Conan, the recommended approach is via generators that will point to the packages installed location.

@omgronny
Copy link
Author

omgronny commented Feb 4, 2025

Thanks, I removed the export_sources

And I figured out that it is two packages upload:

-------- Uploading artifacts --------
data/123: Uploading recipe 'data/123#380038b55720b81aa592f1a712b3ce55' (6.6KB)
data/123: Uploading package 'data/123#380038b55720b81aa592f1a712b3ce55:6e165a47e6418bad4277a1d7e313a37ca8d54358#ca423ffd57d1a6b5ac8becc38f447a5e' (733.8MB)

And the second one is actually contains include directory!

Could you please help me with proper including the second package to my project?

$ conan search "data/123#380038b55720b81aa592f1a712b3ce55:6e165a47e6418bad4277a1d7e313a37ca8d54358#ca423ffd57d1a6b5ac8becc38f447a5e"
ERROR: Specifying a recipe revision or package ID is not allowed

And I get on conan install:

ERROR: Package 'data/123' not resolved: Unable to find 'data/123#380038b55720b81aa592f1a712b3ce55:6e165a47e6418bad4277a1d7e313a37ca8d54358#ca423ffd57d1a6b5ac8becc38f447a5e' in remotes.

How can I specify it?

@memsharded
Copy link
Member

And I figured out that it is two packages upload:

Those are not 2 packages, that is 1 recipe + 1 package binary built from that recipe.
They go together, a package binary cannot exist without a recipe. Although a recipe might have no binaries if it hasn't built any yet

Could you please help me with proper including the second package to my project?

You don't need to do anything special to include it in your project, just treat it as any other package, for example as the zlib package, as described in the getting started in https://docs.conan.io/2/tutorial/consuming_packages/build_simple_cmake_project.html. Have you already gone through the tutorial to learn how to consume packages?

You need:

  • To have a conanfile
  • Add a requires to your data/1.2.3 to your conanfile. Do not add the package_id there.
  • Make sure the conanfile declares the generators such as CMakeDeps and CMakeToolchain, depending on your build system.
  • Do the conan install
  • Use cmake or your build system to build your project

You don't have to worry about the location of the project in the cache, no need to do conan search to get the location or anything like that.

@omgronny
Copy link
Author

omgronny commented Feb 4, 2025

Okay, thanks, now I understand more about conan.
Yes, I have added the dependency to requires.

Returning to your first message. I did run

  • conan export-pkg
  • checked that headers are in the folder conan cache path data/123#380038b55720b81aa592f1a712b3ce55:6e165a47e6418bad4277a1d7e313a37ca8d54358#ca423ffd57d1a6b5ac8becc38f447a5e
  • conan upload
  • conan remove
  • conan install, it downloads the package
  • checked folder again, and it still has the headers
  • try to build my project

But I still get the same error

The result of conan install:

$ conan install conanfile.py --output-folder /home/roman_glinskikh/repo1/build --profile /home/roman_glinskikh/repo1/cmake/conan/x86_64/clang17.profile --profile:build /home/roman_glinskikh/repo1/cmake/conan/x86_64/clang17.profile --build=missing --update -sbuild_type=Release -ssanitize=False

======== Input profiles ========
Profile host:
[settings]
arch=x86_64
build_type=Release
compiler=clang
compiler.cppstd=20
compiler.libcxx=libc++
compiler.version=17
os=Linux
sanitize=False
[options]
reflect-cpp/*:compiler.cppstd=20
[buildenv]
CC=/usr/bin/clang-17
CXX=/usr/bin/clang++-17
CPLUS_INCLUDE_PATH=/usr/lib/llvm-17/include/c++/v1/

Profile build:
[settings]
arch=x86_64
build_type=Release
compiler=clang
compiler.cppstd=20
compiler.libcxx=libc++
compiler.version=17
os=Linux
sanitize=True
[options]
reflect-cpp/*:compiler.cppstd=20
[buildenv]
CC=/usr/bin/clang-17
CXX=/usr/bin/clang++-17
CPLUS_INCLUDE_PATH=/usr/lib/llvm-17/include/c++/v1/


======== Computing dependency graph ========
arrow/18.1.0: Checking remote: conancenter
data/123: Not found in local cache, looking in remotes...
data/123: Checking remote: conancenter
data/123: Checking remote: artifactory
data/123: Downloaded recipe revision aeb8f8d8f1fcfe2411ddd068f6901087
Graph root
    conanfile.py (repo/None): /home/roman_glinskikh/repo1/conanfile.py
Requirements
    arrow/18.1.0#032d83f98246ca1d0facc6413141392e - Cache (conancenter)
    data/123#aeb8f8d8f1fcfe2411ddd068f6901087 - Download (artifactory)

======== Computing necessary packages ========
    arrow/18.1.0#032d83f98246ca1d0facc6413141392e:b2d8edd6e0c9be5bcda249191d1bc5a1eeabcfc2#57ca86e44ecd37d43b9f412c72a75a6c - Cache
data/123#aeb8f8d8f1fcfe2411ddd068f6901087:062a827c1030df026f8987d16ecfe78764da7afe#1212ca7300ff9a0f318519046abd3fc9 - Download (artifactory)

======== Installing packages ========

-------- Downloading 1 package --------
data/123: Retrieving package 062a827c1030df026f8987d16ecfe78764da7afe from remote 'artifactory'
data/123: Downloading 733.6MB conan_package.tgz
data/123: Decompressing 733.6MB conan_package.tgz
data/123: Package installed 062a827c1030df026f8987d16ecfe78764da7afe
data/123: Downloaded package revision 1212ca7300ff9a0f318519046abd3fc9
WARN: deprecated: Usage of deprecated Conan 1.X features that will be removed in Conan 2.X:
WARN: deprecated:     'user_info' used in: data/123

======== Finalizing install (deploy, generators) ========
conanfile.py (repo/None): Writing generators to /home/roman_glinskikh/repo1/build
conanfile.py (repo/None): Generator 'CMakeToolchain' calling 'generate()'
conanfile.py (repo/None): CMakeToolchain generated: conan_toolchain.cmake
conanfile.py (repo/None): CMakeToolchain: Preset 'conan-release' added to CMakePresets.json.
    (cmake>=3.23) cmake --preset conan-release
    (cmake<3.23) cmake <path> -G "Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake  -DCMAKE_POLICY_DEFAULT_CMP0091=NEW -DCMAKE_BUILD_TYPE=Release
conanfile.py (repo/None): CMakeToolchain generated: /home/roman_glinskikh/repo1/build/CMakePresets.json
conanfile.py (repo/None): CMakeToolchain generated: /home/roman_glinskikh/repo1/CMakeUserPresets.json
conanfile.py (repo/None): Generator 'CMakeDeps' calling 'generate()'
conanfile.py (repo/None): CMakeDeps necessary find_package() and targets for your CMakeLists.txt
    find_package(Arrow)
    find_package(data)
    target_link_libraries(... arrow::arrow data::data)
conanfile.py (repo/None): Generating aggregated env files
conanfile.py (repo/None): Generated aggregated env files: ['conanbuild.sh', 'conanrun.sh']
Install finished successfully

@memsharded
Copy link
Member

The output of conan install is looking good now.

It would be necessary to reproduce the issue, please provide:

  • the full conanfile.py you are using as consumer depending on the data/123 package
  • I'd suggest to simplify it to a minimal reproducible case
  • the full CMakeLists.txt to reproduce, much better if it is minimal
  • the exact CMake command you are using, as the output reads, the best is cmake --preset
  • the full output of the cmake command.

@omgronny
Copy link
Author

omgronny commented Feb 5, 2025

conanfile_data.py which I use to upload the package:

class DataConan(ConanFile):
    name = "data"
    version = 123
    license = "None"
    url = "..."
    description = "data"
    settings = ("build_type", "sanitize")
    options = {}
    generators = "CMakeDeps"
    revision_mode = "hash"
    requires = []

    component_directories = [
        ...
    ]

    def layout(self):
        self.folders.source = "."
        self.folders.build = "build"

    def package(self):
        for component_directory in DataConan.component_directories:
            component_path = Path(self.source_folder) / "data" / component_directory
            for include_dir in component_path.rglob("**/include"):
                copy(self, "*.h", include_dir, f"{self.package_folder}/include")
                copy(self, "*.hpp", include_dir, f"{self.package_folder}/include")

            for include_dir in component_path.rglob("**/include"):
                copy(self, "*.h", include_dir, f"{self.package_folder}/include")

            copy(
                self,
                "*",
                f"{self.build_folder}/include_proto/{component_directory}",
                f"{self.package_folder}/include_proto/{component_directory}",
            )
            copy(
                self,
                "lib*",
                f"{self.build_folder}/lib",
                f"{self.package_folder}/lib",
                keep_path=False,
            )

    def package_info(self):
        self.cpp_info.libs = [
           ...
        ]
        self.cpp_info.system_libs = ["pthread"]
        self.user_info.PROTO_PATH = os.path.join(self.package_folder, "include_proto")

conanfile.py I use to download the package:

class RepoConan(ConanFile):
    name = "repo"
    settings = ("build_type", "compiler")
    options = {}
    generators = ("CMakeToolchain", "CMakeDeps")
    requires = [
        "arrow/18.1.0",
    ]

    def requirements(self):
        if not (repo_root / "data").exists():
            self.requires(f"data/123")

    default_options = {
        "arrow/*:fPIC": False,
        "arrow/*:shared": False,
        "arrow/*:with_csv": True,
    }

def package_info(self):
    self.cpp_info.requires.append("boost::headers")

CMakeLists.txt:

cmake_minimum_required(VERSION 3.30.0)
project(repo)

message("Using conan profile: ${CONAN_PROFILE}")

find_program(CONAN conan)
if(NOT CONAN)
  message(FATAL_ERROR "conan not found")
endif()

if(INSTALL_CONAN)

  execute_process(
    RESULT_VARIABLE CONAN_RETURN_CODE
    OUTPUT_FILE "${CMAKE_BINARY_DIR}/conan.log"
    ERROR_FILE "${CMAKE_BINARY_DIR}/conan.log"
    COMMAND "${CONAN}" "install"
        "${ROOT}/conanfile.py"
        "--output-folder" "${CMAKE_BINARY_DIR}"
        "--profile" "${CONAN_PROFILE}"
        "--profile:build" "${CONAN_PROFILE}"
        "--build=missing"
        "--update"
        "-sbuild_type=${CMAKE_BUILD_TYPE}"
        ${CONAN_INSTALL_FLAGS}
  )

endif()

set(INCLUDE_DIRECTORIES)

find_package(Arrow REQUIRED)

add_library(CONAN_PKG::arrow ALIAS arrow::arrow)

add_subdirectory(<some_subdirectory>)

if(EXISTS "${ROOT}/data")
    message("Using `data` from sources")
    add_subdirectory(data)
else()
    message("Using `data` from conan")

    add_library(data_deps INTERFACE)
    target_link_libraries(data_deps INTERFACE <lib> <lib>)
    foreach(CONAN_TARGET ${CONAN_TARGETS})
        if (NOT CONAN_TARGET STREQUAL "CONAN_PKG::data")
            target_link_libraries(data_deps INTERFACE ${CONAN_TARGET})
        endif()
    endforeach()
    target_include_directories(data_deps INTERFACE ${CONAN_INCLUDE_DIRS_DATA})

    add_library(<lib> INTERFACE)
    target_link_libraries(<lib> INTERFACE
            data_<lib>
            data_deps
    )

endif()

add_subdirectory(...)

cmake output. It actually runs successfully.

$ /usr/bin/cmake .. -DCMAKE_BUILD_TYPE=Release -DINSTALL_CONAN=1
LLVM version: 17
-- The C compiler identification is Clang 17.0.6
-- The CXX compiler identification is Clang 17.0.6
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/clang-17 - 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/clang++-17 - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
Cmake generator: Ninja
default log level: Info
Build type: Release
compiler: clang
Using conan profile: /home/roman_glinskikh/repo1/clang17.profile
updating conan settings
running conan install
conan installed successfully
-- Conan: Component target declared 'Arrow::arrow_static'
-- Conan: Target declared 'arrow::arrow'
Unknown team
-- Looking for sys/types.h
-- Looking for sys/types.h - found
-- Looking for stdint.h
-- Looking for stdint.h - found
-- Looking for stddef.h
-- Looking for stddef.h - found
-- Looking for unistd.h
-- Looking for unistd.h - found
Using `data` from conan
-- Configuring done (4.5s)
-- Generating done (2.1s)
-- Build files have been written to: /home/roman_glinskikh/repo1/build1

But when I run ninja -j 8, I have

/home/roman_glinskikh/repo1/<some.cpp>:1:10: fatal error: '<lib>/<header>.h' file not found
    1 | #include "<lib>/<header>.h"
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.

@memsharded
Copy link
Member

The issue is in the CMakeLists.txt and trying to define the imported targets manually, for example it seems the CONAN_INCLUDE_DIRS_DATA might not be correct, you can try printing it to debug it.

The recommended way to do it is that there should be a find_package(data) in exactly the same way there is a find_package(arrow).

Then, it is necessary to pass the toolchain, either via:

  • cmake -DCMAKE_TOOLCHAIN_FILE=.../conan_toolchain.cmake
  • or cmake --preset conan-xxxx

This will greatly simplify your CMake code, your conanfiles and will help to scale much easier, add more dependencies with just 1 line.

If you want cmake to call conan install, you can use the CMake dependency provider implemented in https://github.com/conan-io/cmake-conan. In any case, the CMakeLists.txt should not contain Conan specific code.

You might also be interested in tracking the progress in "Workspaces", like #17675, see https://docs.conan.io/2/incubating.html -> Workspaces, a feature oriented to be able to work simultaneously on different Conan packages.

@omgronny
Copy link
Author

omgronny commented Feb 5, 2025

Thank you

I actually have the line set(CMAKE_TOOLCHAIN_FILE "${CMAKE_BINARY_DIR}/conan_toolchain.cmake") in my CMakeLists.txt, I just didn't think it was important when minimizing.

Also, the conan install commands is in conan_install.cmake file and it includes to CMakeLists.txt

I removed the line with CONAN_INCLUDE_DIRS_DATA, and replaced it with find_package(data REQUIRED)

but now at this exact line I get an error

CMake Error at build1/cmakedeps_macros.cmake:66 (message):
  Library 'data_<lib>' not found in package.  If 'data_<lib>' is
  a system library, declare it with 'cpp_info.system_libs' property
Call Stack (most recent call first):

I actually have in my conanfile_data.py:

def package_info(self):
    self.cpp_info.libs = [
        ...,
        <lib>,
        ...
    ]
    ...

But I think it was not called in conan export-pkg step.
However I can find it in $(conan cache path ...)/lib folder

Previous time I was trying to use conan create instead of conan export-pkg and had some build issues, so I don't use it. But conan create did call the package_info method and conan export-pkg does not.
It is just my wild guess, and I don't actually know that is the problem

@memsharded
Copy link
Member

I actually have the line set(CMAKE_TOOLCHAIN_FILE "${CMAKE_BINARY_DIR}/conan_toolchain.cmake") in my CMakeLists.txt, I just didn't think it was important when minimizing.

The toolchain files in CMake are not intended to be defined in CMakeLists.txt, that is not recommended by CMake. CMake defined this to be defined externally, either in command line arg or in presets.
It might work if defined before the project() call, can you please double check it is before project()?

I removed the line with CONAN_INCLUDE_DIRS_DATA, and replaced it with find_package(data REQUIRED)

It is not about just that line. The whole definition of the add_library(data_deps INTERFACE) and all the following lines should be replaced with the find_package(data) and then just use the data::data defined target.

You can do a quick proof of concept, something like this:

  • In a new, empty folder
  • conan new cmake_lib -d requires=data/1.2.3 # or the exact version you are using
  • Check the generated files. Check specially the CMakeLists.txt.
  • You might need to customize in the .cpp generated code the #include <data.h> that is by default created and replace for your exact #include
  • Also the call in code to data() you might want to replace it for something that your data library actually has
  • Then, you can try it in different ways, for example:
    • Normal consuming flow with conan install . + cmake --preset conan-xxx + cmake --build --preset conan-release
    • Directly calling conan build . do all those steps automatically

Please try that and let us know.

Previous time I was trying to use conan create instead of conan export-pkg and had some build issues, so I don't use it. But conan create did call the package_info method and conan export-pkg does not.

Neither conan create or conan export-pkg in Conan 2 will call the package_info() method if there is a test_package folder to test the package. Because the package_info() method is a method to provide information to the consumers, so it is triggered when there is a consumer. If there is no test_package, there will not be consumer and it will not be triggered.

@omgronny
Copy link
Author

omgronny commented Feb 5, 2025

Yes, it helped, thank you!

I still have some problems with proto cmake targets, but file not found error is definitely solved

@omgronny
Copy link
Author

omgronny commented Feb 5, 2025

@memsharded could you please help me with a further problem:

I test my package with two copies of repo: repo and repo1. repo has a folder data which I package and upload, and then I download it in repo1 and try to build

my ninja -j 8 command in repo1/build fails with linker errors of mimalloc:

ld.lld-17: error: undefined symbol: mi_memalign
>>> referenced by allocator.cpp:223 (/home/roman_glinskikh/repo/repo/data/.../allocator.cpp:223)
>>>               allocator.cpp.obj:(memalign) in archive /home/roman_glinskikh/.conan2/p/data2a72632b04a2/p/lib/<lib>.a

And I noticed that the path in error refers to repo and the folder data inside it.

I include mimalloc in project via this in CMakeLists.txt

find_package(mimalloc REQUIRED)
...
add_library(CONAN_PKG::mimalloc ALIAS mimalloc-static)

How can I fix the linker issue?
Thank you

@memsharded
Copy link
Member

I am not sure why you are using something like add_library(CONAN_PKG::mimalloc ALIAS mimalloc-static)

The find_package() already defines the targets that must be used, something like mimalloc::mimalloc. The CONAN_PKG::mimalloc was something of the legacy generators, I think you can drop it and use the "upstream" target name. The overall idea is that CMakeLists.txt doesn't need to have anything that is conan specific, not a single "conan" reference or variable, as shown in the generated CMakeLists.txt above with conan new cmake_lib.

@omgronny
Copy link
Author

omgronny commented Feb 6, 2025

Yes, I get it now, and my linker problems have solved. I should have added proper target_link_libraries.
Thank you.

I got that any conan-specific things are not recommended in cmake. But could you please explain how to get a package path inside of cmake file? I also have some logic for generating proto-files depends on wether I have my data sources or not. And if not, I have to get a path to include_proto folder inside a downloaded package

In conan 1.x I was doing it via if(DEFINED ${CONAN_USER_DATA_PROTO_PATH}), but as far as I can see, it is not correct in conan2 and this variable is never defined

So how can I do it?
Thank you

@omgronny
Copy link
Author

omgronny commented Feb 6, 2025

UPD: I found out that ${data_PACKAGE_FOLDER_RELEASE} works

I suppose this is the solution

@memsharded
Copy link
Member

I got that any conan-specific things are not recommended in cmake. But could you please explain how to get a package path inside of cmake file? I also have some logic for generating proto-files depends on wether I have my data sources or not. And if not, I have to get a path to include_proto folder inside a downloaded package

The recommended way is decoupling responsibilities and abstracting that away in the build system:

  • Do you need your build system to use some "folder" where some files are to be found? Make it a MY_DATA_FOLDER variable. In this way your build system can even work manually, by putting the data in the folder you want and just passing the cmake -DMY_DATA_FOLDER=xxxx
  • Have the consumer recipe to define in the generate() with the CMakeToolchain or equivalent something like: toolchain.cache_variables["MY_DATA_FOLDER"] = self.dependencies["mydep"].package_folder
  • This way the build system has build system responsibilities, and the package manager has package manager responsibilities, and they are nicely decoupled which helps a lot to reduce issues, improves debugging and is more future-proof (for example, it won't break if in the future the Conan internal data_PACKAGE_FOLDER_RELEASE variable name changes.

@omgronny
Copy link
Author

omgronny commented Feb 7, 2025

Well, it definitely makes sense

Thank you for your help, it is compiling now

@omgronny omgronny closed this as completed Feb 7, 2025
@memsharded
Copy link
Member

Happy that it is compiling now and happy to help!

Thanks to you for the feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants