Skip to content

Commit

Permalink
cmake: interface library for sof static libraries
Browse files Browse the repository at this point in the history
Target dependencies have to be added in the same CMakeLists in which
they are declared. CMake interface library is needed to enable adding
static libraries to sof target from subdirectories.

Signed-off-by: Janusz Jankowski <[email protected]>
  • Loading branch information
jajanusz authored and tlauda committed Aug 9, 2019
1 parent 788000f commit ea71535
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
8 changes: 6 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ add_library(sof_options INTERFACE)

target_link_libraries(sof_options INTERFACE sof_public_headers)

# interface library that is used only as container for sof statically
# linked libraries
add_library(sof_static_libraries INTERFACE)

# get compiler name and version
execute_process(
COMMAND ${CMAKE_C_COMPILER} --version
Expand Down Expand Up @@ -117,6 +121,7 @@ target_include_directories(sof_public_headers INTERFACE ${GENERATED_DIRECTORY}/i
if(BUILD_LIBRARY)
add_library(sof SHARED "")
target_link_libraries(sof PRIVATE sof_options)
target_link_libraries(sof PRIVATE sof_static_libraries)
install(TARGETS sof DESTINATION lib)

add_subdirectory(src)
Expand Down Expand Up @@ -166,9 +171,8 @@ add_executable(sof "")
target_link_libraries(sof PRIVATE sof_options)
target_link_libraries(sof PRIVATE sof_ld_scripts)
target_link_libraries(sof PRIVATE sof_ld_flags)
target_link_libraries(sof PRIVATE sof_static_libraries)

sof_add_build_counter_rule()

add_subdirectory(src)

target_link_libraries(sof PRIVATE sof_lib)
17 changes: 7 additions & 10 deletions src/arch/xtensa/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -154,24 +154,21 @@ add_local_sources(sof
exc-dump.S
)

add_library(sof_lib INTERFACE)
target_link_libraries(sof_lib INTERFACE sof_options)

# TODO: order of these libraries does matter, what is bad,
# we should switch to building with thin archives without symbols index
# and made it before final link so dependencies won't matter
target_link_libraries(sof_lib INTERFACE xtos)
target_link_libraries(sof_lib INTERFACE hal)
target_link_libraries(sof_static_libraries INTERFACE xtos)
target_link_libraries(sof_static_libraries INTERFACE hal)

target_link_libraries(sof_lib INTERFACE xlevel2)
target_link_libraries(sof_lib INTERFACE xlevel3)
target_link_libraries(sof_lib INTERFACE xlevel4)
target_link_libraries(sof_lib INTERFACE xlevel5)
target_link_libraries(sof_static_libraries INTERFACE xlevel2)
target_link_libraries(sof_static_libraries INTERFACE xlevel3)
target_link_libraries(sof_static_libraries INTERFACE xlevel4)
target_link_libraries(sof_static_libraries INTERFACE xlevel5)

if(build_bootloader)
add_local_sources(sof main-entry.S)
else()
target_link_libraries(sof_lib INTERFACE reset)
target_link_libraries(sof_static_libraries INTERFACE reset)
endif()

target_link_libraries(sof_ld_flags INTERFACE "-lgcc")
Expand Down

0 comments on commit ea71535

Please sign in to comment.