cmake: add sof_add_static_library utility function

Adding static libraries properly may be troublesome for developers
that are not familiar with CMake, so function that makes it easier
should be useful.

Usually developer will just add sources directly to the target.
Using static libraries should be limited just to closed / precompiled
3rd party components.

Signed-off-by: Janusz Jankowski <janusz.jankowski@linux.intel.com>
This commit is contained in:
Janusz Jankowski 2019-08-09 13:05:10 +02:00 committed by Tomasz Lauda
parent ea71535a7e
commit 15065eb01c
1 changed files with 16 additions and 0 deletions

View File

@ -43,3 +43,19 @@ function(add_local_sources target)
target_sources(${target} PRIVATE ${path})
endforeach()
endfunction()
# Declares new static lib with given name and path that will be linked
# to sof binary.
function(sof_add_static_library lib_name lib_path)
# we need libs to be visible in the root CMakeLists, so use GLOBAL
add_library(${lib_name} STATIC IMPORTED GLOBAL)
if(IS_ABSOLUTE ${lib_path})
set(lib_abs_path ${lib_path})
else()
set(lib_abs_path ${CMAKE_CURRENT_SOURCE_DIR}/${lib_path})
endif()
set_target_properties(${lib_name} PROPERTIES IMPORTED_LOCATION ${lib_abs_path})
target_link_libraries(sof_static_libraries INTERFACE ${lib_name})
endfunction()