From 7b3d9efc042bec4ce23a6e75553cced3d14d1542 Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Wed, 7 Jul 2021 16:04:17 +0200 Subject: [PATCH] CMake: Place internal apps in the correct output directory In a -debug-and-release build, apps were placed under bin/Release rather than just bin. Apply the logic we use for tools for apps as well. Rename and move the common functions into QtTargetHelpers.cmake. Pick-to: 6.2 Fixes: QTBUG-95028 Change-Id: I5a9082ea50c9238c8fcf0c6dd099708fbc571bf8 Reviewed-by: Qt CI Bot Reviewed-by: Joerg Bornemann --- cmake/QtAppHelpers.cmake | 1 + cmake/QtFrameworkHelpers.cmake | 2 +- cmake/QtTargetHelpers.cmake | 24 ++++++++++++++++++++++++ cmake/QtToolHelpers.cmake | 27 +++++---------------------- 4 files changed, 31 insertions(+), 23 deletions(-) diff --git a/cmake/QtAppHelpers.cmake b/cmake/QtAppHelpers.cmake index c40488cc664..4301b7e4800 100644 --- a/cmake/QtAppHelpers.cmake +++ b/cmake/QtAppHelpers.cmake @@ -40,6 +40,7 @@ function(qt_internal_add_app target) ) qt_internal_add_target_aliases("${target}") _qt_internal_apply_strict_cpp("${target}") + qt_internal_adjust_main_config_runtime_output_dir("${target}" "${output_directory}") # To mimic the default behaviors of qt_app.prf, we by default enable GUI Windows applications, # but don't enable macOS bundles. diff --git a/cmake/QtFrameworkHelpers.cmake b/cmake/QtFrameworkHelpers.cmake index 5fd8896ec42..596b480218b 100644 --- a/cmake/QtFrameworkHelpers.cmake +++ b/cmake/QtFrameworkHelpers.cmake @@ -111,7 +111,7 @@ function(qt_finalize_framework_headers_copy target) # Create a fake header file and copy it into the framework by marking it as PUBLIC_HEADER. # CMake now takes care of creating the symlink. set(fake_header ${target}_fake_header.h) - qt_get_main_cmake_configuration(main_config) + qt_internal_get_main_cmake_configuration(main_config) file(GENERATE OUTPUT ${fake_header} CONTENT "// ignore this file\n" CONDITION "$") string(PREPEND fake_header "${CMAKE_CURRENT_BINARY_DIR}/") diff --git a/cmake/QtTargetHelpers.cmake b/cmake/QtTargetHelpers.cmake index a4114a6eb32..266bcac490f 100644 --- a/cmake/QtTargetHelpers.cmake +++ b/cmake/QtTargetHelpers.cmake @@ -736,3 +736,27 @@ function(qt_internal_qtfy_target out_var target) set(${out_var} "Qt${target}" PARENT_SCOPE) set(${out_var}_versioned "Qt${PROJECT_VERSION_MAJOR}${target}" PARENT_SCOPE) endfunction() + +function(qt_internal_get_main_cmake_configuration out_var) + if(CMAKE_BUILD_TYPE) + set(config "${CMAKE_BUILD_TYPE}") + elseif(QT_MULTI_CONFIG_FIRST_CONFIG) + set(config "${QT_MULTI_CONFIG_FIRST_CONFIG}") + endif() + set("${out_var}" "${config}" PARENT_SCOPE) +endfunction() + +function(qt_internal_get_upper_case_main_cmake_configuration out_var) + qt_internal_get_main_cmake_configuration("${out_var}") + string(TOUPPER "${${out_var}}" upper_config) + set("${out_var}" "${upper_config}" PARENT_SCOPE) +endfunction() + +function(qt_internal_adjust_main_config_runtime_output_dir target output_dir) + # When building Qt with multiple configurations, place the main configuration executable + # directly in ${output_dir}, rather than a ${output_dir}/ subdirectory. + qt_internal_get_upper_case_main_cmake_configuration(main_cmake_configuration) + set_target_properties("${target}" PROPERTIES + RUNTIME_OUTPUT_DIRECTORY_${main_cmake_configuration} "${output_dir}" + ) +endfunction() diff --git a/cmake/QtToolHelpers.cmake b/cmake/QtToolHelpers.cmake index 4274e622a49..c1b6b0cdbff 100644 --- a/cmake/QtToolHelpers.cmake +++ b/cmake/QtToolHelpers.cmake @@ -149,7 +149,10 @@ function(qt_internal_add_tool target_name) set(install_dir "${arg_INSTALL_DIR}") endif() - qt_internal_add_executable("${target_name}" OUTPUT_DIRECTORY "${QT_BUILD_DIR}/${install_dir}" + set(output_dir "${QT_BUILD_DIR}/${install_dir}") + + qt_internal_add_executable("${target_name}" + OUTPUT_DIRECTORY "${output_dir}" ${bootstrap} ${exceptions} NO_INSTALL @@ -173,6 +176,7 @@ function(qt_internal_add_tool target_name) ) qt_internal_add_target_aliases("${target_name}") _qt_internal_apply_strict_cpp("${target_name}") + qt_internal_adjust_main_config_runtime_output_dir("${target_name}" "${output_dir}") if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.19.0" AND QT_FEATURE_debug_and_release) set_property(TARGET "${target_name}" @@ -209,12 +213,6 @@ function(qt_internal_add_tool target_name) set_property(GLOBAL APPEND PROPERTY QT_USER_FACING_TOOL_TARGETS ${target_name}) endif() - # If building with a multi-config configuration, the main configuration tool will be placed in - # ./bin, while the rest will be in specific subdirectories. - qt_get_tool_cmake_configuration(tool_cmake_configuration) - set_target_properties("${target_name}" PROPERTIES - RUNTIME_OUTPUT_DIRECTORY_${tool_cmake_configuration} "${QT_BUILD_DIR}/${install_dir}" - ) if(NOT arg_NO_INSTALL AND arg_TOOLS_TARGET) # Assign a tool to an export set, and mark the module to which the tool belongs. @@ -410,21 +408,6 @@ endif() ) endfunction() -function(qt_get_tool_cmake_configuration out_var) - qt_get_main_cmake_configuration("${out_var}") - string(TOUPPER "${${out_var}}" upper_config) - set("${out_var}" "${upper_config}" PARENT_SCOPE) -endfunction() - -function(qt_get_main_cmake_configuration out_var) - if(CMAKE_BUILD_TYPE) - set(config "${CMAKE_BUILD_TYPE}") - elseif(QT_MULTI_CONFIG_FIRST_CONFIG) - set(config "${QT_MULTI_CONFIG_FIRST_CONFIG}") - endif() - set("${out_var}" "${config}" PARENT_SCOPE) -endfunction() - # Returns the target name for the tool with the given name. # # In most cases, the target name is the same as the tool name.