@@ -1101,6 +1101,49 @@ def WriteLinkForArch(self, ninja_file, spec, config_name, config,
1101
1101
else :
1102
1102
command = command + '_notoc'
1103
1103
1104
+ if config .get ('let_qmake_do_the_linking' , 0 ):
1105
+ def toAbsPaths (paths ):
1106
+ return [os .path .relpath (path , self .toplevel_build ) if os .path .isabs (path ) else path
1107
+ for path in paths ]
1108
+ def qmakeLiteral (s ):
1109
+ return s .replace ('"' , '\\ "' )
1110
+
1111
+ # Generate this file for all solink targets, this assumes that
1112
+ # a .pro file will pick up this pri file and do the rest of the work.
1113
+ pri_file = open (os .path .join (self .toplevel_build , self .name + "_linking.pri" ), 'w' )
1114
+
1115
+ if self .flavor == 'win' :
1116
+ # qmake will take care of the manifest
1117
+ ldflags = filter (lambda x : not x .lower ().startswith ('/manifest' ), ldflags )
1118
+
1119
+ # Replace "$!PRODUCT_DIR" with "$$PWD" in link flags (which might contain some -L directives).
1120
+ prefixed_lflags = [self .ExpandSpecial (f , '$$PWD' ) for f in ldflags ]
1121
+ prefixed_library_dirs = ['-L' + self .ExpandSpecial (f , '$$PWD' ) for f in config .get ('library_dirs' , [])]
1122
+ prefixed_libraries = gyp .common .uniquer ([self .ExpandSpecial (f , '$$PWD' ) for f in spec .get ('libraries' , [])])
1123
+ if self .flavor == 'mac' :
1124
+ prefixed_libraries = self .xcode_settings .AdjustLibraries (prefixed_libraries )
1125
+ elif self .flavor == 'win' :
1126
+ prefixed_libraries = self .msvs_settings .AdjustLibraries (prefixed_libraries )
1127
+
1128
+ # Make sure that we have relative paths to our out/(Release|Debug), where we generate our .pri file, and then prepend $$PWD to them.
1129
+ prefixed_object_and_archives = ['$$PWD/' + o for o in toAbsPaths (link_deps )]
1130
+
1131
+ pri_file .write ("QMAKE_LFLAGS += %s\n " % qmakeLiteral (' ' .join (prefixed_lflags )))
1132
+ # Follow the logic of the solink rule.
1133
+ if self .flavor != 'mac' and self .flavor != 'win' :
1134
+ pri_file .write ("LIBS_PRIVATE += -Wl,--whole-archive %s -Wl,--no-whole-archive\n " % qmakeLiteral (' ' .join (prefixed_object_and_archives )))
1135
+ else :
1136
+ pri_file .write ("LIBS_PRIVATE += %s\n " % qmakeLiteral (' ' .join (prefixed_object_and_archives )))
1137
+ # External libs have to come after objects/archives, the linker resolve them in order.
1138
+ pri_file .write ("LIBS_PRIVATE += %s\n " % qmakeLiteral (' ' .join (prefixed_library_dirs + prefixed_libraries )))
1139
+ # Make sure that if ninja modifies one of the inputs, qmake/make will link again.
1140
+ pri_file .write ("POST_TARGETDEPS += %s\n " % qmakeLiteral (' ' .join (prefixed_object_and_archives )))
1141
+ pri_file .close ()
1142
+
1143
+ # In this mode we prevent letting ninja link at all.
1144
+ command = 'phony'
1145
+ command_suffix = ''
1146
+
1104
1147
if len (solibs ):
1105
1148
extra_bindings .append (('solibs' , gyp .common .EncodePOSIXShellList (solibs )))
1106
1149
0 commit comments