Skip to content

Compile options - #221

Merged
mikaelarguedas merged 4 commits into
masterfrom
compile_options
Jun 17, 2017
Merged

mikaelarguedas merged 4 commits into
masterfrom
compile_options

Conversation

@mikaelarguedas

Copy link
Copy Markdown
Member

This is part of ros2/ros2#362

I open a PR for this one because there is slightly more change than the other repos.

  • I tried to get rid of the COMPILE_FLAGS property that is deprecated in cmake. There is one spot I left it (see inline comment) because that would require duplicating code.

Connects to ros2/ros2#362

make ARM happy?

pass flag to specific targets explicitly

remove todo, compiler come from redefinition of typedef
@mikaelarguedas mikaelarguedas added the in progress Actively being worked on (Kanban column) label Jun 17, 2017
macro(set_properties _build_type)
set_target_properties(${_target_name} PROPERTIES
COMPILE_FLAGS "${_extension_compile_flags}"
COMPILE_FLAGS ${_extension_compile_flags}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't use COMPILE_OPTIONS here because the evaluation of _extension_compile_flags results in a string.
We could work around it by checking the compiler within this macro and make a different call to "set_target_properties" with COMPILE_DEFINITION only if the compiler supports the flags we want

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently the variable contains a string. Have you tried to convert it into a list and then use COMPILE_OPTIONS?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point! 2865b64

@mikaelarguedas mikaelarguedas added in review Waiting for review (Kanban column) and removed in progress Actively being worked on (Kanban column) labels Jun 17, 2017
set(_extension_compile_flags "-Wall -Wextra")
elseif("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(_extension_compile_flags "-Wall;-Wextra")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest to not use a semicolon here. Just pass both value parts as separate values and the variable will be a list (same as the add_compile_options invocation above).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fair enough 3042142

@dirk-thomas

dirk-thomas commented Jun 17, 2017 •

Copy link
Copy Markdown
Member

While this looks good I am not sure CMake allows multiple values per property (see https://cmake.org/cmake/help/v3.5/command/set_target_properties.html). Have you checked that all warning levels are being enabled as desired?

@mikaelarguedas

mikaelarguedas commented Jun 17, 2017 •

Copy link
Copy Markdown
Member Author

looks like it works as expected:

  set(a "")
  get_target_property(a ${_target_name} COMPILE_OPTIONS)
  message(FATAL_ERROR "COMPILE_OPTIONS:${a}")

prints:

COMPILE_OPTIONS:-Wall;-Wextra

I'll check the compilet invocation tomorrow to confirm that it passes the flags as expected.
The alternatives being:

  target_compile_options(${rosidl_generate_interfaces_TARGET}${_target_suffix}
    PUBLIC -Wall -Wextra -Wpedantic)

or switch back to use the deprecate COMPILE_FLAGS

@dirk-thomas dirk-thomas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for checking. I am pretty confident that the compiler args are fine if CMake reports the property correctly

@mikaelarguedas

Copy link
Copy Markdown
Member Author

confirmed passing -Warguedas in the same line makes the comipler complain. I'm going to squash and merge this

@mikaelarguedas
mikaelarguedas merged commit ab077c3 into master Jun 17, 2017
@mikaelarguedas
mikaelarguedas deleted the compile_options branch June 17, 2017 19:35
@mikaelarguedas mikaelarguedas removed the in review Waiting for review (Kanban column) label Jun 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants