colcon / colcon-cmake

Extension for colcon to support CMake packages
http://colcon.readthedocs.io
Apache License 2.0
16 stars 25 forks source link

Default build type should be release #96

Closed fred-apex-ai closed 3 years ago

fred-apex-ai commented 3 years ago

Hey there, I was surprised to notice that in a plain colcon build --packages-select foo, it defaults to unix makefiles and doesn't set the build type. That is, in the build directory,

grep CMAKE_BUILD_TYPE CMakeCache.txt
CMAKE_BUILD_TYPE:STRING=

and the compiler invocation has no optimization flags in it; e.g.

/usr/bin/c++ -o foo.o -c foo.cpp

I'm aware that the build type is ignored when generating multiconfigurations for IDEs and the potential confusion about that; see https://stackoverflow.com/a/24470998/14409577

I also know how to opt in to build in release mode with

colcon build --packages-select foo --cmake-args -DCMAKE_BUILD_TYPE=Release

But I would expect that a C++ robotics package by default is built in release mode because performance matters. After all, why do we use C++?

Was this is discussed before and there are arguments that I'm missing?

fyi @nnmm

dirk-thomas commented 3 years ago

I was surprised to notice that in a plain colcon build --packages-select foo, it defaults to unix makefiles and doesn't set the build type.

The reason is that this is the default behavior of CMake. colcon doesn't try to change reasonable defaults since that would surprise users familiar with the native tools.

You could put this configuration option into the defaults.yaml file if you prefer a custom default value.

dirk-thomas commented 3 years ago

I will go ahead and close the ticket assuming my previous comment answered your question.

Nate711 commented 1 year ago

I think the fact that release mode can only be specified with -DCMAKE_BUILD_TYPE=Release should be documented somewhere besides this one github issue. If you try googling colcon build release mode you'll see what I mean. Perhaps put this information on the ros2 tutorial page? https://docs.ros.org/en/humble/Tutorials.html