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

HACK: Allow resolution of current project's path at build time #326

Merged
merged 3 commits into from
Oct 31, 2023
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
15 changes: 10 additions & 5 deletions cmake/xacro-extras.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,13 @@ function(xacro_add_xacro_file input)
message(FATAL_ERROR "no <output> specified for: " ${input})
endif()
endif()
# message(STATUS "output: ${output}")

## determine absolute output target location
if(IS_ABSOLUTE ${output})
set(abs_output ${output})
else()
set(abs_output ${CMAKE_CURRENT_BINARY_DIR}/${output})
endif()
# message(STATUS "abs_output: ${abs_output}")

## export abs_output to parent scope in variable ${_XACRO_OUTPUT}
if(NOT _XACRO_OUTPUT)
Expand All @@ -77,9 +75,17 @@ ${_xacro_err}")

separate_arguments(_xacro_deps_result)

## HACK: ament package resolution doesn't work at build time yet
# - Augment AMENT_PREFIX_PATH to include ${PROJECT_BINARY_DIR}/ament_cmake_index
# - Create a symlink from there to the actual source directory to find source files
set(PROJECT_BUILD_INDEX "${PROJECT_BINARY_DIR}/ament_cmake_index")
execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory "${PROJECT_BUILD_INDEX}/share")
execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink "${PROJECT_SOURCE_DIR}" "${PROJECT_BUILD_INDEX}/share/${PROJECT_NAME}")

## command to actually call xacro
add_custom_command(OUTPUT ${output}
COMMAND xacro -o ${abs_output} ${input} ${_XACRO_REMAP}
list(JOIN AMENT_PREFIX_PATH ":" AMENT_PREFIX_PATH_ENV) # format as colon-separated list
add_custom_command(OUTPUT ${abs_output}
COMMAND ${CMAKE_COMMAND} -E env AMENT_PREFIX_PATH="${PROJECT_BUILD_INDEX}:${AMENT_PREFIX_PATH_ENV}" xacro -o ${abs_output} ${input} ${_XACRO_REMAP}
DEPENDS ${input} ${_xacro_deps_result} ${_XACRO_DEPENDS}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "xacro: generating ${output} from ${input}"
Expand Down Expand Up @@ -124,7 +130,6 @@ function(xacro_add_files)

# have INSTALL option, but no TARGET: fallback to default target
if(_XACRO_INSTALL AND NOT _XACRO_TARGET)
# message(STATUS "xacro: no TARGET specified, using default")
set(_XACRO_TARGET _xacro_auto_generate)
endif()

Expand Down