summaryrefslogtreecommitdiffstats
path: root/src/activeqt/control/Qt6AxServerMacros.cmake
blob: 24cbaabf04cd511e3f8b088fbf001a06760a6735 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# Adds an ActiveX server executable, generates an IDL file and links the produced .tbl to the
# executable.
# Arguments: See qt6_target_idl
#
# This function is currently in Technical Preview.
# Its signature and behavior might change.
function(qt6_add_axserver_executable target)
    cmake_parse_arguments(arg "NO_AX_SERVER_REGISTRATION" "" "" ${ARGN})
    if(arg_NO_AX_SERVER_REGISTRATION)
        set(arg_NO_AX_SERVER_REGISTRATION "NO_AX_SERVER_REGISTRATION")
    else()
        unset(arg_NO_AX_SERVER_REGISTRATION)
    endif()
    qt_add_executable(${target} ${arg_UNPARSED_ARGUMENTS})
    set_target_properties(${target} PROPERTIES WIN32_EXECUTABLE TRUE)
    target_link_libraries(${target} PRIVATE ${QT_CMAKE_EXPORT_NAMESPACE}::AxServer)
    qt6_target_idl(${target} ${arg_NO_AX_SERVER_REGISTRATION})
endfunction()

# Adds an ActiveX server library, generates an IDL file and links the produced .tbl to the
# dll.
# Arguments: See qt6_target_idl
#
# This function is currently in Technical Preview.
# Its signature and behavior might change.
function(qt6_add_axserver_library target)
    cmake_parse_arguments(arg "NO_AX_SERVER_REGISTRATION" "" "" ${ARGN})
    if(arg_NO_AX_SERVER_REGISTRATION)
        set(arg_NO_AX_SERVER_REGISTRATION "NO_AX_SERVER_REGISTRATION")
    else()
        unset(arg_NO_AX_SERVER_REGISTRATION)
    endif()
    add_library(${target} SHARED ${arg_UNPARSED_ARGUMENTS})
    target_link_libraries(${target} PRIVATE ${QT_CMAKE_EXPORT_NAMESPACE}::AxServer)
    qt6_target_idl(${target} ${arg_NO_AX_SERVER_REGISTRATION})
endfunction()

# Adds post-build rules to generate and link IDC/MIDL artifacts to the library or executable.
# Arguments:
#   NO_AX_SERVER_REGISTRATION skips the ActiveX server registration.
#      Note: You may also use the QT_NO_AX_SERVER_REGISTRATION variable to globally skip
#      the ActiveX server registrations.
#
# This function is currently in Technical Preview.
# Its signature and behavior might change.
function(qt6_target_idl target)
    cmake_parse_arguments(arg "NO_AX_SERVER_REGISTRATION" "" "" ${ARGN})
    if(NOT WIN32)
        return()
    endif()

    set(output_idl "${CMAKE_CURRENT_BINARY_DIR}/${target}$<CONFIG>.idl")
    set(output_tlb "${CMAKE_CURRENT_BINARY_DIR}/${target}$<CONFIG>.tlb")

    _qt_internal_get_tool_wrapper_script_path(tool_wrapper)
    set(tlb_command_list "")

    # Wrap tool paths in $<COMMAND_CONFIG> to ensure we use the release tool when building debug
    # targets in a multi-config build, because the debug tool is usually not built by default.
    if(CMAKE_GENERATOR STREQUAL "Ninja Multi-Config" AND CMAKE_VERSION VERSION_GREATER_EQUAL "3.20")
        set(cmb "$<COMMAND_CONFIG:")
        set(cme ">")
    else()
        set(cmb "")
        set(cme "")
    endif()

    set(idc_target "${QT_CMAKE_EXPORT_NAMESPACE}::idc")
    set(idc_target_file "$<TARGET_FILE:${idc_target}>")
    set(idc_target_file_command_config_wrapped "${cmb}${idc_target_file}${cme}")

    list(APPEND tlb_command_list
        COMMAND
            "${tool_wrapper}"
            "${idc_target_file_command_config_wrapped}"
            "$<TARGET_FILE:${target}>"
            /idl "${output_idl}" -version 1.0
    )

    list(APPEND tlb_command_list
        COMMAND
            "${tool_wrapper}" midl "${output_idl}" /nologo /tlb "${output_tlb}"
    )

    set(rc_files "$<FILTER:$<TARGET_PROPERTY:${target},SOURCES>,INCLUDE,\\.rc$>")
    set(have_rc_files "$<NOT:$<BOOL:$<STREQUAL:${rc_files},>>>")

    set(no_rc_cmd "echo$<SEMICOLON>No rc-file linked into project. The type library of the \
${target} target will be a separate file.")

    set(idc_args
        "$<SEMICOLON>$<TARGET_FILE:${target}>$<SEMICOLON>/tlb$<SEMICOLON>${output_tlb}")

    # Split command into two parts, so that COMMAND_CONFIG can be applied only to the idc tool path,
    # but not the target and tlb files.
    set(cmd_part1 "${cmb}$<IF:${have_rc_files},${idc_target_file},${no_rc_cmd}>${cme}")
    set(cmd_part2 "$<${have_rc_files}:${idc_args}>")

    list(APPEND tlb_command_list
        COMMAND
            "${tool_wrapper}" "${cmd_part1}" "${cmd_part2}"
    )

    if(NOT arg_NO_AX_SERVER_REGISTRATION AND NOT QT_NO_AX_SERVER_REGISTRATION)
        list(APPEND tlb_command_list
            COMMAND
                "${tool_wrapper}"
                "${idc_target_file_command_config_wrapped}"
                "$<TARGET_FILE:${target}>" /regserver
        )
    endif()
    add_custom_command(TARGET ${target} POST_BUILD
        ${tlb_command_list}
        DEPENDS
            "${idc_target}"
        VERBATIM
        COMMAND_EXPAND_LISTS
    )
endfunction()

if(NOT QT_NO_CREATE_VERSIONLESS_FUNCTIONS)
    function(qt_add_axserver_executable)
        qt6_add_axserver_executable(${ARGV})
    endfunction()
    function(qt_add_axserver_library)
        qt6_add_axserver_library(${ARGV})
    endfunction()
    function(qt_target_idl)
        qt6_target_idl(${ARGV})
    endfunction()
endif()