Skip to content

Fixes sources jar path #58

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

Draft
wants to merge 1 commit into
base: galactic-devel
Choose a base branch
from
Draft
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
2 changes: 2 additions & 0 deletions rcljava/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ add_source_jar("${PROJECT_NAME}-source_jar"
${${PROJECT_NAME}_sources}
OUTPUT_NAME
${PROJECT_NAME}-source
JAR_ROOT_PATH
"src/main/java/"
)

install_jar("${PROJECT_NAME}-source_jar" "share/${PROJECT_NAME}/java")
Expand Down
12 changes: 9 additions & 3 deletions rcljava_common/cmake/Modules/JavaExtra.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ function(add_source_jar _TARGET_NAME)

cmake_parse_arguments(_add_source_jar
""
"OUTPUT_NAME"
"OUTPUT_NAME;JAR_ROOT_PATH"

Choose a reason for hiding this comment

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

On one hand, it seems like it should be the responsibility of the caller to remove any prefix paths, but on the other hand it's convenient to let the function take care of it. The downside of letting this function remove the prefix is that it is assuming that all source files have the same prefix.

I think it would safer to instead let the caller deal with the prefix and they can inform this function by passing a WORKING_DIRECTORY argument used when calling the jar command below.

Please add documentation for the new argument to the docblock above.

"SOURCES"
${ARGN}
)
Expand All @@ -192,10 +192,16 @@ function(add_source_jar _TARGET_NAME)
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)

set(_FIXED_PATH_FILES)
foreach(_SOURCE_FILE IN LISTS _SOURCE_FILES)
string(REPLACE ${_add_source_jar_JAR_ROOT_PATH} "" _FIXED_PATH_FILE ${_SOURCE_FILE})
list(APPEND _FIXED_PATH_FILES ${_FIXED_PATH_FILE})
endforeach()

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}
COMMAND ${Java_JAR_EXECUTABLE} -cf ${_JAVA_JAR_SOURCES_OUTPUT} ${_FIXED_PATH_FILES}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${_add_source_jar_JAR_ROOT_PATH}
)
add_custom_target(${_TARGET_NAME} ALL DEPENDS ${_add_source_jar_OUTPUT_NAME})

Expand Down