Repository navigation
Added support for compile options - #844
mathias-luedtke wants to merge 14 commits into
Conversation
CMake 2.8.12 is not available in default python environment
7ba5067 to
ce6f354
Compare
| # LIBRARIES projlib1 projlib2 | ||
| # CATKIN_DEPENDS roscpp | ||
| # DEPENDS Eigen | ||
| # DEFINES MYDEFINE=1 |
There was a problem hiding this comment.
Should this be named COMPILE_OPTIONS to match the underlying variable as well as used CMake function? Then defines would need to be passed as -Dkey=value but it allows to pass anything else too.
There was a problem hiding this comment.
These are not compile options, but definitions. -D is added automatically: https://github.com/ipa-mdl/catkin/blob/compile-options/cmake/catkin_package.cmake#L385
(I have adopted the syntax from #610)
There was a problem hiding this comment.
I saw that. But internally they are stored as compile options. Why should the user not be able to pass compile options which are not definitions through catkin_package?
|
|
||
| set(PKG_COMPILE_OPTIONS ${${PROJECT_NAME}_COMPILE_OPTIONS}) | ||
| separate_arguments(PKG_COMPILE_OPTIONS) | ||
| separate_arguments(PROJECT_DEFINES) |
There was a problem hiding this comment.
Why is this necessary? The argument is already received as a list from cmake_parse_arguments.
There was a problem hiding this comment.
I wasn't aware of that, this was only a safe guard. If cmake_parse_arguments already takes care of it this line can be omitted.
There was a problem hiding this comment.
In the context of the related discussion I should clarify that I assume the arguments are being passed as a list, like this (same as e.g. DEPENDS):
catkin_package(DEFINED "something" "something-else")
| endforeach() | ||
|
|
||
| set(PKG_COMPILE_OPTIONS ${${PROJECT_NAME}_COMPILE_OPTIONS}) | ||
| separate_arguments(PKG_COMPILE_OPTIONS) |
There was a problem hiding this comment.
Same as for the next line. Why should we allow the user to specify a space separated string if CMake provides support for lists natively?
There was a problem hiding this comment.
Nothing prevents the user from specifying set(${PROJECT_NAME}_COMPILE_OPTIONS "-Wall -DBla -fomit-frame-pointer").
As testing for unique options is crucial, we need to split the string into single options.
There was a problem hiding this comment.
I would expect the arguments to be passed separately and not in a single string, e.g.:
set(${PROJECT_NAME}_COMPILE_OPTIONS "-Wall" "-DBla" "-fomit-frame-pointer")
And while setting a global variable like this is possible it is hard to discover. Having a documented argument in catkin_package is imo preferred.
There was a problem hiding this comment.
I would expect the arguments to be passed separately and not in a single string
I have seen add_definitions("...") in a couple of projects, so people might pass it as full string because they have found it somewhere in a stackoverflow answer.
IMHO if we need to check for conflicting settings then we should split them.
There was a problem hiding this comment.
Ok, if we want to support both uses cases that sounds good.
| break() | ||
| elseif(_elem MATCHES ${_expr}) | ||
| set(_found TRUE) | ||
| message(WARNING "could not add '${_item}' (from '${source}'), already contained: '${_elem}'") |
There was a problem hiding this comment.
This warning would also appear if the two values _item and _elem are identical which doesn't make much sense.
There was a problem hiding this comment.
This case should be covered by if(_elem STREQUAL _item).
There was a problem hiding this comment.
Good point. I missed that condition above. Sorry for the noise.
| # | ||
| # Append key[=value] elements from one list to another list if they are not already in the target list. | ||
| # | ||
| macro(list_append_keys_from listname source) |
There was a problem hiding this comment.
Please convert this into a function (see #835).
Also passing the source list name as source unnecessarily restricts how this function can be called. I would suggest considering all ARGN (beside listname) to be appended.
There was a problem hiding this comment.
I didn't want to make this macro overly complex and spared the outer loop for ARGN since it was not needed for the use case. Its calling convention differs from list_append_unique, because it simplified the calling code.
I am not sure if this can be implemented as a function. I have not found any way to read a named variable that was defined in the parent scope.
There was a problem hiding this comment.
The calling code will be almost identical. Either you call list_append_keys_from(targte_list_name source_list_name) or list_append_keys_from(targte_list_name ${source_list_name}). But the second signature also support calling it without having a source list in the first place but just plain items, e.g. list_append_keys_from(targte_list_name "one" "two" "three" ${or_even_another_list}).
The implemenation is very similar to list_append_unique, simply loop over ${ARGN}.
There was a problem hiding this comment.
And I now remember the reason for not passing the elements directly: I wanted to print the source of the conflicting entry in the warning.
There was a problem hiding this comment.
I would suggest passing an optional keyword argument like CONTEXT for this purpose.
There was a problem hiding this comment.
Does an optional CONTEXT variable work with a variable argument list?
There was a problem hiding this comment.
Yes, except that the variable argument list can't contain that specific keyword, so I think CONTEXT would be "safe". It needs to be extracted and used with something like this:
cmake_parse_arguments(ARG "" "CONTEXT" "" ${ARGN})
# ARG_CONTEXT
# ARG_UNPARSED_ARGUMENTS
There was a problem hiding this comment.
I have not found any way to read a named variable that was defined in the parent scope.
Not sure what I have tested back then. ${${listname}} works like a charm...
| @@ -0,0 +1,22 @@ | |||
| # | |||
| # Append key[=value] elements from one list to another list if they are not already in the target list. | |||
There was a problem hiding this comment.
The docblock should document all arguments.
There was a problem hiding this comment.
I just copied it from list_append_unique and missed adding proper argument documentation, I can add this after we have decided on the parameter list below.
|
What do you think of using |
|
Yes, if the argument is called In |
f2f30e7 to
42f2088
Compare
42f2088 to
b8b58ed
Compare
|
@dirk-thomas: Thanks for your feedback! I have updated the code accordingly. In the end it will be reduced to 2-3 commis. |
dirk-thomas
left a comment
There was a problem hiding this comment.
I am sorry for the late response. Sadly there is only very little ROS 1 time. Since a new release of this package is planned for the near future I would like to get this in though. Please see the few inline comment / questions.
|
|
||
| set(PKG_COMPILE_OPTIONS ${${PROJECT_NAME}_COMPILE_OPTIONS}) | ||
| separate_arguments(PKG_COMPILE_OPTIONS) | ||
| separate_arguments(PROJECT_COMPILE_OPTIONS) |
There was a problem hiding this comment.
Since this is a user provided variable I don't think it is a good idea to mutate it. This should store the modified value in a local variable instead.
There was a problem hiding this comment.
Good point, I will change it.
| # :param CONTEXT: context to be printen in case of errors | ||
| # :type CONTEXT: string | ||
| # | ||
| # :param LEVEL: level of the error message |
There was a problem hiding this comment.
This should mention the default level.
| @@ -0,0 +1,55 @@ | |||
| # | |||
| # Append key[=value] elements from one list to another list if they are not already in the target list. | |||
There was a problem hiding this comment.
If the same key is being inserted multiple time with different values shouldn't the last one be used (instead of the first one)?
There was a problem hiding this comment.
If I recall it correctly, the dependencies will be resolved first.
So changing some options might break ABI or even API.
There was a problem hiding this comment.
Well, I guess that is the problem of trying to set different values (coming from different packages). You already have the same problem with two different values both coming from dependencies because you have little control in which order they are being found.
I think it is just counter intuitive if this function uses the first value.
There was a problem hiding this comment.
You already have the same problem with two different values both coming from dependencies because you have little control in which order they are being found.
You have proposed that in this case the dependencies must be resolved separately and cannot use the combined compile options.
I think it is just counter intuitive if this function uses the first value.
For me it's not counter intuitive, it resembles the C++ map::insert logic
There was a problem hiding this comment.
We should clarify the goal here first. Then come up with the behavior and name of this function.
The function is being used when calling find_package(catkin REQUIRED COMPONENTS foo bar) where as both components might have (recursive) dependencies themselves. What do you expect to happen if they export different values for the same key and why?
Re-reading some of this thread in the original comment you mentioned that this would be a "collision" and considered to print a warning.
There was a problem hiding this comment.
What do you expect to happen if they export different values for the same key and why?
As we discussed it should print a warning (in any case).
It might even better to issue a fatal error, as the situation is unresolvable (?).
This way it doesn't matter which comes first or last ;)
There was a problem hiding this comment.
Since you are proposing the feature I will leave it up to you to decide if it is a warning by default or an error.
From my point of view this new feature will likely not be widely usable for e.g. setting the compiler standard version (which was one reason it was proposed in the first place I think). Simply because any situation where packages don't agree on the value are going to be a problem.
There was a problem hiding this comment.
Right now I don't know if we should merge it.
It adds complexity, but might lead to problems if it gets used widely.
For the C++ standards issue I have implemented other work-arounds.
There was a problem hiding this comment.
Right now I don't know if we should merge it.
It adds complexity, but might lead to problems if it gets used widely.
I share your concern.
For the C++ standards issue I have implemented other work-arounds.
Depending on which CMake versions you need to support CMAKE_CXX_STANDARD might be an interesting option too (to be used in your enable_cxx11_support package).
There was a problem hiding this comment.
Depending on which CMake versions you need to support CMAKE_CXX_STANDARD might be an interesting option too (to be used in your enable_cxx11_support package).
The package was meant for indigo as well, so I don't want to rely on new CMake features.
It seems like most users have settled to set the C++11 options in any depending package :-/
| break() | ||
| elseif(elem MATCHES ${expr}) | ||
| set(found TRUE) | ||
| message(${ARG_LEVEL} "could not add '${item}' (from '${ARG_CONTEXT}'), already contained: '${elem}'") |
There was a problem hiding this comment.
What if this is intentionally passed? Related to the question above.
| @@ -1,4 +1,6 @@ | |||
| language: python | |||
| dist: trusty | |||
| sudo: required | |||
There was a problem hiding this comment.
Is this necessary for this PR? If not please remove it from this patch.
There was a problem hiding this comment.
Not sure about sudo: required (I guess this is the default anyways.)
dist: trusty is required because of cmake_minimum_required(VERSION 2.8.12), which is needed for add_compile_options in the tests. As an alternative add_definitions could be used though.
| list_append_deduplicate | ||
| list_append_unique | ||
| list_insert_in_workspace_order | ||
| list_insert_options |
There was a problem hiding this comment.
Would list_append_unique_options make more sense for the name? Since the values are always appended. The only difference to the list_append_unique function above is that is only considers the key part and not the value when checking for existence.
There was a problem hiding this comment.
I am not in favor of a particular name.
I have chosen "insert" because of the setmap logic, but if you like list_append_unique_options better that's fine for me as well.
| # :type ARGN: list key[=value] strings | ||
| # | ||
| # :param CONTEXT: context to be printen in case of erros | ||
| # :param CONTEXT: context to be printen in case of errors |
|
I can address the simple issues tomorrow. However, I am not sure about the first/last-issue. In which order do the dependencies get resolved? |
I don't think the order will equal the topological order at build time. Especially since there might be packages which don't have to processed sequentially but can be build in parallel. From a CMake point of view it calls |
"depth first" with the order of depends passed by the author of each package. |
|
As discussed this feature might introduce more problems (conflicting settings..) than it solves. @dirk-thomas: Thanks for reviewing and discussing it! |
|
Thank you for your effort! |
After the discussions in #610 I have now refactored and improved #842
<comp>_COMPILE_OPTIONSandcatkin_COMPILE_OPTIONSkeyvs.key=vs.key=val1vs.key=val2)<comp>_COMPILE_OPTIONSwill be passed to CMake config incatkin_packageCOMPILE_OPTIONSoption tocatkin_packageI made the decision to switch to compile options completely for the following reasons:
add_compile_optionscan handle all*_DEFINITIONSsettingsadd_compile_optionsandadd_definitionsOpen issues:
test/test_list_append_keys_from.cmaketo catkin tests? It prints CMake warnings..Not sure if theDEFINESoption is really needed. In most cases<comp>_COMPILE_OPTIONSmight be more reasonable, since it can be passed to the exporting package easily (seeset_compile_optionsexample package)