summaryrefslogtreecommitdiffstats
path: root/tools/qmake/mkspecs/features/gyp_generator.prf
blob: 96de5e2804e8532d12beccaae0f64bfae587a896 (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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
# 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)

defineReplace(mocAction) {
    INPUT_FILE = $$1
    OUTPUT_NAME = $$mocOutput($$INPUT_FILE)
    DEFINES_LIST = $$join(DEFINES, " -D", -D)
    INCPATH = $$join(INCLUDEPATH, " -I", -I)
    MOC_COMMAND = $$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 = $$absolute_path($$MOC_DIR, $$OUT_PWD)$${QMAKE_DIR_SEP}$${OUTPUT_NAME}
    contents = "      {" \
               "        'action_name':'$$OUTPUT_NAME'," \
               "        'inputs': ['$$INPUT_FILE',]," \
               "        'outputs': ['$$OUTPUT_FILE',]," \
               "        'action': ["
    for(token, MOC_COMMAND): contents += "          '$$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 = $$absolute_path($$RCC_DIR, $$OUT_PWD)$${QMAKE_DIR_SEP}$${OUTPUT_NAME}
    contents = "      {" \
               "        'action_name':'$$OUTPUT_NAME'," \
               "        'inputs': ['$$INPUT_FILE',]," \
               "        'outputs': ['$$OUTPUT_FILE',]," \
               "        'action': [" \
               "          '$$clean_path($$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()
MOCABLE_HEADERS = $$findMocables($$HEADERS)
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 += "    ],"
}

# Split LIBS into linker flags and actual libraries, and add them to the
# appropriate section (ldflags vs link_settings: libraries) in the gyp file.
LIBRARIES = $$find(LIBS, "-l")
LIBRARIES = $$unique(LIBRARIES)
for (library, LIBRARIES): LIBS -= "$$library"

GYP_CONTENTS += "    'ldflags': ["
for (lib, LIBS): GYP_CONTENTS += "      '$$lib',"
for (rpath, QMAKE_RPATHDIR): GYP_CONTENTS += "      '$$QMAKE_RPATH$$rpath',"
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 += "    'link_settings': {" \
                "      'libraries': ["
for (library, LIBRARIES): GYP_CONTENTS += "        '$$library',"
macx {
    FRAMEWORKS = $$find(LIBS, "Q*")
    FRAMEWORKS = $$unique(FRAMEWORKS)
    FRAMEWORKS ~= s/-.*/
    FRAMEWORKS -= "-framework"
    for (framework, FRAMEWORKS): {
        framework_name = $$join(framework, "", "", ".framework")
        GYP_CONTENTS += "        '$$framework_name',"
    }

    FRAMEWORK_PATHS = $$find(LIBS, "-F*")
    FRAMEWORK_PATHS = $$unique(FRAMEWORK_PATHS)
    FRAMEWORK_PATHS -= "-framework"
    for (framework_path, FRAMEWORK_PATHS): GYP_CONTENTS += "        '$$framework_path',"
    !isEmpty(QMAKE_FRAMEWORKPATH): GYP_CONTENTS += "        '-F$$QMAKE_FRAMEWORKPATH',"
}
GYP_CONTENTS += "      ]," \
             "    },"

!isEmpty(GYPDEPENDENCIES) {
  GYP_CONTENTS += "    'dependencies': ["
  for (dep, GYPDEPENDENCIES): GYP_CONTENTS += "      '$$dep',"
  GYP_CONTENTS += "    ],"
}
!isEmpty(DEFINES) {
  GYP_CONTENTS += "    'defines': ["
  for (define, DEFINES): GYP_CONTENTS += "      '$$define',"
  GYP_CONTENTS += "    ],"
}
!isEmpty(PER_CONFIG_DEFINES) {
  GYP_CONTENTS += "    'configurations': {"\
                  "      'Release': {" \
                  "        'defines': ["
  for (define, PER_CONFIG_DEFINES): GYP_CONTENTS += "          '$$replace(define,%config,Release)',"
  GYP_CONTENTS += "        ]," \
                  "      }," \
                  "      'Debug': {" \
                  "        'defines': ["
  for (define, PER_CONFIG_DEFINES): GYP_CONTENTS += "          '$$replace(define,%config,Debug)',"
  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 = $$absolute_path($$RCC_DIR, $$OUT_PWD)$${QMAKE_DIR_SEP}$${RCC_CPP}
  GYP_CONTENTS += "      '$$RCC_CPP',"
}

# Add moc output files to compile that aren't included at the end of any other source
MOC_OUT_PATH = $$absolute_path($$MOC_DIR, $$OUT_PWD)$${QMAKE_DIR_SEP}
for (mocable_header, MOCABLE_HEADERS) {
    !contains(INCLUDED_MOC_FILES, $$mocOutput($$mocable_header)) {
        GYP_CONTENTS += "      '$$MOC_OUT_PATH$$mocOutput($$mocable_header)',"
    }
}

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

# Some needed files (like devtools_resources.pak) are both _generated_ as part of the build process and are _needed_ as part of the build process.
!isEmpty(COPY_FILES) {
  GYP_CONTENTS += "    'copies': ["
  for (index, 0..$$size(COPY_FILES)) {
    copyFile = $$member(COPY_FILES, $$index)
    !isEmpty(copyFile) {
      copyDestination = $$member(COPY_DESTINATIONS, $$index)
      GYP_CONTENTS += "        {'destination': '$$copyDestination', 'files': ['$$copyFile']},"
    }
  }
  GYP_CONTENTS += "    ],"
}

# Generate the actions for moc, copy
GYP_CONTENTS += "    'actions': ["
for(resourcefile, RESOURCES): GYP_CONTENTS += $$rccAction($$resourcefile)
for(header, MOCABLE_HEADERS): GYP_CONTENTS += $$mocAction($$header)
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 =