From ad089dcdc4daa928f63a676147053daee9a5998d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Risto=20Peja=C5=A1inovi=C4=87?= Date: Fri, 4 Oct 2024 23:26:07 +0200 Subject: [PATCH] Fix issue when ip_link() is called on IP defined in different source directory --- cmake/utils/socmake_graph.cmake | 13 ++++++++++++ tests/ip_link/ip_link1.cmake | 2 -- .../ip_link_different_subdir.cmake | 20 +++++++++++++++++++ .../ips/CMakeLists.txt | 4 ++++ 4 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 tests/ip_link/ip_link_different_subdir/ip_link_different_subdir.cmake create mode 100644 tests/ip_link/ip_link_different_subdir/ips/CMakeLists.txt diff --git a/cmake/utils/socmake_graph.cmake b/cmake/utils/socmake_graph.cmake index be11139..e36b9f1 100644 --- a/cmake/utils/socmake_graph.cmake +++ b/cmake/utils/socmake_graph.cmake @@ -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) @@ -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) diff --git a/tests/ip_link/ip_link1.cmake b/tests/ip_link/ip_link1.cmake index de4ddee..e496987 100644 --- a/tests/ip_link/ip_link1.cmake +++ b/tests/ip_link/ip_link1.cmake @@ -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() - - diff --git a/tests/ip_link/ip_link_different_subdir/ip_link_different_subdir.cmake b/tests/ip_link/ip_link_different_subdir/ip_link_different_subdir.cmake new file mode 100644 index 0000000..271c289 --- /dev/null +++ b/tests/ip_link/ip_link_different_subdir/ip_link_different_subdir.cmake @@ -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() diff --git a/tests/ip_link/ip_link_different_subdir/ips/CMakeLists.txt b/tests/ip_link/ip_link_different_subdir/ips/CMakeLists.txt new file mode 100644 index 0000000..ed92fb1 --- /dev/null +++ b/tests/ip_link/ip_link_different_subdir/ips/CMakeLists.txt @@ -0,0 +1,4 @@ +add_ip(top) + +ip_sources(top SYSTEMRDL + ${CMAKE_CURRENT_LIST_DIR}/src.rdl)