How can I use (configuration file for) external header files that contain compile-time dependent #defines?

Imagine that I am compiling a (static) library libfoo.athat provides a header file foo.h. I will link my application APPwith libfoo.aand #include <foo.h>in my source code. libfoouses CMakeas a build system with user-defined variables, such as those BUILD_WITH_OPTION_BARthat are passed as definitions to the compiler:

ADD_DEFINITIONS(BUILD_WITH_OPTION_BAR)

Inside foo.hwe will find ads #ifdefusing this option:

#ifdef BUILD_WITH_OPTION_BAR
   typedef long long int fooInt;
#else
   typedef int fooInt;
#endif

My question is: How should I know, inside my own APP, what libfoo.awas created with or without BUILD_WITH_OPTION_BAR?

In other words: where and when do I need to identify BUILD_WITH_OPTION_BARinside mine APP?

My basic understanding is that the library libfooshould provide some kind of file config.hthat is included internally foo.h, but how do you get optional #define BUILD_WITH_OPTION_BAR where there is compilation time ( libfoo)?

I found this related question: add_definitions vs. configure_file , but it does not discuss how . It really does.

+4
source share
1 answer

- config.h , . config.h .

Cmake .

CONFIGURE_FILE(<src filename>, <dest filename>)

"config.h.in", "config.h". .in:

#cmakedefine BUILD_WITH_OPTION_BAR 1

#define BUILD_WITH_OPTION_BAR 1

, .

. https://cmake.org/cmake/help/v3.0/command/configure_file.html http://www.vtk.org/Wiki/CMake:How_To_Write_Platform_Checks .

+1

Source: https://habr.com/ru/post/1648065/


All Articles