Skip to content

Commit

Permalink
Fix issue when ip_link() is called on IP defined in different src dir (
Browse files Browse the repository at this point in the history
  • Loading branch information
Risto97 authored Oct 4, 2024
1 parent d7d403d commit 8b4e8d0
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 2 deletions.
6 changes: 6 additions & 0 deletions cmake/utils/socmake_graph.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ function(__flatten_graph_recursive NODE RET)
if(LINK_LIBS STREQUAL "LINK_LIBS-NOTFOUND") # Not needed
set(LINK_LIBS "")
endif()

# Workaround a mechanism described in (https://cmake.org/cmake/help/v3.30/prop_tgt/INTERFACE_LINK_LIBRARIES.html)
list(FILTER LINK_LIBS EXCLUDE REGEX "::@")

# message("LINK LIBS for lib: ${NODE} are: ${LINK_LIBS}")
foreach(lib ${LINK_LIBS})
__flatten_graph_recursive(${lib} LIB_ADDED)
Expand Down Expand Up @@ -102,6 +106,8 @@ function(__all_vertices_removed NODE RET)
if(LINK_LIBS STREQUAL "LINK_LIBS-NOTFOUND")
set(LINK_LIBS "")
endif()
# Workaround a mechanism described in (https://cmake.org/cmake/help/v3.30/prop_tgt/INTERFACE_LINK_LIBRARIES.html)
list(FILTER LINK_LIBS EXCLUDE REGEX "::@")

compare_lists("${RM_LIST}" "${LINK_LIBS}" L_EQ)
set(${RET} ${L_EQ} PARENT_SCOPE)
Expand Down
2 changes: 0 additions & 2 deletions tests/ip_link/ip_link1.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,3 @@ function(${${TEST_NAME}})
list(SUBLIST V_SOURCES 6 2 CURRENT_V_FILES)
ct_assert_equal(CURRENT_V_FILES "ip1_f1.v;ip1_f2.v")
endfunction()


Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Test workaround for quirk at https://cmake.org/cmake/help/v3.30/prop_tgt/INTERFACE_LINK_LIBRARIES.html
# In case INTERFACE library ("top" in this case) is defined in a subdirectory
# and target_link_libraries() was called on that lib ("top") from a different source directory
# CMake wraps INTERFACE_LINK_LIBRARIES with ::@(directory-id);...;::@
# Graph traversal functions should ignore this wrapper

include("${CMAKE_CURRENT_LIST_DIR}/../../../CMakeLists.txt")
set(THIS_DIR ${CMAKE_CURRENT_LIST_DIR})

set(TEST_NAME ip_link_different_subdir)
ct_add_test(NAME ${TEST_NAME})
function(${${TEST_NAME}})
add_ip(subip)

add_subdirectory(${THIS_DIR}/ips "ips")
ip_link(top subip)

# This would normally fail, as flatten_graph would fail
get_ip_sources(SOURCES top SYSTEMRDL)
endfunction()
14 changes: 14 additions & 0 deletions tests/ip_link/ip_link_different_subdir/ips/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
add_ip(top)

ip_sources(top SYSTEMRDL
${CMAKE_CURRENT_LIST_DIR}/src.rdl)


add_subdirectory(ip2)
add_subdirectory(ip3)
add_subdirectory(ip4)

ip_link(ip2 ip4)

ip_link(top ip3)
ip_link(ip3 ip2)
2 changes: 2 additions & 0 deletions tests/ip_link/ip_link_different_subdir/ips/ip2/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
add_ip(ip2)

2 changes: 2 additions & 0 deletions tests/ip_link/ip_link_different_subdir/ips/ip3/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
add_ip(ip3)

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_ip(ip4)

0 comments on commit 8b4e8d0

Please sign in to comment.