diff options
author | Alexandru Croitor <alexandru.croitor@qt.io> | 2022-10-28 12:41:13 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2022-11-09 17:12:16 +0000 |
commit | 5efe02dd5a806d423bed094c2fcfd32cd17f4b7e (patch) | |
tree | 0ccd84559c424203e7b0c73b57b0b9b1e27806db | |
parent | 55eba6cf1b0b9011eb6c9526fb1ead8433a9b754 (diff) |
CMake: Execute shiboken with appropriate PATH on Windows
Previously one had to add the Qt bin dir and libclang.dll dir to
PATH manually to ensure shiboken successfully runs when
building Qt for Python using CMake without setup.py.
This should not be necessary though, because the build system knows
where Qt is (usually via the --qtpaths option) and where libclang is
(via LLVM_INSTALL_DIR and friends).
Introduce a CMake function that generates a batch shell script wrapper
for a given tool. The wrapper will have PATH set to the Qt bin dir
and libclang dir.
Generate such a wrapper for shiboken and use it everywhere we call
shiboken to generate bindings.
The wrapper is only created on Windows.
All mentions of Shiboken6::shiboken in custom commands now need to be
wrapped in $<TARGET_FILE> because automatic target path conversion
only happens if the target appears as the first argument to a custom
command, and that is not the case anymore with the wrapper script
being at the front.
As a drive-by, the indentation of custom commands is now adjusted
for easier readability and to conform with the indentation used
in the Qt build system.
Fixes: PYSIDE-1844
Change-Id: I287adeedf234d0272c2963e96ae2aa5c4c0f0c83
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Reviewed-by: Shyamnath Premnadh <Shyamnath.Premnadh@qt.io>
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
(cherry picked from commit cc0481a46f801473c3dbabe855534a7aa034443f)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | sources/pyside6/cmake/Macros/PySideModules.cmake | 7 | ||||
-rw-r--r-- | sources/pyside6/doc/CMakeLists.txt | 34 | ||||
-rw-r--r-- | sources/pyside6/tests/pysidetest/CMakeLists.txt | 15 | ||||
-rw-r--r-- | sources/shiboken6/cmake/ShibokenHelpers.cmake | 74 | ||||
-rw-r--r-- | sources/shiboken6/shibokenmodule/CMakeLists.txt | 22 | ||||
-rw-r--r-- | sources/shiboken6/tests/minimalbinding/CMakeLists.txt | 18 | ||||
-rw-r--r-- | sources/shiboken6/tests/otherbinding/CMakeLists.txt | 18 | ||||
-rw-r--r-- | sources/shiboken6/tests/samplebinding/CMakeLists.txt | 18 | ||||
-rw-r--r-- | sources/shiboken6/tests/smartbinding/CMakeLists.txt | 18 |
9 files changed, 170 insertions, 54 deletions
diff --git a/sources/pyside6/cmake/Macros/PySideModules.cmake b/sources/pyside6/cmake/Macros/PySideModules.cmake index 08b2127ed..cca66be8e 100644 --- a/sources/pyside6/cmake/Macros/PySideModules.cmake +++ b/sources/pyside6/cmake/Macros/PySideModules.cmake @@ -126,7 +126,12 @@ macro(create_pyside_module) install(FILES ${module_GLUE_SOURCES} DESTINATION share/PySide6${pyside6_SUFFIX}/typesystems/glue) endif() - set(shiboken_command Shiboken6::shiboken6 ${GENERATOR_EXTRA_FLAGS} + shiboken_get_tool_shell_wrapper(shiboken tool_wrapper) + + set(shiboken_command + ${tool_wrapper} + $<TARGET_FILE:Shiboken6::shiboken6> + ${GENERATOR_EXTRA_FLAGS} "--include-paths=${shiboken_include_dirs}" "--typesystem-paths=${pyside_binary_dir}${PATH_SEP}${pyside6_SOURCE_DIR}${PATH_SEP}${${module_TYPESYSTEM_PATH}}" --output-directory=${CMAKE_CURRENT_BINARY_DIR} diff --git a/sources/pyside6/doc/CMakeLists.txt b/sources/pyside6/doc/CMakeLists.txt index 2f64952de..6fb492973 100644 --- a/sources/pyside6/doc/CMakeLists.txt +++ b/sources/pyside6/doc/CMakeLists.txt @@ -213,21 +213,27 @@ configure_file("conf.py.in" "rst/conf.py" @ONLY) set(CODE_SNIPPET_ROOT "${CMAKE_CURRENT_BINARY_DIR}/rst/codesnippets") +shiboken_get_tool_shell_wrapper(shiboken tool_wrapper) + add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/rst/PySide6/QtCore/index.rst" - COMMAND Shiboken6::shiboken6 --generator-set=qtdoc ${global_header} - --enable-pyside-extensions - --include-paths="${QT_INCLUDE_DIR}${PATH_SEP}${pyside6_SOURCE_DIR}${PATH_SEP}${TS_ROOT}" - --api-version=${SUPPORTED_QT_VERSION} - --typesystem-paths="${QDOC_TYPESYSTEM_PATH}" - --library-source-dir=${QT_SRC_DIR} - --documentation-data-dir=${DOC_DATA_DIR}/webxml - --output-directory=${CMAKE_CURRENT_BINARY_DIR}/rst - --documentation-code-snippets-dir=${CODE_SNIPPET_ROOT} - --snippets-path-rewrite=${QT_ROOT_PATH}:${CODE_SNIPPET_ROOT} - --documentation-extra-sections-dir=${CMAKE_CURRENT_BINARY_DIR}/rst/extras - --additional-documentation=${CMAKE_CURRENT_BINARY_DIR}/rst/additionaldocs.lst - --inheritance-file=${ENV_INHERITANCE_FILE} - ${global_typesystem} + COMMAND + ${tool_wrapper} + $<TARGET_FILE:Shiboken6::shiboken6> + --generator-set=qtdoc + ${global_header} + --enable-pyside-extensions + --include-paths="${QT_INCLUDE_DIR}${PATH_SEP}${pyside6_SOURCE_DIR}${PATH_SEP}${TS_ROOT}" + --api-version=${SUPPORTED_QT_VERSION} + --typesystem-paths="${QDOC_TYPESYSTEM_PATH}" + --library-source-dir=${QT_SRC_DIR} + --documentation-data-dir=${DOC_DATA_DIR}/webxml + --output-directory=${CMAKE_CURRENT_BINARY_DIR}/rst + --documentation-code-snippets-dir=${CODE_SNIPPET_ROOT} + --snippets-path-rewrite=${QT_ROOT_PATH}:${CODE_SNIPPET_ROOT} + --documentation-extra-sections-dir=${CMAKE_CURRENT_BINARY_DIR}/rst/extras + --additional-documentation=${CMAKE_CURRENT_BINARY_DIR}/rst/additionaldocs.lst + --inheritance-file=${ENV_INHERITANCE_FILE} + ${global_typesystem} WORKING_DIRECTORY ${${module}_SOURCE_DIR} COMMENT "Running generator to generate documentation...") diff --git a/sources/pyside6/tests/pysidetest/CMakeLists.txt b/sources/pyside6/tests/pysidetest/CMakeLists.txt index 81fae5084..e88b866c4 100644 --- a/sources/pyside6/tests/pysidetest/CMakeLists.txt +++ b/sources/pyside6/tests/pysidetest/CMakeLists.txt @@ -73,10 +73,15 @@ make_path(testbinding_include_dirs ${pyside6_BINARY_DIR} make_path(testbinding_typesystem_path ${pyside6_SOURCE_DIR} ${pyside6_BINARY_DIR}) +shiboken_get_tool_shell_wrapper(shiboken tool_wrapper) + add_custom_command( -OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/mjb_rejected_classes.log" - BYPRODUCTS ${testbinding_SRC} - COMMAND Shiboken6::shiboken6 ${GENERATOR_EXTRA_FLAGS} + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/mjb_rejected_classes.log" + BYPRODUCTS ${testbinding_SRC} + COMMAND + ${tool_wrapper} + $<TARGET_FILE:Shiboken6::shiboken6> + ${GENERATOR_EXTRA_FLAGS} ${CMAKE_CURRENT_SOURCE_DIR}/pysidetest_global.h --include-paths=${testbinding_include_dirs} ${shiboken_framework_include_dirs_option} @@ -84,8 +89,8 @@ OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/mjb_rejected_classes.log" --output-directory=${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/typesystem_pysidetest.xml --api-version=${SUPPORTED_QT_VERSION} -WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} -COMMENT "Running generator for test binding..." + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMENT "Running generator for test binding..." ) include_directories(${CMAKE_CURRENT_SOURCE_DIR} diff --git a/sources/shiboken6/cmake/ShibokenHelpers.cmake b/sources/shiboken6/cmake/ShibokenHelpers.cmake index 27f8cc29b..991026913 100644 --- a/sources/shiboken6/cmake/ShibokenHelpers.cmake +++ b/sources/shiboken6/cmake/ShibokenHelpers.cmake @@ -670,3 +670,77 @@ macro(create_generator_target library_name) add_custom_target(${library_name}_generator DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/mjb_rejected_classes.log") add_dependencies(${library_name} ${library_name}_generator) endmacro() + +# Generate a shell script wrapper that sets environment variables for executing a specific tool. +# +# tool_name should be a unique tool name, preferably without spaces. +# Returns the wrapper path in path_out_var. +# +# Currently adds the Qt bin dir and the libclang.dll bin dir to PATH. +# On platforms other than Windows, returs an empty string. +# Meant to be used as the first argument to add_custom_command's COMMAND option. +function(shiboken_get_tool_shell_wrapper tool_name path_out_var) + # No need for a wrapper on non Windows hosts. + if(NOT CMAKE_HOST_WIN32) + set(${path_out_var} "" PARENT_SCOPE) + return() + endif() + + # Generate the wrapper only once during the execution of CMake. + get_property(is_called GLOBAL PROPERTY "_shiboken_tool_wrapper_${tool_name}_created") + + if(is_called) + get_property(wrapper_path GLOBAL PROPERTY "_shiboken_tool_wrapper_${tool_name}_path") + set(${path_out_var} "${wrapper_path}" PARENT_SCOPE) + return() + endif() + + set(path_dirs "") + set(path_dirs_native "") + + # Assert that Qt is already found. + if(NOT QT6_INSTALL_PREFIX OR NOT QT6_INSTALL_BINS) + message(FATAL_ERROR "Qt should have been found already by now.") + endif() + + # Get path to the Qt bin dir. + set(qt_bin_dir "${QT6_INSTALL_PREFIX}/${QT6_INSTALL_BINS}") + list(APPEND path_dirs "${qt_bin_dir}") + + # Get path to libclang.dll. + set(libclang_bin_dir "") + if(DEFINED ENV{LLVM_INSTALL_DIR}) + set(libclang_bin_dir "$ENV{LLVM_INSTALL_DIR}/bin") + elseif(DEFINED ENV{CLANG_INSTALL_DIR}) + set(libclang_bin_dir "$ENV{CLANG_INSTALL_DIR}/bin") + else() + message(WARNING + "Couldn't find libclang.dll. " + "You will likely need to add it manually to PATH to ensure the build succeeds.") + endif() + if(libclang_bin_dir) + list(APPEND path_dirs "${libclang_bin_dir}") + endif() + + # Convert the paths from unix-style to native Windows style. + foreach(path_dir IN LISTS path_dirs) + if(EXISTS "${path_dir}") + file(TO_NATIVE_PATH "${path_dir}" path_dir_native) + list(APPEND path_dirs_native "${path_dir_native}") + endif() + endforeach() + + set(wrapper_dir "${CMAKE_BINARY_DIR}/.qfp/bin") + file(MAKE_DIRECTORY "${wrapper_dir}") + set(wrapper_path "${wrapper_dir}/${tool_name}_wrapper.bat") + + file(WRITE "${wrapper_path}" "@echo off +set PATH=${path_dirs_native};%PATH% +%*") + + # Remember the creation of the file for a specific tool. + set_property(GLOBAL PROPERTY "_shiboken_tool_wrapper_${tool_name}_path" "${wrapper_path}") + set_property(GLOBAL PROPERTY "_shiboken_tool_wrapper_${tool_name}_created" TRUE) + + set(${path_out_var} "${wrapper_path}" PARENT_SCOPE) +endfunction() diff --git a/sources/shiboken6/shibokenmodule/CMakeLists.txt b/sources/shiboken6/shibokenmodule/CMakeLists.txt index cd0dc176d..1a3d42a1b 100644 --- a/sources/shiboken6/shibokenmodule/CMakeLists.txt +++ b/sources/shiboken6/shibokenmodule/CMakeLists.txt @@ -7,17 +7,19 @@ set(sample_SRC ${CMAKE_CURRENT_BINARY_DIR}/Shiboken/shiboken_module_wrapper.cpp) set(shibokenmodule_TYPESYSTEM ${CMAKE_CURRENT_SOURCE_DIR}/typesystem_shiboken.xml) +shiboken_get_tool_shell_wrapper(shiboken tool_wrapper) + add_custom_command( -OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/mjb_rejected_classes.log" -BYPRODUCTS ${sample_SRC} -# Note: shiboken6 is an executable target. By not specifying its explicit -# path, CMAKE figures it out, itself! -# This fixes an issue with Visual Studio, see https://github.com/PySide/shiboken6/pull/11 -COMMAND Shiboken6::shiboken6 - --project-file=${CMAKE_CURRENT_BINARY_DIR}/shibokenmodule.txt ${GENERATOR_EXTRA_FLAGS} -DEPENDS ${shibokenmodule_TYPESYSTEM} -WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} -COMMENT "Running generator for 'Shiboken'..." + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/mjb_rejected_classes.log" + BYPRODUCTS ${sample_SRC} + COMMAND + ${tool_wrapper} + $<TARGET_FILE:Shiboken6::shiboken6> + --project-file=${CMAKE_CURRENT_BINARY_DIR}/shibokenmodule.txt + ${GENERATOR_EXTRA_FLAGS} + DEPENDS ${shibokenmodule_TYPESYSTEM} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMENT "Running generator for 'Shiboken'..." ) add_library(shibokenmodule MODULE ${sample_SRC}) diff --git a/sources/shiboken6/tests/minimalbinding/CMakeLists.txt b/sources/shiboken6/tests/minimalbinding/CMakeLists.txt index 1b6b37e31..1b8c259e6 100644 --- a/sources/shiboken6/tests/minimalbinding/CMakeLists.txt +++ b/sources/shiboken6/tests/minimalbinding/CMakeLists.txt @@ -15,13 +15,19 @@ ${CMAKE_CURRENT_BINARY_DIR}/minimal/minbooluser_wrapper.cpp configure_file("${CMAKE_CURRENT_SOURCE_DIR}/minimal-binding.txt.in" "${CMAKE_CURRENT_BINARY_DIR}/minimal-binding.txt" @ONLY) +shiboken_get_tool_shell_wrapper(shiboken tool_wrapper) + add_custom_command( -OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/mjb_rejected_classes.log" -BYPRODUCTS ${minimal_SRC} -COMMAND Shiboken6::shiboken6 --project-file=${CMAKE_CURRENT_BINARY_DIR}/minimal-binding.txt ${GENERATOR_EXTRA_FLAGS} -DEPENDS ${minimal_TYPESYSTEM} ${CMAKE_CURRENT_SOURCE_DIR}/global.h Shiboken6::shiboken6 -WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} -COMMENT "Running generator for 'minimal' test binding..." + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/mjb_rejected_classes.log" + BYPRODUCTS ${minimal_SRC} + COMMAND + ${tool_wrapper} + $<TARGET_FILE:Shiboken6::shiboken6> + --project-file=${CMAKE_CURRENT_BINARY_DIR}/minimal-binding.txt + ${GENERATOR_EXTRA_FLAGS} + DEPENDS ${minimal_TYPESYSTEM} ${CMAKE_CURRENT_SOURCE_DIR}/global.h Shiboken6::shiboken6 + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMENT "Running generator for 'minimal' test binding..." ) add_library(minimal MODULE ${minimal_SRC}) diff --git a/sources/shiboken6/tests/otherbinding/CMakeLists.txt b/sources/shiboken6/tests/otherbinding/CMakeLists.txt index e516371b9..c5e5390fb 100644 --- a/sources/shiboken6/tests/otherbinding/CMakeLists.txt +++ b/sources/shiboken6/tests/otherbinding/CMakeLists.txt @@ -22,13 +22,19 @@ ${CMAKE_CURRENT_BINARY_DIR}/other/valuewithunitintmillimeter_wrapper.cpp configure_file("${CMAKE_CURRENT_SOURCE_DIR}/other-binding.txt.in" "${CMAKE_CURRENT_BINARY_DIR}/other-binding.txt" @ONLY) +shiboken_get_tool_shell_wrapper(shiboken tool_wrapper) + add_custom_command( -OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/mjb_rejected_classes.log" -BYPRODUCTS ${other_SRC} -COMMAND Shiboken6::shiboken6 --project-file=${CMAKE_CURRENT_BINARY_DIR}/other-binding.txt ${GENERATOR_EXTRA_FLAGS} -DEPENDS ${other_TYPESYSTEM} ${CMAKE_CURRENT_SOURCE_DIR}/global.h Shiboken6::shiboken6 -WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} -COMMENT "Running generator for 'other' test binding..." + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/mjb_rejected_classes.log" + BYPRODUCTS ${other_SRC} + COMMAND + ${tool_wrapper} + $<TARGET_FILE:Shiboken6::shiboken6> + --project-file=${CMAKE_CURRENT_BINARY_DIR}/other-binding.txt + ${GENERATOR_EXTRA_FLAGS} + DEPENDS ${other_TYPESYSTEM} ${CMAKE_CURRENT_SOURCE_DIR}/global.h Shiboken6::shiboken6 + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMENT "Running generator for 'other' test binding..." ) add_library(other MODULE ${other_SRC}) diff --git a/sources/shiboken6/tests/samplebinding/CMakeLists.txt b/sources/shiboken6/tests/samplebinding/CMakeLists.txt index 7576f6734..dd793a525 100644 --- a/sources/shiboken6/tests/samplebinding/CMakeLists.txt +++ b/sources/shiboken6/tests/samplebinding/CMakeLists.txt @@ -142,13 +142,19 @@ ${CMAKE_CURRENT_BINARY_DIR}/sample/union_wrapper.cpp configure_file("${CMAKE_CURRENT_SOURCE_DIR}/sample-binding.txt.in" "${CMAKE_CURRENT_BINARY_DIR}/sample-binding.txt" @ONLY) +shiboken_get_tool_shell_wrapper(shiboken tool_wrapper) + add_custom_command( -OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/mjb_rejected_classes.log" -BYPRODUCTS ${sample_SRC} -COMMAND Shiboken6::shiboken6 --project-file=${CMAKE_CURRENT_BINARY_DIR}/sample-binding.txt ${GENERATOR_EXTRA_FLAGS} -DEPENDS ${sample_TYPESYSTEM} ${CMAKE_CURRENT_SOURCE_DIR}/global.h Shiboken6::shiboken6 -WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} -COMMENT "Running generator for 'sample' test binding..." + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/mjb_rejected_classes.log" + BYPRODUCTS ${sample_SRC} + COMMAND + ${tool_wrapper} + $<TARGET_FILE:Shiboken6::shiboken6> + --project-file=${CMAKE_CURRENT_BINARY_DIR}/sample-binding.txt + ${GENERATOR_EXTRA_FLAGS} + DEPENDS ${sample_TYPESYSTEM} ${CMAKE_CURRENT_SOURCE_DIR}/global.h Shiboken6::shiboken6 + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMENT "Running generator for 'sample' test binding..." ) add_library(sample MODULE ${sample_SRC}) diff --git a/sources/shiboken6/tests/smartbinding/CMakeLists.txt b/sources/shiboken6/tests/smartbinding/CMakeLists.txt index 7c5d0808f..577c8936f 100644 --- a/sources/shiboken6/tests/smartbinding/CMakeLists.txt +++ b/sources/shiboken6/tests/smartbinding/CMakeLists.txt @@ -31,13 +31,19 @@ ${CMAKE_CURRENT_BINARY_DIR}/smart/stduniqueptrvirtualmethodtester_wrapper.cpp configure_file("${CMAKE_CURRENT_SOURCE_DIR}/smart-binding.txt.in" "${CMAKE_CURRENT_BINARY_DIR}/smart-binding.txt" @ONLY) +shiboken_get_tool_shell_wrapper(shiboken tool_wrapper) + add_custom_command( -OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/mjb_rejected_classes.log" -BYPRODUCTS ${smart_SRC} -COMMAND Shiboken6::shiboken6 --project-file=${CMAKE_CURRENT_BINARY_DIR}/smart-binding.txt ${GENERATOR_EXTRA_FLAGS} -DEPENDS ${smart_TYPESYSTEM} ${CMAKE_CURRENT_SOURCE_DIR}/global.h Shiboken6::shiboken6 -WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} -COMMENT "Running generator for 'smart' test binding..." + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/mjb_rejected_classes.log" + BYPRODUCTS ${smart_SRC} + COMMAND + ${tool_wrapper} + $<TARGET_FILE:Shiboken6::shiboken6> + --project-file=${CMAKE_CURRENT_BINARY_DIR}/smart-binding.txt + ${GENERATOR_EXTRA_FLAGS} + DEPENDS ${smart_TYPESYSTEM} ${CMAKE_CURRENT_SOURCE_DIR}/global.h Shiboken6::shiboken6 + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMENT "Running generator for 'smart' test binding..." ) add_library(smart MODULE ${smart_SRC}) |