Skip to content

Commit f10eb71

Browse files
committed
Fix Java core-models build script
This fixes two problems with the core-models build script: 1. Use of add_library with target_source_files listing the same source led to including the *source* files along with every build target, hence multiple builds of the same file 2. Using add_custom_command to create a pre-build hook instead of a normal file-producing command meant java_class_loader.cpp and its dependencies were rebuilt on every build.
1 parent 8d66028 commit f10eb71

File tree

2 files changed

+29
-19
lines changed

2 files changed

+29
-19
lines changed

src/java_bytecode/CMakeLists.txt

+11-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
1-
get_filename_component(JAVA_CORE_MODELS_INC "library/java_core_models.inc" REALPATH BASE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
2-
set_source_files_properties("library/java_core_models.inc" GENERATED)
1+
# include here the targets defined in library/
2+
add_subdirectory(library)
33

4+
# target 'java_bytecode' depends on all .cpp and .h files
45
file(GLOB sources "*.cpp")
56
file(GLOB_RECURSE headers "*.h")
6-
add_subdirectory(library)
7-
8-
add_library(java_bytecode ${sources} ${headers} )
9-
add_dependencies(java_bytecode core_models_files)
7+
add_library(java_bytecode ${sources} ${headers})
108

9+
# define the include directories (passed to the compiler with -I) that those
10+
# targets wishing to depend on the target 'java_bytecode' may want to use
1111
generic_includes(java_bytecode)
1212

13+
# target 'java-core-models-inc' is defined in library/
14+
add_dependencies(java_bytecode java-core-models-inc)
15+
16+
# if you link java_bytecode.a in, then you also need to link other .a libraries
17+
# in
1318
target_link_libraries(java_bytecode util goto-programs miniz json)
+18-13
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
find_package(Java REQUIRED)
22
include(UseJava)
33
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
106
add_executable(java-converter converter.cpp)
117

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)
1821

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

Comments
 (0)