summaryrefslogtreecommitdiffstats
path: root/tools/qmake/mkspecs/features/gyp_generator.prf
blob: eea11ef096ce4c554a3f63383904dcf1f81a57c7 (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
# This file is loaded after the dummy .pro and all the default_post ran.
# This is the right point to extract the variables we're interested in and generate
# the .gyp file that we'll use later on when running gyp

load(functions)
load(moc)
load(resources)

MOC_GEN_DIR = <(SHARED_INTERMEDIATE_DIR)/moc
RCC_GEN_DIR = <(SHARED_INTERMEDIATE_DIR)/rcc

defineReplace(mocAction) {
    INPUT_FILE = $$1
    OUTPUT_NAME = $$mocOutput($$INPUT_FILE)
    DEFINES_LIST = $$join(DEFINES, " -D", -D)
    INCPATH = $$join(INCLUDEPATH, " -I", -I)
    MOC_COMMAND = $$clean_path($$mocCmdBase())
    MOC_COMMAND = $$replace(MOC_COMMAND, $$re_escape("$(DEFINES)"), $$DEFINES_LIST)
    MOC_COMMAND = $$replace(MOC_COMMAND, $$re_escape("$(INCPATH)"), $$INCPATH)
    MOC_COMMAND = $$split(MOC_COMMAND, " ")
    OUTPUT_FILE = $$MOC_GEN_DIR/$${OUTPUT_NAME}
    contents = "      {" \
               "        'action_name':'$$OUTPUT_NAME'," \
               "        'inputs': ['$$INPUT_FILE',]," \
               "        'outputs': ['$$OUTPUT_FILE',]," \
               "        'action': ["
    for(token, MOC_COMMAND): contents += "          '$$replace(token,\',)',"
    contents += "          '$$INPUT_FILE'," \
                "          '-o'," \
                "          '$$OUTPUT_FILE'," \
                "        ]," \
                "     },"

    return($$contents)
}

defineReplace(rccAction) {
    INPUT_FILE = $$1
    OUTPUT_NAME = $$rccOutput($$INPUT_FILE)
    EXTERN_FUNC = $$rccExternFunc($$INPUT_FILE)
    OUTPUT_FILE = $$RCC_GEN_DIR/$${OUTPUT_NAME}
    CLEAN_QMAKE_RCC = $$clean_path($$QMAKE_RCC)
    contents = "      {" \
               "        'action_name':'$$OUTPUT_NAME'," \
               "        'inputs': ['$$INPUT_FILE',]," \
               "        'outputs': ['$$OUTPUT_FILE',]," \
               "        'action': [" \
               "          '$$replace(CLEAN_QMAKE_RCC,\',)',"
    for(resource_flag, $$QMAKE_RESOURCE_FLAGS): contents += "          '$$resource_flag',"
    contents += "          '-name'," \
                "          '$$EXTERN_FUNC'," \
                "          '$$INPUT_FILE'," \
                "          '-o'," \
                "          '$$OUTPUT_FILE',"
    contents += "        ]," \
                "     },"

    return($$contents)
}

isEmpty(GYPFILE): GYPFILE = $$replace(_PRO_FILE_, .pro$, .gyp)

TARGET_TYPE = $$toGypTargetType()
MOCABLES = $$findMocables($$HEADERS)
MOCABLES += $$findMocables($$SOURCES)
INCLUDED_MOC_FILES = $$findIncludedMocFiles($$SOURCES)

GYP_CONTENTS =  "{" \
                "  'targets': [" \
                "  {" \
                "    'target_name': '$$TARGET'," \
                "    'type': '$$TARGET_TYPE',"
!isEmpty(GYPINCLUDES) {
GYP_CONTENTS += "    'includes': ["
for (incl, GYPINCLUDES): GYP_CONTENTS += "      '$$incl',"
GYP_CONTENTS += "    ],"
}

!isEmpty(QMAKE_FRAMEWORKPATH) {
    GYP_CONTENTS += "    'mac_framework_dirs': ["
    for(path, QMAKE_FRAMEWORKPATH): GYP_CONTENTS += "      '$$path',"
    GYP_CONTENTS += "    ],"
}

!isEmpty(QMAKE_CFLAGS) {
    GYP_CONTENTS += "    'cflags': ["
    for(flag, QMAKE_CFLAGS): GYP_CONTENTS += "      '$$flag',"
    GYP_CONTENTS += "    ],"
}
!isEmpty(QMAKE_CXXFLAGS) {
    GYP_CONTENTS += "    'cflags_cc': ["
    for(flag, QMAKE_CXXFLAGS): GYP_CONTENTS += "      '$$flag',"
    GYP_CONTENTS += "    ],"
}

GYP_CONTENTS += "    'defines': ["
for (define, DEFINES): GYP_CONTENTS += "      '$$define',"
!isEmpty(QMAKE_LIBDIR_EGL): GYP_CONTENTS += "      'QT_LIBDIR_EGL=\"$${QMAKE_DIR_SEP}$$relative_path($$QMAKE_LIBDIR_EGL, $$[QT_SYSROOT])\"',"
!isEmpty(QMAKE_LIBDIR_OPENGL_ES2): GYP_CONTENTS += "      'QT_LIBDIR_GLES2=\"$${QMAKE_DIR_SEP}$$relative_path($$QMAKE_LIBDIR_OPENGL_ES2, $$[QT_SYSROOT])\"',"
GYP_CONTENTS += "    ],"

!isEmpty(GYP_DYLIB_INSTALL_NAME_BASE) {
  GYP_CONTENTS += "    'xcode_settings': {" \
                  "      'DYLIB_INSTALL_NAME_BASE': '$$GYP_DYLIB_INSTALL_NAME_BASE'," \
                  "    },"
}

# Source files to compile
GYP_CONTENTS += "    'sources': ["
for (sourcefile, SOURCES): GYP_CONTENTS += "      '$$sourcefile',"
for (headerfile, HEADERS): GYP_CONTENTS += "      '$$headerfile',"

# Add Sources generated by rcc from qrc files.
for (resourcefile, RESOURCES) {
  RCC_CPP = $$replace(resourcefile, .qrc, .cpp)
  RCC_CPP = $$join(RCC_CPP, "qrc_", qrc_)
  RCC_CPP = $$RCC_GEN_DIR/$${RCC_CPP}
  GYP_CONTENTS += "      '$$RCC_CPP',"
}

# Add moc output files to compile that aren't included at the end of any other source
for (mocable, MOCABLES) {
    !contains(INCLUDED_MOC_FILES, $$mocOutput($$mocable)) {
        GYP_CONTENTS += "      '$$MOC_GEN_DIR/$$mocOutput($$mocable)',"
    }
}

GYP_CONTENTS += "    ],"
GYP_CONTENTS += "    'include_dirs': ["
for (path, INCLUDEPATH): GYP_CONTENTS += "      '$$path',"
# qmake already added MOC_DIR to INCLUDEPATH, but we're telling gyp to use a different one.
GYP_CONTENTS += "      '$$MOC_GEN_DIR',"
GYP_CONTENTS += "    ],"

# Generate the actions for moc and rcc
GYP_CONTENTS += "    'actions': ["
for(resourcefile, RESOURCES): GYP_CONTENTS += $$rccAction($$resourcefile)
for(mocable, MOCABLES): GYP_CONTENTS += $$mocAction($$mocable)
GYP_CONTENTS += "    ]," \
                "  },"

GYP_CONTENTS += "  ]," \
                "}"

!build_pass: write_file($$GYPFILE, GYP_CONTENTS)

# Overwriting the generated gyp file seems like a good reason to re-gyp
unix: system("touch $$QTWEBENGINE_ROOT/src/core/gyp_run.pro")

# The generated Makefile shouldn't build anything by itself, just re-run qmake if necessary
TEMPLATE = aux
SOURCES =
HEADERS =
RESOURCES =