-
Notifications
You must be signed in to change notification settings - Fork 194
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
Handle OPTIONAL_COMPONENTS in find_package(YARP) #1741
Handle OPTIONAL_COMPONENTS in find_package(YARP) #1741
Conversation
871f1d5
to
19a87ba
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks.
Unfortunately I made a lot of changes in order to fix static builds, and this will no longer apply... Also I consider "not supporting OPTIONAL_COMPONENTS
" a bug, therefore I would like this in 3.0.1... do you mind moving your branch to the latest master?
19a87ba
to
d266987
Compare
d266987
to
f61845f
Compare
@drdanz rebased, updated and tested with yarp/src/libYARP_init/YARP_OSConfigStatic.cmake.in Lines 64 to 89 in f23f86b
Unless I'm wrong, this block loops over |
b1b13da
to
a18b531
Compare
@PeterBowman This is required because, in order to support static plugins, there is a circular dependency in static builds that does not exist in shared builds. i.e. |
HINTS "${YARP_CMAKECONFIG_DIR}" | ||
NO_DEFAULT_PATH) | ||
if(YARP_${_yarp_module}_FOUND) | ||
list(APPEND YARP_LIBRARIES YARP::YARP_${_yarp_module}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this is correct...
In my opinion, YARP_LIBRARIES
should always contain all the COMPONENTS
, even if not found, so that linking will fail if one component is missing.
For the OPTIONAL_COMPONENTS
this check makes sense though.
So I'd say this should be something like
if(YARP_FIND_REQUIRED_${_yarp_module} OR YARP_${_yarp_module}_FOUND)
list(APPEND YARP_LIBRARIES YARP::YARP_${_yarp_module})
endif()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@PeterBowman does this ^ make sense to you?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CMake should raise an error during the generate phase (non-fatal, though), check the output I copy-pasted at #1740 to see what I mean. Anyway, I'd consider the YARP_LIBRARIES
variable unreachable in such case: if I issue a find_package(YARP 3.0 COMPONENTS asdf)
call and the YARP_asdf
component is not found, YARP_FOUND
will be set to FALSE
(by check_required_components()
), so I think it's safe to assume that nobody will reference YARP_LIBRARIES
nor any other variable or target (since YARP will not be regarded by CMake as found on system).
Still not sure, I ran a |
There is another annoying problem with using For example: cmake_minimum_required(VERSION 3.0)
project(test_fs)
include(FeatureSummary)
find_package(YARP COMPONENTS conf OS gsl math)
feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES) will print:
Using I think this can be fixed in a hackish way by setting set_property(GLOBAL PROPERTY _CMAKE_YARP_${_yarp_module}_TRANSITIVE_DEPENDENCY TRUE) (note: this should be done for YCM as well, but we should ensure that it is not set to true yet) |
Is it feasible to include a |
Will cmake 3.9 version allow to replace |
Done: 8f582d3 |
cmake/template/YARPConfig.cmake.in
Outdated
NO_DEFAULT_PATH) | ||
set(_YARP_FIND_PART_${_yarp_module}_REQUIRED) | ||
# Only propagate REQUIRED if module was not passed to OPTIONAL_COMPONENTS | ||
if(YARP_FIND_PARTS_REQUIRED AND YARP_FIND_REQUIRED_${_yarp_module}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note to self: YARP_FIND_REQUIRED
instead of YARP_FIND_PARTS_REQUIRED
.
You are right, sorry. Similarly, |
I'd say let's stick with |
Result of expanding that CMake variable on a simple downstream app (plain foreach(_component YARP_priv_hmac;YARP_yarpcar;YARP_priv_xmlrpcpp;YARP_sig;YARP_wire_rep_utils;YARP_math;YARP_eigen;YARP_yarpmod;YARP_dev;YARP_rosmsg;YARP_rosmsg_native;YARP_rosmsg_std_msgs;YARP_rosmsg_actionlib_msgs;YARP_rosmsg_diagnostic_msgs;YARP_rosmsg_geometry_msgs;YARP_rosmsg_nav_msgs;YARP_rosmsg_sensor_msgs;YARP_rosmsg_shape_msgs;YARP_rosmsg_stereo_msgs;YARP_rosmsg_trajectory_msgs;YARP_rosmsg_visualization_msgs;YARP_rosmsg_tf;YARP_rosmsg_tf2_msgs ) BTW it's called 420 times; in 419 of them, |
foreach(_component YARP_priv_hmac;YARP_yarpcar;YARP_priv_xmlrpcpp;YARP_sig;YARP_wire_rep_utils;YARP_math;YARP_eigen;YARP_yarpmod;YARP_dev;YARP_rosmsg;YARP_rosmsg_native;YARP_rosmsg_std_msgs;YARP_rosmsg_actionlib_msgs;YARP_rosmsg_diagnostic_msgs;YARP_rosmsg_geometry_msgs;YARP_rosmsg_nav_msgs;YARP_rosmsg_sensor_msgs;YARP_rosmsg_shape_msgs;YARP_rosmsg_stereo_msgs;YARP_rosmsg_trajectory_msgs;YARP_rosmsg_visualization_msgs;YARP_rosmsg_tf;YARP_rosmsg_tf2_msgs ) That's correct...
That's a little weird, does this mean that the |
Anyway, this is unrelated to this patch, we can fix it (if it requires fixing) on a separate PR. |
a18b531
to
771e62b
Compare
There is no way to make this work with `find_dependency()` since it passes caller's REQUIRED to the underlying `find_package()` call. That is, no error should be raised if an optional component was not found while issuing a `find_package(YARP REQUIRED ...)` command.
771e62b
to
7858479
Compare
Yes.
We'd have to add this tweak on the YCM side, too (InstallBasicPackageFiles.cmake). That is, I can apply that hack around each
Removing [WIP] label, please review. I'm not touching YARP_OSConfigStatic.cmake.in since it has nothing to do with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM now
Merged, thanks.
This tweak would useful be for CMake < 3.9 only, since the new ones use |
There is no way to make this work with
find_dependency()
since it passes caller'sREQUIRED
option to the underlyingfind_package()
call. That is, no error should be raised if an optional component was notfound while issuing a
find_package(YARP REQUIRED ...)
command. See also this related discussion in the CMake's community mailing list: ref.Example invocation (tested with YARP static and shared builds):
find_package(YARP REQUIRED COMPONENTS OS dev OPTIONAL_COMPONENTS math asdf)
CMake issues a diagnostic message for the missing
YARP_asdf
component:-- Could NOT find YARP_asdf (missing: YARP_asdf_DIR)
This is a follow-up proposal to #1715. The CMake <3.9 fix was introduced in #1731.