conan-io / conan

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

[question] How to install runtime dependencies alongside conan ones? #16735

Open Todiq opened 1 month ago

Todiq commented 1 month ago

What is your question?

Related to https://github.com/conan-io/conan/issues/16726

Please clone https://github.com/Todiq/test_conan

On windows with msvc installed, run python build.py

I am getting the following error:

-- Install configuration: "Release"
-- Installing: D:/test_conan/Release/lib/betaimpl.lib
-- Installing: D:/test_conan/Release/./betaimpl.dll
-- Installing: D:/test_conan/Release/./beta.exe
CMake Error at beta/build/windows-msvc/cmake_install.cmake:73 (file):
  file Could not resolve runtime dependencies:

    betaimpl.dll

This behaviour will happen even if the following block is added to the CMakeLists.txt of the betaimpl lib:

install(TARGETS ${PROJECT_NAME}
    RUNTIME_DEPENDENCY_SET my_app_deps
    DESTINATION ${DEPS_DESTINATION}
)

Removing the same code from the CMakeLists.txt of beta (executable) successfully installs betaimpl.dll, but not beta.exe anymore.

Linux behaves the same, but does not throw a cmake error. Can anyone give me a hand? Thanks in advance!

Have you read the CONTRIBUTING guide?

jcar87 commented 1 month ago

According to CMake documentation: https://cmake.org/cmake/help/latest/command/file.html#get-runtime-dependencies

if beta.exe depends on beteaimpl.dll, and they are in the same directory, it should have considered that directory already so it should be resolved. Although I wonder if it's looking in the installed location or the original location - if it's the location from the build tree, it may in a different folder.

You may have some luck doing any of the following:

OR

something like $<TARGET_FILE_DIR:betaimpl>, e.g:

install(RUNTIME_DEPENDENCY_SET my_app_deps
    PRE_EXCLUDE_REGEXES
        [=[api-ms-]=]
        [=[ext-ms-]=]
        [[kernel32\.dll]]
        [[libc\.so\..*]] [[libgcc_s\.so\..*]] [[libm\.so\..*]] [[libstdc\+\+\.so\..*]]
    POST_EXCLUDE_REGEXES
        [=[.*system32\/.*\.dll]=]
        [=[^\/(lib|usr\/lib|usr\/local\/lib)]=]
    DIRECTORIES ${CONAN_RUNTIME_LIB_DIRS} $<TARGET_FILE_DIR:betaimpl>
)

Don't think this is a Conan bug - although I think it would be useful to clarify in our documentation that more work needs to be done to ensure cmake

I'm unsure, but as a third option you may want to add the target for betaimpl to the install(TARGETS...) in the top level file and that might work - or might cause cmake to complain a file already exists.

Todiq commented 1 month ago

@jcar87

You are right, you are supposed to install every target you require in the final package and not let cmake resolve that automatically for you: https://gitlab.kitware.com/cmake/cmake/-/issues/22987

I added

install(TARGETS ${PROJECT_NAME}
    RUNTIME_DEPENDENCY_SET my_app_deps
    DESTINATION ${DEPS_DESTINATION}
)

to the CMakeLists.txt of betaimpl, but that still leads to the same issue.

The only way to resolve that error is to not write install(RUNTIME_DEPENDENCY_SET my_app_deps and do simpler target installs: install(TARGETS ${PROJECT_NAME})

Since removing DIRECTORIES ${CONAN_RUNTIME_LIB_DIRS} from the install(RUNTIME_DEPENDENCY_SET my_app_deps block does not fix anything either (as a matter of fact, it does make things worse since cmake won't find the third parties dependencies), we can indeed conclude that it is not a conan bug. I am thus closing the ticket.

Thanks for your clarifications!

Todiq commented 1 month ago

@jcar87

I fixed the example and on Windows, we can observe that libxml2.dll is not installed, while it is on Linux. Could you please have a look?