|
1 | 1 | find_package(Java REQUIRED)
|
2 | 2 | include(UseJava)
|
3 | 3 | set(CMAKE_JAVA_COMPILE_FLAGS -sourcepath "src" -d "classes" -XDignore.symbol.file)
|
4 |
| -file(GLOB_RECURSE java_sources "*.java") |
5 |
| -set(JAR_NAME "core-models") |
6 |
| -add_jar(${JAR_NAME} ${java_sources}) |
7 |
| -get_filename_component(CORE_MODELS_JAR "core-models.jar" REALPATH BASE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) |
8 |
| -get_filename_component(JAVA_CORE_MODELS_INC "java_core_models.inc" REALPATH BASE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) |
9 |
| -file(GLOB_RECURSE jars "*.jar") |
| 4 | + |
| 5 | +# create a target for the executable performing the .jar -> .inc conversion |
10 | 6 | add_executable(java-converter converter.cpp)
|
11 | 7 |
|
12 |
| -add_custom_target(core_models_files) |
13 |
| -add_dependencies(core_models_files ${JAR_NAME}) |
14 |
| -add_custom_command(TARGET core_models_files |
15 |
| - PRE_BUILD |
16 |
| - COMMAND java-converter JAVA_CORE_MODELS core-models.jar > ${JAVA_CORE_MODELS_INC} |
17 |
| - ) |
| 8 | +# create a target 'core-models.jar' that depends on all .java files in src/ |
| 9 | +file(GLOB_RECURSE java_sources "src/*.java") |
| 10 | +add_jar("core-models" ${java_sources}) |
| 11 | + |
| 12 | +# define a cmake variable with the full path of the .inc file |
| 13 | +set(JAVA_CORE_MODELS_INC "${CMAKE_CURRENT_BINARY_DIR}/java_core_models.inc") |
| 14 | + |
| 15 | +# define a rule telling cmake how to generate the file ${JAVA_CORE_MODELS_INC} from |
| 16 | +# the .jar file by running the java-converter; the output file depends on the |
| 17 | +# .jar file but also on the converter (!) |
| 18 | +add_custom_command(OUTPUT ${JAVA_CORE_MODELS_INC} |
| 19 | + COMMAND java-converter "JAVA_CORE_MODELS" "core-models.jar" > ${JAVA_CORE_MODELS_INC} |
| 20 | + DEPENDS "core-models.jar" java-converter) |
18 | 21 |
|
19 |
| -set_source_files_properties("java_core_models.inc" GENERATED) |
| 22 | +# create a target 'core-models-inc' that depends on the .inc file |
| 23 | +add_custom_target(java-core-models-inc |
| 24 | + DEPENDS ${JAVA_CORE_MODELS_INC}) |
0 commit comments