-
Notifications
You must be signed in to change notification settings - Fork 1k
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][1.55.0] "CMakeDeps" doesn't provide IMPORTED_LOCATION[_<CONFIG>]
target properties for its generated Imported Targets?
#12654
Comments
IMPORTED_LOCATION[_<CONFIG>]
target properties?IMPORTED_LOCATION[_<CONFIG>]
target properties for its generated Imported Targets?
Hi @hwhsu1231 thanks for raising this question. The targets such was In #12077 we made sure that the intermediate targets that do have the CMakeDeps generates targets such the following:
Works as expected by propagating the correct compiler and linker flags. However, the use of both generator expressions conditional on the build configuration, and interface link libraries, make them unsuitable for consumer CMake projects to make assumptions about which properties they can query. Arguably, this is how CMake targets work - but it would be great if we were provided with use cases to understand the need to query these properties from the consumer side. |
@jcar87 So what should I do to make |
The As I've explained before:
should work exactly the same when consuming Qt from a binary distribution of Qt, or from Conan Center. Is this not the case? |
The problem I'm facing is that I "cannot" use the generator expression $<TARGET_RUNTIME_DLLS:${tgt}> in the following codes to copy DLLs of add_executable(main "main.cpp")
target_link_libraries(main PRIVATE Qt6::Core)
add_custom_command(TARGET main POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
"$<TARGET_RUNTIME_DLLS:main>"
"$<TARGET_FILE_DIR:main>"
COMMAND_EXPAND_LISTS) if the following target properties of |
@hwhsu1231 thanks so much for providing this example. The internal targets (generated by CMakeDeps) that would be transitively linked by From what I can see from the documentation here: https://cmake.org/cmake/help/latest/manual/cmake-generator-expressions.7.html#genex:TARGET_RUNTIME_DLLS I believe the issue here would by cause by the internal targets generated by |
We may be able to provide a workaround or an alternative for this on the other hand - could you confirm which operating system and CMake generator you are using? Cheers! |
|
Any news about this issue, do someone have a workaround? |
According to the CMake Docs, it seems that the reason is because CMakeDeps declares those Imported Targets as I was wondering why not just declare them as:
If I didn't understand wrong, the |
Take Protobuf for example.
Screeshots: |
Hi @hwhsu1231! Thanks for the thorough analysis. You are certainly on the right track!! The key information is in the documentation of the For imported targets (as are the ones generated by
This is not directly an issue with the The issue here lies with those internal targets I mentioned earlier. The "public" target The issue when it comes to We're currently looking into this issue to see if we can ensure the behaviour is more correct. WorkaroundsIn the command lineIf you enable the In Visual StudioIf your CMake generator is the default Visual Studio generator (which will solution
note that you need to make sure you are using the @EstebanDugueperoux2 - please let me know if this is a suitable workaround to get the DLLs, while we work on a long term solution that enables the use of the |
For shared libraries, it would help to also set the |
@jcar87 - Should this issue be added the label |
I'm running into the same problem as detailed in #12957. The workaround above is only partial. It will address runtime staging of the libraries for e.g. running from an IDE, but not for the cmake |
Sadly I too have this problem, so for now I'm using a workaround as I only need to install 1 .dll that is also managed by me. include(CMakePrintHelpers)
cmake_print_properties(
TARGETS myConanDep::myConanDep
PROPERTIES
IMPORTED
IMPORTED_COMMON_LANGUAGE_RUNTIME
IMPORTED_CONFIGURATIONS
IMPORTED_GLOBAL
IMPORTED_IMPLIB
IMPORTED_IMPLIB_Debug
IMPORTED_IMPLIB_Release
IMPORTED_LIBNAME
IMPORTED_LIBNAME_Debug
IMPORTED_LIBNAME_Release
IMPORTED_LINK_DEPENDENT_LIBRARIES
IMPORTED_LINK_DEPENDENT_LIBRARIES_Debug
IMPORTED_LINK_DEPENDENT_LIBRARIES_Release
IMPORTED_LINK_INTERFACE_LANGUAGES
IMPORTED_LINK_INTERFACE_LANGUAGES_Debug
IMPORTED_LINK_INTERFACE_LANGUAGES_Release
IMPORTED_LINK_INTERFACE_LIBRARIES
IMPORTED_LINK_INTERFACE_LIBRARIES_Debug
IMPORTED_LINK_INTERFACE_LIBRARIES_Release
IMPORTED_LINK_INTERFACE_MULTIPLICITY
IMPORTED_LINK_INTERFACE_MULTIPLICITY_Debug
IMPORTED_LINK_INTERFACE_MULTIPLICITY_Release
IMPORTED_LOCATION
IMPORTED_LOCATION_Debug
IMPORTED_LOCATION_Release
IMPORTED_NO_SONAME
IMPORTED_NO_SONAME_Debug
IMPORTED_NO_SONAME_Release
IMPORTED_OBJECTS
IMPORTED_OBJECTS_Debug
IMPORTED_OBJECTS_Release
IMPORTED_SONAME
IMPORTED_SONAME_Debug
IMPORTED_SONAME_Release
IMPORT_PREFIX
IMPORT_SUFFIX
INCLUDE_DIRECTORIES
INSTALL_NAME_DIR
INSTALL_REMOVE_ENVIRONMENT_RPATH
INSTALL_RPATH
INSTALL_RPATH_USE_LINK_PATH
INTERFACE_AUTOUIC_OPTIONS
INTERFACE_COMPILE_DEFINITIONS
INTERFACE_COMPILE_FEATURES
INTERFACE_COMPILE_OPTIONS
INTERFACE_INCLUDE_DIRECTORIES
INTERFACE_LINK_DEPENDS
INTERFACE_LINK_DIRECTORIES
INTERFACE_LINK_LIBRARIES
INTERFACE_LINK_OPTIONS
INTERFACE_POSITION_INDEPENDENT_CODE
INTERFACE_PRECOMPILE_HEADERS
INTERFACE_SOURCES
INTERFACE_SYSTEM_INCLUDE_DIRECTORIES
LIBRARY_OUTPUT_DIRECTORY
LIBRARY_OUTPUT_DIRECTORY_Debug
LIBRARY_OUTPUT_DIRECTORY_Release
LIBRARY_OUTPUT_NAME
LIBRARY_OUTPUT_NAME_Debug
LIBRARY_OUTPUT_NAME_Release
LINK_DEPENDS
LINK_DEPENDS_NO_SHARED
LINK_DIRECTORIES
LINK_FLAGS
LINK_FLAGS_Debug
LINK_FLAGS_Release
LINK_INTERFACE_LIBRARIES
LINK_INTERFACE_LIBRARIES_Debug
LINK_INTERFACE_LIBRARIES_Release
LINK_INTERFACE_MULTIPLICITY
LINK_INTERFACE_MULTIPLICITY_Debug
LINK_INTERFACE_MULTIPLICITY_Release
LINK_LIBRARIES
LINK_OPTIONS
LOCATION
LOCATION_Debug
LOCATION_Release
MANUALLY_ADDED_DEPENDENCIES
MSVC_RUNTIME_LIBRARY
NAME
NO_SONAME
NO_SYSTEM_FROM_IMPORTED
OUTPUT_NAME
OUTPUT_NAME_Debug
OUTPUT_NAME_Release
PCH_WARN_INVALID
PCH_INSTANTIATE_TEMPLATES
PDB_NAME
PDB_NAME_Debug
PDB_NAME_Release
PDB_OUTPUT_DIRECTORY
PDB_OUTPUT_DIRECTORY_Debug
PDB_OUTPUT_DIRECTORY_Release
PRECOMPILE_HEADERS
PRECOMPILE_HEADERS_REUSE_FROM
PREFIX
PRIVATE_HEADER
PUBLIC_HEADER
RESOURCE
RUNTIME_OUTPUT_DIRECTORY
RUNTIME_OUTPUT_DIRECTORY_Debug
RUNTIME_OUTPUT_DIRECTORY_Release
RUNTIME_OUTPUT_NAME
RUNTIME_OUTPUT_NAME_Debug
RUNTIME_OUTPUT_NAME_Release
SOURCE_DIR
SOURCES
STATIC_LIBRARY_FLAGS
STATIC_LIBRARY_FLAGS_Debug
STATIC_LIBRARY_FLAGS_Release
STATIC_LIBRARY_OPTIONS
SUFFIX
TYPE
VERSION
) |
Hi, |
Conan CMakeDeps is already generating a variable for binaries: set({{ pkg_name }}_INCLUDE_DIRS{{ config_suffix }} {{ global_cpp.include_paths }})
...
set({{ pkg_name }}_LIB_DIRS{{ config_suffix }} {{ global_cpp.lib_paths }})
set({{ pkg_name }}_BIN_DIRS{{ config_suffix }} {{ global_cpp.bin_paths }}) |
Not in my case. What am I doing wrong? Do I need to set something special in the dependency recipe I have overlooked? message("${fbxsdk_BIN_DIR}") #empty
message("${fbxsdk_BIN_DIRS}") #empty
message("${fbxsdk_BIN_DIRS_RELEASE}") #empty
message("${fbxsdk_INCLUDE_DIR}") # this one is correct This is my case file - fbxsdk-config.cmake, generated by the conan 1.59: ########## MACROS ###########################################################################
#############################################################################################
# Requires CMake > 3.15
if(${CMAKE_VERSION} VERSION_LESS "3.15")
message(FATAL_ERROR "The 'CMakeDeps' generator only works with CMake >= 3.15")
endif()
if(fbxsdk_FIND_QUIETLY)
set(fbxsdk_MESSAGE_MODE VERBOSE)
else()
set(fbxsdk_MESSAGE_MODE STATUS)
endif()
include(${CMAKE_CURRENT_LIST_DIR}/cmakedeps_macros.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/fbxsdkTargets.cmake)
include(CMakeFindDependencyMacro)
check_build_type_defined()
foreach(_DEPENDENCY ${fbxsdk_FIND_DEPENDENCY_NAMES} )
# Check that we have not already called a find_package with the transitive dependency
if(NOT ${_DEPENDENCY}_FOUND)
find_dependency(${_DEPENDENCY} REQUIRED ${${_DEPENDENCY}_FIND_MODE})
endif()
endforeach()
set(fbxsdk_VERSION_STRING "2017.0.1")
set(fbxsdk_INCLUDE_DIRS ${fbxsdk_INCLUDE_DIRS_RELEASE} )
set(fbxsdk_INCLUDE_DIR ${fbxsdk_INCLUDE_DIRS_RELEASE} )
set(fbxsdk_LIBRARIES ${fbxsdk_LIBRARIES_RELEASE} )
set(fbxsdk_DEFINITIONS ${fbxsdk_DEFINITIONS_RELEASE} )
# Only the first installed configuration is included to avoid the collision
foreach(_BUILD_MODULE ${fbxsdk_BUILD_MODULES_PATHS_RELEASE} )
message(${fbxsdk_MESSAGE_MODE} "Conan: Including build module from '${_BUILD_MODULE}'")
include(${_BUILD_MODULE})
endforeach() This is part of the fbxsdk recipe. I'm not setting anything special. To my knowledge, the "bin" should be a default for binary dir: import os
from conan import ConanFile
from conan.tools.files import copy
from conans.model.version import Version
class CWExchange(ConanFile):
name = "fbxsdk"
version = "2017.0.1"
settings = "os", "compiler", "arch"
...
build_policy = "never"
def package(self):
copy(self, "*", "./include/", os.path.join(self.package_folder, "include"), keep_path=True)
copy(self, "*.lib", "./lib/", os.path.join(self.package_folder, "lib"), keep_path=False)
copy(self, "*.dll", "./bin/", os.path.join(self.package_folder, "bin"), keep_path=False)
def package_info(self):
self.cpp_info.libs = ["libfbxsdk"] |
In Conan 2.0, the requirement traits decide what is propagated and what not. For a presentation about it you can check: https://docs.conan.io/2/knowledge/videos.html (first video), and also https://docs.conan.io/2/reference/conanfile/methods/requirements.html#requirement-traits The |
I've added the options = {"shared": [True, False]}
default_options = {"shared": True} Re-exported the package, and clean configured the cmake, also no luck. I've then commented out the package_type in the cache recipe itself, and just tried to regenerate the conan deps files. And still nothing. |
I think we need a reproducible case. This is what I am trying: from conan import ConanFile
from conan.tools.cmake import cmake_layout
class pkgRecipe(ConanFile):
name = "pkg"
version = "0.1"
# Binary configuration
settings = "os", "compiler", "build_type", "arch"
options = {"shared": [True, False], "fPIC": [True, False]}
default_options = {"shared": False, "fPIC": True}
def layout(self):
cmake_layout(self) Then: $ conan export-pkg . -o *:shared=True Then, in another place: $ conan install --requires=pkg/0.1 -o *:shared=True -g CMakeDeps And the final file contains: set(pkg_INCLUDE_DIRS_RELEASE "${pkg_PACKAGE_FOLDER_RELEASE}/include")
...
set(pkg_LIB_DIRS_RELEASE "${pkg_PACKAGE_FOLDER_RELEASE}/lib")
set(pkg_BIN_DIRS_RELEASE "${pkg_PACKAGE_FOLDER_RELEASE}/bin") Maybe if you can provide something simple like the above that helps reproduce, that would be great. Thanks! |
Aren't you by chance using conan v2? Nevertheless, since the topic is captioned 1.55.0 I used 1.59 :) I had one problem with cmake_layout() it complained:
but it exported the recipe so I tried to
In both cases I needed to call the conan 1 variant for installation:
This is the console output of the second option (exactly your recipe) if it could be of any help:
But in both cases no binary dir in the pkg-config.cmake I've also tried the package_type which would be the preferred way of doing this: from conan import ConanFile
from conan.tools.cmake import cmake_layout
class pkgRecipe(ConanFile):
name = "pkg"
version = "0.1"
# Binary configuration
settings = "os", "compiler", "build_type", "arch"
package_type = "shared-library"
def layout(self):
cmake_layout(self) It generated a different package hash so it was successful but still no BINARY_DIR/S after that. Every time I have deleted the results of the install command just to be extra sure it's generated over. |
The problem is that this is not really related to the original ticket, so it was confusing to me, it is difficult to track things, and easy to assume 2.0 for new reports that are not that direct follow up from the previous conversation.
It is true that Conan 1.X is not generating the |
I just came across this issue while trying to compile lld with Conan. |
@jcar87, @memsharded: It seems as if there's 2 issues here:
The question then is - should Conan produce targets that work as expected with CMake or should CMake fix this apparent oversight or both? |
Regarding the targets types, there are 2.X roadmap plans to improve the CMakeDeps to be able to generate them better. But that is a massive effort, so it will take time. In the meantime, getting the information from |
Thanks @memsharded. Unfortunately, my usecase (a third party tool that I'm altering) requires that Conan remain an implementation detail. I've got a couple of ideas, though... I've raised https://gitlab.kitware.com/cmake/cmake/-/issues/24967 to capture this limitation of the CMake "runtime DLL" functionality... |
One of the use case of the imported location is to collect the shared libraries of dependencies. This can be done with a |
Any Progress? option(VCPKG_APPLOCAL_DEPS "Automatically copy dependencies into the output directory for executables." ON) option(X_VCPKG_APPLOCAL_DEPS_INSTALL "(experimental) Automatically copy dependencies into the install target directory for executables. Requires CMake 3.14." OFF) links: |
Friendly ping, anything I can do to help move this forward? |
Maybe it's not an ez work 🥲 |
Conan 2.4 added in #15914 the This approach is the CMake recommended way to get the shared library dependencies, instead of using imported locations. The solution is documented in https://docs.conan.io/2/reference/tools/cmake/cmaketoolchain.html#conan-runtime-lib-dirs |
hi @memsharded, wouldn't How can we copy the dependency .dll files in post-build? |
Have a question regarding this. conan/conan/tools/cmake/toolchain/blocks.py Line 610 in da2b385
So let me ask. Why it uses bindir on Windows? What's the purpose?
|
HI @TsXor
The convention is to put Windows "DLLs" in the "bin" folder, not the "lib" folder, because they are considered pure executables, the linker doesn't link to DLLs in Windows, only to the importing libraries (static .lib libraries), so they are pure runtime "bin", not "libs" |
My fault. Checked cmake doc and realized that I should use
|
We can use a detached cmake script. For example:
Content of
|
Conan 2.9 added a new It can be used with This generator defines the correct imported location for targets. I am closing this ticket as solved, please create new tickets against the new |
Problem Description
This issue is related to the one I posted before, which was closed with the new release version 1.55.0:
IMPORTED_LOCATION_<CONFIG>
properties for Imported Targets created byCMakeDeps
. #12077In short, the problem mentioned in the above issue is that "CMakeDeps" generator doesn't provide the following target properties for its generated Imported Targets:
IMPORTED_LOCATION
IMPORTED_LOCATION_<CONFIG>
However, it seems that this problem is still not solved after conducting some experiments, #12077 (comment).
@memsharded @lasote
What do I miss? If I do miss somehting in the demo, can you provide a correct demonstration?
Thanks.
The text was updated successfully, but these errors were encountered: