conan-io / conan

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

[question] How to deploy conan libraries with my application using cmake install() #7402

Closed glennaycock closed 5 months ago

glennaycock commented 4 years ago

I ported my cross-platform, modern CMake-based application to use Conan library packages with transparent integration (conan_paths.cmake). Build and tests are good.

When I run the installer (cmake --install | build INSTALL project), everything is installed into the correct location. Now I need to include the new Conan libraries.

Since imported targets cannot be directly installed via cmake install(), I use workarounds such as:

install(
  PROGRAMS $<TARGET_FILE:sometarget>
  DESTINATION ${CMAKE_INSTALL_BINDIR}
)

However, since the Conan library targets are imported as INTERFACE, those generator expressions don't work with libname::libname targets defined in the generated Findlibname scripts. Using "$<TARGET_FILE:CONAN_LIB::_libnamelibname[d]>" does work; however, on windows I get the linker file (.lib) instead of the runtime file (.dll).

I read the following:

Short of using a python script to convert the json deployment file into a cmake include with install(), I don't see any direct/easy way to deploy the Conan libraries.

What is the most efficient way to install Conan libaries along side my application for deployment?

memsharded commented 4 years ago

Hi @glennaycock

I think we need to understand the case a bit better, not fully sure I understood it. Let me summarize:

If that is the case, maybe you want to have a look to the imports functionality ([imports] in conanfile.txt,imports()in conanfile.py). With that you can define which files are imported from the cache to the local folder, with which patterns (*.dll), and how. This copy will be done automatically when you executeconan install``. Have a look to https://docs.conan.io/en/latest/using_packages/conanfile_txt.html#imports.

glennaycock commented 4 years ago

@memsharded,

Thanks for the quick response. I am responding to your summary points below:

memsharded commented 4 years ago

Hi @glennaycock

Ok, then. I think now I understand it better:

Let me know if that works ok. Thanks!

glennaycock commented 4 years ago

This led me down a path I didn't intend to take. I had to complete the conan build of my application, which I never intended to use, in order for imports() to work. In the course of doing so, I got side tracked trying to fix my other conan package.

I don't think static linking is going to work in the short term.

memsharded commented 4 years ago

Hi @glennaycock

Sorry I didn't fully understand. I got that static linking is not going to work.

But I didn't get:

I had to complete the conan build of my application, which I never intended to use, in order for imports() to work.

Could you please clarify? Can you tell why imports() will not copy the DLLs or shared libraries from the packages to your local folder?

arturpilaszkiewicz commented 3 years ago

I'll hijack this thread as i've recently stumbled upon this issue myself

I think the question is about easy global installation of conanfile targets (libs/bins) that are required for runtime to a designated prefix

In cmake current best way to achieve that is to add custom install step that executes conan imports ${CMAKE_SOURCE_DIR}/conanfile.txt -imf ${CMAKE_INSTALL_PREFIX}

@memsharded would this be the best recommended way ?

nmgwddj commented 3 years ago

I have the same problem.

Project 1 Use Conan management to generate a .dll file and header file for use in other projects. Project 2 only uses the product of Project 1, a .dll file and some header files.

If I define the imports function in the conanfile.py of project 2, I can copy the dynamic library of project 1 to the CMake cache directory. But when I execute cmake install, it cannot install the files imported into the cache to the CMAKE_INSTALL_PREFIX folder that I specified when I initialized CMake.

arturpilaszkiewicz commented 3 years ago

@nmgwddj I'm doing it via custom target

add_custom_target( conan-install COMMAND conan imports ${CMAKE_SOURCE_DIR}/conanfile.py -imf ${CMAKE_INSTALL_PREFIX} )

AntonRechkov commented 2 years ago

Unfortunately if you have more dependencies than one, and you need to copy shared libraries into install folder that approach would not work.

I need to copy shared library to multiple location and with cmake IMPORTED_LIBRARY I cannot use cmake_custom_command or install.

memsharded commented 2 years ago

An update about future Conan 2.0 approach (feature already available in released 2.0 alpha):

memsharded commented 5 months ago

I am closing this ticket as outdated, Conan 2 new deployers would be recommended for this use case, please create new tickets if there is any further question, thanks!