improve: simplify xmake.lua
This commit is contained in:
1 parent
4502296915
commit
06237c103a
4 files changed
+217
-563
No files matched your search
@@ -1,17 +1,18 @@
|
||||
if not make_ros_config then
|
||||
includes("../../xmake/ros2.lua")
|
||||
end
|
||||
|
||||
add_requires("pkgconfig::eigen3", {system = true})
|
||||
add_cxxflags("-Wall", "-Wextra")
|
||||
if is_mode("release") then
|
||||
set_optimize("faster")
|
||||
end
|
||||
|
||||
-- ============================================================================
|
||||
-- Field Localization
|
||||
-- ============================================================================
|
||||
|
||||
-- ============================================================================
|
||||
-- ROS 2 dependency configuration
|
||||
-- ============================================================================
|
||||
|
||||
local ros_direct_packages = {
|
||||
local ros_common = make_ros_config({
|
||||
"rclcpp",
|
||||
"std_srvs",
|
||||
"tf2",
|
||||
@@ -19,9 +20,7 @@ local ros_direct_packages = {
|
||||
"nav_msgs",
|
||||
"geometry_msgs",
|
||||
"tf2_ros",
|
||||
}
|
||||
|
||||
local message_packages = {
|
||||
}, {
|
||||
"statistics_msgs",
|
||||
"rosgraph_msgs",
|
||||
"rcl_interfaces",
|
||||
@@ -34,229 +33,7 @@ local message_packages = {
|
||||
"std_msgs",
|
||||
"tf2_msgs",
|
||||
"builtin_interfaces",
|
||||
}
|
||||
|
||||
local ros_config_cache = nil
|
||||
|
||||
local function ros_common()
|
||||
|
||||
on_load(function(target)
|
||||
|
||||
local function get_ros_config()
|
||||
|
||||
if ros_config_cache then
|
||||
return ros_config_cache
|
||||
end
|
||||
|
||||
-- Discover ROS installation.
|
||||
local ROS = os.getenv("ROS_PREFIX")
|
||||
|
||||
if ROS and ROS ~= "" then
|
||||
|
||||
if not os.isdir(ROS .. "/include")
|
||||
or not os.isdir(ROS .. "/lib") then
|
||||
raise("Invalid ROS_PREFIX: " .. ROS)
|
||||
end
|
||||
|
||||
else
|
||||
|
||||
local ament_prefix_path = os.getenv("AMENT_PREFIX_PATH")
|
||||
ROS = nil
|
||||
|
||||
if ament_prefix_path then
|
||||
for prefix in string.gmatch(
|
||||
ament_prefix_path,
|
||||
"[^:]+"
|
||||
) do
|
||||
|
||||
if os.isdir(prefix .. "/include")
|
||||
and os.isdir(prefix .. "/lib") then
|
||||
ROS = prefix
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if not ROS then
|
||||
local distro = os.getenv("ROS_DISTRO")
|
||||
if distro and distro ~= "" then
|
||||
local candidate = "/opt/ros/" .. distro
|
||||
if os.isdir(candidate .. "/include")
|
||||
and os.isdir(candidate .. "/lib") then
|
||||
|
||||
ROS = candidate
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if not ROS then
|
||||
raise(
|
||||
"ROS installation not found. "
|
||||
.. "Source ROS setup or set ROS_PREFIX / ROS_DISTRO."
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
-- Resolve ROS include directories.
|
||||
local script = path.join(
|
||||
target:scriptdir(),
|
||||
"../../tools/_internal/resolve_ros_includes.py"
|
||||
)
|
||||
|
||||
if not os.isfile(script) then
|
||||
raise("ROS include resolver not found: " .. script)
|
||||
end
|
||||
|
||||
local output_file = path.join(
|
||||
os.tmpdir(),
|
||||
"field_localization_ros_include_dirs.txt"
|
||||
)
|
||||
|
||||
local error_file = path.join(
|
||||
os.tmpdir(),
|
||||
"field_localization_ros_include_errors.txt"
|
||||
)
|
||||
|
||||
os.tryrm(output_file)
|
||||
os.tryrm(error_file)
|
||||
|
||||
os.execv("python3", {
|
||||
script,
|
||||
"--prefix", ROS,
|
||||
"--roots", table.concat(ros_direct_packages, ","),
|
||||
}, {
|
||||
stdout = output_file,
|
||||
stderr = error_file,
|
||||
})
|
||||
|
||||
local file = io.open(output_file, "r")
|
||||
|
||||
if not file then
|
||||
|
||||
local error_message = ""
|
||||
|
||||
local error_handle = io.open(error_file, "r")
|
||||
if error_handle then
|
||||
error_message = error_handle:read("*a")
|
||||
error_handle:close()
|
||||
end
|
||||
|
||||
raise(
|
||||
"Failed to resolve ROS includes:\n"
|
||||
.. error_message
|
||||
)
|
||||
end
|
||||
|
||||
local output = file:read("*a")
|
||||
file:close()
|
||||
|
||||
if output == "" then
|
||||
raise("ROS dependency resolver returned empty output.")
|
||||
end
|
||||
|
||||
-- Collect and deduplicate include directories.
|
||||
local project_include = path.join(
|
||||
target:scriptdir(),
|
||||
"include"
|
||||
)
|
||||
|
||||
local includes = {project_include}
|
||||
local include_seen = {
|
||||
[project_include] = true
|
||||
}
|
||||
|
||||
for line in output:gmatch("[^\r\n]+") do
|
||||
|
||||
line = line:gsub("^%s+", "")
|
||||
line = line:gsub("%s+$", "")
|
||||
|
||||
if line ~= "" and not include_seen[line] then
|
||||
table.insert(includes, line)
|
||||
include_seen[line] = true
|
||||
end
|
||||
end
|
||||
|
||||
-- Collect message typesupport libraries.
|
||||
local libs = {}
|
||||
|
||||
for _, pkg in ipairs(message_packages) do
|
||||
|
||||
for _, suffix in ipairs({
|
||||
"__rosidl_typesupport_cpp",
|
||||
"__rosidl_typesupport_introspection_cpp",
|
||||
}) do
|
||||
|
||||
local name = pkg .. suffix
|
||||
|
||||
if os.isfile(ROS .. "/lib/lib" .. name .. ".so") then
|
||||
table.insert(libs, name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- ROS runtime libraries.
|
||||
local runtime_libraries = {
|
||||
"rclcpp",
|
||||
"rcl",
|
||||
"rcl_action",
|
||||
"tf2",
|
||||
"tf2_ros",
|
||||
"rosidl_typesupport_cpp",
|
||||
"rosidl_typesupport_c",
|
||||
"rosidl_runtime_c",
|
||||
"rmw",
|
||||
"rmw_implementation",
|
||||
"rmw_dds_common",
|
||||
"rcutils",
|
||||
"rcpputils",
|
||||
"tracetools",
|
||||
"rcl_logging_interface",
|
||||
"rcl_yaml_param_parser",
|
||||
"libstatistics_collector",
|
||||
}
|
||||
|
||||
for _, name in ipairs(runtime_libraries) do
|
||||
|
||||
if os.isfile(ROS .. "/lib/lib" .. name .. ".so") then
|
||||
table.insert(libs, name)
|
||||
end
|
||||
end
|
||||
|
||||
ros_config_cache = {
|
||||
prefix = ROS,
|
||||
includes = includes,
|
||||
libs = libs,
|
||||
}
|
||||
|
||||
return ros_config_cache
|
||||
end
|
||||
|
||||
local config = get_ros_config()
|
||||
|
||||
local project_include = path.join(target:scriptdir(), "include")
|
||||
for _, dir in ipairs(config.includes) do
|
||||
if dir ~= project_include then target:add("sysincludedirs", dir) end
|
||||
end
|
||||
target:add("includedirs", project_include)
|
||||
|
||||
target:add(
|
||||
"defines",
|
||||
"DEFAULT_RMW_IMPLEMENTATION=rmw_fastrtps_cpp"
|
||||
)
|
||||
|
||||
target:add("linkdirs", config.prefix .. "/lib")
|
||||
target:add("rpathdirs", config.prefix .. "/lib")
|
||||
target:add("runenvs", "LD_LIBRARY_PATH", config.prefix .. "/lib")
|
||||
|
||||
target:add(
|
||||
"linkgroups",
|
||||
config.libs,
|
||||
{group = true}
|
||||
)
|
||||
|
||||
end)
|
||||
end
|
||||
|
||||
})
|
||||
|
||||
-- ============================================================================
|
||||
-- Core library: independent of ROS 2
|
||||
|
||||
Reference in new issue
Block a user