I have a C++ library which does some numerical work. The main parameter is the number of segments. For speed it matters a factor 3 that the number of segment is const, however I would like to define it at compile time using -DSEGMENTS 32. The header looks like this:
#ifdef SEGMENTS
const int segments = SEGMENTS
#else
const int segments = 20
#endif
That works. However, programs linking with this library don't get the -DSEGMENTS and thus segments is always 20. Without the const I know the solution, but with I don't know. I can imagine some extern trick or installing the header after precompiling if that is possible with cmake.
const. Tag changed to reflect the text of your question