Ver código fonte

Fix cmake dependencies for file generation

- QtProtobuf generator does not regenerate files if proto are unchanged
- Fix find_package directives broken after components introduction
Viktor Kopp 5 anos atrás
pai
commit
b289fe37b4

+ 1 - 2
ProjectConfig.cmake.in

@@ -1,6 +1,5 @@
-message(STATUS ${CMAKE_CURRENT_LIST_DIR})
 foreach(component ${@PROJECT_NAME@_FIND_COMPONENTS})
   # For requested component, execute its "config" script
-  message(STATUS "Including ${CMAKE_CURRENT_LIST_DIR}/${component}Config.cmake...")
+  #message(STATUS "Including ${CMAKE_CURRENT_LIST_DIR}/${component}Config.cmake...")
   include(${CMAKE_CURRENT_LIST_DIR}/${component}Config.cmake)
 endforeach()

+ 1 - 1
cmake/QtProtobufCommon.cmake

@@ -1,4 +1,4 @@
-find_package(QtProtobuf REQUIRED)
+find_package(QtProtobufProject COMPONENTS QtProtobuf QtGrpc REQUIRED)
 
 function(protobuf_generate_all)
     set(options)

+ 1 - 1
src/grpc/QtGrpcConfig.cmake.in

@@ -1,6 +1,6 @@
 include(CMakeFindDependencyMacro)
 
-find_dependency(QtProtobuf REQUIRED CONFIG)
+find_dependency(QtProtobufProject COMPONENTS QtProtobuf REQUIRED CONFIG)
 
 if (NOT TARGET @TARGET@ AND NOT @TARGET@_BINARY_DIR)
     include("${CMAKE_CURRENT_LIST_DIR}/@TARGET_EXPORT@.cmake")

+ 4 - 3
src/protobuf/QtProtobufGen.cmake.in

@@ -9,8 +9,6 @@ function(generate_qtprotobuf)
 
     set(GEN_TARGET ${generate_qtprotobuf_TARGET}_qtprotobuf_generate)
 
-    add_custom_target(${GEN_TARGET})
-
     if(NOT DEFINED QTPROTOBUF_EXECUTABLE)
         set(QTPROTOBUF_EXECUTABLE @QTPROTOBUF_EXECUTABLE_INSTALL@)
     endif()
@@ -37,7 +35,8 @@ function(generate_qtprotobuf)
         set_property(SOURCE ${OUT_DIR}/${GENERATED_BASENAME}.cpp PROPERTY SKIP_AUTOMOC ON)
     endforeach()
 
-    add_custom_command(TARGET ${GEN_TARGET}
+    add_custom_command(
+            OUTPUT ${QTPROTOBUF_GENERATED_SOURCES} ${QTPROTOBUF_GENERATED_HEADERS}
             COMMAND $<TARGET_FILE:protobuf::protoc>
                 --@GENERATOR_TARGET@_opt=out=${OUT_DIR}
                 --plugin=protoc-gen-@GENERATOR_TARGET@=${QTPROTOBUF_EXECUTABLE}
@@ -48,6 +47,8 @@ function(generate_qtprotobuf)
             DEPENDS ${PROTO_FILES}
             COMMENT "Generating test headers"
     )
+    
+    add_custom_target(${GEN_TARGET} DEPENDS ${QTPROTOBUF_GENERATED_SOURCES} ${QTPROTOBUF_GENERATED_HEADERS} ${PROTO_FILES})
 
     qt5_wrap_cpp(MOC_SOURCES ${QTPROTOBUF_GENERATED_HEADERS})
     list(APPEND GENERATED_SOURCES ${MOC_SOURCES})