Update autoware_set_compile_options
Description
autoware_set_compile_options
is used in many places across packages but not all, the test targets are missing.
Calling the function for every cmake target is a bit tedious and can be forgotten. It could be useful to investigate if the settings can be applied in a less manual fashion.
Within autoware_set_compile_options
, several minor things could be improved:
C++ standard
In https://gitlab.com/autowarefoundation/autoware.auto/AutowareAuto/-/blob/master/src/tools/autoware_auto_cmake/cmake/autoware_auto_cmake.cmake#L23, C++14 is chosen as
set(CMAKE_CXX_STANDARD 14)
but this may end up as -std=gnu14
with g++
. We should additionally set
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
Setting the standard is repeated in over 50 CMakeLists.txt
files. We could check if that can be avoided so we follow the DRY principle and just modify autoware_set_compile_options
compiler flags
The precise way to check for a compiler is with
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
But in https://gitlab.com/autowarefoundation/autoware.auto/AutowareAuto/-/blob/master/src/tools/autoware_auto_cmake/cmake/autoware_auto_cmake.cmake#L52, the decision is based on the platform
if (WIN32)
...
else()
if (NOT APPLE)
endif()
```cmake
if(NOT APPLE)
# GCC/G++ Only, not CLang
target_compile_options(${target}
PUBLIC $<$<COMPILE_LANGUAGE:CXX>: -Wuseless-cast>)
Definition of Done
autoware_set_compile_options
should
-
enforce strict C++14 settings -
apply compiler settings based on checking the compiler, not the platform
The cmake function autoware_set_compile_options
should be
-
used with all C++ targets (incl. test targets) in Autoware.Auto, either by explicitly calling it or another mechanism that avoid repetition (preferred) -
recommended in dev guidelines/MR template (may be no op) -
Remove redundant definitions of warnings and C++ standard from CMakeList.txt
: search for STANDARD and-Wall
-
follow-up issue for TODO(Fred)
comments
Update docs:
-
docs/building/index.md talks about compiler settings as updated in !833 (merged)