diff options
author | Alexey Edelev <alexey.edelev@qt.io> | 2021-03-11 19:13:03 +0100 |
---|---|---|
committer | Alexey Edelev <alexey.edelev@qt.io> | 2021-03-23 13:10:08 +0100 |
commit | b8935eca5625be034632200adcccf18a398f67a2 (patch) | |
tree | 4dc4117a1383dc71f4292248119910dba2d8184e | |
parent | 2b2de60a369ba195703435328fc3812dbef430e5 (diff) |
Add qt6_target_typelibs function
qt6_target_typelibs should replace the qmake functionality associated
with the TYPELIBS variable. This function adds custom call of the
dumpcpp program to generate typelib-related sources and adds the
sources to the target.
Pick-to: 6.1
Task-number: QTBUG-78167
Change-Id: I7b61a2b1804162e723e862945a9650a00776e678
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
-rw-r--r-- | CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/activeqt/container/Qt6AxContainerMacros.cmake | 72 | ||||
-rw-r--r-- | tests/auto/CMakeLists.txt | 4 | ||||
-rw-r--r-- | tests/auto/cmake/CMakeLists.txt | 42 | ||||
-rw-r--r-- | tests/auto/cmake/test_target_typelibs/CMakeLists.txt | 9 | ||||
-rw-r--r-- | tests/auto/cmake/test_target_typelibs/main.cpp | 36 | ||||
-rw-r--r-- | tests/auto/cmake/test_target_typelibs_absolute/CMakeLists.txt | 9 | ||||
-rw-r--r-- | tests/auto/cmake/test_target_typelibs_absolute/main.cpp | 36 | ||||
-rw-r--r-- | tests/auto/cmake/test_target_typelibs_empty_libs/CMakeLists.txt | 9 | ||||
-rw-r--r-- | tests/auto/cmake/test_target_typelibs_empty_libs/main.cpp | 36 | ||||
-rw-r--r-- | tests/auto/cmake/test_target_typelibs_non_existing_libs/CMakeLists.txt | 9 | ||||
-rw-r--r-- | tests/auto/cmake/test_target_typelibs_non_existing_libs/main.cpp | 36 | ||||
-rw-r--r-- | tests/auto/cmake/test_target_typelibs_out_dir/CMakeLists.txt | 12 | ||||
-rw-r--r-- | tests/auto/cmake/test_target_typelibs_out_dir/main.cpp | 36 | ||||
-rw-r--r-- | tests/auto/dumpcpp/CMakeLists.txt | 4 | ||||
-rw-r--r-- | tests/manual/dumpcpp/CMakeLists.txt | 2 |
16 files changed, 346 insertions, 8 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 392016c..b04e4fe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,4 +31,6 @@ if(NOT TARGET Qt::Gui OR NOT TARGET Qt::Widgets OR NOT TARGET Qt::PrintSupport) return() endif() +include("${CMAKE_CURRENT_SOURCE_DIR}/src/activeqt/container/Qt6AxContainerMacros.cmake") + qt_build_repo() diff --git a/src/activeqt/container/Qt6AxContainerMacros.cmake b/src/activeqt/container/Qt6AxContainerMacros.cmake new file mode 100644 index 0000000..4e90943 --- /dev/null +++ b/src/activeqt/container/Qt6AxContainerMacros.cmake @@ -0,0 +1,72 @@ +# Generates a C++ namespace for a type library and adds generated sources to the target. Arguments: +# +# LIBRARIES: List of type libraries. A type library (.tlb) is a binary file that stores information +# about a COM or DCOM object's properties and methods in a form that is accessible to other +# applications at runtime. The list may contain either the path to the library or the name +# of the library. +# If the library name is specified, the function will search for the library according to the +# CMake find_file function rules. See https://cmake.org/cmake/help/latest/command/find_file.html +# for details. +# Note: The library name must include a file suffix, e.g "ieframe.dll". +# +# OUTPUT_DIRECTORY: Custom location of the generated source files. +# ${CMAKE_CURRENT_BINARY_DIR} is the default location if not specified. (OPTIONAL) +# +# COMPAT: Adds compatibility flag to the dumpcpp call, that generates namespace with +# dynamicCall-compatible API. (OPTIONAL) +# +# This function is currently in Technical Preview. +# Its signature and behavior might change. +function(qt6_target_typelibs target) + cmake_parse_arguments(arg "COMPAT" "OUTPUT_DIRECTORY" "LIBRARIES" ${ARGN}) + if(NOT arg_LIBRARIES) + message(FATAL_ERROR "qt6_target_typelibs: LIBRARIES are not specified") + endif() + + set(output_directory "${CMAKE_CURRENT_BINARY_DIR}") + if(arg_OUTPUT_DIRECTORY) + set(output_directory "${arg_OUTPUT_DIRECTORY}") + endif() + + set(extra_args "") + if(arg_COMPAT) + list(APPEND extra_args "-compat") + endif() + + set(out_sources "") + foreach(lib IN LISTS arg_LIBRARIES) + unset(libpath CACHE) + # If lib exists on the filesystem, we assume the user provided the path. + get_filename_component(lib_abspath "${lib}" ABSOLUTE) + if(EXISTS "${lib_abspath}") + set(libpath "${lib_abspath}") + else() + find_file(libpath NAMES "${lib}") + if(NOT libpath) + message(FATAL_ERROR "qt6_target_typelibs: Unable to find type lib with name ${lib}") + endif() + endif() + + get_filename_component(out_basename "${libpath}" NAME_WE) + set(out_filebasepath "${output_directory}/${out_basename}") + + set(out_header "${out_filebasepath}.h") + set_source_files_properties("${out_header}" PROPERTIES HEADER_FILE_ONLY TRUE) + set(out_source "${out_filebasepath}.cpp") + list(APPEND out_sources "${out_header}" "${out_source}") + + add_custom_command(OUTPUT "${out_header}" "${out_source}" + COMMAND ${QT_CMAKE_EXPORT_NAMESPACE}::dumpcpp + "${libpath}" -o "${out_filebasepath}" + ${extra_args} + DEPENDS ${QT_CMAKE_EXPORT_NAMESPACE}::dumpcpp + WORKING_DIRECTORY "${output_directory}" + COMMENT "Generate type lib sources ${out_header} ${out_source}..." + ) + endforeach() + + set_source_files_properties("${out_sources}" PROPERTIES SKIP_AUTOGEN TRUE) + + target_sources(${target} PRIVATE "${out_sources}") + target_include_directories(${target} PRIVATE "${output_directory}") +endfunction() diff --git a/tests/auto/CMakeLists.txt b/tests/auto/CMakeLists.txt index 2502019..adb25cf 100644 --- a/tests/auto/CMakeLists.txt +++ b/tests/auto/CMakeLists.txt @@ -2,8 +2,8 @@ add_subdirectory(conversion) add_subdirectory(qaxobject) -# add_subdirectory(dumpcpp) (needs typelib target) # special case -# add_subdirectory(cmake) # special case +add_subdirectory(dumpcpp) +add_subdirectory(cmake) if(NOT GCC) add_subdirectory(qaxscript) endif() diff --git a/tests/auto/cmake/CMakeLists.txt b/tests/auto/cmake/CMakeLists.txt index 4f15a69..7c882c2 100644 --- a/tests/auto/cmake/CMakeLists.txt +++ b/tests/auto/cmake/CMakeLists.txt @@ -1,12 +1,44 @@ -cmake_minimum_required(VERSION 2.8) +cmake_minimum_required(VERSION 3.14) -project(qmake_cmake_files) +project(qtactivetqt_cmake_tests) enable_testing() -find_package(Qt5Core REQUIRED) +set(required_packages Core) +set(optional_packages Widgets Gui) -include("${_Qt5CTestMacros}") +# Setup the test when called as a completely standalone project. +if(TARGET Qt6::Core) + # Tests are built as part of the qtactiveqt build tree. + # Setup paths so that the Qt packages are found. + qt_internal_set_up_build_dir_package_paths() +endif() -expect_pass(test_modules) +find_package(Qt6 REQUIRED COMPONENTS ${required_packages}) +find_package(Qt6 OPTIONAL_COMPONENTS ${optional_packages}) + +# Setup common test variables which were previously set by ctest_testcase_common.prf. +set(CMAKE_MODULES_UNDER_TEST "${required_packages}") +foreach(qt_package ${optional_packages}) + set(package_name "${QT_CMAKE_EXPORT_NAMESPACE}${qt_package}") + list(APPEND CMAKE_MODULES_UNDER_TEST "${qt_package}") +endforeach() + +foreach(qt_package ${CMAKE_MODULES_UNDER_TEST}) + if(${package_name}_FOUND) + set(CMAKE_${qt_package}_MODULE_MAJOR_VERSION "${${package_name}_VERSION_MAJOR}") + set(CMAKE_${qt_package}_MODULE_MINOR_VERSION "${${package_name}_VERSION_MINOR}") + set(CMAKE_${qt_package}_MODULE_PATCH_VERSION "${${package_name}_VERSION_PATCH}") + endif() +endforeach() + +include("${_Qt6CTestMacros}") + +if(TARGET Qt6::Widgets AND TARGET Qt6::Gui) + _qt_internal_test_expect_pass(test_target_typelibs) + _qt_internal_test_expect_pass(test_target_typelibs_absolute) + _qt_internal_test_expect_fail(test_target_typelibs_empty_libs) + _qt_internal_test_expect_fail(test_target_typelibs_non_existing_libs) + _qt_internal_test_expect_pass(test_target_typelibs_out_dir) +endif() diff --git a/tests/auto/cmake/test_target_typelibs/CMakeLists.txt b/tests/auto/cmake/test_target_typelibs/CMakeLists.txt new file mode 100644 index 0000000..44ce88f --- /dev/null +++ b/tests/auto/cmake/test_target_typelibs/CMakeLists.txt @@ -0,0 +1,9 @@ +cmake_minimum_required(VERSION 3.14) +project(tst_typelibs) + +find_package(Qt6 COMPONENTS AxContainer Gui Widgets CONFIG REQUIRED) + +add_executable(tst_typelibs main.cpp) +target_link_libraries(tst_typelibs PRIVATE Qt6::AxContainer Qt6::Gui Qt6::Widgets) + +qt6_target_typelibs(tst_typelibs LIBRARIES "ieframe.dll") diff --git a/tests/auto/cmake/test_target_typelibs/main.cpp b/tests/auto/cmake/test_target_typelibs/main.cpp new file mode 100644 index 0000000..1b848bc --- /dev/null +++ b/tests/auto/cmake/test_target_typelibs/main.cpp @@ -0,0 +1,36 @@ +/**************************************************************************** +** +** Copyright (C) 2021 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "ieframe.h" + +int main(int argc, char *argv[]) +{ + SHDocVw::WebBrowser* webBrowser = new SHDocVw::WebBrowser; + delete webBrowser; + return 0; +} diff --git a/tests/auto/cmake/test_target_typelibs_absolute/CMakeLists.txt b/tests/auto/cmake/test_target_typelibs_absolute/CMakeLists.txt new file mode 100644 index 0000000..f8455fa --- /dev/null +++ b/tests/auto/cmake/test_target_typelibs_absolute/CMakeLists.txt @@ -0,0 +1,9 @@ +cmake_minimum_required(VERSION 3.14) +project(tst_typelibs) + +find_package(Qt6 COMPONENTS AxContainer Gui Widgets CONFIG REQUIRED) + +add_executable(tst_typelibs main.cpp) +target_link_libraries(tst_typelibs PRIVATE Qt6::AxContainer Qt6::Gui Qt6::Widgets) + +qt6_target_typelibs(tst_typelibs LIBRARIES "$ENV{SystemRoot}/System32/ieframe.dll") diff --git a/tests/auto/cmake/test_target_typelibs_absolute/main.cpp b/tests/auto/cmake/test_target_typelibs_absolute/main.cpp new file mode 100644 index 0000000..1b848bc --- /dev/null +++ b/tests/auto/cmake/test_target_typelibs_absolute/main.cpp @@ -0,0 +1,36 @@ +/**************************************************************************** +** +** Copyright (C) 2021 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "ieframe.h" + +int main(int argc, char *argv[]) +{ + SHDocVw::WebBrowser* webBrowser = new SHDocVw::WebBrowser; + delete webBrowser; + return 0; +} diff --git a/tests/auto/cmake/test_target_typelibs_empty_libs/CMakeLists.txt b/tests/auto/cmake/test_target_typelibs_empty_libs/CMakeLists.txt new file mode 100644 index 0000000..1bbeed7 --- /dev/null +++ b/tests/auto/cmake/test_target_typelibs_empty_libs/CMakeLists.txt @@ -0,0 +1,9 @@ +cmake_minimum_required(VERSION 3.14) +project(tst_typelibs) + +find_package(Qt6 COMPONENTS AxContainer Gui Widgets CONFIG REQUIRED) + +add_executable(tst_typelibs main.cpp) +target_link_libraries(tst_typelibs PRIVATE Qt6::AxContainer Qt6::Gui Qt6::Widgets) + +qt6_target_typelibs(tst_typelibs) diff --git a/tests/auto/cmake/test_target_typelibs_empty_libs/main.cpp b/tests/auto/cmake/test_target_typelibs_empty_libs/main.cpp new file mode 100644 index 0000000..1b848bc --- /dev/null +++ b/tests/auto/cmake/test_target_typelibs_empty_libs/main.cpp @@ -0,0 +1,36 @@ +/**************************************************************************** +** +** Copyright (C) 2021 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "ieframe.h" + +int main(int argc, char *argv[]) +{ + SHDocVw::WebBrowser* webBrowser = new SHDocVw::WebBrowser; + delete webBrowser; + return 0; +} diff --git a/tests/auto/cmake/test_target_typelibs_non_existing_libs/CMakeLists.txt b/tests/auto/cmake/test_target_typelibs_non_existing_libs/CMakeLists.txt new file mode 100644 index 0000000..448732a --- /dev/null +++ b/tests/auto/cmake/test_target_typelibs_non_existing_libs/CMakeLists.txt @@ -0,0 +1,9 @@ +cmake_minimum_required(VERSION 3.14) +project(tst_typelibs) + +find_package(Qt6 COMPONENTS AxContainer Gui Widgets CONFIG REQUIRED) + +add_executable(tst_typelibs main.cpp) +target_link_libraries(tst_typelibs PRIVATE Qt6::AxContainer Qt6::Gui Qt6::Widgets) + +qt6_target_typelibs(tst_typelibs LIBRARIES "ieframe.dll" "qt100notexistinglib.dll") diff --git a/tests/auto/cmake/test_target_typelibs_non_existing_libs/main.cpp b/tests/auto/cmake/test_target_typelibs_non_existing_libs/main.cpp new file mode 100644 index 0000000..1b848bc --- /dev/null +++ b/tests/auto/cmake/test_target_typelibs_non_existing_libs/main.cpp @@ -0,0 +1,36 @@ +/**************************************************************************** +** +** Copyright (C) 2021 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "ieframe.h" + +int main(int argc, char *argv[]) +{ + SHDocVw::WebBrowser* webBrowser = new SHDocVw::WebBrowser; + delete webBrowser; + return 0; +} diff --git a/tests/auto/cmake/test_target_typelibs_out_dir/CMakeLists.txt b/tests/auto/cmake/test_target_typelibs_out_dir/CMakeLists.txt new file mode 100644 index 0000000..66e753e --- /dev/null +++ b/tests/auto/cmake/test_target_typelibs_out_dir/CMakeLists.txt @@ -0,0 +1,12 @@ +cmake_minimum_required(VERSION 3.14) +project(tst_typelibs) + +find_package(Qt6 COMPONENTS AxContainer Gui Widgets CONFIG REQUIRED) + +add_executable(tst_typelibs main.cpp) +target_link_libraries(tst_typelibs PRIVATE Qt6::AxContainer Qt6::Gui Qt6::Widgets) +target_include_directories(tst_typelibs PRIVATE "${CMAKE_CURRENT_BINARY_DIR}") + +qt6_target_typelibs(tst_typelibs LIBRARIES "ieframe.dll" + OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/typelibs" +) diff --git a/tests/auto/cmake/test_target_typelibs_out_dir/main.cpp b/tests/auto/cmake/test_target_typelibs_out_dir/main.cpp new file mode 100644 index 0000000..6a3ecb4 --- /dev/null +++ b/tests/auto/cmake/test_target_typelibs_out_dir/main.cpp @@ -0,0 +1,36 @@ +/**************************************************************************** +** +** Copyright (C) 2021 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "typelibs/ieframe.h" + +int main(int argc, char *argv[]) +{ + SHDocVw::WebBrowser* webBrowser = new SHDocVw::WebBrowser; + delete webBrowser; + return 0; +} diff --git a/tests/auto/dumpcpp/CMakeLists.txt b/tests/auto/dumpcpp/CMakeLists.txt index 91da6c3..051e7f5 100644 --- a/tests/auto/dumpcpp/CMakeLists.txt +++ b/tests/auto/dumpcpp/CMakeLists.txt @@ -4,7 +4,7 @@ ## tst_dumpcpp Test: ##################################################################### -qt_add_test(tst_dumpcpp +qt_internal_add_test(tst_dumpcpp SOURCES tst_dumpcpp.cpp PUBLIC_LIBRARIES @@ -16,5 +16,7 @@ qt_add_test(tst_dumpcpp #### Keys ignored in scope 1:.:.:dumpcpp.pro:<TRUE>: # TYPELIBS = "$$(SystemRoot)\\system32\\ieframe.dll" +qt6_target_typelibs(tst_dumpcpp LIBRARIES "ieframe.dll") # special case + ## Scopes: ##################################################################### diff --git a/tests/manual/dumpcpp/CMakeLists.txt b/tests/manual/dumpcpp/CMakeLists.txt index 44e94a8..6909014 100644 --- a/tests/manual/dumpcpp/CMakeLists.txt +++ b/tests/manual/dumpcpp/CMakeLists.txt @@ -22,5 +22,7 @@ qt_internal_add_manual_test(dumpcpp # special case # TEMPLATE = "app" # TYPELIBS = "$$(SystemRoot)\\system32\\ieframe.dll" +qt6_target_typelibs(tst_dumpcpp LIBRARIES "ieframe.dll") # special case + ## Scopes: ##################################################################### |