Переглянути джерело

Initiall crosscompiling support

- Add support of the two-steps crosscompiling.
- Fix issues in Wrap scripts
- Update README
- Set the CMP0112 policy to old, to avoid configuration warnings
- Add a sample toolchain file to examples

Fixes: #149
Alexey Edelev 3 роки тому
батько
коміт
c1cdd261ac

+ 23 - 8
CMakeLists.txt

@@ -1,4 +1,5 @@
 cmake_minimum_required(VERSION 3.14)
+cmake_policy(VERSION 3.6...3.14)
 
 set(QT_PROTOBUF_VERSION 0.5.0)
 set(QT_PROTOBUF_NAMESPACE QtProtobuf)
@@ -20,10 +21,21 @@ set(QT_PROTOBUF_CMAKE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
 set(QT_PROTOBUF_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
 set(QT_PROTOBUF_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}")
 
-list(APPEND CMAKE_MODULE_PATH ${QT_PROTOBUF_CMAKE_DIR})
+list(PREPEND CMAKE_MODULE_PATH ${QT_PROTOBUF_CMAKE_DIR})
 
 find_package(WrapgRPC)
-find_package(WrapProtobuf COMPONENTS Protoc OPTIONAL_COMPONENTS Generator Protobuf REQUIRED)
+if(NOT CMAKE_CROSSCOMPILING)
+    find_package(WrapProtobuf COMPONENTS Protoc OPTIONAL_COMPONENTS Generator Protobuf REQUIRED)
+else()
+    if(NOT QT_PROTOBUF_HOST_PATH)
+        message(FATAL_ERROR "QT_PROTOBUF_HOST_PATH is not specified. You shall specify
+QT_PROTOBUF_HOST_PATH to find the host version of QtProtobufGenerator")
+    endif()
+    find_package(${QT_PROTOBUF_NAMESPACE} COMPONENTS ProtobufGenerator CONFIG REQUIRED
+        PATHS ${QT_PROTOBUF_HOST_PATH}
+        NO_DEFAULT_PATH
+    )
+endif()
 find_package(Threads)
 find_package(${QT_VERSIONED_PREFIX} COMPONENTS Core Qml CONFIG REQUIRED)
 find_package(${QT_VERSIONED_PREFIX} OPTIONAL_COMPONENTS Network Quick Gui CONFIG)
@@ -90,20 +102,23 @@ if(QT_PROTOBUF_FIELD_ENUM)
 endif()
 
 configure_package_config_file(
-    "${CMAKE_CURRENT_SOURCE_DIR}/ProjectConfig.cmake.in" "${QT_PROTOBUF_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
+    "${CMAKE_CURRENT_SOURCE_DIR}/ProjectConfig.cmake.in" "${QT_PROTOBUF_BINARY_DIR}/${QT_PROTOBUF_NAMESPACE}Config.cmake"
     INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake")
 
-install(FILES "${QT_PROTOBUF_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
-    DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
+install(FILES "${QT_PROTOBUF_BINARY_DIR}/${QT_PROTOBUF_NAMESPACE}Config.cmake"
+    DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${QT_PROTOBUF_NAMESPACE}"
     COMPONENT dev
 )
-export(PACKAGE ${PROJECT_NAME})
+export(PACKAGE ${QT_PROTOBUF_NAMESPACE})
 install(FILES "${QT_PROTOBUF_CMAKE_DIR}/FindWrapProtobuf.cmake"
-    DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
+    DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${QT_PROTOBUF_NAMESPACE}"
     COMPONENT dev
 )
 
-add_subdirectory("src/generator")
+if(NOT CMAKE_CROSSCOMPILING)
+    add_subdirectory("src/generator")
+endif()
+
 add_subdirectory("src/protobuf")
 if(TARGET ${QT_VERSIONED_PREFIX}::Network)
     if(${QT_VERSIONED_PREFIX}Core_VERSION VERSION_LESS "5.12.4")

+ 9 - 4
ProjectConfig.cmake.in

@@ -5,12 +5,17 @@ list(PREPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")
 foreach(component ${@PROJECT_NAME@_FIND_COMPONENTS})
     # For requested component, execute its "config" script
     if(component STREQUAL "ProtobufGenerator")
-        include(${CMAKE_CURRENT_LIST_DIR}/@QT_PROTOBUF_NAMESPACE@qtprotobufgenConfig.cmake)
-        continue()
+        if(NOT CMAKE_CROSSCOMPILING)
+            set(component_config "${CMAKE_CURRENT_LIST_DIR}/${QT_PROTOBUF_NAMESPACE}qtprotobufgenConfig.cmake")
+        else()
+            set(component_config "${QT_PROTOBUF_HOST_PATH}/${QT_PROTOBUF_NAMESPACE}/${QT_PROTOBUF_NAMESPACE}qtprotobufgenConfig.cmake")
+        endif()
+    else()
+        set(component_config "${CMAKE_CURRENT_LIST_DIR}/${QT_PROTOBUF_NAMESPACE}${component}Config.cmake")
     endif()
-    set(component_config "${CMAKE_CURRENT_LIST_DIR}/@QT_PROTOBUF_NAMESPACE@${component}Config.cmake")
+    get_filename_component(component_config "${component_config}" ABSOLUTE)
     if(NOT EXISTS "${component_config}")
-        message(FATAL_ERROR "Component ${component} not found")
+        message(FATAL_ERROR "Component ${component} not found. ${component_config} doesn't exist.")
     endif()
     include("${component_config}")
 endforeach()

+ 77 - 3
README.md

@@ -25,6 +25,8 @@ QtProtobuf provides Qt-native support of Google protocol buffers. Generated code
 
 [Windows Build](#windows-build)
 
+[Cross-compiling](#cross-compiling)
+
 [Usage](#usage)
 
 [Integration with CMake project](#integration-with-cmake-project)
@@ -64,7 +66,7 @@ QtProtobuf provides Qt-native support of Google protocol buffers. Generated code
 
 Check installation of following packages in your system:
 
-- cmake 3.6 or higher
+- cmake 3.14 or higher
 - Qt 5.12.4 or higher
 - protobuf 3.6.0 or higher (might be used from submodule)
 - golang 1.10 or higher
@@ -162,7 +164,7 @@ git submodule add https://github.com/semlanik/qtprotobuf.git qtprotobuf
 git submodule init qtprotobuf
 git submodule update qtprotobuf
 
-#(Optional) You also may initialize all internal QtProtobuf sub-modules for all-in-one build using steps bellow:
+#(Optional) You also may initialize all internal QtProtobuf sub-modules for all-in-one build using steps below:
 cd qtprotobuf
 git submodule update --init --recursive
 ```
@@ -253,9 +255,81 @@ cmake ..
 cmake --build . [--config <RELEASE|DEBUG>] -- /m:<N>
 ```
 
+## Cross-compiling
+
+>**Note:** Cross-compiling support is available since version 0.6.0
+
+Cross compiling is only supported in the prefixed builds of QtProtobuf. It's split into three parts:
+
+- Build and install the Qt framework for the target system (Instructions could be found in the documentation for the Qt Framework)
+- Build for the host system
+- Build for the target system
+
+### Build for the host system
+
+Build for the host system must be prefixed, that means you should install it to the system or the temporary directory,
+using the following steps:
+
+```bash
+mkdir build-host
+cd build-host
+cmake </path/to/qtprotobuf/sources> -DQT_PROTOBUF_MAKE_TESTS=OFF -DQT_PROTOBUF_MAKE_EXAMPLES=OFF -DCMAKE_INSTALL_PREFIX=</host/sysroot/prefix>
+cmake --build . -- -j<N>
+cmake --install .
+```
+
+### Build for the target system
+
+To build QtProtobuf correctly for the target system you need to specify compiler and other build essentials in the CMake toolchain file.
+Also it's necessary to specify the QT_PROTOBUF_HOST_PATH variable, that is used to find a host binary of the QtProtobuf generator.
+
+:warning: **IMPORTANT** The QT_PROTOBUF_HOST_PATH variable shall point to the *<lib|lib32|lib64>/cmake* directory of the host QtProtobuf installation.
+
+Typical toolchain file looks as following:
+
+```cmake
+set(CMAKE_SYSTEM_NAME Linux)
+
+set(CMAKE_SYSROOT /usr/armv7a-hardfloat-linux-gnueabi/)
+
+set(CMAKE_C_COMPILER /usr/bin/armv7a-hardfloat-linux-gnueabi-gcc)
+set(CMAKE_CXX_COMPILER /usr/bin/armv7a-hardfloat-linux-gnueabi-g++)
+
+set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) # Important to look programms in the host sysroot only
+set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
+set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
+set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE BOTH) # Important to look packages in both the host and target sysroots
+```
+
+Using the below steps configure and build the target QtProtobuf:
+
+>**Note:** Use values of the expressions same as in the *Build for the host system* step.
+
+```bash
+mkdir build-host
+cd build-host
+cmake </path/to/qtprotobuf/sources> -DQT_PROTOBUF_MAKE_TESTS=OFF -DQT_PROTOBUF_MAKE_EXAMPLES=OFF -DCMAKE_INSTALL_PREFIX="</target/sysroot/prefix>" -DCMAKE_TOOLCHAIN_FILE="</path/to/toolchain.cmake>" -DQT_PROTOBUF_HOST_PATH="</host/sysroot/prefix>/<lib|lib32|lib64>/cmake" -DCMAKE_PREFIX_PATH="</target/sysroot/cross-compiled/qt>"
+```
+
+### Build your project using the target QtProtobuf
+
+>**Note:** Only the CMake-based user projects have a cross-compiling support.
+
+When you build your own project using the target QtProtobuf, it's recommented to use the same toolchain file as you used to compile QtProtobuf.
+You also still need to specify the QT_PROTOBUF_HOST_PATH variable to find the host QtProtobuf generator. Use the following steps as example:
+
+```bash
+mkdir build-clienttutorial
+cd build-clienttutorial
+cmake </path/to/qtprotobuf/sources/examples/clienttutorial> -DCMAKE_PREFIX_PATH="</target/sysroot/prefix>;</target/sysroot/cross-compiled/qt>" -DQT_PROTOBUF_HOST_PATH="</host/sysroot/prefix>/<lib|lib32|lib64>/cmake" -DCMAKE_TOOLCHAIN_FILE="</path/to/toolchain.cmake>"
+
+```
+
+If you build the shared version of the QtProtobuf libraries don't forget to copy them to the target filesystem before running the application.
+
 ## Conan build
 
-QtProtobuf supports conan builds since version 0.4.0.
+>**Note:** QtProtobuf supports conan builds since version 0.4.0.
 
 ### Build QtProtobuf
 

+ 10 - 3
cmake/FindWrapProtobuf.cmake

@@ -14,7 +14,9 @@ else()
     set(FIND_LIBRARY_USE_LIB64_PATHS FALSE)
 endif()
 
+set(WrapProtobuf_REQUIRED_VARS)
 if("Protobuf" IN_LIST WrapProtobuf_FIND_COMPONENTS OR NOT WrapProtobuf_FIND_COMPONENTS)
+    list(APPEND WrapProtobuf_REQUIRED_VARS Protobuf_INCLUDE_DIRS)
     set(WrapProtobuf_Protobuf_FOUND TRUE)
     if(NOT TARGET protobuf::libprotobuf)
         find_library(Protobuf_LIBRARY protobuf)
@@ -44,6 +46,7 @@ if("Protobuf" IN_LIST WrapProtobuf_FIND_COMPONENTS OR NOT WrapProtobuf_FIND_COMP
 endif()
 
 if("Protoc" IN_LIST WrapProtobuf_FIND_COMPONENTS OR NOT WrapProtobuf_FIND_COMPONENTS)
+    list(APPEND WrapProtobuf_REQUIRED_VARS Protoc_INCLUDE_DIRS)
     set(WrapProtobuf_Protoc_FOUND TRUE)
     if(NOT TARGET protobuf::libprotoc)
         find_package(Threads REQUIRED)
@@ -78,6 +81,7 @@ if("Protoc" IN_LIST WrapProtobuf_FIND_COMPONENTS OR NOT WrapProtobuf_FIND_COMPON
 endif()
 
 if("Generator" IN_LIST WrapProtobuf_FIND_COMPONENTS OR NOT WrapProtobuf_FIND_COMPONENTS)
+    list(APPEND WrapProtobuf_REQUIRED_VARS Protobuf_Protoc_EXECUTABLE)
     set(WrapProtobuf_Generator_FOUND TRUE)
     if(NOT TARGET protobuf::protoc)
         find_program(Protobuf_Protoc_EXECUTABLE protoc)
@@ -89,16 +93,19 @@ if("Generator" IN_LIST WrapProtobuf_FIND_COMPONENTS OR NOT WrapProtobuf_FIND_COM
         else()
             set(WrapProtobuf_Generator_FOUND FALSE)
         endif()
+    else()
+        set(Protobuf_Protoc_EXECUTABLE "protobuf::protoc")
     endif()
 endif()
 
 if(WrapProtobuf_FIND_COMPONENTS)
     include(FindPackageHandleStandardArgs)
     find_package_handle_standard_args(WrapProtobuf HANDLE_COMPONENTS
-        REQUIRED_VARS Protoc_INCLUDE_DIRS Protobuf_INCLUDE_DIRS
+        REQUIRED_VARS ${WrapProtobuf_REQUIRED_VARS}
     )
 elseif(TARGET protobuf::protoc AND TARGET protobuf::libprotoc AND TARGET protobuf::libprotobuf)
     include(FindPackageHandleStandardArgs)
-    find_package_handle_standard_args(WrapProtobuf REQUIRED_VARS
-        Protoc_INCLUDE_DIRS Protobuf_INCLUDE_DIRS)
+    find_package_handle_standard_args(WrapProtobuf
+        REQUIRED_VARS ${WrapProtobuf_REQUIRED_VARS}
+    )
 endif()

+ 3 - 1
examples/addressbook/CMakeLists.txt

@@ -10,6 +10,8 @@ qt_protobuf_internal_add_example(TARGET ${TARGET}
                    QML_DIR ${CMAKE_CURRENT_SOURCE_DIR}/qml)
 
 add_custom_command(TARGET ${TARGET}
-    COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/../addressbookserver/cert.pem $<TARGET_FILE_DIR:${TARGET}>)
+    COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/../addressbookserver/cert.pem"
+            "$<TARGET_FILE_DIR:${TARGET}>"
+)
 
 set(CLIENT_EXEC_PATH ${CMAKE_CURRENT_BINARY_DIR}/${TARGET} PARENT_SCOPE)

+ 5 - 1
examples/addressbookserver/CMakeLists.txt

@@ -25,5 +25,9 @@ if(MSVC)
    target_compile_definitions(${TARGET} PRIVATE _WIN32_WINNT=0x600 _SCL_SECURE_NO_WARNINGS _CRT_SECURE_NO_WARNINGS _WINSOCK_DEPRECATED_NO_WARNINGS)
 endif()
 add_custom_command(TARGET ${TARGET}
-    COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/cert.pem ${CMAKE_CURRENT_SOURCE_DIR}/key.pem $<TARGET_FILE_DIR:${TARGET}>)
+    COMMAND ${CMAKE_COMMAND} -E copy
+            "${CMAKE_CURRENT_SOURCE_DIR}/cert.pem"
+            "${CMAKE_CURRENT_SOURCE_DIR}/key.pem"
+            "$<TARGET_FILE_DIR:${TARGET}>"
+)
 set(SERVER_EXEC_PATH ${CMAKE_CURRENT_BINARY_DIR}/${TARGET} PARENT_SCOPE)

+ 6 - 3
examples/clienttutorial/CMakeLists.txt

@@ -10,12 +10,15 @@ set(CMAKE_AUTORCC ON)
 
 find_package(Qt5 COMPONENTS Core Quick REQUIRED)
 set(CMAKE_POSITION_INDEPENDENT_CODE ${Qt5_POSITION_INDEPENDENT_CODE})
-
+set(QT_PROTOBUF_NAMESPACE QtProtobuf)
+if(NOT TARGET ${QT_PROTOBUF_NAMESPACE}::qtprotobufgen)
+    find_package(${QT_PROTOBUF_NAMESPACE} COMPONENTS ProtobufGenerator CONFIG REQUIRED)
+endif()
 if(NOT TARGET ${QT_PROTOBUF_NAMESPACE}::Protobuf)
-    find_package(${QT_PROTOBUF_NAMESPACE} COMPONENTS Protobuf REQUIRED)
+    find_package(${QT_PROTOBUF_NAMESPACE} COMPONENTS Protobuf CONFIG REQUIRED)
 endif()
 if(NOT TARGET ${QT_PROTOBUF_NAMESPACE}::Grpc)
-    find_package(${QT_PROTOBUF_NAMESPACE} COMPONENTS Grpc REQUIRED)
+    find_package(${QT_PROTOBUF_NAMESPACE} COMPONENTS Grpc CONFIG REQUIRED)
 endif()
 
 add_executable(clienttutorial main.cpp echoclientengine.cpp qml.qrc)

+ 11 - 0
examples/example_crosscompiling_toolchain.cmake

@@ -0,0 +1,11 @@
+set(CMAKE_SYSTEM_NAME Linux)
+
+set(CMAKE_SYSROOT /usr/armv7a-hardfloat-linux-gnueabi/)
+
+set(CMAKE_C_COMPILER /usr/bin/armv7a-hardfloat-linux-gnueabi-gcc)
+set(CMAKE_CXX_COMPILER /usr/bin/armv7a-hardfloat-linux-gnueabi-g++)
+
+set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
+set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
+set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
+set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE BOTH) 

+ 3 - 1
examples/simplechat/CMakeLists.txt

@@ -10,6 +10,8 @@ qt_protobuf_internal_add_example(TARGET ${TARGET}
                    QML_DIR ${CMAKE_CURRENT_SOURCE_DIR})
 
 add_custom_command(TARGET ${TARGET}
-    COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/../addressbookserver/cert.pem $<TARGET_FILE_DIR:${TARGET}>)
+    COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/../addressbookserver/cert.pem"
+            "$<TARGET_FILE_DIR:${TARGET}>"
+)
 
 set(CLIENT_EXEC_PATH ${CMAKE_CURRENT_BINARY_DIR}/${TARGET} PARENT_SCOPE)

+ 4 - 0
src/generator/QtqtprotobufgenConfig.cmake.in

@@ -1,6 +1,10 @@
 include(CMakeFindDependencyMacro)
+
 # We only look for protoc, libprotoc should already be in rpath or linked statically
+set(_save_cmake_module_path "${CMAKE_MODULE_PATH}")
+set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")
 find_package(WrapProtobuf COMPONENTS Generator REQUIRED)
+set(CMAKE_MODULE_PATH "${_save_cmake_module_path}")
 
 if(NOT TARGET @QT_PROTOBUF_NAMESPACE@::@target@)
     include("${CMAKE_CURRENT_LIST_DIR}/@target_export@.cmake")

+ 1 - 1
src/grpc/CMakeLists.txt

@@ -56,7 +56,7 @@ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/qt_lib_grpc.pri.in"
 if(QT_PROTOBUF_INSTALL)
     qt_protobuf_extract_qt_variable(QT_HOST_DATA)
     install(FILES "${QT_PROTOBUF_BINARY_DIR}/qt_lib_grpc.pri"
-            DESTINATION "${QT_HOST_DATA}/mkspecs/modules"
+            DESTINATION "${CMAKE_INSTALL_PREFIX}/${QT_HOST_DATA}/mkspecs/modules"
             COMPONENT dev
     )
 endif()

+ 5 - 3
src/grpc/quick/CMakeLists.txt

@@ -11,7 +11,7 @@ set(CMAKE_AUTORCC ON)
 qt_protobuf_extract_qt_variable(QT_INSTALL_QML)
 
 if(NOT WIN32)
-    set(TARGET_IMPORTS_DIR ${QT_INSTALL_QML}/QtGrpc)
+    set(TARGET_IMPORTS_DIR ${CMAKE_INSTALL_PREFIX}/${QT_INSTALL_QML}/QtGrpc)
 else()
     set(TARGET_IMPORTS_DIR ${CMAKE_INSTALL_LIBDIR}/qml/QtGrpc)
 endif()
@@ -59,8 +59,10 @@ else()
 endif()
 
 add_custom_command(TARGET ${TARGET}
-    COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/qmldir $<TARGET_FILE_DIR:${TARGET}>/qmldir
-    COMMENT "Copying qmldir to binary directory")
+    COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/qmldir"
+            "$<TARGET_FILE_DIR:${TARGET}>/qmldir"
+    COMMENT "Copying qmldir to binary directory"
+)
 
 if(QT_PROTOBUF_INSTALL)
     install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/qmldir DESTINATION "${TARGET_IMPORTS_DIR}" COMPONENT lib)

+ 1 - 1
src/protobuf/CMakeLists.txt

@@ -76,7 +76,7 @@ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/qt_lib_protobuf.pri.in"
 if(QT_PROTOBUF_INSTALL)
     qt_protobuf_extract_qt_variable(QT_HOST_DATA)
     install(FILES "${QT_PROTOBUF_BINARY_DIR}/qt_lib_protobuf.pri"
-        DESTINATION "${CMAKE_INSTAL_PREFIX}${QT_HOST_DATA}/mkspecs/modules"
+        DESTINATION "${CMAKE_INSTALL_PREFIX}/${QT_HOST_DATA}/mkspecs/modules"
         COMPONENT dev
     )
 endif()

+ 3 - 2
src/protobuf/quick/CMakeLists.txt

@@ -11,7 +11,7 @@ set(CMAKE_AUTORCC ON)
 qt_protobuf_extract_qt_variable(QT_INSTALL_QML)
 
 if(NOT WIN32)
-    set(TARGET_IMPORTS_DIR ${QT_INSTALL_QML}/QtProtobuf)
+    set(TARGET_IMPORTS_DIR ${CMAKE_INSTALL_PREFIX}/${QT_INSTALL_QML}/QtProtobuf)
 else()
     set(TARGET_IMPORTS_DIR ${CMAKE_INSTALL_LIBDIR}/qml/QtProtobuf)
 endif()
@@ -72,7 +72,8 @@ else()
 endif()
 
 add_custom_command(TARGET ${TARGET}
-    COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/qmldir $<TARGET_FILE_DIR:${TARGET}>/qmldir
+    COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/qmldir"
+            "$<TARGET_FILE_DIR:${TARGET}>/qmldir"
     COMMENT "Copying qmldir to binary directory")
 if(QT_PROTOBUF_INSTALL)
     install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/qmldir DESTINATION "${TARGET_IMPORTS_DIR}" COMPONENT lib)

+ 4 - 0
src/wellknowntypes/QtProtobufWellKnownTypesConfig.cmake.in

@@ -1,5 +1,9 @@
 include(CMakeFindDependencyMacro)
+
+set(_save_cmake_module_path "${CMAKE_MODULE_PATH}")
+set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")
 find_dependency(WrapProtobuf COMPONENTS Protobuf REQUIRED)
+set(CMAKE_MODULE_PATH "${_save_cmake_module_path}")
 
 if(NOT TARGET @QT_PROTOBUF_NAMESPACE@::@target@)
     include("${CMAKE_CURRENT_LIST_DIR}/@target_export@.cmake")