[SECP256K1] CMake: set default build configuration and optimization
Summary:
The optimization flags when configured with autotools are as set like:
- Always use -g, unless something is set in the CFLAGS as an
environment variable.
- Append -O3 if coverage is not enabled, -O0 otherwise.
This diff adds some kind of similar behavior to CMake:
- If no build configuration is defined, use RelWithDebInfo (release
with debug information).
- Set the flags to -g -O3 for this configuration.
With this diff, the CMake default build will have the same flags than
autotools by default, i.e. -g -O3. It is still possible to select a
different build configuration (and then use the associated flags), and
also pass additional flags through the CMAKE_C_FLAGS cache variable.
Note: It is not possible to select the optimization level with
autotools; since the -O3 flag is appended to the CFLAGS it will take
precedence over any passed value. As a consequence, I don't know what
the CFLAGS=-O0 case is testing in the Travis build, but it is not
testing against a non optimized binary.
Test Plan:
cmake -GNinja .. ninja -v secp256k1
Check the -g -O3 flags are used.
ninja check-secp256k1
Repeat the same steps when building secp256k1 as a standalone project,
expect the same result.
cmake -GNinja .. -DCMAKE_BUILD_TYPE=Debug ninja -v secp256k1
Check the -g3 -O2 flags are used.
ninja check-secp256k1
Repeat the same steps when building secp256k1 as a standalone project,
expect the flag -g only (CMake defaults for the Debug configuration).
Run the Travis build (see
https://travis-ci.org/Fabcien/secp256k1/builds/643874641).
Reviewers: #bitcoin_abc, deadalnix
Reviewed By: #bitcoin_abc, deadalnix
Differential Revision: https://reviews.bitcoinabc.org/D5106