summaryrefslogtreecommitdiffstats
path: root/build/qmake/mkspecs/features/gyp_generator.prf
blob: 5cf0e3eb5bde473dc3a0bab5d1c1e1cde9674a2d (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
# 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)

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)
}

GYPI_FILE = $$replace(_PRO_FILE_, .pro$, .gyp)

TARGET_TYPE = $$toGypTargetType()
MOCABLE_HEADERS = $$findMocables($$HEADERS)
MOCABLE_SOURCES = $$findMocables($$SOURCES)

GYPI_CONTENTS =  "{" \
                 "  'targets': [" \
                 "  {" \
                 "    'target_name': '$$TARGET'," \
                 "    'type': '$$TARGET_TYPE'," \
                 "    'includes': [" \
                 "      '../blinq.gypi'," \
                 "    ]," \
                 "    'ldflags': ["
for (lib, LIBS): GYPI_CONTENTS += "      '$$lib',"
!isEmpty(QMAKE_RPATHDIR): GYPI_CONTENTS += "      '$$QMAKE_RPATH$$QMAKE_RPATHDIR',"

GYPI_CONTENTS += "    ],"

!isEmpty(GYPDEPENDENCIES) {
  GYPI_CONTENTS += "    'dependencies': ["
  for (dep, GYPDEPENDENCIES): GYPI_CONTENTS += "      '$$dep',"
  GYPI_CONTENTS += "    ],"
}
!isEmpty(DEFINES) {
  GYPI_CONTENTS += "    'defines': ["
  for (define, DEFINES): GYPI_CONTENTS += "      '$$define',"
  GYPI_CONTENTS += "    ],"
}
!isEmpty(PER_CONFIG_DEFINES) {
  GYPI_CONTENTS += "    'configurations': {"\
                   "      'Release': {" \
                   "        'defines': ["
  for (define, PER_CONFIG_DEFINES): GYPI_CONTENTS += "          '$$replace(define,%config,Release)',"
  GYPI_CONTENTS += "        ]," \
                   "      }," \
                   "      'Debug': {" \
                   "        'defines': ["
  for (define, PER_CONFIG_DEFINES): GYPI_CONTENTS += "          '$$replace(define,%config,Debug)',"
  GYPI_CONTENTS += "        ]," \
                   "      }," \
                   "    },"
}
GYPI_CONTENTS += "    'sources': ["
for (sourcefile, SOURCES): GYPI_CONTENTS += "      '$$sourcefile',"
for (headerfile, HEADERS): GYPI_CONTENTS += "      '$$headerfile',"
MOC_OUT_PATH = $$absolute_path($$MOC_DIR, $$OUT_PWD)$${QMAKE_DIR_SEP}
for (mocable_header, MOCABLE_HEADERS): GYPI_CONTENTS += "       '$$MOC_OUT_PATH$$mocOutput($$mocable_header)',"
for (mocable_source, MOCABLE_SOURCES): GYPI_CONTENTS += "       '$$MOC_OUT_PATH$$mocOutput($$mocable_source)',"
GYPI_CONTENTS += "    ],"
!isEmpty(INCLUDEPATH) {
  GYPI_CONTENTS += "    'include_dirs': ["
  for (path, INCLUDEPATH): GYPI_CONTENTS += "      '$$path',"
  GYPI_CONTENTS += "    ],"
}
# Generate the actions for moc
!isEmpty(MOCABLE_HEADERS)|!isEmpty(MOCABLE_SOURCES) {
    GYPI_CONTENTS += "    'actions': ["
    for(header, MOCABLE_HEADERS): GYPI_CONTENTS += $$mocAction($$header)
    GYPI_CONTENTS += "    ],"
}

GYPI_CONTENTS += "  }," \
                 "  ]," \
                 "}"

write_file($$GYPI_FILE, GYPI_CONTENTS)

# Overwriting the generated gyp file seems like a good reason to re-gyp
unix: phony_variable_name_for_qmake_to_be_happy=$$system("touch $$BLINQ_ROOT/build/build.pro")

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