angles icon indicating copy to clipboard operation
angles copied to clipboard

Ensure that M_PI is defined in any downstream compilation unit in Windows

Open traversaro opened this issue 10 months ago • 0 comments

The PR https://github.com/ros/angles/pull/34 fixed the use of angles in some downstream compilation units, but not in all of them. The problem is that in this project M_PI is used in a public header, so just adding #define _USE_MATH_DEFINES in the header works if a compilation unit uses this header as:

#include <angles/angles.h>

#include <cmath>

but will fail if it is used as:

#include <cmath>

#include <angles/angles.h>

as in the second case, _USE_MATH_DEFINES is defined once math.h was already included, and so it is not possible to "retroactively" set it.

To ensure that _USE_MATH_DEFINES is always defined, we set it via CMake. I also left the _USE_MATH_DEFINES defined in the code to avoid breaking downstream consumers that do not use CMake, but I wrapped it with #ifndef _USE_MATH_DEFINES to avoid warnings.

traversaro avatar Feb 12 '25 18:02 traversaro