Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In CMake, is it possible to build a dependency imported from a build tree?

I am trying to use the CMake feature for exporting/importing targets from a build tree (see this wiki page). I have this dependency library:

add_library(dependency SHARED dependency.cpp)
export(TARGETS dependency FILE dependency-targets.cmake)

And an executable uses this library in another project:

include(${DEPENDENCY_PATH}/dependency-targets.cmake)

add_executable(main-app main.cpp)
target_link_libraries(main-app dependency)

This works fine. While I do understand that this export/import mechanism "only" provide a convenient way to reference external binaries, I am wondering whether dependency could be compiled when running make in main-app? Either using the import mechanism (which I doubt) or using another one ?

like image 516
piwi Avatar asked Nov 12 '22 11:11

piwi


1 Answers

You could look into the "superbuild" pattern and ExternalProject.

The gist of the idea is that you set up one "superbuild" project which will use just ExternalProject_Add() commands; this will set up your real project and all its dependencies.

like image 80
Angew is no longer proud of SO Avatar answered Dec 09 '22 09:12

Angew is no longer proud of SO