summaryrefslogtreecommitdiffstats
path: root/tests/auto/tools/moc/CMakeLists.txt
blob: 1377c48306ae2f35e093f2dcbe0ee8482dd0715c (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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause

#####################################################################
## tst_moc Test:
#####################################################################

if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
    cmake_minimum_required(VERSION 3.16)
    project(tst_moc LANGUAGES CXX)
    find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
endif()

set(JSON_HEADERS
        backslash-newlines.h
        c-comments.h
        cstyle-enums.h
        cxx11-enums.h
        cxx11-explicit-override-control.h
        cxx11-final-classes.h
        cxx11-trailing-return.h
        cxx17-namespaces.h
        dir-in-include-path.h
        escapes-in-string-literals.h
        enum_with_include.h
        forward-declared-param.h
        function-with-attributes.h
        gadgetwithnoenums.h
        grand-parent-gadget-class.h
        moc_include.h
        namespace.h
        namespaced-flags.h
        namespaced-base-class.h
        no-keywords.h
        non-gadget-parent-class.h
        oldstyle-casts.h
        parse-defines.h
        plugin_metadata.h
        pointery_to_incomplete.h
        pure-virtual-signals.h
        qinvokable.h
        qprivateslots.h
        qtbug-35657-gadget.h
        related-metaobjects-in-gadget.h
        related-metaobjects-in-namespaces.h
        related-metaobjects-name-conflict.h
        signal-with-default-arg.h
        single-quote-digit-separator-n3781.h
        single_function_keyword.h
        slots-with-void-template.h
        task192552.h
        task234909.h
        task240368.h
        task87883.h
        trigraphs.h
        using-namespaces.h
)

qt_wrap_cpp(comparison_relevant_moc_list ${JSON_HEADERS}
    TARGET tst_moc
    OPTIONS
        "-Muri=com.company.app"
        "-Muri=com.company.app.private"
        "-DDEFINE_CMDLINE_EMPTY="
        "-DDEFINE_CMDLINE_SIGNAL=void cmdlineSignal(const QMap<int, int> &i)"
        "--output-json"
)

list(TRANSFORM comparison_relevant_moc_list  APPEND ".json" OUTPUT_VARIABLE moc_json_files)

qt_internal_add_test(tst_moc
    SOURCES
        cxx-attributes.h
        tst_moc.cpp
        ${comparison_relevant_moc_list}
    INCLUDE_DIRECTORIES
        testproject
        testproject/include
    MOC_OPTIONS
        "-Muri=com.company.app"
        "-Muri=com.company.app.private"
        "-DDEFINE_CMDLINE_EMPTY="
        "-DDEFINE_CMDLINE_SIGNAL=void cmdlineSignal(const QMap<int, int> &i)"
        "--output-json"
    EXCEPTIONS
)

qt_internal_extend_target(tst_moc LIBRARIES Qt::CorePrivate)

qt_internal_extend_target(tst_moc CONDITION CMAKE_CROSSCOMPILING
    DEFINES
        MOC_CROSS_COMPILED
)

if (UNIX AND (CLANG OR GCC OR QCC))
    qt_wrap_cpp(os9_moc os9-newlines.h)
endif()

qt_internal_extend_target(tst_moc CONDITION UNIX AND (CLANG OR GCC OR QCC)
    SOURCES
        os9-newlines.h
        win-newlines.h
        ${os9_moc}
)

qt_internal_extend_target(tst_moc CONDITION CLANG OR GCC
    SOURCES
        dollars.h
)

qt_internal_extend_target(tst_moc CONDITION TARGET Qt::DBus
    LIBRARIES
        Qt::DBus
)

qt_internal_extend_target(tst_moc CONDITION TARGET Qt::Concurrent
    LIBRARIES
        Qt::Concurrent
)

qt_internal_extend_target(tst_moc CONDITION TARGET Qt::Network
    LIBRARIES
        Qt::Network
)

qt_internal_extend_target(tst_moc CONDITION TARGET Qt::Sql
    LIBRARIES
        Qt::Sql
)

get_target_property(target_binary_dir tst_moc BINARY_DIR)
set(cmake_autogen_cache_file
    "${target_binary_dir}/CMakeFiles/tst_moc_autogen.dir/ParseCache.txt")
set(cmake_autogen_info_file
    "${target_binary_dir}/CMakeFiles/tst_moc_autogen.dir/AutogenInfo.json")
set(moc_json_out ${target_binary_dir}/moc_json_out)

file(REMOVE ${moc_json_out})
foreach(filename ${moc_json_files})
    file(APPEND ${moc_json_out} "${filename}\n")
endforeach()

set(metatype_file "allmocs.json")
configure_file("allmocs_baseline_in.json" "${target_binary_dir}/allmocs_baseline.json")

add_custom_command(TARGET tst_moc
    POST_BUILD
    COMMAND ${QT_CMAKE_EXPORT_NAMESPACE}::moc
        -o "allmocs.json"
        --collect-json  "@${moc_json_out}"
    COMMENT "Running moc with --collect-json"
    VERBATIM
)

# Add dependencies that are implicitly used inside the test
add_dependencies(tst_moc
    Qt::qtpaths
    Qt::moc
)