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

How to use conan-2 to package an existing library( ITK ) #17447

Open
1 task done
986247404 opened this issue Dec 11, 2024 · 7 comments
Open
1 task done

How to use conan-2 to package an existing library( ITK ) #17447

986247404 opened this issue Dec 11, 2024 · 7 comments
Assignees

Comments

@986247404
Copy link

What is your question?

Hi!
I want to package the compiled ITK library. The conan command is " conan export-pkg . -s build_type=Release". But I can't use this recipe in a cmake project through find_package(). What should i do ? Looking forward to your reply.
My conanfile.py like this:

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

class ITKConan(ConanFile):
name = "itk"
version = "5.1.0"
settings = "os", "compiler", "build_type", "arch"
package_type = "shared-library"

def layout(self):
    self.folders.build = "."
    self.folders.source = self.folders.build
    self.cpp.source.includedirs = ["include"]
    self.cpp.build.libdirs = ["lib"]
    self.cpp.build.bindirs = ["bin"]

def package(self):
    local_include_folder = os.path.join(self.source_folder, self.cpp.source.includedirs[0])
    local_lib_folder = os.path.join(self.build_folder, self.cpp.build.libdirs[0])
    local_bin_folder = os.path.join(self.build_folder, self.cpp.build.bindirs[0])
    copy(self, "*", local_include_folder, os.path.join(self.package_folder, "include")
         , keep_path=True)
    copy(self, "*", src=local_lib_folder,
         dst=os.path.join(self.package_folder, "lib"), keep_path=True)
    copy(self, "*", src=local_bin_folder,
         dst=os.path.join(self.package_folder, "bin"), keep_path=True)

def package_info(self):
    self.cpp_info.libs = collect_libs(self, folder=os.path.join(
        self.package_folder, "lib"))

Have you read the CONTRIBUTING guide?

  • I've read the CONTRIBUTING guide
@memsharded memsharded self-assigned this Dec 11, 2024
@memsharded
Copy link
Member

Hi @986247404

Thanks for your question.

I think it is very likely that you are missing a lot of information in the package_info() method.
You can also use the in-package xxx-config.cmake files if you prefer (and only using CMake in the consumers), see https://docs.conan.io/2/examples/tools/cmake/cmake_toolchain/use_package_config_cmake.html

Otherwise, it is possible that it is necessary to specify in the package_info() the includedirs, libdirs, etc. It is also possible that the collect_libs is not finding all libraries either.

And finally it is also very important the consumer code, using CMakeToolchain, CMakeDeps, and calling cmake ... correctly with the generated files. It would help to get the full details of the consumer, the exact commands you are using both to create the package and to consume it, and the full output of the commands. Thanks for the feedback.

@986247404
Copy link
Author

Hi @986247404

Thanks for your question.

I think it is very likely that you are missing a lot of information in the package_info() method. You can also use the in-package xxx-config.cmake files if you prefer (and only using CMake in the consumers), see https://docs.conan.io/2/examples/tools/cmake/cmake_toolchain/use_package_config_cmake.html

Otherwise, it is possible that it is necessary to specify in the package_info() the includedirs, libdirs, etc. It is also possible that the collect_libs is not finding all libraries either.

And finally it is also very important the consumer code, using CMakeToolchain, CMakeDeps, and calling cmake ... correctly with the generated files. It would help to get the full details of the consumer, the exact commands you are using both to create the package and to consume it, and the full output of the commands. Thanks for the feedback.

Many thanks for your replying. If a library don't have xxx-config.cmake files and , what should i do to package a conan recipe and used in cmake project. Are xxx-config.cmake files "nice to have" or strictly required?

@memsharded
Copy link
Member

The xxx-config.cmake file is necessary if you are using that package from a CMake project. This file can be:

@valgur
Copy link
Contributor

valgur commented Dec 12, 2024

Is there anything missing from the ConanCenter version of ITK (https://conan.io/center/recipes/itk)? I'm not trying to imply that you should use it necessarily, just curious.

@986247404
Copy link
Author

The xxx-config.cmake file is necessary if you are using that package from a CMake project. This file can be:

Thanks a lot.

@986247404
Copy link
Author

Is there anything missing from the ConanCenter version of ITK (https://conan.io/center/recipes/itk)? I'm not trying to imply that you should use it necessarily, just curious.

Because i have to use Module_ITKDCMTK and Module_IODCMTK modules in ITK.

@valgur
Copy link
Contributor

valgur commented Dec 16, 2024

Ok, in that case you might want to give the updated recipe in conan-io/conan-center-index#21651 a try, which adds DCMTK support. It's also available at https://github.com/valgur/conan-center-index?tab=readme-ov-file#setup.

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

3 participants