From a45b371de07eb381876f10b2ded40c1e1d674df5 Mon Sep 17 00:00:00 2001 From: Anonymous Maarten Date: Wed, 22 Nov 2023 23:28:39 +0100 Subject: [PATCH] cmake: create and install SDL3::Jar target for Android --- CMakeLists.txt | 18 ++++++++++++++++-- cmake/SDL3Config.cmake.in | 5 +++++ cmake/SDL3jarTargets.cmake.in | 10 ++++++++++ cmake/test/CMakeLists.txt | 4 ++++ test/CMakeLists.txt | 14 +++++++------- 5 files changed, 42 insertions(+), 9 deletions(-) create mode 100644 cmake/SDL3jarTargets.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 6eb4b369e..9a04b2b39 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1350,6 +1350,10 @@ if(ANDROID) VERSION "${SDL3_VERSION}" ) set_property(TARGET SDL3-jar PROPERTY OUTPUT "${SDL3_BINARY_DIR}/SDL3-${SDL3_VERSION}.jar") + add_library(SDL3__Jar INTERFACE) + add_library(SDL3::Jar ALIAS SDL3__Jar) + get_property(sdl3_jar_location TARGET SDL3-jar PROPERTY JAR_FILE) + set_property(TARGET SDL3__Jar PROPERTY JAR_FILE "${sdl3_jar_location}") set(javasourcesjar "${SDL3_BINARY_DIR}/SDL3-${SDL3_VERSION}-sources.jar") string(REGEX REPLACE "${android_java_sources_root}/" "" sdl_relative_java_sources "${SDL_JAVA_SOURCES}") add_custom_command( @@ -3292,6 +3296,7 @@ sdl_cmake_config_find_pkg_config_commands(SDL_TEST_FIND_PKG_CONFIG_COMMANDS include(CMakePackageConfigHelpers) configure_package_config_file(cmake/SDL3Config.cmake.in SDL3Config.cmake + NO_SET_AND_CHECK_MACRO PATH_VARS CMAKE_INSTALL_PREFIX INSTALL_DESTINATION "${SDL_SDL_INSTALL_CMAKEDIR}" ) @@ -3421,10 +3426,19 @@ if(NOT SDL_DISABLE_INSTALL) endif() if(ANDROID) - set(SDL_INSTALL_JAVADIR "${CMAKE_INSTALL_DATAROOTDIR}/java" CACHE PATH "Path where to install java clases + java sources") if(TARGET SDL3-jar) - install(FILES "${SDL3_BINARY_DIR}/SDL3.jar" "${SDL3_BINARY_DIR}/SDL3-${SDL3_VERSION}.jar" + set(SDL_INSTALL_JAVADIR "${CMAKE_INSTALL_DATAROOTDIR}/java" CACHE PATH "Path where to install java clases + java sources") + install(FILES $ DESTINATION "${SDL_INSTALL_JAVADIR}/SDL3") + configure_package_config_file(cmake/SDL3jarTargets.cmake.in SDL3jarTargets.cmake + INSTALL_DESTINATION "${SDL_SDL_INSTALL_CMAKEDIR}" + PATH_VARS SDL_INSTALL_JAVADIR + NO_CHECK_REQUIRED_COMPONENTS_MACRO + INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}" + ) + install(FILES "${CMAKE_CURRENT_BINARY_DIR}/SDL3jarTargets.cmake" + DESTINATION "${SDL_SDL_INSTALL_CMAKEDIR}" + ) endif() if(TARGET SDL3-javasources) install(FILES "${SDL3_BINARY_DIR}/SDL3-${SDL3_VERSION}-sources.jar" diff --git a/cmake/SDL3Config.cmake.in b/cmake/SDL3Config.cmake.in index d8b029d4f..10f87283b 100644 --- a/cmake/SDL3Config.cmake.in +++ b/cmake/SDL3Config.cmake.in @@ -48,6 +48,11 @@ else() endif() endif() +if(ANDROID AND EXISTS "${CMAKE_CURRENT_LIST_DIR}/SDL3jarTargets.cmake") + include("${CMAKE_CURRENT_LIST_DIR}/SDL3jarTargets.cmake") + set(SDL3_Jar_FOUND TRUE) +endif() + if(SDL3_SDL3-shared_FOUND OR SDL3_SDL3-static_FOUND) set(SDL3_SDL3_FOUND TRUE) endif() diff --git a/cmake/SDL3jarTargets.cmake.in b/cmake/SDL3jarTargets.cmake.in new file mode 100644 index 000000000..732d293ce --- /dev/null +++ b/cmake/SDL3jarTargets.cmake.in @@ -0,0 +1,10 @@ +@PACKAGE_INIT@ + +set_and_check(SDL3_JAR "@PACKAGE_SDL_INSTALL_JAVADIR@/SDL3/SDL3-@SDL3_VERSION@.jar") + +if(NOT TARGET SDL3::Jar) + add_library(SDL3::Jar INTERFACE IMPORTED) + set_property(TARGET SDL3::Jar PROPERTY JAR_FILE "${SDL3_JAR}") +endif() + +unset(SDL3_JAR) diff --git a/cmake/test/CMakeLists.txt b/cmake/test/CMakeLists.txt index 83ee81dc5..f03590f20 100644 --- a/cmake/test/CMakeLists.txt +++ b/cmake/test/CMakeLists.txt @@ -93,4 +93,8 @@ find_package(SDL3 REQUIRED CONFIG COMPONENTS SDL3) add_executable(gui-whatever WIN32 main_gui.c) target_link_libraries(gui-whatever PRIVATE SDL3::SDL3) +if(ANDROID) + find_package(SDL3 REQUIRED CONFIG COMPONENTS Jar) +endif() + feature_summary(WHAT ALL) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 9171dfd1c..9b917c9c0 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -583,7 +583,7 @@ if(SDL_INSTALL_TESTS) ) endif() -if(ANDROID AND TARGET SDL3-jar) +if(ANDROID AND TARGET SDL3::Jar) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/../cmake/android") find_package(SdlAndroid MODULE) if(SdlAndroid_FOUND) @@ -640,14 +640,14 @@ if(ANDROID AND TARGET SDL3-jar) COMMAND ${CMAKE_COMMAND} -E make_directory "${classes_path}" COMMAND ${Java_JAVAC_EXECUTABLE} -source 1.8 -target 1.8 - -bootclasspath "$" + -bootclasspath "$" "${JAVA_PACKAGE_DIR}/SDLEntryTestActivity.java" "${JAVA_PACKAGE_DIR}/SDLTestActivity.java" $ - -cp "$:${path_android_jar}" + -cp "$:${SDL_ANDROID_PLATFORM_ANDROID_JAR}" -d "${classes_path}" COMMAND ${Java_JAR_EXECUTABLE} cf "${OUT_JAR}" -C "${classes_path}" . - DEPENDS $ "$" "${JAVA_PACKAGE_DIR}/SDLTestActivity.java" "${JAVA_PACKAGE_DIR}/SDLEntryTestActivity.java" + DEPENDS $ "$" "${JAVA_PACKAGE_DIR}/SDLTestActivity.java" "${JAVA_PACKAGE_DIR}/SDLEntryTestActivity.java" ) add_custom_target(${TEST}-jar DEPENDS "${OUT_JAR}") set_property(TARGET ${TEST}-jar PROPERTY OUTPUT "${OUT_JAR}") @@ -663,10 +663,10 @@ if(ANDROID AND TARGET SDL3-jar) OUTPUT "${classes_dex}" COMMAND SdlAndroid::d8 $ - $ - --lib "${path_android_jar}" + $ + --lib "${SDL_ANDROID_PLATFORM_ANDROID_JAR}" --output "${dexworkdir}" - DEPENDS $ $ + DEPENDS $ $ ) add_custom_target(${TEST}-dex DEPENDS "${classes_dex}") set_property(TARGET ${TEST}-dex PROPERTY OUTPUT "${classes_dex}")