Skip to content
Snippets Groups Projects
Commit 4319a915 authored by Alexandru Croitor's avatar Alexandru Croitor
Browse files

Discussion and conclusion around qt6_add_executable API

parent 10909897
No related branches found
No related tags found
No related merge requests found
......@@ -118,5 +118,103 @@ endfunction()
# Pros: With CMake <= 3.18 users need to call only 1 function at the end of the scope
# instead of multiple depending on platform.
# Automatically called with >= 3.19.
# We can call qt_import_qml_plugins in the finalize function,
# to handle the static Qt example scenario.
# Cons: User still needs to call function manually with CMake <= 3.18.
# Hard to say if 1 function taking one target will be enough.
# =============================================================================================
# During meeting discussed some additional approaches
# =============================================================================================
# Approach 5
# Check for a specifically defined function, and call it as setup in-between the other behaviour
function(qt6_add_executable target)
add_executable(${target})
# ....
if(DEFINED my_custom_setup_function)
my_custom_setup_function()
endif()
qt_android_generate_deployment_settings("${target}")
# ....
endfunction()
function(my_custom_setup_function target)
set_target_properties(foo PROPERTIES QT_ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/bla")
endfunction()
# Picks up the my_custom_setup_function provided by the project developer
qt6_add_executable(target)
# Pros: Works with older CMake versions.
# Doesn't require explicit call from user
# Doesn't pollute qt6_add_executable API
# Cons: Only one function can be declared for the whole CMake project.
# Function implementor will have have to add target specific
# conditional scopes for each target they define.
# A function can't be undefined, so kinda pollutes the project.
# =====================================================================================
# Approach 6
# Combination of approach 1.1 and other ideas
# Split Target creation and linking to Qt into helper function.
# Add new finalize function.
# User either opts into finalizing to be done explicitly / manually.
# or stays with the default behaviour.
function(qt6_create_executable target)
if(ANDROID)
add_library("${target}" MODULE ${ARGN})
else()
add_executable("${target}" ${ARGN})
endif()
target_link_libraries("${target}" PRIVATE Qt::Core)
endfunction()
function(qt6_finalize_executable target)
if(ANDROID)
qt_android_generate_deployment_settings("${target}")
qt_android_add_apk_target("${target}")
endif()
endfunction()
function(qt6_add_executable target)
qt6_create_executable()
# If user didn't opt into customization, run the finalizer right now.
if(NOT arg_NEEDS_CUSTOMIZATION)
set_target_properties(${target} PROPERTIES _qt_needs_finalizer FALSE)
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.19")
cmake_language(EVAL CODE "cmake_language(DEFER CALL \"qt6_finalize_executable(${target})\")")
else()
qt6_finalize_executable(${target})
endif()
else()
# Can we issue a warning based on this in some way? Probably not without CMake >= 3.19, in which case
# it doesn't make sense?
set_target_properties(${target} PROPERTIES _qt_needs_finalizer TRUE)
endif()
endfunction()
# 1 No opt-in, finalizer automatically called.
# With CMake >= 3.19 the finalizer will be called at the end of the scope
# With CMake <= 3.18 the finalizer will be called inside qt6_add_executable.
qt6_add_executable(target)
# 2 User opted in, they will run it manually.
qt6_add_executable(target NEEDS_CUSTOMIZATION)
set_target_properties(foo PROPERTIES QT_ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/bla")
qt6_finalize_executable()
# Pros: Sensible defaults.
# Works with older CMake versions.
# Introducing a new option for opt in is compatible with existing API.
# Automatic finalization with CMake >= 3.19
# It was decided to go with approach 6.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment