-
Notifications
You must be signed in to change notification settings - Fork 260
Description
What is your question?
I have an application and a library, lets call them APP and LibA. LibA depends on OpenSLL built as a shared library and APP depends on LibA. Both APP and LibA are using Conan2 through the conan_provider.cmake file to keep the CMakeLists free from conan specific code.
APP uses CMake to create an installer. When I run cmake install the application and all DLLs should end up in the install directory. Using CMake I can gather the system DLLs needed and they install correctly. But I can't figure out how to install the needed OpenSSL DLLs (libssl-3.dll and libcrypto-3.dll).
Expectation
Install DLL dependencies using standard CMake. It would be great to not have to list the dependencies by name but I am ok doing that if needed.
Not sure but is this related to the new CMakeDeps2 generator? should I be using that?
Kind of Working
Combining some approaches I tried below I added to my CMakeLists.txt. This does require knowing the dependencies by name and use the LIB_BIN_DIRS_${CONFIG} variable that find_package seems to populate.
SET(MYLIB_RUNTIME_DEPS "${openssl_BIN_DIRS_RELEASE}")
configure_file(./install-runtime-deps.cmake.in "${PROJECT_BINARY_DIR}/install-runtime-deps.cmake" @ONLY)
install(SCRIPT "${PROJECT_BINARY_DIR}/install-runtime-deps.cmake")
in the configure file
file(GET_RUNTIME_DEPENDENCIES
RESOLVED_DEPENDENCIES_VAR _FOUND_DEPS
UNRESOLVED_DEPENDENCIES_VAR _MISSING_DEPS
LIBRARIES @CMAKE_RUNTIME_OUTPUT_DIRECTORY@/@CMAKE_SHARED_LIBRARY_PREFIX@MyLib@CMAKE_SHARED_LIBRARY_SUFFIX@
DIRECTORIES @openssl_BIN_DIRS_RELEASE@
PRE_EXCLUDE_REGEXES
[[api-ms-win-.*]]
[[ext-ms-.*]]
[[kernel32\.dll]]
[[user32\.dll]]
[[msvcrt.*\.dll]]
POST_EXCLUDE_REGEXES
[[.*[/\]system32[/\].*\.dll]]
)
message(STATUS "Resolved deps: ${_FOUND_DEPS}")
message(WARNING "Unresolved deps: ${_MISSING_DEPS}")
file(INSTALL ${_FOUND_DEPS} DESTINATION @CMAKE_INSTALL_BINDIR@)
This seems to work, but not the most concise. Is the variable openssl_BIN_DIRS_RELEASE that comes from CMakeDeps and find_package reliable and ok to use?
Other Attempts
CONAN_RUNTIME_LIB_DIRS
This variable seems to only be set in the toolchain generator, but the conan_provider.cmake uses CMakeDeps as far as I understand.
file(GET_RUNTIME_DEPENDENCIES ...)
install(CODE [=[
file(GET_RUNTIME_DEPENDENCIES
RESOLVED_DEPENDENCIES_VAR _FOUND_DEPS
UNRESOLVED_DEPENDENCIES_VAR _MISSING_DEPS
EXECUTABLES $<TARGET_FILE:APP>
POST_EXCLUDE_REGEXES
[[.*[/\]system32[/\].*\.dll]]
)
message(STATUS "Resolved deps: ${_FOUND_DEPS}")
message(WARNING "Unresolved deps: ${_MISSING_DEPS}")
file(INSTALL ${DAP_FOUND_DEPS} DESTINATION $<INSTALL_PREFIX>)
]=]
)
This correctly identifies the missing DLLs but does not find them, I see my message output as:
Unresolved deps: libcrypto-3.dll;libssl-3.dll
TARGET_RUNTIME_DLLS
Using the generator expression $<TARGET_RUNTIME_DLLS:APP> should list the DLLs needed by the target but the CMake code
add_custom_command(TARGET APP POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy -t $<TARGET_FILE_DIR:APP> $<TARGET_RUNTIME_DLLS:APP>
COMMAND_EXPAND_LISTS
)
results in no arguments to the copy ($<TARGET_RUNTIME_DLLS:APP> is empty).
Copy files in generate
There is an example in the docs that copies DLLs during the generate step. This works to get the DLLs in the build folder. From there I guess the CMakeLists could assume that the DLLs are in the build folder?
Have you read the CONTRIBUTING guide?
- I've read the CONTRIBUTING guide