Skip to content

Commit

Permalink
Update java API to use new proto files
Browse files Browse the repository at this point in the history
  • Loading branch information
jdorn-gt authored and eschulte committed Apr 9, 2020
1 parent e2215a8 commit 0e5f8c1
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 20 deletions.
28 changes: 18 additions & 10 deletions java/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,30 @@ file(
# Building the gtirb protobuf files into java
# ---------------------------------------------------------------------------

file(GLOB GTIRB_PROTO_FILES ${PROJECT_SOURCE_DIR}/proto/*.proto)
# Directory containing the configured *.proto file
set(GTIRB_JAVA_PROTO_DIR "${CMAKE_CURRENT_BINARY_DIR}/proto")

# Directory containing the *.class files generated from the *.proto files
set(GTIRB_JAVA_PROTO_CLASS_DIR
"${CMAKE_CURRENT_BINARY_DIR}/com/grammatech/gtirb/proto"
)

# Configure the *.proto files
gtirb_make_proto_files(GTIRB_PROTO_FILES DIRECTORY ${GTIRB_JAVA_PROTO_DIR})

# Add commands to compile the *.proto files to *.class files
foreach(GTIRB_PROTO_FILE ${GTIRB_PROTO_FILES})
get_filename_component(GTIRB_PROTO_BASENAME ${GTIRB_PROTO_FILE} NAME_WE)
set(GTIRB_PROTO_CLASS_FILE
${GTIRB_JAVA_PROTO_CLASS_DIR}/${GTIRB_PROTO_BASENAME}OuterClass.java
)
add_custom_command(
OUTPUT
${CMAKE_CURRENT_SOURCE_DIR}/com/grammatech/gtirb/proto/${GTIRB_PROTO_BASENAME}OuterClass.java
OUTPUT ${GTIRB_PROTO_CLASS_FILE}
COMMAND ${Protobuf_PROTOC_EXECUTABLE}
--java_out=${CMAKE_CURRENT_SOURCE_DIR}
--proto_path=${PROJECT_SOURCE_DIR}/proto ${GTIRB_PROTO_FILE}
)
list(
APPEND
GTIRB_PROTOBUF_JAVA
${CMAKE_CURRENT_SOURCE_DIR}/com/grammatech/gtirb/proto/${GTIRB_PROTO_BASENAME}OuterClass.java
--java_out=${CMAKE_CURRENT_BINARY_DIR}
--proto_path=${GTIRB_JAVA_PROTO_DIR} ${GTIRB_PROTO_FILE}
)
list(APPEND GTIRB_PROTOBUF_JAVA ${GTIRB_PROTO_CLASS_FILE})
endforeach()

# ---------------------------------------------------------------------------
Expand Down
27 changes: 24 additions & 3 deletions proto/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
file(GLOB PROTO_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.proto.in)
set(PROTO_FILES
${PROTO_FILES}
file(GLOB PROTO_IN_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.proto.in)
set(PROTO_IN_FILES
${PROTO_IN_FILES}
PARENT_SCOPE
)

function(GTIRB_MAKE_PROTO_FILES VAR)
cmake_parse_arguments(GTIRB_MAKE_PROTO "" "DIRECTORY" "" ${ARGN})

if(NOT GTIRB_MAKE_PROTO_DIRECTORY)
set(GTIRB_MAKE_PROTO_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
endif()

message(STATUS "generating proto files in ${GTIRB_MAKE_PROTO_DIRECTORY}")
set(PROTO_FILES)
foreach(PROTO_IN_FILE ${PROTO_IN_FILES})
get_filename_component(PROTO_FILE ${PROTO_IN_FILE} NAME_WE)
set(PROTO_FILE "${GTIRB_MAKE_PROTO_DIRECTORY}/${PROTO_FILE}.proto")
configure_file(${PROTO_IN_FILE} ${PROTO_FILE} @ONLY)
list(APPEND PROTO_FILES ${PROTO_FILE})
endforeach()
set(${VAR}
${PROTO_FILES}
PARENT_SCOPE
)
endfunction()
8 changes: 1 addition & 7 deletions src/gtirb/proto/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,7 @@ else()
add_compile_options(-include "${CMAKE_SOURCE_DIR}/include/gtirb/Export.hpp")
endif()

set(PROTO_CPP_FILES)
foreach(PROTO_FILE_IN ${PROTO_FILES})
get_filename_component(PROTO_CPP_FILE ${PROTO_FILE_IN} NAME_WE)
set(PROTO_CPP_FILE "${CMAKE_CURRENT_BINARY_DIR}/${PROTO_CPP_FILE}.proto")
configure_file(${PROTO_FILE_IN} ${PROTO_CPP_FILE} @ONLY)
list(APPEND PROTO_CPP_FILES ${PROTO_CPP_FILE})
endforeach()
gtirb_make_proto_files(PROTO_CPP_FILES)

protobuf_generate_cpp(
PROTO_CPP_SOURCES PROTO_CPP_HEADERS EXPORT_MACRO "GTIRB_EXPORT_API"
Expand Down

0 comments on commit 0e5f8c1

Please sign in to comment.