Skip to content
Merged
Show file tree
Hide file tree
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
10 changes: 10 additions & 0 deletions rcljava/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,16 @@ add_jar("${PROJECT_NAME}_jar"
install_jar("${PROJECT_NAME}_jar" "share/${PROJECT_NAME}/java")
ament_export_jars("share/${PROJECT_NAME}/java/${PROJECT_NAME}.jar")

add_source_jar("${PROJECT_NAME}-source_jar"
${${PROJECT_NAME}_sources}
OUTPUT_NAME
${PROJECT_NAME}-source
)

install_jar("${PROJECT_NAME}-source_jar" "share/${PROJECT_NAME}/java")
ament_export_jars("share/${PROJECT_NAME}/java/${PROJECT_NAME}-source.jar")


if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
find_package(std_msgs REQUIRED)
Expand Down
43 changes: 43 additions & 0 deletions rcljava_common/cmake/Modules/JavaExtra.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,46 @@ function(ament_add_junit_tests TARGET_NAME)

add_dependencies(${TARGET_NAME} "${TARGET_NAME}_jar")
endfunction()

#
# Creates a sources jar from list of source files
#
# :param OUTPUT_NAME: Name of Jar
# :type OUTPUT_NAME: string
# :param SOURCES: Sources files
# :type SOURCES: String list with file names
#
# @public
#
function(add_source_jar _TARGET_NAME)

cmake_parse_arguments(_add_source_jar
""
"OUTPUT_NAME"
"SOURCES"
${ARGN}
)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably handle the case where OUTPUT_NAME is not given. Maybe it can default to the "${_TARGET_NAME}.jar"?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

if(NOT _add_source_jar_OUTPUT_NAME)
set(_add_source_jar_OUTPUT_NAME "${_TARGET_NAME}.jar")
endif()

set(_SOURCE_FILES ${_add_source_jar_SOURCES} ${_add_source_jar_UNPARSED_ARGUMENTS})
set(_JAVA_JAR_SOURCES_OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_add_source_jar_OUTPUT_NAME}.jar)

add_custom_command(
OUTPUT ${_add_source_jar_OUTPUT_NAME}
COMMAND ${Java_JAR_EXECUTABLE} -cf ${_JAVA_JAR_SOURCES_OUTPUT} ${_SOURCE_FILES}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
add_custom_target(${_TARGET_NAME} ALL DEPENDS ${_add_source_jar_OUTPUT_NAME})

# Set install property (for 'install_jar()').
set_property(
TARGET ${_TARGET_NAME}
PROPERTY
INSTALL_FILES
${_JAVA_JAR_SOURCES_OUTPUT}
)

endfunction()