Prechádzať zdrojové kódy

Fix the use of the qt installation path for the pri files and plugins

- Install qml plugins and pri-file to the standard Qt paths only if
  the Qt install prefix is the same to CMAKE_INSTALL_PREFIX. This
  make possible to keep all artifacts in custom-prefixed install
  folder without disturbing the Qt installation
- Move the pri generating functionality ti the
  qt_protobuf_internal_generate_pri function.
- Add explicit install prefix to the windows packaginf rules

Fixes: #222
Alexey Edelev 3 rokov pred
rodič
commit
671d223d94

+ 2 - 1
.github/workflows/tagadd.yml

@@ -54,12 +54,13 @@ jobs:
       id: build_release_windows
       run: |
         mkdir build-static
+        mkdir install
         cd build-static
         setx GOROOT "c:\Go"
         setx path "%path%;C:\Qt\5.15.2\msvc2019_64\bin;C:\Go\bin;C:\yasm"
         set GOROOT="c:\Go"
         set PATH="%PATH%;C:\Qt\5.15.2\msvc2019_64\bin;C:\Go\bin;C:\yasm"
-        cmake -DCMAKE_PREFIX_PATH="C:\Qt\5.15.2\msvc2019_64;C:\Go\bin;C:\yasm" -DBUILD_SHARED_LIBS=OFF -DQT_PROTOBUF_MAKE_TESTS=OFF -DQT_PROTOBUF_MAKE_EXAMPLES=OFF -DCMAKE_BUILD_TYPE=Release ..
+        cmake -DCMAKE_PREFIX_PATH="C:\Qt\5.15.2\msvc2019_64;C:\Go\bin;C:\yasm" -DBUILD_SHARED_LIBS=OFF -DQT_PROTOBUF_MAKE_TESTS=OFF -DQT_PROTOBUF_MAKE_EXAMPLES=OFF -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="../install" ..
         cmake --build . --config Release --parallel
         cpack -G ZIP -C Release -v
         mkdir artifacts

+ 25 - 0
cmake/QtProtobufInternalHelpers.cmake

@@ -411,3 +411,28 @@ function(qt_protobuf_internal_install_targets)
         )
     endforeach()
 endfunction()
+
+function(qt_protobuf_internal_generate_pri target)
+    string(TOLOWER "${target}" target_lower)
+    set(pri_name "qt_lib_${target_lower}.pri")
+
+    configure_file("${CMAKE_CURRENT_SOURCE_DIR}/${pri_name}.in"
+        "${QT_PROTOBUF_BINARY_DIR}/${pri_name}" @ONLY
+    )
+
+    if(QT_PROTOBUF_INSTALL)
+        qt_protobuf_extract_qt_variable(QT_INSTALL_ARCHDATA)
+        qt_protobuf_extract_qt_variable(QT_INSTALL_PREFIX)
+
+        if("${QT_INSTALL_PREFIX}" STREQUAL "${CMAKE_INSTALL_PREFIX}")
+            set(mkspec_install_dir "${QT_INSTALL_ARCHDATA}/mkspecs/modules")
+        else()
+            set(mkspec_install_dir "${CMAKE_INSTALL_PREFIX}/mkspecs/modules")
+        endif()
+
+        install(FILES "${QT_PROTOBUF_BINARY_DIR}/${pri_name}"
+            DESTINATION "${mkspec_install_dir}"
+            COMPONENT dev
+        )
+    endif()
+endfunction()

+ 1 - 11
src/grpc/CMakeLists.txt

@@ -49,17 +49,7 @@ if(NOT BUILD_SHARED_LIBS)
     set(QT_PROTOBUF_EXTRA_CONFIG "staticlib") #extra config for .pri file in case if static build enabled
 endif()
 
-configure_file("${CMAKE_CURRENT_SOURCE_DIR}/qt_lib_grpc.pri.in"
-    "${QT_PROTOBUF_BINARY_DIR}/qt_lib_grpc.pri" @ONLY
-)
-
-if(QT_PROTOBUF_INSTALL)
-    qt_protobuf_extract_qt_variable(QT_HOST_DATA)
-    install(FILES "${QT_PROTOBUF_BINARY_DIR}/qt_lib_grpc.pri"
-            DESTINATION "${CMAKE_INSTALL_PREFIX}/${QT_HOST_DATA}/mkspecs/modules"
-            COMPONENT dev
-    )
-endif()
+qt_protobuf_internal_generate_pri(Grpc)
 
 if(TARGET Qt5::Quick)
     add_subdirectory("quick")

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

@@ -9,9 +9,10 @@ set(CMAKE_AUTOMOC_MOC_OPTIONS -Muri=QtGrpc)
 set(CMAKE_AUTORCC ON)
 
 qt_protobuf_extract_qt_variable(QT_INSTALL_QML)
+qt_protobuf_extract_qt_variable(QT_INSTALL_PREFIX)
 
-if(NOT WIN32)
-    set(TARGET_IMPORTS_DIR ${CMAKE_INSTALL_PREFIX}/${QT_INSTALL_QML}/QtGrpc)
+if("${QT_INSTALL_PREFIX}" STREQUAL "${CMAKE_INSTALL_PREFIX}")
+    set(TARGET_IMPORTS_DIR ${QT_INSTALL_QML}/QtGrpc)
 else()
     set(TARGET_IMPORTS_DIR ${CMAKE_INSTALL_LIBDIR}/qml/QtGrpc)
 endif()

+ 1 - 11
src/protobuf/CMakeLists.txt

@@ -69,17 +69,7 @@ if(NOT BUILD_SHARED_LIBS)
                                               # build enabled
 endif()
 
-configure_file("${CMAKE_CURRENT_SOURCE_DIR}/qt_lib_protobuf.pri.in"
-    "${QT_PROTOBUF_BINARY_DIR}/qt_lib_protobuf.pri" @ONLY
-)
-
-if(QT_PROTOBUF_INSTALL)
-    qt_protobuf_extract_qt_variable(QT_HOST_DATA)
-    install(FILES "${QT_PROTOBUF_BINARY_DIR}/qt_lib_protobuf.pri"
-        DESTINATION "${CMAKE_INSTALL_PREFIX}/${QT_HOST_DATA}/mkspecs/modules"
-        COMPONENT dev
-    )
-endif()
+qt_protobuf_internal_generate_pri(Protobuf)
 
 if(TARGET Qt5::Quick)
     add_subdirectory("quick")

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

@@ -9,9 +9,10 @@ set(CMAKE_AUTOMOC_MOC_OPTIONS -Muri=QtProtobuf)
 set(CMAKE_AUTORCC ON)
 
 qt_protobuf_extract_qt_variable(QT_INSTALL_QML)
+qt_protobuf_extract_qt_variable(QT_INSTALL_PREFIX)
 
-if(NOT WIN32)
-    set(TARGET_IMPORTS_DIR ${CMAKE_INSTALL_PREFIX}/${QT_INSTALL_QML}/QtProtobuf)
+if("${QT_INSTALL_PREFIX}" STREQUAL "${CMAKE_INSTALL_PREFIX}")
+    set(TARGET_IMPORTS_DIR ${QT_INSTALL_QML}/QtProtobuf)
 else()
     set(TARGET_IMPORTS_DIR ${CMAKE_INSTALL_LIBDIR}/qml/QtProtobuf)
 endif()

+ 6 - 2
tests/test_extra_namespace_qml/CMakeLists.txt

@@ -23,5 +23,9 @@ qt_protobuf_internal_add_target_windeployqt(TARGET ${TARGET} QML_DIR ${CMAKE_CUR
 
 add_test(NAME ${TARGET} COMMAND ${TARGET})
 
-set_tests_properties(${TARGET} PROPERTIES
-    ENVIRONMENT QML2_IMPORT_PATH=$<TARGET_FILE_DIR:${PROTOBUF_QUICK_PLUGIN_NAME}>/..)
+if(NOT QT_PROTOBUF_STATIC AND NOT QT_PROTOBUF_STANDALONE_TESTS)
+    set_tests_properties(${TARGET} PROPERTIES
+        ENVIRONMENT "QML2_IMPORT_PATH=$ENV{QML2_IMPORT_PATH}${path_separator}\
+$<TARGET_FILE_DIR:${QT_PROTOBUF_NAMESPACE}::${PROTOBUF_QUICK_PLUGIN_NAME}>/.."
+    )
+endif()