Consider a C++ project, organized in a git repository. Assume that the git repository has a submodule from which a library is built on which the (super)project depends. If the (super)project depends not only on the library but on the library built with specific (CMake) parameters, how can it be ensured that the submodule is built with these parameters when the (super)project is built?
The build options (like MYLIB_WITH_SQLITE
) must be added to the interface of the library, that is, to the MYLIB_DEFINITIONS
variable in case of an old-school config-module, or to the INTERFACE_COMPILE_DEFINITIONS
property, if the library creates its config-module with the install(EXPORT ...)
command:
add_library(mylib ...)
if(MYLIB_WITH_SQLITE)
target_compile_definitions(mylib PUBLIC MYLIB_WITH_SQLITE)
endif()
...
install(TARGETS mylib EXPORT mylib-targets ...)
install(EXPORT mylib-targets ...)
And in the consuming library or executable you can write simple compile-time checks:
#ifndef MYLIB_WITH_SQLITE
#error mylib must be built with sqlite
#endif
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With