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