Repository navigation
Explicitly set C11 and C++14 via the CMake variables - #141
Conversation
|
👍 If you want I think I have a "compile_options" branch on all repos to do this and pass the additional flags using Just never had time to properly test it 😖 |
| include_directories(include) | ||
|
|
||
| set(CMAKE_C_STANDARD 99) | ||
| set(CMAKE_CXX_STANDARD 14) |
There was a problem hiding this comment.
These variables should only be set if they are not yet defined in order to not prevent overriding the value.
Same below.
| 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") |
|
|
||
| if(NOT WIN32) | ||
| set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wpedantic") | ||
| set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic") |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) ...
There was a problem hiding this comment.
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
There was a problem hiding this comment.
I went ahead and reverted to checking the compiler instead of the operating system in 2ecb36d
| endif() | ||
|
|
||
| if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") | ||
| add_compile_options("-Wall -Wextra") |
There was a problem hiding this comment.
Should we add -Wpedantic here?
There was a problem hiding this comment.
I think that we didn't because of the memory tools. see ros2/ros2#305
…AGS and CMAKE_CXX_FLAGS
|
I just rebased this to resolve any potential conflicts, let me know if there's any further work that needs to be done. |
|
Also, pushed a last minute change to pass the compiler flags as a list, not as a string, to |
|
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
|
@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? |
|
It's ok, the title of the PR is what will appear in the history of this repo and you already updated it accrdingly 👍 |
This PR uses
CMAKE_C_STANDARDandCMAKE_CXX_STANDARDto set C11 and C++14 respectively.