Tech /

C Make Build Deps





edit SideBar

C Make Build Deps

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()

Manifest File

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

Usage

builddep_find_lib(foo)
builddep_find_lib(bar)

add_executable(helloworld
  helloworld.cpp
)

target_link_libraries(helloworld
  PRIVATE
    foo
    bar
)
Recent Changes (All) | Edit SideBar Page last modified on 04 April 2019, at 12:08 PM UTC Edit Page | Page History
Powered by PmWiki