It is quite simple to do in a standard makefile
GOVFLAGS= -lgov
# Library has been build, all objectfiles are left in build directory
timings: benchmark/timings.c $(LIBNAME)
# compile benchmark/timings.c, link it with all objectfiles
# and put executable in build directory
$(CC) $(CFLAGS) $^ $(GOVFLAGS) -o timings
profiling:
# Call makefile again with additional flag "-fprofile-arcs"
# to generate the *gcda files while making the benchmark function
make CFLAGS="$(CFLAGS) -fprofile-arcs" timings
# run the "before" benchmark
./timings
# remove static library and objectfiles. *gcda files stay, of course
rm -f *.a *.o timings
# Call makefile again with additional flag "-fbranch-probabilities"
# to build the library with the actual optimizations.
make CFLAGS="$(CFLAGS) -fbranch-probabilities"
# snipped: part of benchmarking that builds and runs the "after"
# benchmark
I was not able to find a method to call cmake
recursively like make
as shown above. I tried to do it by hand but I was not able to find a way to keep the *gcda
files because I found no way to the same thing twice, as is needed for this method of profiling, and different targets compile in different sub-directories.
Another problem: its legacy code, so I have to take what is there, no changes in project structure (e.g. moving directories around etc.).
The build uses a separate directory for building (as in mkdir build && cd build && cmake .. -DOPTIONS=ARGS
).
No modern cmake cmake_minimum_required(VERSION 3.10)
available.
How can I call cmake
from within CMakeLists.txt
to translate the above makefile
snippet into a working cmake-script?
Alternative solutions are welcome, too, of course, I am fully aware of the risk that it might be an XY problem!