Build library dependencies from anywhere in the source tree.

If you already have all your libraries under your project root, you don't need this.

Manifest Utils

include(/path/to/ManifestFile)

Add a library from anywhere in the source tree, only once, as a "subdirectory"

function(builddep_find_lib lib_name)
    # Already loaded?
    get_property(${lib_name}_defined_globally GLOBAL PROPERTY global_${lib_name}_loaded DEFINED)

    if(NOT ${lib_name}_defined_globally)
        define_property(GLOBAL PROPERTY global_${lib_name}loaded
            BRIEF_DOCS "Boolean variable indicating whether a lib was loaded"
            FULL_DOCS "See Brief Docs")
        set_property(GLOBAL PROPERTY global
${lib_name}_loaded FALSE)
    endif(NOT ${lib_name}_defined_globally)

    get_property(${lib_name}_loaded GLOBAL PROPERTY global_${lib_name}_loaded)

    # Use the two arg form of add_subdirectory to specify the binary_dir for the dependency
    if(NOT ${lib_name}loaded)
        set_property(GLOBAL PROPERTY global
${lib_name}_loaded TRUE)
        string(TOUPPER ${lib_name} lib_name_upper)
        add_subdirectory(${${lib_name_upper}_IMPORT_DIR} ${CMAKE_BINARY_DIR}/${lib_name})
    endif(NOT ${lib_name}_loaded)
endfunction()

Add just the library's public includes.

Only needed to handle circular header deps.

function(builddep_target_add_headers target_name scope lib_name)
  string(TOUPPER ${lib_name} lib_name_upper)
  target_include_directories(${target_name} ${scope} ${${lib_name_upper}_IMPORT_DIR}/include)
endfunction()

$[Get Code]1

Manifest File

set(FOO_IMPORT_DIR /path/to/foo)
set(BAR_IMPORT_DIR /path/to/bar)

$[Get Code]2

Usage

builddep_find_lib(foo)
builddep_find_lib(bar)

add_executable(helloworld
  helloworld.cpp
)

target_link_libraries(helloworld
  PRIVATE
    foo
    bar
)

$[Get Code]3