Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ with git and CMake: How to build submodules with specific parameters?

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?

like image 565
Max Flow Avatar asked Jul 22 '15 14:07

Max Flow


1 Answers

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
like image 199
tamas.kenez Avatar answered Sep 22 '22 23:09

tamas.kenez