From 15065eb01c620f7fcb46440a4a6d54576b272511 Mon Sep 17 00:00:00 2001 From: Janusz Jankowski Date: Fri, 9 Aug 2019 13:05:10 +0200 Subject: [PATCH] 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 --- scripts/cmake/misc.cmake | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/scripts/cmake/misc.cmake b/scripts/cmake/misc.cmake index 5be68fca8..4b2f90be1 100644 --- a/scripts/cmake/misc.cmake +++ b/scripts/cmake/misc.cmake @@ -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()