Skip to content

Explicitly set C11 and C++14 via the CMake variables - #141

Merged
mikaelarguedas merged 7 commits into
ros2:masterfrom
esteve:c99
Jun 16, 2017
Merged

mikaelarguedas merged 7 commits into
ros2:masterfrom
esteve:c99

Conversation

@esteve

@esteve esteve commented Jun 6, 2017

Copy link
Copy Markdown
Member

This PR uses CMAKE_C_STANDARD and CMAKE_CXX_STANDARD to set C11 and C++14 respectively.

@esteve esteve added the in progress Actively being worked on (Kanban column) label Jun 6, 2017
@mikaelarguedas

mikaelarguedas commented Jun 6, 2017 •

Copy link
Copy Markdown
Member

👍 If you want I think I have a "compile_options" branch on all repos to do this and pass the additional flags using add_compile_options rather than appending the flags to both the C and C++ flags

Just never had time to properly test it 😖

@wjwwood wjwwood added in review Waiting for review (Kanban column) and removed in progress Actively being worked on (Kanban column) labels Jun 6, 2017
Comment thread rcl/CMakeLists.txt Outdated
include_directories(include)

set(CMAKE_C_STANDARD 99)
set(CMAKE_CXX_STANDARD 14)

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.

These variables should only be set if they are not yet defined in order to not prevent overriding the value.

Same below.

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.

Fixed in 4e092bc

Comment thread rcl/CMakeLists.txt Outdated
if(NOT WIN32)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -Wall -Wextra")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_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.

These two lines could become a one-liner by using add_compile_options (I don't mind making the change if it's ok with you @esteve )

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.

That'd be great, thanks!

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.

Done in f4cb532

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.

Also done for rcl_lifecycle in cc2c9a5

Comment thread rcl_lifecycle/CMakeLists.txt Outdated

if(NOT WIN32)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wpedantic")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic")

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.

These two lines could become a one-liner by using add_compile_options.
Also I think the previous condition was more accurate: CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang" because these flags are compiler dependant rather than Platform dependant

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.

That's true, though wouldn't that be only for the case where rcl is being compiled on Windows with Clang or GCC? The rest of ROS2 uses the same style if(NOT WIN32) ...

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.

Yeah my goal is to start converting the other ones to use the same logic. I agree that there are for now few configurations where this doesn't give the same result but that will be more future proof if we add more platforms in the future

@esteve esteve Jun 15, 2017 •

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.

I went ahead and reverted to checking the compiler instead of the operating system in 2ecb36d

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.

Also done for rcl_lifecycle in cc2c9a5

@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.

LGTM.

Comment thread rcl/CMakeLists.txt Outdated
endif()

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options("-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.

Should we add -Wpedantic here?

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 think that we didn't because of the memory tools. see ros2/ros2#305

@esteve

esteve commented Jun 15, 2017

Copy link
Copy Markdown
Member Author

I just rebased this to resolve any potential conflicts, let me know if there's any further work that needs to be done.

@esteve

esteve commented Jun 15, 2017

Copy link
Copy Markdown
Member Author

Also, pushed a last minute change to pass the compiler flags as a list, not as a string, to add_compile_options()

@mikaelarguedas

Copy link
Copy Markdown
Member

Thanks @esteve, I'm putting CI results on this ticket ros2/ros2#362.

I think that we're good to go. Though this package actually needs c11 otherwise there are warnings on macos. Can you cherry-pick this commit 71bb5bb? thanks!

avoid typedef redifinition warning on macos

remove todo, compiler come from redefinition of typedef
@esteve esteve changed the title Explicitly set C99 and C++14 via the CMake variables Explicitly set C11 and C++14 via the CMake variables Jun 16, 2017
@esteve

esteve commented Jun 16, 2017

Copy link
Copy Markdown
Member Author

@mikaelarguedas done. I've updated the PR title, but unfortunately the branch name is c99, shall I close this and open a new one with a better name?

@mikaelarguedas

Copy link
Copy Markdown
Member

It's ok, the title of the PR is what will appear in the history of this repo and you already updated it accrdingly 👍

@mikaelarguedas
mikaelarguedas merged commit 0f25199 into ros2:master Jun 16, 2017
@mikaelarguedas mikaelarguedas removed the in review Waiting for review (Kanban column) label Jun 16, 2017
@esteve
esteve deleted the c99 branch June 19, 2017 08:10
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.

4 participants