From 2c230f0d3e38579c56640751df871cc93fc06878 Mon Sep 17 00:00:00 2001 From: lethosor Date: Mon, 24 Oct 2016 22:51:27 -0400 Subject: [PATCH] Improve protobuf file regeneration (no longer uses a dummy status.txt file) --- library/CMakeLists.txt | 23 ++++++++++------------- library/proto/.gitignore | 1 - plugins/CMakeLists.txt | 23 ++++++++++------------- plugins/proto/.gitignore | 1 - 4 files changed, 20 insertions(+), 28 deletions(-) diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index cb919f935..ed5bfdcd2 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -215,7 +215,6 @@ ENDIF() # Protobuf FILE(GLOB PROJECT_PROTOS ${CMAKE_CURRENT_SOURCE_DIR}/proto/*.proto) -SET(PROTO_STATUS_FILE ${CMAKE_CURRENT_SOURCE_DIR}/proto/status.txt) STRING(REPLACE ".proto" ".pb.cc" PROJECT_PROTO_SRCS "${PROJECT_PROTOS}") STRING(REPLACE ".proto" ".pb.h" PROJECT_PROTO_HDRS "${PROJECT_PROTOS}") STRING(REPLACE "/proto/" "/proto/tmp/" PROJECT_PROTO_TMP_FILES "${PROJECT_PROTO_SRCS};${PROJECT_PROTO_HDRS}") @@ -223,33 +222,31 @@ SET_SOURCE_FILES_PROPERTIES(${PROJECT_PROTO_SRCS} ${PROJECT_PROTO_HDRS} PROPERTIES GENERATED TRUE) # Force a re-gen if any *.pb.* files are missing -IF(EXISTS ${PROTO_STATUS_FILE}) - FOREACH(file IN LISTS PROJECT_PROTO_SRCS PROJECT_PROTO_HDRS) - IF(NOT EXISTS ${file}) - MESSAGE("Resetting generate_proto_core because '${file}' is missing") - FILE(REMOVE ${PROTO_STATUS_FILE}) - BREAK() - ENDIF() - ENDFOREACH() -ENDIF() +# (only runs when cmake is run, but better than nothing) +FOREACH(file IN LISTS PROJECT_PROTO_SRCS PROJECT_PROTO_HDRS) + IF(NOT EXISTS ${file}) + # MESSAGE("Resetting generate_proto_core because '${file}' is missing") + FILE(REMOVE ${PROJECT_PROTO_TMP_FILES}) + BREAK() + ENDIF() +ENDFOREACH() LIST(APPEND PROJECT_HEADERS ${PROJECT_PROTO_HDRS}) LIST(APPEND PROJECT_SOURCES ${PROJECT_PROTO_SRCS}) ADD_CUSTOM_COMMAND( - OUTPUT ${PROTO_STATUS_FILE} + OUTPUT ${PROJECT_PROTO_TMP_FILES} COMMAND protoc-bin -I=${CMAKE_CURRENT_SOURCE_DIR}/proto/ --cpp_out=dllexport_decl=DFHACK_EXPORT:${CMAKE_CURRENT_SOURCE_DIR}/proto/tmp/ ${PROJECT_PROTOS} COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PROJECT_PROTO_TMP_FILES} ${CMAKE_CURRENT_SOURCE_DIR}/proto/ - COMMAND ${CMAKE_COMMAND} -E touch ${PROTO_STATUS_FILE} COMMENT "Generating core protobufs" DEPENDS protoc-bin ${PROJECT_PROTOS} ) -ADD_CUSTOM_TARGET(generate_proto_core DEPENDS ${PROTO_STATUS_FILE}) +ADD_CUSTOM_TARGET(generate_proto_core DEPENDS ${PROJECT_PROTO_TMP_FILES}) # Merge headers into sources SET_SOURCE_FILES_PROPERTIES( ${PROJECT_HEADERS} PROPERTIES HEADER_FILE_ONLY TRUE ) diff --git a/library/proto/.gitignore b/library/proto/.gitignore index 3a96bb3d9..befabf79d 100644 --- a/library/proto/.gitignore +++ b/library/proto/.gitignore @@ -1,4 +1,3 @@ *.pb.cc *.pb.cc.rule *.pb.h -status.txt diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index f0bb847bf..612a49715 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -42,7 +42,6 @@ install(DIRECTORY raw/ # Protobuf FILE(GLOB PROJECT_PROTOS ${CMAKE_CURRENT_SOURCE_DIR}/proto/*.proto) -SET(PROTO_STATUS_FILE ${CMAKE_CURRENT_SOURCE_DIR}/proto/status.txt) STRING(REPLACE ".proto" ".pb.cc" PROJECT_PROTO_SRCS "${PROJECT_PROTOS}") STRING(REPLACE ".proto" ".pb.h" PROJECT_PROTO_HDRS "${PROJECT_PROTOS}") STRING(REPLACE "/proto/" "/proto/tmp/" PROJECT_PROTO_TMP_FILES "${PROJECT_PROTO_SRCS};${PROJECT_PROTO_HDRS}") @@ -50,18 +49,17 @@ SET_SOURCE_FILES_PROPERTIES(${PROJECT_PROTO_SRCS} ${PROJECT_PROTO_HDRS} PROPERTIES GENERATED TRUE) # Force a re-gen if any *.pb.* files are missing -IF(EXISTS ${PROTO_STATUS_FILE}) - FOREACH(file IN LISTS PROJECT_PROTO_SRCS PROJECT_PROTO_HDRS) - IF(NOT EXISTS ${file}) - MESSAGE("Resetting generate_proto because '${file}' is missing") - FILE(REMOVE ${PROTO_STATUS_FILE}) - BREAK() - ENDIF() - ENDFOREACH() -ENDIF() +# (only runs when cmake is run, but better than nothing) +FOREACH(file IN LISTS PROJECT_PROTO_SRCS PROJECT_PROTO_HDRS) + IF(NOT EXISTS ${file}) + # MESSAGE("Resetting generate_proto because '${file}' is missing") + FILE(REMOVE ${PROJECT_PROTO_TMP_FILES}) + BREAK() + ENDIF() +ENDFOREACH() ADD_CUSTOM_COMMAND( - OUTPUT ${PROTO_STATUS_FILE} + OUTPUT ${PROJECT_PROTO_TMP_FILES} COMMAND protoc-bin -I=${dfhack_SOURCE_DIR}/library/proto/ -I=${CMAKE_CURRENT_SOURCE_DIR}/proto/ --cpp_out=${CMAKE_CURRENT_SOURCE_DIR}/proto/tmp/ @@ -69,11 +67,10 @@ ADD_CUSTOM_COMMAND( COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PROJECT_PROTO_TMP_FILES} ${CMAKE_CURRENT_SOURCE_DIR}/proto/ - COMMAND ${CMAKE_COMMAND} -E touch ${PROTO_STATUS_FILE} COMMENT "Generating plugin protobufs" DEPENDS protoc-bin ${PROJECT_PROTOS} ) -add_custom_target(generate_proto DEPENDS ${PROTO_STATUS_FILE}) +ADD_CUSTOM_TARGET(generate_proto DEPENDS ${PROJECT_PROTO_TMP_FILES}) SET_SOURCE_FILES_PROPERTIES( Brushes.h PROPERTIES HEADER_FILE_ONLY TRUE ) diff --git a/plugins/proto/.gitignore b/plugins/proto/.gitignore index 3a96bb3d9..befabf79d 100644 --- a/plugins/proto/.gitignore +++ b/plugins/proto/.gitignore @@ -1,4 +1,3 @@ *.pb.cc *.pb.cc.rule *.pb.h -status.txt