I need to conditionally compile several parts of the code, depending on the presence of some libraries in the system or not. Their presence is determined during the CMake configuration phase, and I plan to tell the compiler the results using preprocessor definitions (e.g. #ifdef (LIB_DEFINED) ... #endif).
I know of two ways to achieve this in CMake:
- Place the template file with these preprocessor definitions, pass it to CMakeLists for configure_file (), and finally # include the generated configuration file in each source file
- Use add_definitions (-DLIB_DEFINED) directly in CMakeLists directly.
The first approach seems more complicated to me, so are there any advantages to using it instead of the second (for example, avoiding some portability issues)?
source
share