Skip to content

Commit

Permalink
Fix issue when ip_link() is called on IP defined in different source …
Browse files Browse the repository at this point in the history
…directory
  • Loading branch information
Risto97 committed Oct 4, 2024
1 parent 3e1d111 commit ad089dc
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
13 changes: 13 additions & 0 deletions cmake/utils/socmake_graph.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ 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(GET LINK_LIBS -1 LAST_LIB)
if(LAST_LIB STREQUAL "::@")
list(FILTER LINK_LIBS EXCLUDE REGEX "::@")
endif()

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

compare_lists("${RM_LIST}" "${LINK_LIBS}" L_EQ)
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()
4 changes: 4 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,4 @@
add_ip(top)

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

0 comments on commit ad089dc

Please sign in to comment.