Przeglądaj źródła

Fix missing header files when extending targets

- Move auto generator directives to the top-level
  CMakeLists.txt.
- Use APPEND property when adding PUBLIC_HEADER
  to the target.

Fixes #238
Alexey Edelev 3 lat temu
rodzic
commit
7eeb2915c3

+ 4 - 1
CMakeLists.txt

@@ -10,7 +10,7 @@ project(${QT_PROTOBUF_NAMESPACE} VERSION ${QT_PROTOBUF_VERSION} LANGUAGES CXX)
 
 # Conan support, optional
 if(EXISTS "${CMAKE_BINARY_DIR}/conanbuildinfo.cmake")
-    include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
+    include("${CMAKE_BINARY_DIR}/conanbuildinfo.cmake")
     conan_basic_setup()
 endif()
 
@@ -40,6 +40,9 @@ find_package(Threads)
 find_package(${QT_VERSIONED_PREFIX} COMPONENTS Core Qml CONFIG REQUIRED)
 find_package(${QT_VERSIONED_PREFIX} OPTIONAL_COMPONENTS Network Quick Gui CONFIG)
 
+set(CMAKE_AUTOMOC ON)
+set(CMAKE_AUTORCC ON)
+
 set(CMAKE_CXX_STANDARD 14)
 set(CMAKE_CXX_STANDARD_REQUIRED ON)
 set(CMAKE_POSITION_INDEPENDENT_CODE ${${QT_VERSIONED_PREFIX}_POSITION_INDEPENDENT_CODE})

+ 7 - 11
cmake/QtProtobufInternalHelpers.cmake

@@ -77,9 +77,7 @@ function(qt_protobuf_internal_add_example)
     cmake_parse_arguments(arg "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
 
     set(CMAKE_INCLUDE_CURRENT_DIR ON)
-    set(CMAKE_AUTOMOC ON)
-    set(CMAKE_AUTORCC ON)
-
+    
     file(GLOB PROTO_FILES ABSOLUTE ${arg_PROTO_FILES})
     file(GLOB SOURCES ${arg_SOURCES})
 
@@ -169,14 +167,11 @@ function(qt_protobuf_internal_add_library target)
     set(target_install_libdir "${CMAKE_INSTALL_LIBDIR}")
     set(target_install_cmakedir "${CMAKE_INSTALL_LIBDIR}/cmake/${QT_PROTOBUF_NAMESPACE}")
 
-    set(CMAKE_AUTOMOC ON)
-    set(CMAKE_AUTORCC ON)
-
     if(NOT arg_SOURCES)
         message(FATAL_ERROR "SOURCES are not specified for ${target}")
     endif()
 
-    file(GLOB sources ${arg_SOURCES} ${arg_PUBLIC_HEADER})
+    file(GLOB sources ${arg_SOURCES})
     add_library(${target} ${sources})
 
     if(NOT BUILD_SHARED_LIBS)
@@ -280,13 +275,14 @@ function(qt_protobuf_internal_extend_target target)
     endif()
 
     if(arg_PUBLIC_HEADER)
-        file(GLOB PUBLIC_HEADER ${arg_PUBLIC_HEADER})
+        file(GLOB public_header_paths ${arg_PUBLIC_HEADER})
         qt_protobuf_internal_generate_qt_headers(generated_public_header
-            PUBLIC_HEADER ${PUBLIC_HEADER}
+            PUBLIC_HEADER ${public_header_paths}
             TARGET ${target}
         )
-        set_target_properties(${target} PROPERTIES
-            PUBLIC_HEADER "${PUBLIC_HEADER};${generated_public_header}")
+        set_property(TARGET ${target} APPEND PROPERTY
+            PUBLIC_HEADER "${public_header_paths};${generated_public_header}")
+        target_sources(${target} PRIVATE ${public_header_paths})
     endif()
 
     if(arg_LIBRARIES)

+ 1 - 4
cmake/QtProtobufTestHelpers.cmake

@@ -98,7 +98,4 @@ macro(qt_protobuf_internal_find_dependencies)
         add_definitions(-DQT_PROTOBUF_STATIC)# add_definitions is used because old cmake versions
                                              # compatibility
     endif()
-
-    set(CMAKE_AUTOMOC ON)
-    set(CMAKE_AUTORCC ON)
-endmacro()
+endmacro()

+ 1 - 1
src/generator/CMakeLists.txt

@@ -41,4 +41,4 @@ if(QT_PROTOBUF_INSTALL)
         DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${QT_PROTOBUF_NAMESPACE}"
         COMPONENT dev
     )
-endif()
+endif()