From 789c8de3df0c18fe8b0912286e4c1810542a79e9 Mon Sep 17 00:00:00 2001 From: Matthew Woehlke Date: Thu, 20 Apr 2017 14:44:25 -0400 Subject: UseJava: Support namespaced exports Add NAMESPACE option to export_jars and install_jar_exports. Import JAR's as imported static libraries rather than custom targets, as this is necessary to allow the imported targets to contain ':' in their names. (This also means they won't show up in VS projects, which is more consistent with other imported targets.) Also, improve the documentation to be more stylistically consistent with documentation elsewhere. --- Modules/UseJava.cmake | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/Modules/UseJava.cmake b/Modules/UseJava.cmake index 93255ae..8ae3720 100644 --- a/Modules/UseJava.cmake +++ b/Modules/UseJava.cmake @@ -244,21 +244,23 @@ # # :: # -# install_jar_exports(TARGETS jar1 [jar2 ...] -# FILE export_filename -# DESTINATION destination [COMPONENT component]) +# install_jar_exports(TARGETS jars... +# [NAMESPACE ] +# FILE +# DESTINATION [COMPONENT ]) # -# This command installs a target export file export_filename for the named jar -# targets to the given DESTINATION. Its function is similar to that of -# install(EXPORTS). +# This command installs a target export file ```` for the named jar +# targets to the given ``DESTINATION``. Its function is similar to that of +# :command:`install(EXPORTS ...)`. # # :: # -# export_jars(TARGETS jar1 [jar2 ...] -# FILE export_filename) +# export_jars(TARGETS jars... +# [NAMESPACE ] +# FILE ) # -# This command writes a target export file export_filename for the named jar -# targets. Its function is similar to that of export(). +# This command writes a target export file ```` for the named jar +# targets. Its function is similar to that of :command:`export(...)`. # # :: # @@ -424,10 +426,12 @@ endfunction() function(__java_export_jar VAR TARGET PATH) get_target_property(_jarpath ${TARGET} JAR_FILE) get_filename_component(_jarname ${_jarpath} NAME) + set(_target "${_jar_NAMESPACE}${TARGET}") __java_lcat(${VAR} - "# Create imported target ${TARGET}" - "add_custom_target(${TARGET})" - "set_target_properties(${TARGET} PROPERTIES" + "# Create imported target ${_target}" + "add_library(${_target} IMPORTED STATIC)" + "set_target_properties(${_target} PROPERTIES" + " IMPORTED_LOCATION \"${PATH}/${_jarname}\"" " JAR_FILE \"${PATH}/${_jarname}\")" "" ) @@ -1341,7 +1345,7 @@ function(export_jars) # Parse and validate arguments cmake_parse_arguments(_export_jars "" - "FILE" + "FILE;NAMESPACE" "TARGETS" ${ARGN} ) @@ -1351,6 +1355,7 @@ function(export_jars) if (NOT _export_jars_TARGETS) message(SEND_ERROR "export_jars: TARGETS must be specified.") endif() + set(_jar_NAMESPACE "${_export_jars_NAMESPACE}") # Set content of generated exports file string(REPLACE ";" " " __targets__ "${_export_jars_TARGETS}") @@ -1373,7 +1378,7 @@ function(install_jar_exports) # Parse and validate arguments cmake_parse_arguments(_install_jar_exports "" - "FILE;DESTINATION;COMPONENT" + "FILE;DESTINATION;COMPONENT;NAMESPACE" "TARGETS" ${ARGN} ) @@ -1386,6 +1391,7 @@ function(install_jar_exports) if (NOT _install_jar_exports_TARGETS) message(SEND_ERROR "install_jar_exports: TARGETS must be specified.") endif() + set(_jar_NAMESPACE "${_install_jar_exports_NAMESPACE}") if (_install_jar_exports_COMPONENT) set (_COMPONENT COMPONENT ${_install_jar_exports_COMPONENT}) -- cgit v0.12 From 0bee006602f07e26d052ba30541e6ce61a621b63 Mon Sep 17 00:00:00 2001 From: Matthew Woehlke Date: Thu, 20 Apr 2017 15:11:27 -0400 Subject: Tests: Test namespaces with exported JARs --- Tests/JavaExportImport/BuildExport/CMakeLists.txt | 5 ++++- Tests/JavaExportImport/Import/CMakeLists.txt | 2 +- Tests/JavaExportImport/InstallExport/CMakeLists.txt | 1 + 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Tests/JavaExportImport/BuildExport/CMakeLists.txt b/Tests/JavaExportImport/BuildExport/CMakeLists.txt index 953f9d0..fa7e501 100644 --- a/Tests/JavaExportImport/BuildExport/CMakeLists.txt +++ b/Tests/JavaExportImport/BuildExport/CMakeLists.txt @@ -7,4 +7,7 @@ find_package(Java COMPONENTS Development) include(UseJava) add_jar(${PROJECT_NAME} Foo.java) -export_jars(TARGETS ${PROJECT_NAME} FILE JavaBuildExportTestConfig.cmake) +export_jars( + TARGETS ${PROJECT_NAME} + NAMESPACE foo:: + FILE JavaBuildExportTestConfig.cmake) diff --git a/Tests/JavaExportImport/Import/CMakeLists.txt b/Tests/JavaExportImport/Import/CMakeLists.txt index 79a1447..13ec05d 100644 --- a/Tests/JavaExportImport/Import/CMakeLists.txt +++ b/Tests/JavaExportImport/Import/CMakeLists.txt @@ -11,4 +11,4 @@ find_package(JavaInstallExportTest REQUIRED) add_jar(${PROJECT_NAME} SOURCES Import.java - INCLUDE_JARS foo bar) + INCLUDE_JARS foo::foo bar::bar) diff --git a/Tests/JavaExportImport/InstallExport/CMakeLists.txt b/Tests/JavaExportImport/InstallExport/CMakeLists.txt index 0a9afd9..2923beb 100644 --- a/Tests/JavaExportImport/InstallExport/CMakeLists.txt +++ b/Tests/JavaExportImport/InstallExport/CMakeLists.txt @@ -10,5 +10,6 @@ add_jar(${PROJECT_NAME} Bar.java) install_jar(${PROJECT_NAME} DESTINATION share/java) install_jar_exports( TARGETS ${PROJECT_NAME} + NAMESPACE bar:: FILE JavaInstallExportTestConfig.cmake DESTINATION share/cmake) -- cgit v0.12