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

[build] CMake: simplify source JAR creation and install #6831

Merged
merged 2 commits into from
Jul 15, 2024
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
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ if("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Windows")
message(STATUS "Platform version: ${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}")
endif()

cmake_minimum_required(VERSION 3.11)
cmake_minimum_required(VERSION 3.21)
project(allwpilib)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")

Expand Down
16 changes: 5 additions & 11 deletions apriltag/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,22 +87,16 @@ endif()

if(WITH_JAVA_SOURCE)
include(UseJava)
file(GLOB APRILTAG_SOURCES src/main/java/edu/wpi/first/apriltag/*.java)
add_jar(
include(CreateSourceJar)
add_source_jar(
apriltag_src_jar
RESOURCES
NAMESPACE "edu/wpi/first/apriltag" ${APRILTAG_SOURCES}
NAMESPACE
"edu/wpi/first/apriltag/jni"
src/main/java/edu/wpi/first/apriltag/jni/AprilTagJNI.java
BASE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}/src/main/java
OUTPUT_NAME apriltag-sources
OUTPUT_DIR ${WPILIB_BINARY_DIR}/${java_lib_dest}
)

get_property(APRILTAG_SRC_JAR_FILE TARGET apriltag_src_jar PROPERTY JAR_FILE)
install(FILES ${APRILTAG_SRC_JAR_FILE} DESTINATION "${java_lib_dest}")

set_property(TARGET apriltag_src_jar PROPERTY FOLDER "java")

install_jar(apriltag_src_jar DESTINATION ${java_lib_dest})
endif()

generate_resources(
Expand Down
15 changes: 5 additions & 10 deletions cameraserver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,16 @@ endif()

if(WITH_JAVA_SOURCE)
include(UseJava)
file(GLOB CAMERASERVER_SOURCES src/main/java/edu/wpi/first/cameraserver/*.java)
file(GLOB VISION_SOURCES src/main/java/edu/wpi/first/vision/*.java)
add_jar(
include(CreateSourceJar)
add_source_jar(
cameraserver_src_jar
RESOURCES
NAMESPACE "edu/wpi/first/cameraserver" ${CAMERASERVER_SOURCES}
NAMESPACE "edu/wpi/first/vision" ${VISION_SOURCES}
BASE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}/src/main/java
OUTPUT_NAME cameraserver-sources
OUTPUT_DIR ${WPILIB_BINARY_DIR}/${java_lib_dest}
)

get_property(CAMERASERVER_SRC_JAR_FILE TARGET cameraserver_src_jar PROPERTY JAR_FILE)
install(FILES ${CAMERASERVER_SRC_JAR_FILE} DESTINATION "${java_lib_dest}")

set_property(TARGET cameraserver_src_jar PROPERTY FOLDER "java")

install_jar(cameraserver_src_jar DESTINATION ${java_lib_dest})
endif()

file(GLOB_RECURSE cameraserver_native_src src/main/native/cpp/*.cpp)
Expand Down
34 changes: 34 additions & 0 deletions cmake/modules/CreateSourceJar.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
macro(add_source_jar target)
set(oneValueArgs OUTPUT_NAME OUTPUT_DIR)
cmake_parse_arguments(SOURCE_JAR "" "${oneValueArgs}" "BASE_DIRECTORIES" ${ARGN})
foreach(base_package_dir ${SOURCE_JAR_BASE_DIRECTORIES})
file(GLOB_RECURSE directories LIST_DIRECTORIES true ${base_package_dir}/*.directoriesonly)
# Find all packages
foreach(directory ${directories})
cmake_path(
RELATIVE_PATH
directory
BASE_DIRECTORY ${base_package_dir}
OUTPUT_VARIABLE package_name
)
file(GLOB package_sources ${directory}/*.java)
if(package_sources STREQUAL "")
continue()
endif()
# If package sources are scattered across different places, consolidate them under one package
list(FIND packages ${package_name} index)
if(index EQUAL -1)
list(APPEND packages ${package_name})
endif()
list(APPEND ${package_name} ${package_sources})
endforeach()
endforeach()
set(resources "")
foreach(package ${packages})
string(APPEND resources "NAMESPACE \"${package}\" ${${package}} ")
endforeach()
cmake_language(
EVAL CODE
"add_jar(${target} RESOURCES ${resources} OUTPUT_NAME ${SOURCE_JAR_OUTPUT_NAME} OUTPUT_DIR ${SOURCE_JAR_OUTPUT_DIR})"
)
endmacro()
15 changes: 5 additions & 10 deletions cscore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -129,21 +129,16 @@ endif()

if(WITH_JAVA_SOURCE)
include(UseJava)
file(GLOB CSCORE_SOURCES src/main/java/edu/wpi/first/cscore/*.java)
file(GLOB CSCORE_RAW_SOURCES src/main/java/edu/wpi/first/cscore/raw/*.java)
add_jar(
include(CreateSourceJar)
add_source_jar(
cscore_src_jar
RESOURCES
NAMESPACE "edu/wpi/first/cscore" ${CSCORE_SOURCES}
NAMESPACE "edu/wpi/first/cscore/raw" ${CSCORE_RAW_SOURCES}
BASE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}/src/main/java
OUTPUT_NAME cscore-sources
OUTPUT_DIR ${WPILIB_BINARY_DIR}/${java_lib_dest}
)

get_property(CSCORE_SRC_JAR_FILE TARGET cscore_src_jar PROPERTY JAR_FILE)
install(FILES ${CSCORE_SRC_JAR_FILE} DESTINATION "${java_lib_dest}")

set_property(TARGET cscore_src_jar PROPERTY FOLDER "java")

install_jar(cscore_src_jar DESTINATION ${java_lib_dest})
endif()

if(WITH_TESTS)
Expand Down
24 changes: 7 additions & 17 deletions hal/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,28 +80,18 @@ endif()

if(WITH_JAVA_SOURCE)
include(UseJava)
file(GLOB HAL_SOURCES src/main/java/edu/wpi/first/hal/*.java src/generated/main/java/*.java)
file(GLOB HAL_CAN_SOURCES src/main/java/edu/wpi/first/hal/can/*.java)
file(GLOB HAL_SIMULATION_SOURCES src/main/java/edu/wpi/first/hal/simulation/*.java)
file(GLOB HAL_UTIL_SOURCES src/main/java/edu/wpi/first/hal/util/*.java)
add_jar(
include(CreateSourceJar)
add_source_jar(
hal_src_jar
RESOURCES
NAMESPACE "edu/wpi/first/hal" ${HAL_SOURCES}
NAMESPACE "edu/wpi/first/hal/can" ${HAL_CAN_SOURCES}
NAMESPACE
"edu/wpi/first/hal/communication"
src/main/java/edu/wpi/first/hal/communication/NIRioStatus.java
NAMESPACE "edu/wpi/first/hal/simulation" ${HAL_SIMULATION_SOURCES}
NAMESPACE "edu/wpi/first/hal/util" ${HAL_UTIL_SOURCES}
BASE_DIRECTORIES
${CMAKE_CURRENT_SOURCE_DIR}/src/main/java
${CMAKE_CURRENT_SOURCE_DIR}/src/generated/main/java
OUTPUT_NAME wpiHal-sources
OUTPUT_DIR ${WPILIB_BINARY_DIR}/${java_lib_dest}
)

get_property(HAL_SRC_JAR_FILE TARGET hal_src_jar PROPERTY JAR_FILE)
install(FILES ${HAL_SRC_JAR_FILE} DESTINATION "${java_lib_dest}")

set_property(TARGET hal_src_jar PROPERTY FOLDER "java")

install_jar(hal_src_jar DESTINATION ${java_lib_dest})
endif()

if(WITH_TESTS)
Expand Down
19 changes: 7 additions & 12 deletions ntcore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,23 +76,18 @@ endif()

if(WITH_JAVA_SOURCE)
include(UseJava)
file(
GLOB NTCORE_SOURCES
src/main/java/edu/wpi/first/networktables/*.java
src/generated/main/java/*.java
)
add_jar(
include(CreateSourceJar)
add_source_jar(
ntcore_src_jar
RESOURCES
NAMESPACE "edu/wpi/first/networktables" ${NTCORE_SOURCES}
BASE_DIRECTORIES
${CMAKE_CURRENT_SOURCE_DIR}/src/main/java
${CMAKE_CURRENT_SOURCE_DIR}/src/generated/main/java
OUTPUT_NAME ntcore-sources
OUTPUT_DIR ${WPILIB_BINARY_DIR}/${java_lib_dest}
)

get_property(NTCORE_SRC_JAR_FILE TARGET ntcore_src_jar PROPERTY JAR_FILE)
install(FILES ${NTCORE_SRC_JAR_FILE} DESTINATION "${java_lib_dest}")

set_property(TARGET ntcore_src_jar PROPERTY FOLDER "java")

install_jar(ntcore_src_jar DESTINATION ${java_lib_dest})
endif()

add_executable(ntcoredev src/dev/native/cpp/main.cpp)
Expand Down
13 changes: 5 additions & 8 deletions romiVendordep/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,16 @@ endif()

if(WITH_JAVA_SOURCE)
include(UseJava)
file(GLOB_RECURSE ROMIVENDORDEP_SOURCES src/main/java/*.java)
add_jar(
include(CreateSourceJar)
add_source_jar(
romiVendordep_src_jar
RESOURCES
NAMESPACE "edu/wpi/first/wpilibj/romi" ${ROMIVENDORDEP_SOURCES}
BASE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}/src/main/java
OUTPUT_NAME romiVendordep-sources
OUTPUT_DIR ${WPILIB_BINARY_DIR}/${java_lib_dest}
)

get_property(ROMIVENDORDEP_SRC_JAR_FILE TARGET romiVendordep_src_jar PROPERTY JAR_FILE)
install(FILES ${ROMIVENDORDEP_JAR_FILE} DESTINATION "${java_lib_dest}")

set_property(TARGET romiVendordep_src_jar PROPERTY FOLDER "java")

install_jar(romiVendordep_src_jar DESTINATION ${java_lib_dest})
endif()

file(GLOB_RECURSE romiVendordep_native_src src/main/native/cpp/*.cpp)
Expand Down
21 changes: 7 additions & 14 deletions wpilibNewCommands/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,18 @@ endif()

if(WITH_JAVA_SOURCE)
include(UseJava)
file(GLOB WPILIBNEWCOMMANDS_SOURCES src/main/java/edu/wpi/first/wpilibj2/command/*.java)
file(
GLOB WPILIBNEWCOMMANDS_BUTTON_SOURCES
src/main/java/edu/wpi/first/wpilibj2/command/button/*.java
src/generated/main/java/edu/wpi/first/wpilibj2/command/button/*.java
)
add_jar(
include(CreateSourceJar)
add_source_jar(
wpilibNewCommands_src_jar
RESOURCES
NAMESPACE "edu/wpi/first/wpilibj2/command" ${WPILIBNEWCOMMANDS_SOURCES}
NAMESPACE "edu/wpi/first/wpilibj2/command/button" ${WPILIBNEWCOMMANDS_BUTTON_SOURCES}
BASE_DIRECTORIES
${CMAKE_CURRENT_SOURCE_DIR}/src/main/java
${CMAKE_CURRENT_SOURCE_DIR}/src/generated/main/java
OUTPUT_NAME wpilibNewCommands-sources
OUTPUT_DIR ${WPILIB_BINARY_DIR}/${java_lib_dest}
)

get_property(WPILIBNEWCOMMANDS_SRC_JAR_FILE TARGET wpilibNewCommands_src_jar PROPERTY JAR_FILE)
install(FILES ${WPILIBNEWCOMMANDS_SRC_JAR_FILE} DESTINATION "${java_lib_dest}")

set_property(TARGET wpilibNewCommands_src_jar PROPERTY FOLDER "java")

install_jar(wpilibNewCommands_src_jar DESTINATION ${java_lib_dest})
endif()

file(
Expand Down
66 changes: 20 additions & 46 deletions wpilibj/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ if(WITH_JAVA)
NO_DEFAULT_PATH
)

configure_file(src/generate/WPILibVersion.java.in WPILibVersion.java)
configure_file(
src/generate/WPILibVersion.java.in
generated/main/java/edu/wpi/first/wpilibj/WPILibVersion.java
)

file(GLOB_RECURSE JAVA_SOURCES src/main/java/*.java src/generated/main/java/*.java)
file(GLOB EJML_JARS "${WPILIB_BINARY_DIR}/wpimath/thirdparty/ejml/*.jar")
Expand All @@ -26,7 +29,7 @@ if(WITH_JAVA)
add_jar(
wpilibj_jar
${JAVA_SOURCES}
${CMAKE_CURRENT_BINARY_DIR}/WPILibVersion.java
${CMAKE_CURRENT_BINARY_DIR}/generated/main/java/edu/wpi/first/wpilibj/WPILibVersion.java
INCLUDE_JARS
hal_jar
ntcore_jar
Expand All @@ -51,53 +54,24 @@ endif()

if(WITH_JAVA_SOURCE)
include(UseJava)
file(
GLOB WPILIBJ_SOURCES
src/main/java/edu/wpi/first/wpilibj/*.java
src/generated/main/java/edu/wpi/first/wpilibj/*.java
)
file(GLOB WPILIBJ_COUNTER_SOURCES src/main/java/edu/wpi/first/wpilibj/counter/*.java)
file(GLOB WPILIBJ_DRIVE_SOURCES src/main/java/edu/wpi/first/wpilibj/drive/*.java)
file(GLOB WPILIBJ_EVENT_SOURCES src/main/java/edu/wpi/first/wpilibj/event/*.java)
file(GLOB WPILIBJ_INTERFACES_SOURCES src/main/java/edu/wpi/first/wpilibj/interfaces/*.java)
file(GLOB WPILIBJ_MOTORCONTROL_SOURCES src/main/java/edu/wpi/first/wpilibj/motorcontrol*.java)
file(GLOB WPILIBJ_SHUFFLEBOARD_SOURCES src/main/java/edu/wpi/first/wpilibj/shuffleboard*.java)
file(
GLOB WPILIBJ_SIMULATION_SOURCES
src/main/java/edu/wpi/first/wpilibj/simulation/*.java
src/generated/main/java/edu/wpi/first/wpilibj/simulation/*.java
)
file(GLOB WPILIBJ_SMARTDASHBOARD_SOURCES src/main/java/edu/wpi/first/wpilibj/*.java)
file(
GLOB WPILIBJ_UTIL_SOURCES
src/main/java/edu/wpi/first/wpilibj/*.java
${CMAKE_CURRENT_BINARY_DIR}/WPILibVersion.java
)
add_jar(
include(CreateSourceJar)
# Generate version file if it wasn't generated already
if(NOT WITH_JAVA)
configure_file(
src/generate/WPILi1bVersion.java.in
generated/main/java/edu/wpi/first/wpilibj/WPILibVersion.java
)
endif()
add_source_jar(
wpilibj_src_jar
RESOURCES
NAMESPACE "edu/wpi/first/wpilibj" ${WPILIBJ_SOURCES}
NAMESPACE "edu/wpi/first/wpilibj/counter" ${WPILIBJ_COUNTER_SOURCES}
NAMESPACE "edu/wpi/first/wpilibj/drive" ${WPILIBJ_DRIVE_SOURCES}
NAMESPACE "edu/wpi/first/wpilibj/event" ${WPILIBJ_EVENT_SOURCES}
NAMESPACE "edu/wpi/first/wpilibj/interfaces" ${WPILIBJ_INTERFACES_SOURCES}
NAMESPACE
"edu/wpi/first/wpilibj/internal"
src/main/java/edu/wpi/first/wpilibj/internal/DriverStationModeThread.java
NAMESPACE
"edu/wpi/first/wpilibj/livewindow"
src/main/java/edu/wpi/first/wpilibj/livewindow/LiveWindow.java
NAMESPACE "edu/wpi/first/wpilibj/motorcontrol" ${WPILIBJ_MOTORCONTROL_SOURCES}
NAMESPACE "edu/wpi/first/wpilibj/shuffleboard" ${WPILIBJ_SHUFFLEBOARD_SOURCES}
NAMESPACE "edu/wpi/first/wpilibj/simulation" ${WPILIBJ_SIMULATION_SOURCES}
NAMESPACE "edu/wpi/first/wpilibj/smartdashboard" ${WPILIBJ_SMARTDASHBOARD_SOURCES}
NAMESPACE "edu/wpi/first/wpilibj/util" ${WPILIBJ_UTIL_SOURCES}
BASE_DIRECTORIES
${CMAKE_CURRENT_SOURCE_DIR}/src/main/java
${CMAKE_CURRENT_SOURCE_DIR}/src/generated/main/java
${CMAKE_CURRENT_BINARY_DIR}/generated/main/java
OUTPUT_NAME wpilibj-sources
OUTPUT_DIR ${WPILIB_BINARY_DIR}/${java_lib_dest}
)

get_property(WPILIBJ_SRC_JAR_FILE TARGET wpilibj_src_jar PROPERTY JAR_FILE)
install(FILES ${WPILIBJ_SRC_JAR_FILE} DESTINATION "${java_lib_dest}")

set_property(TARGET wpilibj_src_jar PROPERTY FOLDER "java")

install_jar(wpilibj_src_jar DESTINATION ${java_lib_dest})
endif()
Loading
Loading