Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix parse json_output #38

Merged
merged 3 commits into from
Dec 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 81 additions & 48 deletions xrepo.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,8 @@ function(xrepo_package package)
set(configs "${_config_lua_script}")
# Trigger cmake configure when ${_config_lua_script} changes.
set_property(
DIRECTORY
APPEND
DIRECTORY
APPEND
PROPERTY CMAKE_CONFIGURE_DEPENDS
"${_config_lua_script}"
)
Expand Down Expand Up @@ -404,6 +404,10 @@ function(xrepo_target_packages target)
message(STATUS "xrepo: target_link_libraries(${target} ${_visibility} ${${package_name}_LIBRARIES})")
target_link_libraries(${target} ${_visibility} ${${package_name}_LIBRARIES})
endif()
if((DEFINED ${package_name}_SYS_LIBRARIES) AND (NOT ARG_NO_LINK_LIBRARIES))
message(STATUS "xrepo: target_link_libraries(${target} ${_visibility} ${${package_name}_SYS_LIBRARIES})")
target_link_libraries(${target} ${_visibility} ${${package_name}_SYS_LIBRARIES})
endif()
if(DEFINED ${package_name}_DEFINITIONS)
message(STATUS "xrepo: target_compile_definitions(${target} ${_visibility} ${${package_name}_DEFINITIONS})")
target_compile_definitions(${target} ${_visibility} ${${package_name}_DEFINITIONS})
Expand Down Expand Up @@ -508,60 +512,90 @@ macro(_xrepo_fetch_json)
math(EXPR len_end "${len} - 1")
foreach(idx RANGE 0 ${len_end})
# Loop over includedirs.
string(JSON includedirs_len ERROR_VARIABLE includedirs_error LENGTH ${json_output} ${idx} "includedirs")
if("${includedirs_error}" STREQUAL "NOTFOUND" AND NOT "${includedirs_len}" EQUAL 0)
math(EXPR includedirs_end "${includedirs_len} - 1")
foreach(includedirs_idx RANGE 0 ${includedirs_end})
string(JSON dir GET ${json_output} ${idx} includedirs ${includedirs_idx})
# It's difficult to know package name while looping over all packages.
# Thus we use list to collect all include and link dirs.
list(APPEND includedirs ${dir})
#message(STATUS "xrepo DEBUG: includedirs ${idx} ${includedirs_idx} ${dir}")
endforeach()
string(JSON includedirs_type ERROR_VARIABLE includedirs_error TYPE ${json_output} ${idx} "includedirs")
if("${includedirs_type}" STREQUAL "STRING")
string(JSON dir GET ${json_output} ${idx} "includedirs")
list(APPEND includedirs ${dir})
elseif("${includedirs_type}" MATCHES "ARRAY|OBJECT")
string(JSON includedirs_len ERROR_VARIABLE includedirs_error LENGTH ${json_output} ${idx} "includedirs")
if("${includedirs_error}" STREQUAL "NOTFOUND" AND NOT "${includedirs_len}" EQUAL 0)
math(EXPR includedirs_end "${includedirs_len} - 1")
foreach(includedirs_idx RANGE 0 ${includedirs_end})
string(JSON dir GET ${json_output} ${idx} "includedirs" ${includedirs_idx})
# It's difficult to know package name while looping over all packages.
# Thus we use list to collect all include and link dirs.
list(APPEND includedirs ${dir})
#message(STATUS "xrepo DEBUG: includedirs ${idx} ${includedirs_idx} ${dir}")
endforeach()
endif()
endif()

# Loop over linkdirs.
string(JSON linkdirs_len ERROR_VARIABLE linkdirs_error LENGTH ${json_output} ${idx} "linkdirs")
if("${linkdirs_error}" STREQUAL "NOTFOUND" AND NOT "${linkdirs_len}" EQUAL 0)
math(EXPR linkdirs_end "${linkdirs_len} - 1")
foreach(linkdirs_idx RANGE 0 ${linkdirs_end})
string(JSON dir GET ${json_output} ${idx} linkdirs ${linkdirs_idx})
list(APPEND linkdirs ${dir})
#message(STATUS "xrepo DEBUG: linkdirs ${idx} ${linkdirs_idx} ${dir}")
endforeach()
string(JSON linkdirs_type ERROR_VARIABLE linkdirs_error TYPE ${json_output} ${idx} "linkdirs")
if("${linkdirs_type}" STREQUAL "STRING")
string(JSON dir GET ${json_output} ${idx} "linkdirs")
list(APPEND linkdirs ${dir})
elseif("${linkdirs_type}" MATCHES "ARRAY|OBJECT")
string(JSON linkdirs_len ERROR_VARIABLE linkdirs_error LENGTH ${json_output} ${idx} "linkdirs")
if("${linkdirs_error}" STREQUAL "NOTFOUND" AND NOT "${linkdirs_len}" EQUAL 0)
math(EXPR linkdirs_end "${linkdirs_len} - 1")
foreach(linkdirs_idx RANGE 0 ${linkdirs_end})
string(JSON dir GET ${json_output} ${idx} "linkdirs" ${linkdirs_idx})
list(APPEND linkdirs ${dir})
#message(STATUS "xrepo DEBUG: linkdirs ${idx} ${linkdirs_idx} ${dir}")
endforeach()
endif()
endif()

# Loop over links.
string(JSON links_len ERROR_VARIABLE links_error LENGTH ${json_output} ${idx} "links")
if("${links_error}" STREQUAL "NOTFOUND" AND NOT "${links_len}" EQUAL 0)
math(EXPR links_end "${links_len} - 1")
foreach(links_idx RANGE 0 ${links_end})
string(JSON dir GET ${json_output} ${idx} links ${links_idx})
list(APPEND links ${dir})
#message(STATUS "xrepo DEBUG: links ${idx} ${links_idx} ${dir}")
endforeach()
string(JSON links_type ERROR_VARIABLE links_error TYPE ${json_output} ${idx} "links")
if("${links_type}" STREQUAL "STRING")
string(JSON dir GET ${json_output} ${idx} "links")
list(APPEND links ${dir})
elseif("${links_type}" MATCHES "ARRAY|OBJECT")
string(JSON links_len ERROR_VARIABLE links_error LENGTH ${json_output} ${idx} "links")
if("${links_error}" STREQUAL "NOTFOUND" AND NOT "${links_len}" EQUAL 0)
math(EXPR links_end "${links_len} - 1")
foreach(links_idx RANGE 0 ${links_end})
string(JSON dir GET ${json_output} ${idx} "links" ${links_idx})
list(APPEND links ${dir})
#message(STATUS "xrepo DEBUG: links ${idx} ${links_idx} ${dir}")
endforeach()
endif()
endif()

# Loop over syslinks.
string(JSON syslinks_len ERROR_VARIABLE syslinks_error LENGTH ${json_output} ${idx} "syslinks")
if("${syslinks_error}" STREQUAL "NOTFOUND" AND NOT "${syslinks_len}" EQUAL 0)
math(EXPR syslinks_end "${syslinks_len} - 1")
foreach(syslinks_idx RANGE 0 ${syslinks_end})
string(JSON dir GET ${json_output} ${idx} syslinks ${syslinks_idx})
list(APPEND syslinks ${dir})
#message(STATUS "xrepo DEBUG: syslinks ${idx} ${syslinks_idx} ${dir}")
endforeach()
string(JSON syslinks_type ERROR_VARIABLE syslinks_error TYPE ${json_output} ${idx} "syslinks")
if("${syslinks_type}" STREQUAL "STRING")
string(JSON dir GET ${json_output} ${idx} "syslinks")
list(APPEND syslinks ${dir})
elseif("${syslinks_type}" MATCHES "ARRAY|OBJECT")
string(JSON syslinks_len ERROR_VARIABLE syslinks_error LENGTH ${json_output} ${idx} "syslinks")
if("${syslinks_error}" STREQUAL "NOTFOUND" AND NOT "${syslinks_len}" EQUAL 0)
math(EXPR syslinks_end "${syslinks_len} - 1")
foreach(syslinks_idx RANGE 0 ${syslinks_end})
string(JSON dir GET ${json_output} ${idx} "syslinks" ${syslinks_idx})
list(APPEND syslinks ${dir})
#message(STATUS "xrepo DEBUG: syslinks ${idx} ${syslinks_idx} ${dir}")
endforeach()
endif()
endif()

# Loop over defines.
string(JSON defines_len ERROR_VARIABLE defines_error LENGTH ${json_output} ${idx} "defines")
if("${defines_error}" STREQUAL "NOTFOUND" AND NOT "${defines_len}" EQUAL 0)
math(EXPR defines_end "${defines_len} - 1")
foreach(defines_idx RANGE 0 ${defines_end})
string(JSON dir GET ${json_output} ${idx} defines ${defines_idx})
list(APPEND defines ${dir})
#message(STATUS "xrepo DEBUG: defines ${idx} ${defines_idx} ${dir}")
endforeach()
string(JSON defines_type ERROR_VARIABLE defines_error TYPE ${json_output} ${idx} "defines")
if("${defines_type}" STREQUAL "STRING")
string(JSON dir GET ${json_output} ${idx} "defines")
list(APPEND defines ${dir})
elseif("${defines_type}" MATCHES "ARRAY|OBJECT")
string(JSON defines_len ERROR_VARIABLE defines_error LENGTH ${json_output} ${idx} "defines")
if("${defines_error}" STREQUAL "NOTFOUND" AND NOT "${defines_len}" EQUAL 0)
math(EXPR defines_end "${defines_len} - 1")
foreach(defines_idx RANGE 0 ${defines_end})
string(JSON dir GET ${json_output} ${idx} "defines" ${defines_idx})
list(APPEND defines ${dir})
#message(STATUS "xrepo DEBUG: defines ${idx} ${defines_idx} ${dir}")
endforeach()
endif()
endif()
endforeach()

Expand All @@ -585,17 +619,16 @@ macro(_xrepo_fetch_json)

if(DEFINED links)
set(${package_name}_LIBRARIES "${links}" CACHE INTERNAL "")
set(${package_name}_LINK_LIBRARIES "${links}" CACHE INTERNAL "") # Keep compatibility, remove in the future.
list(APPEND xrepo_vars_${package_name} ${package_name}_LIBRARIES)
message(STATUS "xrepo: ${package_name}_LIBRARIES ${${package_name}_LIBRARIES}")
else()
message(STATUS "xrepo fetch --json: ${package_name} links not found")
endif()

if(DEFINED syslinks)
set(${package_name}_LIBRARIES "${syslinks}" CACHE INTERNAL "")
list(APPEND xrepo_vars_${package_name} ${package_name}_LIBRARIES)
message(STATUS "xrepo: ${package_name}_LIBRARIES ${${package_name}_LIBRARIES}")
set(${package_name}_SYS_LIBRARIES "${syslinks}" CACHE INTERNAL "")
list(APPEND xrepo_vars_${package_name} ${package_name}_SYS_LIBRARIES)
message(STATUS "xrepo: ${package_name}_SYS_LIBRARIES ${${package_name}_SYS_LIBRARIES}")
endif()

if(DEFINED defines)
Expand Down
Loading