-
Notifications
You must be signed in to change notification settings - Fork 981
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
[feature] Add executables to cpp_info model #7240
Comments
Things that become possible:
A potential issue on Macos is the requirement to set |
Hi. I'm not opposed to adding a Usually (always?) in the Take the well-know Here, the CMakeLists.txt project(my_pkg)
find_package(protobuf) # Provides targets 'protobuf::libprotobuf' and proposed 'protobuf::protoc'
protobuf_generate_cpp(....) # <-- Here we want to use protoc
add_library(my_pkg ...)
target_link_libraries(my_pkg protobuf::libprotobuf) It is clear that our library But, the
IMO we should encourage raw executables over targets ( There are two challenges with this approach:
About the problem with shared libraries (it is not only Macos and SIP, the problem still exists for the rest of OS), I'm still thinking about how to deal with it. Some ideas, but I need to make up my mind before sharing them. |
BTW, my last approach requires |
Another use case of that is automoc/autouic/autorcc of Qt. Currently it is not possible to use automoc with conan qt recipes and cmake_find_package(_multi) generator. |
Adding executable components to the tree would avoid adding executable-only requirements to libraries. def package_info(self):
self.cpp_info.components["lib"].libs = ["library"]
self.cpp_info.components["lib"].requires = ["libdep::libdep", "exedep::exedep"] Even though the def package_info(self):
self.cpp_info.components["lib"].libs = ["library"]
self.cpp_info.components["lib"].requires = ["libdep::libdep"]
self.cpp_info.components["exe"].executable = "program"
self.cpp_info.components["exe"].requires = ["lib", "exedep::exedep"] |
Hi! Qt is a really good example and a challenging one for the cross-building scenario. First step will be to add the executables to the The problem with these scenarios arises when we enter the cross-building with the two contexts: host and build. If we are cross-building to ARM a package that depends on Qt, we want:
Here, libraries and the The consequence of this is that you shouldn't be using |
If only moc.exe is in PATH, automoc will not work. automoc needs a target called Qt5::moc |
I've been having a quick look to the Qt docs and to Google. I've found this question in Stackoverflow ("CMake CMAKE_AUTOMOC in cross compilation") with the answer I'm copy/pasting here for reference:
One cannot use the |
also: #7444 |
@jgsogo Ignoring the various Qt specific variables (which should be handled by build_modules), I guess I don't really see Conan having the same issue as Qt's builtin cmake scripts. They only have (and can assume) the single distribution of Qt for those scripts, so it makes sense that they don't work for cross compilation -- although thankfully that seems to be easily worked around with a toolchain per the stack overflow post. I guess the way I see it working for conan is that the generated cmake scripts would have the library targets from the requires and the executable targets from the build_requires. If a package has a common require and build_require (e.g. Qt), these two would have to be merged. Of course this needs something like #7324 so that you don't pull an executable's potentially conflicting library requirements into cmake. I don't really know how capable other generators are at handling executables, so I'm not really sure what is needed to be considered there. Also, as a note with Qt: to cross-compile Qt, you need Qt on the build system, i.e. Qt is a build_requires of Qt when cross-compiling. I don't know if conan will handle this at the moment, although I see no reason why conan shouldn't properly handle this (once the build and host graphs are disjoint). |
Hi, @ohanar , thanks for your comments.
Yes, this would be a way to go, merging two different nodes (the one from the build-requires and the one from the requires) into a single generated Then I step back and think if it is those CMake's functions/macros the ones that are broken, and CMake targets should always be the artifacts from the host context and those functions should never use them to run |
FYI, here is a POC of executables imported targets in geographiclib recipe, working with conan 1.32.0 conan-io/conan-center-index@815254d |
There is another use case that might be valid for this cpp_info new model, the COM objects from @thorntonryan
|
Not considering cross compilationStepping away from the cross compilation problem where the build and host profiles are different for a second, how would this work for a more vanilla use case, where a package only distributes an executable? The use case I have in mind in particular is Using the target, an exemplar of what I've been using is: find_package(sphinx REQUIRED)
# Sphinx configuration
set(SPHINX_SOURCE ${CMAKE_CURRENT_SOURCE_DIR})
set(SPHINX_BUILD ${CMAKE_CURRENT_BINARY_DIR}/sphinx)
set(SPHINX_INDEX_FILE ${SPHINX_BUILD}/index.html)
add_custom_command(
OUTPUT ${SPHINX_INDEX_FILE}
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/index.rst
COMMAND sphinx::sphinx-build -b html ${SPHINX_SOURCE} ${SPHINX_BUILD}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating documentation with Sphinx") With your proposal, without using the cmake target, the following change is made: - COMMAND sphinx::sphinx-build -b html ${SPHINX_SOURCE} ${SPHINX_BUILD}
+ COMMAND sphinx-build -b html ${SPHINX_SOURCE} ${SPHINX_BUILD} Do you see any danger here that an ambiguity has been introduced as to the necessity/purpose of the To be explicit about what that ambiguity is:
Considering Cross CompilationComing back to the problem of cross compilation, as you say, the only executable we would ever be interested in here would be the executable exported in the build environment. Wouldn't it then make sense to:
include(${CMAKE_CURRENT_LIST_DIR}/mypkg-build-config.cmake) where the contents of
Then, the exe target This appears to be the pattern that's already being used for different I can't think of a use case for including an executable in the host context, but if it were needed, that could also be accounted for by making it a component property or something, where you have to choose either build or host context, which would switch which def requirements(self):
# default exes=False, this indicates that exes should be
# available in host context
self.requires("protobuf/x.y.z", exes=True)
def build_requirements(self):
# default exes=True. Validation would need to occur
# to ensure that only one profile has exes=True for each
# package required in both
self.tool_requires("protobuf/x.y.z", exes=False) Perhaps this is what you were trying to get at in your comments above and I just misunderstood. Regardless, I think that this would be a reasonable first step to modelling these executable requirements, even if it's not perfect. Having an implementation modelling build executables would help us more readily evaluate the importance of modelling executables in the host context. This can be an iterative process - we don't need to have a perfect solution before we do anything. We don't need perfect to get in the way of useful. User interfaceI think, as a user, using the target is a much more preferable interface to hoping that conan injects the |
@jcar87 @memsharded @lasote how is this going? Any updates to share? |
@memsharded is this on your horizon/roadmap at all? |
What is the current status of this? In the absence of this feature, what is the current best practice for supplying package_info for an executable? |
@peakschris the thing is that this model hasn't been prioritized because for the majority of cases, it is not necessary. Conan is already automatically adding dependencies packages |
@memsharded ok, I can see that. My case is I'm using Bazel to consume conan packages, and bazel requires executables to be wrapped in a sh_binary rule before they are used in the toolchain. E.g:
The bazel/conan integration already creates wrapper rules for each library. I would guess that it would need some metadata for each binary in order to allow it to create these wrapper rules for executables. |
We are releasing in Conan 2.9 a completely new
Current known pending functionality (to be added soon):
The new Your feedback is very importantAs this is a major change, we will only remove the conf gate when we get confirmation from users that it works and solve the issues. Please try the new generator for your project, and let us know if it works. If it doesn't, please re-open this ticket and let us know what failed. Thanks very much! |
Coming from conan-io/conan-center-index#1717 (comment)
Related to #5090
In order to allow a better integration with executables, cpp_info could model those with an extra field similar to the current
cpp_info.libs
. Something similar to the proposal at #5090 withcpp_info.exes = []
that will allow adding<NAME>_EXECUTABLE
being<NAME>
the name of the component or similarcc/ @madebr
The text was updated successfully, but these errors were encountered: