I have a question regarding specific inclusion of functionality using shared libraries. I have my own small in-code profiler, that I am using in multiple projects so usually include as a shared library. Originally I wanted to turn of the profiling code using compile time flag. For example:
#ifdef PROFILEAPP
class Profiler {
static void start() { ... }
static void stop() { ... }
};
#else
class Profiler {
static void start(){}
static void stop(){}
};
However, I this does not work if the lib is compiled before hand without defining the symbols. Note that my library is not header only.
So I found out I can compile two distinct targets using the cmake command:
set_property( TARGET my_lib PROPERTY COMPILE_DEFINITIONS "PROFILEAPP")
This does work but I have to change the linking options in my client application, to cope with two different .so files. However, I’m wondering if this is the way to go? Do libraries like boost do something similar with regard to machine differences? Is there any way I can do the same by just defining PROFILEAPP in my client application?
Keeping two different build configurations is essentially the only thing you can do. Ultimately you’ll find it’s probably simplest to create several build configurations for your application too. Debug, Profile, Release, etc.