Skip to content

Commit

Permalink
xacro_add_files: Resolve current project's path at build time (#326)
Browse files Browse the repository at this point in the history
  • Loading branch information
rhaschke authored Oct 31, 2023
1 parent e242db8 commit ce628cc
Showing 1 changed file with 10 additions and 5 deletions.
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

0 comments on commit ce628cc

Please sign in to comment.