source: trunk/qmake/generators/win32/msvc_vcproj.cpp

Last change on this file was 2, checked in by dmik, 20 years ago

Imported xplatform parts of the official release 3.3.1 from Trolltech

  • Property svn:keywords set to Id
File size: 57.9 KB
Line 
1/****************************************************************************
2** $Id: msvc_vcproj.cpp 2 2005-11-16 15:49:26Z dmik $
3**
4** Implementation of VcprojGenerator class.
5**
6** Copyright (C) 1992-2003 Trolltech AS. All rights reserved.
7**
8** This file is part of qmake.
9**
10** This file may be distributed under the terms of the Q Public License
11** as defined by Trolltech AS of Norway and appearing in the file
12** LICENSE.QPL included in the packaging of this file.
13**
14** This file may be distributed and/or modified under the terms of the
15** GNU General Public License version 2 as published by the Free Software
16** Foundation and appearing in the file LICENSE.GPL included in the
17** packaging of this file.
18**
19** Licensees holding valid Qt Enterprise Edition licenses may use this
20** file in accordance with the Qt Commercial License Agreement provided
21** with the Software.
22**
23** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
24** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
25**
26** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
27** information about Qt Commercial License Agreements.
28** See http://www.trolltech.com/qpl/ for QPL licensing information.
29** See http://www.trolltech.com/gpl/ for GPL licensing information.
30**
31** Contact info@trolltech.com if any conditions of this licensing are
32** not clear to you.
33**
34**********************************************************************/
35
36#include "msvc_vcproj.h"
37#include "option.h"
38#include "qtmd5.h" // SG's MD5 addon
39#include <qdir.h>
40#include <qregexp.h>
41#include <qdict.h>
42#include <quuid.h>
43#include <stdlib.h>
44#include <qsettings.h>
45
46//#define DEBUG_SOLUTION_GEN
47//#define DEBUG_PROJECT_GEN
48
49// Registry keys for .NET version detection -------------------------
50const char* _regNet2002 = "Microsoft\\VisualStudio\\7.0\\Setup\\VC\\ProductDir";
51const char* _regNet2003 = "Microsoft\\VisualStudio\\7.1\\Setup\\VC\\ProductDir";
52
53bool use_net2003_version()
54{
55#ifndef Q_OS_WIN32
56 return FALSE; // Always generate 7.0 versions on other platforms
57#else
58 // Only search for the version once
59 static int current_version = -1;
60 if (current_version!=-1)
61 return (current_version==71);
62
63 // Fallback to .NET 2002
64 current_version = 70;
65
66 // Get registry entries for both versions
67 bool ok = false;
68 QSettings setting;
69 QString path2002 = setting.readEntry(_regNet2002);
70 QString path2003 = setting.readEntry(_regNet2003);
71
72 if ( path2002.isNull() || path2003.isNull() ) {
73 // Only have one MSVC, so use that one
74 current_version = (path2003.isNull() ? 70 : 71);
75 } else {
76 // Have both, so figure out the current
77 QString paths = getenv("PATH");
78 QStringList pathlist = QStringList::split(";", paths.lower());
79
80 path2003 = path2003.lower();
81 QStringList::iterator it;
82 for(it=pathlist.begin(); it!=pathlist.end(); ++it) {
83 if ((*it).contains(path2003)) {
84 current_version = 71;
85 } else if ((*it).contains(path2002)
86 && current_version == 71) {
87 fprintf( stderr, "Both .NET 2002 & .NET 2003 directories for VC found in you PATH variable!\nFallback to .NET 2002 project generation" );
88 current_version = 70;
89 break;
90 }
91 }
92 }
93 return (current_version==71);
94#endif
95};
96
97// Flatfile Tags ----------------------------------------------------
98const char* _slnHeader70 = "Microsoft Visual Studio Solution File, Format Version 7.00";
99const char* _slnHeader71 = "Microsoft Visual Studio Solution File, Format Version 8.00";
100 // The following UUID _may_ change for later servicepacks...
101 // If so we need to search through the registry at
102 // HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\7.0\Projects
103 // to find the subkey that contains a "PossibleProjectExtension"
104 // containing "vcproj"...
105 // Use the hardcoded value for now so projects generated on other
106 // platforms are actually usable.
107const char* _slnMSVCvcprojGUID = "{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}";
108const char* _slnProjectBeg = "\nProject(\"";
109const char* _slnProjectMid = "\") = ";
110const char* _slnProjectEnd = "\nEndProject";
111const char* _slnGlobalBeg = "\nGlobal";
112const char* _slnGlobalEnd = "\nEndGlobal";
113const char* _slnSolutionConf = "\n\tGlobalSection(SolutionConfiguration) = preSolution"
114 "\n\t\tConfigName.0 = Debug"
115 "\n\t\tConfigName.1 = Release"
116 "\n\tEndGlobalSection";
117const char* _slnProjDepBeg = "\n\tGlobalSection(ProjectDependencies) = postSolution";
118const char* _slnProjDepEnd = "\n\tEndGlobalSection";
119const char* _slnProjConfBeg = "\n\tGlobalSection(ProjectConfiguration) = postSolution";
120const char* _slnProjRelConfTag1 = ".Release.ActiveCfg = Release|Win32";
121const char* _slnProjRelConfTag2 = ".Release.Build.0 = Release|Win32";
122const char* _slnProjDbgConfTag1 = ".Debug.ActiveCfg = Debug|Win32";
123const char* _slnProjDbgConfTag2 = ".Debug.Build.0 = Debug|Win32";
124const char* _slnProjConfEnd = "\n\tEndGlobalSection";
125const char* _slnExtSections = "\n\tGlobalSection(ExtensibilityGlobals) = postSolution"
126 "\n\tEndGlobalSection"
127 "\n\tGlobalSection(ExtensibilityAddIns) = postSolution"
128 "\n\tEndGlobalSection";
129// ------------------------------------------------------------------
130
131VcprojGenerator::VcprojGenerator(QMakeProject *p) : Win32MakefileGenerator(p), init_flag(FALSE)
132{
133}
134
135/* \internal
136 Generates a project file for the given profile.
137 Options are either a Visual Studio projectfiles, or
138 solutionfiles by parsing recursive projectdirectories.
139*/
140bool VcprojGenerator::writeMakefile(QTextStream &t)
141{
142 // Check if all requirements are fullfilled
143 if(!project->variables()["QMAKE_FAILED_REQUIREMENTS"].isEmpty()) {
144 fprintf(stderr, "Project file not generated because all requirements not met:\n\t%s\n",
145 var("QMAKE_FAILED_REQUIREMENTS").latin1());
146 return TRUE;
147 }
148
149 // Generate project file
150 if(project->first("TEMPLATE") == "vcapp" ||
151 project->first("TEMPLATE") == "vclib") {
152 debug_msg(1, "Generator: MSVC.NET: Writing project file" );
153 t << vcProject;
154 return TRUE;
155 }
156 // Generate solution file
157 else if(project->first("TEMPLATE") == "vcsubdirs") {
158 debug_msg(1, "Generator: MSVC.NET: Writing solution file" );
159 writeSubDirs(t);
160 return TRUE;
161 }
162 return FALSE;
163
164}
165
166struct VcsolutionDepend {
167 QString uuid;
168 QString vcprojFile, orig_target, target;
169 ::target targetType;
170 bool debugBuild;
171 QStringList dependencies;
172};
173
174QUuid VcprojGenerator::getProjectUUID(const QString &filename)
175{
176 bool validUUID = true;
177
178 // Read GUID from variable-space
179 QUuid uuid = project->first("GUID");
180
181 // If none, create one based on the MD5 of absolute project path
182 if (uuid.isNull() || !filename.isNull()) {
183 QString abspath = filename.isNull()?project->first("QMAKE_MAKEFILE"):filename;
184 qtMD5(abspath.utf8(), (unsigned char*)(&uuid));
185 validUUID = !uuid.isNull();
186 uuid.data4[0] = (uuid.data4[0] & 0x3F) | 0x80; // UV_DCE variant
187 uuid.data3 = (uuid.data3 & 0x0FFF) | (QUuid::Name<<12);
188 }
189
190 // If still not valid, generate new one, and suggest adding to .pro
191 if (uuid.isNull() || !validUUID) {
192 uuid = QUuid::createUuid();
193 fprintf(stderr,
194 "qmake couldn't create a GUID based on filepath, and we couldn't\nfind a valid GUID in the .pro file (Consider adding\n'GUID = %s' to the .pro file)\n",
195 uuid.toString().upper().latin1());
196 }
197
198 // Store GUID in variable-space
199 project->values("GUID") = uuid.toString().upper();
200 return uuid;
201}
202
203QUuid VcprojGenerator::increaseUUID( const QUuid &id )
204{
205 QUuid result( id );
206 Q_LONG dataFirst = (result.data4[0] << 24) +
207 (result.data4[1] << 16) +
208 (result.data4[2] << 8) +
209 result.data4[3];
210 Q_LONG dataLast = (result.data4[4] << 24) +
211 (result.data4[5] << 16) +
212 (result.data4[6] << 8) +
213 result.data4[7];
214
215 if ( !(dataLast++) )
216 dataFirst++;
217
218 result.data4[0] = uchar((dataFirst >> 24) & 0xff);
219 result.data4[1] = uchar((dataFirst >> 16) & 0xff);
220 result.data4[2] = uchar((dataFirst >> 8) & 0xff);
221 result.data4[3] = uchar( dataFirst & 0xff);
222 result.data4[4] = uchar((dataLast >> 24) & 0xff);
223 result.data4[5] = uchar((dataLast >> 16) & 0xff);
224 result.data4[6] = uchar((dataLast >> 8) & 0xff);
225 result.data4[7] = uchar( dataLast & 0xff);
226 return result;
227}
228
229void VcprojGenerator::writeSubDirs(QTextStream &t)
230{
231 if(project->first("TEMPLATE") == "subdirs") {
232 writeHeader(t);
233 Win32MakefileGenerator::writeSubDirs(t);
234 return;
235 }
236
237 t << (use_net2003_version() ? _slnHeader71 : _slnHeader70);
238
239 QDict<VcsolutionDepend> solution_depends;
240
241 QPtrList<VcsolutionDepend> solution_cleanup;
242 solution_cleanup.setAutoDelete(TRUE);
243
244
245 QStringList subdirs = project->variables()["SUBDIRS"];
246 QString oldpwd = QDir::currentDirPath();
247
248 for(QStringList::Iterator it = subdirs.begin(); it != subdirs.end(); ++it) {
249 QFileInfo fi(Option::fixPathToLocalOS((*it), TRUE));
250 if(fi.exists()) {
251 if(fi.isDir()) {
252 QString profile = (*it);
253 if(!profile.endsWith(Option::dir_sep))
254 profile += Option::dir_sep;
255 profile += fi.baseName() + ".pro";
256 subdirs.append(profile);
257 } else {
258 QMakeProject tmp_proj;
259 QString dir = fi.dirPath(), fn = fi.fileName();
260 if(!dir.isEmpty()) {
261 if(!QDir::setCurrent(dir))
262 fprintf(stderr, "Cannot find directory: %s\n", dir.latin1());
263 }
264 if(tmp_proj.read(fn, oldpwd)) {
265 if(tmp_proj.first("TEMPLATE") == "vcsubdirs") {
266 subdirs += fileFixify(tmp_proj.variables()["SUBDIRS"]);
267 } else if(tmp_proj.first("TEMPLATE") == "vcapp" || tmp_proj.first("TEMPLATE") == "vclib") {
268 // Initialize a 'fake' project to get the correct variables
269 // and to be able to extract all the dependencies
270 VcprojGenerator tmp_vcproj(&tmp_proj);
271 tmp_vcproj.setNoIO(TRUE);
272 tmp_vcproj.init();
273 if(Option::debug_level) {
274 QMap<QString, QStringList> &vars = tmp_proj.variables();
275 for(QMap<QString, QStringList>::Iterator it = vars.begin();
276 it != vars.end(); ++it) {
277 if(it.key().left(1) != "." && !it.data().isEmpty())
278 debug_msg(1, "%s: %s === %s", fn.latin1(), it.key().latin1(),
279 it.data().join(" :: ").latin1());
280 }
281 }
282
283 // We assume project filename is [QMAKE_ORIG_TARGET].vcproj
284 QString vcproj = fixFilename(tmp_vcproj.project->first("QMAKE_ORIG_TARGET")) + project->first("VCPROJ_EXTENSION");
285
286 // If file doesn't exsist, then maybe the users configuration
287 // doesn't allow it to be created. Skip to next...
288 if(!QFile::exists(QDir::currentDirPath() + Option::dir_sep + vcproj)) {
289 warn_msg(WarnLogic, "Ignored (not found) '%s'", QString(QDir::currentDirPath() + Option::dir_sep + vcproj).latin1() );
290 goto nextfile; // # Dirty!
291 }
292
293 VcsolutionDepend *newDep = new VcsolutionDepend;
294 newDep->vcprojFile = fileFixify(vcproj);
295 newDep->orig_target = tmp_proj.first("QMAKE_ORIG_TARGET");
296 newDep->target = tmp_proj.first("MSVCPROJ_TARGET").section(Option::dir_sep, -1);
297 newDep->targetType = tmp_vcproj.projectTarget;
298 newDep->debugBuild = tmp_proj.isActiveConfig("debug");
299 newDep->uuid = getProjectUUID(Option::fixPathToLocalOS(QDir::currentDirPath() + QDir::separator() + vcproj)).toString().upper();
300
301 // We want to store it as the .lib name.
302 if(newDep->target.endsWith(".dll"))
303 newDep->target = newDep->target.left(newDep->target.length()-3) + "lib";
304
305 // All projects using Forms are dependent on uic.exe
306 if(!tmp_proj.isEmpty("FORMS"))
307 newDep->dependencies << "uic.exe";
308
309 // Add all unknown libs to the deps
310 QStringList where("QMAKE_LIBS");
311 if(!tmp_proj.isEmpty("QMAKE_INTERNAL_PRL_LIBS"))
312 where = tmp_proj.variables()["QMAKE_INTERNAL_PRL_LIBS"];
313 for(QStringList::iterator wit = where.begin();
314 wit != where.end(); ++wit) {
315 QStringList &l = tmp_proj.variables()[(*wit)];
316 for(QStringList::Iterator it = l.begin(); it != l.end(); ++it) {
317 QString opt = (*it);
318 if(!opt.startsWith("/") && // Not a switch
319 opt != newDep->target && // Not self
320 opt != "opengl32.lib" && // We don't care about these libs
321 opt != "glu32.lib" && // to make depgen alittle faster
322 opt != "kernel32.lib" &&
323 opt != "user32.lib" &&
324 opt != "gdi32.lib" &&
325 opt != "comdlg32.lib" &&
326 opt != "advapi32.lib" &&
327 opt != "shell32.lib" &&
328 opt != "ole32.lib" &&
329 opt != "oleaut32.lib" &&
330 opt != "uuid.lib" &&
331 opt != "imm32.lib" &&
332 opt != "winmm.lib" &&
333 opt != "wsock32.lib" &&
334 opt != "winspool.lib" &&
335 opt != "delayimp.lib" )
336 {
337 newDep->dependencies << opt.section(Option::dir_sep, -1);
338 }
339 }
340 }
341#ifdef DEBUG_SOLUTION_GEN
342 qDebug( "Deps for %20s: [%s]", newDep->target.latin1(), newDep->dependencies.join(" :: " ).latin1() );
343#endif
344 solution_cleanup.append(newDep);
345 solution_depends.insert(newDep->target, newDep);
346 t << _slnProjectBeg << _slnMSVCvcprojGUID << _slnProjectMid
347 << "\"" << newDep->orig_target << "\", \"" << newDep->vcprojFile
348 << "\", \"" << newDep->uuid << "\"";
349 t << _slnProjectEnd;
350 }
351 }
352nextfile:
353 QDir::setCurrent(oldpwd);
354 }
355 }
356 }
357 t << _slnGlobalBeg;
358 t << _slnSolutionConf;
359 t << _slnProjDepBeg;
360
361 // Figure out dependencies
362 for(solution_cleanup.first(); solution_cleanup.current(); solution_cleanup.next()) {
363 if(solution_cleanup.current()->targetType == StaticLib)
364 continue; // Shortcut, Static libs are not dep.
365 int cnt = 0;
366 for(QStringList::iterator dit = solution_cleanup.current()->dependencies.begin();
367 dit != solution_cleanup.current()->dependencies.end();
368 ++dit)
369 {
370 VcsolutionDepend *vc = solution_depends[*dit];
371 if(vc)
372 t << "\n\t\t" << solution_cleanup.current()->uuid << "." << cnt++ << " = " << vc->uuid;
373 }
374 }
375 t << _slnProjDepEnd;
376 t << _slnProjConfBeg;
377 for(solution_cleanup.first(); solution_cleanup.current(); solution_cleanup.next()) {
378 t << "\n\t\t" << solution_cleanup.current()->uuid << _slnProjDbgConfTag1;
379 t << "\n\t\t" << solution_cleanup.current()->uuid << _slnProjDbgConfTag2;
380 t << "\n\t\t" << solution_cleanup.current()->uuid << _slnProjRelConfTag1;
381 t << "\n\t\t" << solution_cleanup.current()->uuid << _slnProjRelConfTag2;
382 }
383 t << _slnProjConfEnd;
384 t << _slnExtSections;
385 t << _slnGlobalEnd;
386}
387
388// ------------------------------------------------------------------------------------------------
389// ------------------------------------------------------------------------------------------------
390
391void VcprojGenerator::init()
392{
393 if( init_flag )
394 return;
395 if(project->first("TEMPLATE") == "vcsubdirs") { //too much work for subdirs
396 init_flag = TRUE;
397 return;
398 }
399
400 debug_msg(1, "Generator: MSVC.NET: Initializing variables" );
401
402/*
403 // Once to be nice and clean code...
404 // Wouldn't life be great?
405
406 // Are we building Qt?
407 bool is_qt =
408 ( project->first("TARGET") == "qt"QTDLL_POSTFIX ||
409 project->first("TARGET") == "qt-mt"QTDLL_POSTFIX );
410
411 // Are we using Qt?
412 bool isQtActive = project->isActiveConfig("qt");
413
414 if ( isQtActive ) {
415 project->variables()["CONFIG"] += "moc";
416 project->variables()["CONFIG"] += "windows";
417 project->variables()["INCLUDEPATH"] += project->variables()["QMAKE_INCDIR_QT"];
418 project->variables()["QMAKE_LIBDIR"] += project->variables()["QMAKE_LIBDIR_QT"];
419
420 if( projectTarget == SharedLib )
421 project->variables()["DEFINES"] += "QT_DLL";
422
423 if( project->isActiveConfig("accessibility" ) )
424 project->variables()["DEFINES"] += "QT_ACCESSIBILITY_SUPPORT";
425
426 if ( project->isActiveConfig("plugin")) {
427 project->variables()["DEFINES"] += "QT_PLUGIN";
428 project->variables()["CONFIG"] += "dll";
429 }
430
431 if( project->isActiveConfig("thread") ) {
432 project->variables()["DEFINES"] += "QT_THREAD_SUPPORT";
433 project->variables()["QMAKE_LIBS"] += project->variables()["QMAKE_LIBS_QT_THREAD"];
434 } else {
435 project->variables()["QMAKE_LIBS"] += project->variables()["QMAKE_LIBS_QT"];
436 }
437 }
438
439 if ( project->isActiveConfig("opengl") ) {
440 project->variables()["CONFIG"] += "windows"; // <-- Also in 'qt' above
441 project->variables()["QMAKE_LIBS"] += project->variables()["QMAKE_LIBS_OPENGL"];
442 project->variables()["QMAKE_LFLAGS"] += project->variables()["QMAKE_LFLAGS_OPENGL"];
443
444 }
445*/
446 initOld(); // Currently calling old DSP code to set variables. CLEAN UP!
447
448 // Figure out what we're trying to build
449 if ( project->first("TEMPLATE") == "vcapp" ) {
450 projectTarget = Application;
451 } else if ( project->first("TEMPLATE") == "vclib") {
452 if ( project->isActiveConfig( "staticlib" ) )
453 projectTarget = StaticLib;
454 else
455 projectTarget = SharedLib;
456 }
457
458 // Setup PCH variables
459 precompH = project->first("PRECOMPILED_HEADER");
460 usePCH = !precompH.isEmpty() && project->isActiveConfig("precompile_header");
461 if (usePCH) {
462 precompHFilename = QFileInfo(precompH).fileName();
463 // Created files
464 QString origTarget = project->first("QMAKE_ORIG_TARGET");
465 precompObj = origTarget + Option::obj_ext;
466 precompPch = origTarget + ".pch";
467 // Add PRECOMPILED_HEADER to HEADERS
468 if (!project->variables()["HEADERS"].contains(precompH))
469 project->variables()["HEADERS"] += precompH;
470 // Return to variable pool
471 project->variables()["PRECOMPILED_OBJECT"] = precompObj;
472 project->variables()["PRECOMPILED_PCH"] = precompPch;
473 }
474
475 initProject(); // Fills the whole project with proper data
476}
477
478void VcprojGenerator::initProject()
479{
480 // Initialize XML sub elements
481 // - Do this first since project elements may need
482 // - to know of certain configuration options
483 initConfiguration();
484 initSourceFiles();
485 initHeaderFiles();
486 initMOCFiles();
487 initUICFiles();
488 initFormsFiles();
489 initTranslationFiles();
490 initLexYaccFiles();
491 initResourceFiles();
492
493 // Own elements -----------------------------
494 vcProject.Name = project->first("QMAKE_ORIG_TARGET");
495 vcProject.Version = use_net2003_version() ? "7.10" : "7.00";
496 vcProject.ProjectGUID = getProjectUUID().toString().upper();
497 vcProject.PlatformName = ( vcProject.Configuration[0].idl.TargetEnvironment == midlTargetWin64 ? "Win64" : "Win32" );
498 // These are not used by Qt, but may be used by customers
499 vcProject.SccProjectName = project->first("SCCPROJECTNAME");
500 vcProject.SccLocalPath = project->first("SCCLOCALPATH");
501}
502
503void VcprojGenerator::initConfiguration()
504{
505 // Initialize XML sub elements
506 // - Do this first since main configuration elements may need
507 // - to know of certain compiler/linker options
508 initCompilerTool();
509 if ( projectTarget == StaticLib )
510 initLibrarianTool();
511 else
512 initLinkerTool();
513 initIDLTool();
514
515 // Own elements -----------------------------
516 QString temp = project->first("BuildBrowserInformation");
517 switch ( projectTarget ) {
518 case SharedLib:
519 vcProject.Configuration[0].ConfigurationType = typeDynamicLibrary;
520 break;
521 case StaticLib:
522 vcProject.Configuration[0].ConfigurationType = typeStaticLibrary;
523 break;
524 case Application:
525 default:
526 vcProject.Configuration[0].ConfigurationType = typeApplication;
527 break;
528 }
529
530 // Release version of the Configuration ---------------
531 VCConfiguration &RConf = vcProject.Configuration[0];
532 RConf.Name = "Release";
533 RConf.Name += ( RConf.idl.TargetEnvironment == midlTargetWin64 ? "|Win64" : "|Win32" );
534 RConf.ATLMinimizesCRunTimeLibraryUsage = ( project->first("ATLMinimizesCRunTimeLibraryUsage").isEmpty() ? _False : _True );
535 RConf.BuildBrowserInformation = triState( temp.isEmpty() ? (short)unset : temp.toShort() );
536 temp = project->first("CharacterSet");
537 RConf.CharacterSet = charSet( temp.isEmpty() ? (short)charSetNotSet : temp.toShort() );
538 RConf.DeleteExtensionsOnClean = project->first("DeleteExtensionsOnClean");
539 RConf.ImportLibrary = RConf.linker.ImportLibrary;
540 RConf.IntermediateDirectory = project->first("OBJECTS_DIR");
541 RConf.OutputDirectory = ".";
542 RConf.PrimaryOutput = project->first("PrimaryOutput");
543 RConf.WholeProgramOptimization = RConf.compiler.WholeProgramOptimization;
544 temp = project->first("UseOfATL");
545 if ( !temp.isEmpty() )
546 RConf.UseOfATL = useOfATL( temp.toShort() );
547 temp = project->first("UseOfMfc");
548 if ( !temp.isEmpty() )
549 RConf.UseOfMfc = useOfMfc( temp.toShort() );
550
551 // Configuration does not need parameters from
552 // these sub XML items;
553 initCustomBuildTool();
554 initPreBuildEventTools();
555 initPostBuildEventTools();
556 initPreLinkEventTools();
557
558 // Debug version of the Configuration -----------------
559 VCConfiguration DConf = vcProject.Configuration[0]; // Create copy configuration for debug
560 DConf.Name = "Debug";
561 DConf.Name += ( DConf.idl.TargetEnvironment == midlTargetWin64 ? "|Win64" : "|Win32" );
562
563 // Set definite values in both configurations
564 RConf.compiler.PreprocessorDefinitions.remove("_DEBUG");
565 DConf.compiler.PreprocessorDefinitions.remove("NDEBUG");
566 RConf.compiler.PreprocessorDefinitions += "NDEBUG";
567 DConf.compiler.PreprocessorDefinitions += "_DEBUG";
568 RConf.linker.GenerateDebugInformation = _False;
569 DConf.linker.GenerateDebugInformation = _True;
570
571 // Modify configurations, based on Qt build
572 if ( project->isActiveConfig("debug") ) {
573 RConf.IntermediateDirectory =
574 RConf.compiler.AssemblerListingLocation =
575 RConf.compiler.ObjectFile = "Release\\";
576 RConf.librarian.OutputFile =
577 RConf.linker.OutputFile = RConf.IntermediateDirectory + "\\" + project->first("MSVCPROJ_TARGET");
578 RConf.linker.parseOptions(project->variables()["QMAKE_LFLAGS_RELEASE"]);
579 RConf.compiler.parseOptions(project->variables()["QMAKE_CFLAGS_RELEASE"]);
580 } else {
581 DConf.IntermediateDirectory =
582 DConf.compiler.AssemblerListingLocation =
583 DConf.compiler.ObjectFile = "Debug\\";
584 DConf.librarian.OutputFile =
585 DConf.linker.OutputFile = DConf.IntermediateDirectory + "\\" + project->first("MSVCPROJ_TARGET");
586 DConf.linker.DelayLoadDLLs.clear();
587 DConf.compiler.parseOptions(project->variables()["QMAKE_CFLAGS_DEBUG"]);
588 }
589
590 // Add Debug configuration to project
591 vcProject.Configuration += DConf;
592}
593
594void VcprojGenerator::initCompilerTool()
595{
596 QString placement = project->first("OBJECTS_DIR");
597 if ( placement.isEmpty() )
598 placement = ".\\";
599
600 VCConfiguration &RConf = vcProject.Configuration[0];
601 RConf.compiler.AssemblerListingLocation = placement ;
602 RConf.compiler.ProgramDataBaseFileName = ".\\" ;
603 RConf.compiler.ObjectFile = placement ;
604 // PCH
605 if ( usePCH ) {
606 RConf.compiler.UsePrecompiledHeader = pchUseUsingSpecific;
607 RConf.compiler.PrecompiledHeaderFile = "$(IntDir)\\" + precompPch;
608 RConf.compiler.PrecompiledHeaderThrough = precompHFilename;
609 RConf.compiler.ForcedIncludeFiles = precompHFilename;
610 // Minimal build option triggers an Internal Compiler Error
611 // when used in conjunction with /FI and /Yu, so remove it
612 project->variables()["QMAKE_CFLAGS_DEBUG"].remove("-Gm");
613 project->variables()["QMAKE_CFLAGS_DEBUG"].remove("/Gm");
614 project->variables()["QMAKE_CXXFLAGS_DEBUG"].remove("-Gm");
615 project->variables()["QMAKE_CXXFLAGS_DEBUG"].remove("/Gm");
616 }
617
618 if ( project->isActiveConfig("debug") ){
619 // Debug version
620 RConf.compiler.parseOptions( project->variables()["QMAKE_CXXFLAGS"] );
621 RConf.compiler.parseOptions( project->variables()["QMAKE_CXXFLAGS_DEBUG"] );
622 if ( project->isActiveConfig("thread") ) {
623 if ( (projectTarget == Application) || (projectTarget == StaticLib) )
624 RConf.compiler.parseOptions( project->variables()["QMAKE_CXXFLAGS_MT_DBG"] );
625 else
626 RConf.compiler.parseOptions( project->variables()["QMAKE_CXXFLAGS_MT_DLLDBG"] );
627 } else {
628 RConf.compiler.parseOptions( project->variables()["QMAKE_CXXFLAGS_MT_DBG"] );
629 }
630 } else {
631 // Release version
632 RConf.compiler.parseOptions( project->variables()["QMAKE_CXXFLAGS"] );
633 RConf.compiler.parseOptions( project->variables()["QMAKE_CXXFLAGS_RELEASE"] );
634 RConf.compiler.PreprocessorDefinitions += "QT_NO_DEBUG";
635 RConf.compiler.PreprocessorDefinitions += "NDEBUG";
636 if ( project->isActiveConfig("thread") ) {
637 if ( (projectTarget == Application) || (projectTarget == StaticLib) )
638 RConf.compiler.parseOptions( project->variables()["QMAKE_CXXFLAGS_MT"] );
639 else
640 RConf.compiler.parseOptions( project->variables()["QMAKE_CXXFLAGS_MT_DLL"] );
641 } else {
642 RConf.compiler.parseOptions( project->variables()["QMAKE_CXXFLAGS_MT"] );
643 }
644 }
645
646 // Common for both release and debug
647 if ( project->isActiveConfig("warn_off") )
648 RConf.compiler.parseOptions( project->variables()["QMAKE_CXXFLAGS_WARN_OFF"] );
649 else if ( project->isActiveConfig("warn_on") )
650 RConf.compiler.parseOptions( project->variables()["QMAKE_CXXFLAGS_WARN_ON"] );
651 if ( project->isActiveConfig("windows") )
652 RConf.compiler.PreprocessorDefinitions += project->variables()["MSVCPROJ_WINCONDEF"];
653
654 // Can this be set for ALL configs?
655 // If so, use qmake.conf!
656 if ( projectTarget == SharedLib )
657 RConf.compiler.PreprocessorDefinitions += "_WINDOWS";
658
659 RConf.compiler.PreprocessorDefinitions += project->variables()["DEFINES"];
660 RConf.compiler.PreprocessorDefinitions += project->variables()["PRL_EXPORT_DEFINES"];
661 QStringList::iterator it;
662 for(it=RConf.compiler.PreprocessorDefinitions.begin();
663 it!=RConf.compiler.PreprocessorDefinitions.end();
664 ++it)
665 (*it).replace('\"', "&quot;");
666
667 RConf.compiler.parseOptions( project->variables()["MSVCPROJ_INCPATH"] );
668}
669
670void VcprojGenerator::initLibrarianTool()
671{
672 VCConfiguration &RConf = vcProject.Configuration[0];
673 RConf.librarian.OutputFile = project->first( "DESTDIR" );
674 if( RConf.librarian.OutputFile.isEmpty() )
675 RConf.librarian.OutputFile = ".\\";
676
677 if( !RConf.librarian.OutputFile.endsWith("\\") )
678 RConf.librarian.OutputFile += '\\';
679
680 RConf.librarian.OutputFile += project->first("MSVCPROJ_TARGET");
681}
682
683void VcprojGenerator::initLinkerTool()
684{
685 VCConfiguration &RConf = vcProject.Configuration[0];
686 RConf.linker.parseOptions( project->variables()["MSVCPROJ_LFLAGS"] );
687 RConf.linker.AdditionalDependencies += project->variables()["MSVCPROJ_LIBS"];
688
689 switch ( projectTarget ) {
690 case Application:
691 RConf.linker.OutputFile = project->first( "DESTDIR" );
692 break;
693 case SharedLib:
694 RConf.linker.parseOptions( project->variables()["MSVCPROJ_LIBOPTIONS"] );
695 RConf.linker.OutputFile = project->first( "DESTDIR" );
696 break;
697 case StaticLib: //unhandled - added to remove warnings..
698 break;
699 }
700
701 if( RConf.linker.OutputFile.isEmpty() )
702 RConf.linker.OutputFile = ".\\";
703
704 if( !RConf.linker.OutputFile.endsWith("\\") )
705 RConf.linker.OutputFile += '\\';
706
707 RConf.linker.OutputFile += project->first("MSVCPROJ_TARGET");
708
709 if ( project->isActiveConfig("debug") ){
710 RConf.linker.parseOptions( project->variables()["QMAKE_LFLAGS_DEBUG"] );
711 } else {
712 RConf.linker.parseOptions( project->variables()["QMAKE_LFLAGS_RELEASE"] );
713 }
714
715 if ( project->isActiveConfig("dll") ){
716 RConf.linker.parseOptions( project->variables()["QMAKE_LFLAGS_QT_DLL"] );
717 }
718
719 if ( project->isActiveConfig("console") ){
720 RConf.linker.parseOptions( project->variables()["QMAKE_LFLAGS_CONSOLE"] );
721 } else {
722 RConf.linker.parseOptions( project->variables()["QMAKE_LFLAGS_WINDOWS"] );
723 }
724
725}
726
727void VcprojGenerator::initIDLTool()
728{
729}
730
731void VcprojGenerator::initCustomBuildTool()
732{
733}
734
735void VcprojGenerator::initPreBuildEventTools()
736{
737}
738
739void VcprojGenerator::initPostBuildEventTools()
740{
741 VCConfiguration &RConf = vcProject.Configuration[0];
742 if ( !project->variables()["QMAKE_POST_LINK"].isEmpty() ) {
743 RConf.postBuild.Description = var("QMAKE_POST_LINK");
744 RConf.postBuild.CommandLine = var("QMAKE_POST_LINK");
745 RConf.postBuild.Description.replace(" && ", " &amp;&amp; ");
746 RConf.postBuild.CommandLine.replace(" && ", " &amp;&amp; ");
747 }
748 if ( !project->variables()["MSVCPROJ_COPY_DLL"].isEmpty() ) {
749 if ( !RConf.postBuild.CommandLine.isEmpty() )
750 RConf.postBuild.CommandLine += " &amp;&amp; ";
751 RConf.postBuild.Description += var("MSVCPROJ_COPY_DLL_DESC");
752 RConf.postBuild.CommandLine += var("MSVCPROJ_COPY_DLL");
753 }
754 if( project->isActiveConfig( "activeqt" ) ) {
755 QString name = project->first( "QMAKE_ORIG_TARGET" );
756 QString nameext = project->first( "TARGET" );
757 QString objdir = project->first( "OBJECTS_DIR" );
758 QString idc = project->first( "QMAKE_IDC" );
759
760 RConf.postBuild.Description = "Finalizing ActiveQt server...";
761 if ( !RConf.postBuild.CommandLine.isEmpty() )
762 RConf.postBuild.CommandLine += " &amp;&amp; ";
763
764 if( project->isActiveConfig( "dll" ) ) { // In process
765 RConf.postBuild.CommandLine +=
766 // call idc to generate .idl file from .dll
767 idc + " &quot;$(TargetPath)&quot; -idl " + objdir + name + ".idl -version 1.0 &amp;&amp; " +
768 // call midl to create implementations of the .idl file
769 project->first( "QMAKE_IDL" ) + " /nologo " + objdir + name + ".idl /tlb " + objdir + name + ".tlb &amp;&amp; " +
770 // call idc to replace tlb...
771 idc + " &quot;$(TargetPath)&quot; /tlb " + objdir + name + ".tlb &amp;&amp; " +
772 // register server
773 idc + " &quot;$(TargetPath)&quot; /regserver";
774 } else { // out of process
775 RConf.postBuild.CommandLine =
776 // call application to dump idl
777 "&quot;$(TargetPath)&quot; -dumpidl " + objdir + name + ".idl -version 1.0 &amp;&amp; " +
778 // call midl to create implementations of the .idl file
779 project->first( "QMAKE_IDL" ) + " /nologo " + objdir + name + ".idl /tlb " + objdir + name + ".tlb &amp;&amp; " +
780 // call idc to replace tlb...
781 idc + " &quot;$(TargetPath)&quot; /tlb " + objdir + name + ".tlb &amp;&amp; " +
782 // call app to register
783 "&quot;$(TargetPath)&quot; -regserver";
784 }
785 }
786}
787
788void VcprojGenerator::initPreLinkEventTools()
789{
790}
791
792
793// ------------------------------------------------------------------
794// Helper functions to do proper sorting of the
795// qstringlists, for both flat and non-flat modes.
796inline bool XLessThanY( QString &x, QString &y, bool flat_mode )
797{
798 if ( flat_mode ) {
799 QString subX = x.mid( x.findRev('\\')+1 );
800 QString subY = y.mid( y.findRev('\\')+1 );
801 return QString::compare(subX, subY) < 0;
802 }
803
804 int xPos = 0;
805 int yPos = 0;
806 int xSlashPos;
807 int ySlashPos;
808 for (;;) {
809 xSlashPos = x.find('\\', xPos);
810 ySlashPos = y.find('\\', yPos);
811
812 if (xSlashPos == -1 && ySlashPos != -1) {
813 return false;
814 } else if (xSlashPos != -1 && ySlashPos == -1) {
815 return true;
816 } else if (xSlashPos == -1 /* && yySlashPos == -1 */) {
817 QString subX = x.mid(xPos);
818 QString subY = y.mid(yPos);
819 return QString::compare(subX, subY) < 0;
820 } else {
821 QString subX = x.mid(xPos, xSlashPos - xPos);
822 QString subY = y.mid(yPos, ySlashPos - yPos);
823 int cmp = QString::compare(subX, subY);
824 if (cmp != 0)
825 return cmp < 0;
826 }
827 xPos = xSlashPos + 1;
828 yPos = ySlashPos + 1;
829 }
830 return false;
831}
832void nonflatDir_BubbleSort( QStringList& list, bool flat_mode )
833{
834 QStringList::Iterator b = list.begin();
835 QStringList::Iterator e = list.end();
836 QStringList::Iterator last = e;
837 --last; // goto last
838 if ( last == b ) // shortcut
839 return;
840 while( b != last ) {// sort them
841 bool swapped = FALSE;
842 QStringList::Iterator swap_pos = b;
843 QStringList::Iterator x = e;
844 QStringList::Iterator y = x;
845 --y;
846 QString swap_str;
847 do {
848 --x;
849 --y;
850 if ( XLessThanY(*x,*y, flat_mode) ) {
851 swapped = TRUE;
852 swap_str = (*x); // Swap -------
853 (*x) = (*y);
854 (*y) = swap_str; // ------------
855 swap_pos = y;
856 }
857 } while( y != b );
858 if ( !swapped )
859 return;
860 b = swap_pos;
861 ++b;
862 }
863}
864// ------------------------------------------------------------------
865
866void VcprojGenerator::initSourceFiles()
867{
868 vcProject.SourceFiles.flat_files = project->isActiveConfig("flat");
869 vcProject.SourceFiles.Name = "Source Files";
870 vcProject.SourceFiles.Filter = "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat";
871 vcProject.SourceFiles.Files += project->variables()["SOURCES"];
872 nonflatDir_BubbleSort( vcProject.SourceFiles.Files,
873 vcProject.SourceFiles.flat_files );
874 vcProject.SourceFiles.Project = this;
875 vcProject.SourceFiles.Config = &(vcProject.Configuration);
876 vcProject.SourceFiles.CustomBuild = none;
877}
878
879void VcprojGenerator::initHeaderFiles()
880{
881 vcProject.HeaderFiles.flat_files = project->isActiveConfig("flat");
882 vcProject.HeaderFiles.Name = "Header Files";
883 vcProject.HeaderFiles.Filter = "h;hpp;hxx;hm;inl";
884 vcProject.HeaderFiles.Files += project->variables()["HEADERS"];
885 if (usePCH) { // Generated PCH cpp file
886 if (!vcProject.HeaderFiles.Files.contains(precompH))
887 vcProject.HeaderFiles.Files += precompH;
888 }
889 nonflatDir_BubbleSort( vcProject.HeaderFiles.Files,
890 vcProject.HeaderFiles.flat_files );
891 vcProject.HeaderFiles.Project = this;
892 vcProject.HeaderFiles.Config = &(vcProject.Configuration);
893 vcProject.HeaderFiles.CustomBuild = moc;
894}
895
896void VcprojGenerator::initMOCFiles()
897{
898 vcProject.MOCFiles.flat_files = project->isActiveConfig("flat");
899 vcProject.MOCFiles.Name = "Generated MOC Files";
900 vcProject.MOCFiles.Filter = "cpp;c;cxx;moc";
901 vcProject.MOCFiles.Files += project->variables()["SRCMOC"];
902 nonflatDir_BubbleSort( vcProject.MOCFiles.Files,
903 vcProject.MOCFiles.flat_files );
904 vcProject.MOCFiles.Project = this;
905 vcProject.MOCFiles.Config = &(vcProject.Configuration);
906 vcProject.MOCFiles.CustomBuild = moc;
907}
908
909void VcprojGenerator::initUICFiles()
910{
911 vcProject.UICFiles.flat_files = project->isActiveConfig("flat");
912 vcProject.UICFiles.Name = "Generated Form Files";
913 vcProject.UICFiles.Filter = "cpp;c;cxx;h;hpp;hxx;";
914 vcProject.UICFiles.Project = this;
915 vcProject.UICFiles.Files += project->variables()["UICDECLS"];
916 vcProject.UICFiles.Files += project->variables()["UICIMPLS"];
917 nonflatDir_BubbleSort( vcProject.UICFiles.Files,
918 vcProject.UICFiles.flat_files );
919 vcProject.UICFiles.Config = &(vcProject.Configuration);
920 vcProject.UICFiles.CustomBuild = none;
921}
922
923void VcprojGenerator::initFormsFiles()
924{
925 vcProject.FormFiles.flat_files = project->isActiveConfig("flat");
926 vcProject.FormFiles.Name = "Forms";
927 vcProject.FormFiles.ParseFiles = _False;
928 vcProject.FormFiles.Filter = "ui";
929 vcProject.FormFiles.Files += project->variables()["FORMS"];
930 nonflatDir_BubbleSort( vcProject.FormFiles.Files,
931 vcProject.FormFiles.flat_files );
932 vcProject.FormFiles.Project = this;
933 vcProject.FormFiles.Config = &(vcProject.Configuration);
934 vcProject.FormFiles.CustomBuild = uic;
935}
936
937void VcprojGenerator::initTranslationFiles()
938{
939 vcProject.TranslationFiles.flat_files = project->isActiveConfig("flat");
940 vcProject.TranslationFiles.Name = "Translations Files";
941 vcProject.TranslationFiles.ParseFiles = _False;
942 vcProject.TranslationFiles.Filter = "ts";
943 vcProject.TranslationFiles.Files += project->variables()["TRANSLATIONS"];
944 nonflatDir_BubbleSort( vcProject.TranslationFiles.Files,
945 vcProject.TranslationFiles.flat_files );
946 vcProject.TranslationFiles.Project = this;
947 vcProject.TranslationFiles.Config = &(vcProject.Configuration);
948 vcProject.TranslationFiles.CustomBuild = none;
949}
950
951void VcprojGenerator::initLexYaccFiles()
952{
953 vcProject.LexYaccFiles.flat_files = project->isActiveConfig("flat");
954 vcProject.LexYaccFiles.Name = "Lex / Yacc Files";
955 vcProject.LexYaccFiles.ParseFiles = _False;
956 vcProject.LexYaccFiles.Filter = "l;y";
957 vcProject.LexYaccFiles.Files += project->variables()["LEXSOURCES"];
958 vcProject.LexYaccFiles.Files += project->variables()["YACCSOURCES"];
959 nonflatDir_BubbleSort( vcProject.LexYaccFiles.Files,
960 vcProject.LexYaccFiles.flat_files );
961 vcProject.LexYaccFiles.Project = this;
962 vcProject.LexYaccFiles.Config = &(vcProject.Configuration);
963 vcProject.LexYaccFiles.CustomBuild = lexyacc;
964}
965
966void VcprojGenerator::initResourceFiles()
967{
968 vcProject.ResourceFiles.flat_files = project->isActiveConfig("flat");
969 vcProject.ResourceFiles.Name = "Resources";
970 vcProject.ResourceFiles.ParseFiles = _False;
971 vcProject.ResourceFiles.Filter = "cpp;ico;png;jpg;jpeg;gif;xpm;bmp;rc;ts";
972 vcProject.ResourceFiles.Files += project->variables()["RC_FILE"];
973 vcProject.ResourceFiles.Files += project->variables()["QMAKE_IMAGE_COLLECTION"];
974 vcProject.ResourceFiles.Files += project->variables()["IMAGES"];
975 vcProject.ResourceFiles.Files += project->variables()["IDLSOURCES"];
976 nonflatDir_BubbleSort( vcProject.ResourceFiles.Files,
977 vcProject.ResourceFiles.flat_files );
978 vcProject.ResourceFiles.Project = this;
979 vcProject.ResourceFiles.Config = &(vcProject.Configuration);
980 vcProject.ResourceFiles.CustomBuild = resource;
981}
982
983/* \internal
984 Sets up all needed variables from the environment and all the different caches and .conf files
985*/
986
987void VcprojGenerator::initOld()
988{
989 if( init_flag )
990 return;
991
992 init_flag = TRUE;
993 QStringList::Iterator it;
994
995 if ( project->isActiveConfig("stl") ) {
996 project->variables()["QMAKE_CFLAGS"] += project->variables()["QMAKE_CFLAGS_STL_ON"];
997 project->variables()["QMAKE_CXXFLAGS"] += project->variables()["QMAKE_CXXFLAGS_STL_ON"];
998 } else {
999 project->variables()["QMAKE_CFLAGS"] += project->variables()["QMAKE_CFLAGS_STL_OFF"];
1000 project->variables()["QMAKE_CXXFLAGS"] += project->variables()["QMAKE_CXXFLAGS_STL_OFF"];
1001 }
1002 if ( project->isActiveConfig("exceptions") ) {
1003 project->variables()["QMAKE_CFLAGS"] += project->variables()["QMAKE_CFLAGS_EXCEPTIONS_ON"];
1004 project->variables()["QMAKE_CXXFLAGS"] += project->variables()["QMAKE_CXXFLAGS_EXCEPTIONS_ON"];
1005 } else {
1006 project->variables()["QMAKE_CFLAGS"] += project->variables()["QMAKE_CFLAGS_EXCEPTIONS_OFF"];
1007 project->variables()["QMAKE_CXXFLAGS"] += project->variables()["QMAKE_CXXFLAGS_EXCEPTIONS_OFF"];
1008 }
1009 if ( project->isActiveConfig("rtti") ) {
1010 project->variables()["QMAKE_CFLAGS"] += project->variables()["QMAKE_CFLAGS_RTTI_ON"];
1011 project->variables()["QMAKE_CXXFLAGS"] += project->variables()["QMAKE_CXXFLAGS_RTTI_ON"];
1012 } else {
1013 project->variables()["QMAKE_CFLAGS"] += project->variables()["QMAKE_CFLAGS_RTTI_OFF"];
1014 project->variables()["QMAKE_CXXFLAGS"] += project->variables()["QMAKE_CXXFLAGS_RTTI_OFF"];
1015 }
1016
1017 // this should probably not be here, but I'm using it to wrap the .t files
1018 if(project->first("TEMPLATE") == "vcapp" )
1019 project->variables()["QMAKE_APP_FLAG"].append("1");
1020 else if(project->first("TEMPLATE") == "vclib")
1021 project->variables()["QMAKE_LIB_FLAG"].append("1");
1022 if ( project->variables()["QMAKESPEC"].isEmpty() )
1023 project->variables()["QMAKESPEC"].append( getenv("QMAKESPEC") );
1024
1025 bool is_qt =
1026 ( project->first("TARGET") == "qt"QTDLL_POSTFIX ||
1027 project->first("TARGET") == "qt-mt"QTDLL_POSTFIX );
1028
1029 QStringList &configs = project->variables()["CONFIG"];
1030
1031 if ( project->isActiveConfig( "shared" ) )
1032 project->variables()["DEFINES"].append( "QT_DLL" );
1033
1034 if ( project->isActiveConfig( "qt_dll" ) &&
1035 configs.findIndex("qt") == -1 )
1036 configs.append("qt");
1037
1038 if ( project->isActiveConfig( "qt" ) ) {
1039 if ( project->isActiveConfig( "plugin" ) ) {
1040 project->variables()["CONFIG"].append( "dll" );
1041 project->variables()["DEFINES"].append( "QT_PLUGIN" );
1042 }
1043 if ( ( project->variables()["DEFINES"].findIndex( "QT_NODLL" ) == -1 ) &&
1044 (( project->variables()["DEFINES"].findIndex( "QT_MAKEDLL" ) != -1 ||
1045 project->variables()["DEFINES"].findIndex( "QT_DLL" ) != -1 ) ||
1046 ( getenv( "QT_DLL" ) && !getenv( "QT_NODLL" ))) ) {
1047 project->variables()["QMAKE_QT_DLL"].append( "1" );
1048 if ( is_qt && !project->variables()["QMAKE_LIB_FLAG"].isEmpty() )
1049 project->variables()["CONFIG"].append( "dll" );
1050 }
1051 }
1052
1053 // If we are a dll, then we cannot be a staticlib at the same time...
1054 if ( project->isActiveConfig( "dll" ) || !project->variables()["QMAKE_APP_FLAG"].isEmpty() ) {
1055 project->variables()["CONFIG"].remove( "staticlib" );
1056 project->variables()["QMAKE_APP_OR_DLL"].append( "1" );
1057 } else {
1058 project->variables()["CONFIG"].append( "staticlib" );
1059 }
1060
1061 // If we need 'qt' and/or 'opengl', then we need windows and not console
1062 if ( project->isActiveConfig( "qt" ) || project->isActiveConfig( "opengl" ) ) {
1063 project->variables()["CONFIG"].append( "windows" );
1064 }
1065
1066 // Decode version, and add it to $$MSVCPROJ_VERSION --------------
1067 if ( !project->variables()["VERSION"].isEmpty() ) {
1068 QString version = project->variables()["VERSION"][0];
1069 int firstDot = version.find( "." );
1070 QString major = version.left( firstDot );
1071 QString minor = version.right( version.length() - firstDot - 1 );
1072 minor.replace( QRegExp( "\\." ), "" );
1073 project->variables()["MSVCPROJ_VERSION"].append( "/VERSION:" + major + "." + minor );
1074 }
1075
1076 // QT ------------------------------------------------------------
1077 if ( project->isActiveConfig("qt") ) {
1078 project->variables()["CONFIG"].append("moc");
1079 project->variables()["INCLUDEPATH"] += project->variables()["QMAKE_INCDIR_QT"];
1080 project->variables()["QMAKE_LIBDIR"] += project->variables()["QMAKE_LIBDIR_QT"];
1081
1082 if ( is_qt && !project->variables()["QMAKE_LIB_FLAG"].isEmpty() ) {
1083 if ( !project->variables()["QMAKE_QT_DLL"].isEmpty() ) {
1084 project->variables()["DEFINES"].append("QT_MAKEDLL");
1085 project->variables()["QMAKE_LFLAGS"].append("/BASE:0x39D00000");
1086 }
1087 } else {
1088 if(project->isActiveConfig("thread"))
1089 project->variables()["QMAKE_LIBS"] += project->variables()["QMAKE_LIBS_QT_THREAD"];
1090 else
1091 project->variables()["QMAKE_LIBS"] += project->variables()["QMAKE_LIBS_QT"];
1092 if ( !project->variables()["QMAKE_QT_DLL"].isEmpty() ) {
1093 int hver = findHighestVersion(project->first("QMAKE_LIBDIR_QT"), "qt");
1094 if( hver==-1 ) {
1095 hver = findHighestVersion( project->first("QMAKE_LIBDIR_QT"), "qt-mt" );
1096 }
1097
1098 if(hver != -1) {
1099 QString ver;
1100 ver.sprintf("qt%s" QTDLL_POSTFIX "%d.lib", (project->isActiveConfig("thread") ? "-mt" : ""), hver);
1101 QStringList &libs = project->variables()["QMAKE_LIBS"];
1102 for(QStringList::Iterator libit = libs.begin(); libit != libs.end(); ++libit)
1103 (*libit).replace(QRegExp("qt(-mt)?\\.lib"), ver);
1104 }
1105 }
1106 if ( project->isActiveConfig( "activeqt" ) ) {
1107 project->variables().remove("QMAKE_LIBS_QT_ENTRY");
1108 project->variables()["QMAKE_LIBS_QT_ENTRY"] = "qaxserver.lib";
1109 if ( project->isActiveConfig( "dll" ) ) {
1110 project->variables()["QMAKE_LIBS"] += project->variables()["QMAKE_LIBS_QT_ENTRY"];
1111 }
1112 }
1113 if ( !project->isActiveConfig("dll") && !project->isActiveConfig("plugin") ) {
1114 project->variables()["QMAKE_LIBS"] +=project->variables()["QMAKE_LIBS_QT_ENTRY"];
1115 }
1116 }
1117 }
1118
1119 // Set target directories ----------------------------------------
1120 // if ( !project->first("OBJECTS_DIR").isEmpty() )
1121 //project->variables()["MSVCPROJ_OBJECTSDIR"] = project->first("OBJECTS_DIR");
1122 // else
1123 //project->variables()["MSVCPROJ_OBJECTSDIR"] = project->isActiveConfig( "release" )?"Release":"Debug";
1124 // if ( !project->first("DESTDIR").isEmpty() )
1125 //project->variables()["MSVCPROJ_TARGETDIR"] = project->first("DESTDIR");
1126 // else
1127 //project->variables()["MSVCPROJ_TARGETDIR"] = project->isActiveConfig( "release" )?"Release":"Debug";
1128
1129 // OPENGL --------------------------------------------------------
1130 if ( project->isActiveConfig("opengl") ) {
1131 project->variables()["QMAKE_LIBS"] += project->variables()["QMAKE_LIBS_OPENGL"];
1132 project->variables()["QMAKE_LFLAGS"] += project->variables()["QMAKE_LFLAGS_OPENGL"];
1133 }
1134
1135 // THREAD --------------------------------------------------------
1136 if ( project->isActiveConfig("thread") ) {
1137 if(project->isActiveConfig("qt"))
1138 project->variables()[is_qt ? "PRL_EXPORT_DEFINES" : "DEFINES"].append("QT_THREAD_SUPPORT" );
1139 if ( !project->variables()["DEFINES"].contains("QT_DLL") && is_qt
1140 && project->first("TARGET") != "qtmain" )
1141 project->variables()["QMAKE_LFLAGS"].append("/NODEFAULTLIB:libc");
1142 }
1143
1144 // ACCESSIBILITY -------------------------------------------------
1145 if(project->isActiveConfig("qt")) {
1146 if ( project->isActiveConfig("accessibility" ) )
1147 project->variables()[is_qt ? "PRL_EXPORT_DEFINES" : "DEFINES"].append("QT_ACCESSIBILITY_SUPPORT");
1148 if ( project->isActiveConfig("tablet") )
1149 project->variables()[is_qt ? "PRL_EXPORT_DEFINES" : "DEFINES"].append("QT_TABLET_SUPPORT");
1150 }
1151
1152 // DLL -----------------------------------------------------------
1153 if ( project->isActiveConfig("dll") ) {
1154 if ( !project->variables()["QMAKE_LIB_FLAG"].isEmpty() ) {
1155 QString ver_xyz(project->first("VERSION"));
1156 ver_xyz.replace(QRegExp("\\."), "");
1157 project->variables()["TARGET_EXT"].append(ver_xyz + ".dll");
1158 } else {
1159 project->variables()["TARGET_EXT"].append(".dll");
1160 }
1161 }
1162 // EXE / LIB -----------------------------------------------------
1163 else {
1164 if ( !project->variables()["QMAKE_APP_FLAG"].isEmpty() )
1165 project->variables()["TARGET_EXT"].append(".exe");
1166 else
1167 project->variables()["TARGET_EXT"].append(".lib");
1168 }
1169
1170 project->variables()["MSVCPROJ_VER"] = "7.00";
1171 project->variables()["MSVCPROJ_DEBUG_OPT"] = "/GZ /ZI";
1172
1173 // INCREMENTAL:NO ------------------------------------------------
1174 if(!project->isActiveConfig("incremental")) {
1175 project->variables()["QMAKE_LFLAGS"].append(QString("/INCREMENTAL:no"));
1176 if ( is_qt )
1177 project->variables()["MSVCPROJ_DEBUG_OPT"] = "/GZ /Zi";
1178 }
1179
1180 // MOC -----------------------------------------------------------
1181 if ( project->isActiveConfig("moc") )
1182 setMocAware(TRUE);
1183
1184 // /VERSION:x.yz -------------------------------------------------
1185 if ( !project->variables()["VERSION"].isEmpty() ) {
1186 QString version = project->variables()["VERSION"][0];
1187 int firstDot = version.find( "." );
1188 QString major = version.left( firstDot );
1189 QString minor = version.right( version.length() - firstDot - 1 );
1190 minor.replace( ".", "" );
1191 project->variables()["QMAKE_LFLAGS"].append( "/VERSION:" + major + "." + minor );
1192 }
1193
1194 project->variables()["QMAKE_LIBS"] += project->variables()["LIBS"];
1195 // Update -lname to name.lib, and -Ldir to
1196 QStringList &libList = project->variables()["QMAKE_LIBS"];
1197 for( it = libList.begin(); it != libList.end(); ) {
1198 QString s = *it;
1199 if( s.startsWith( "-l" ) ) {
1200 it = libList.remove( it );
1201 it = libList.insert( it, s.mid( 2 ) + ".lib" );
1202 } else if( s.startsWith( "-L" ) ) {
1203 it = libList.remove( it );
1204 } else {
1205 it++;
1206 }
1207 }
1208
1209 // Run through all variables containing filepaths, and -----------
1210 // slash-slosh them correctly depending on current OS -----------
1211 project->variables()["QMAKE_FILETAGS"] += QStringList::split(' ', "HEADERS SOURCES DEF_FILE RC_FILE TARGET QMAKE_LIBS DESTDIR DLLDESTDIR INCLUDEPATH");
1212 QStringList &l = project->variables()["QMAKE_FILETAGS"];
1213 for(it = l.begin(); it != l.end(); ++it) {
1214 QStringList &gdmf = project->variables()[(*it)];
1215 for(QStringList::Iterator inner = gdmf.begin(); inner != gdmf.end(); ++inner)
1216 (*inner) = Option::fixPathToTargetOS((*inner), FALSE);
1217 }
1218
1219 // Get filename w/o extention -----------------------------------
1220 QString msvcproj_project = "";
1221 QString targetfilename = "";
1222 if ( project->variables()["TARGET"].count() ) {
1223 msvcproj_project = project->variables()["TARGET"].first();
1224 targetfilename = msvcproj_project;
1225 }
1226
1227 // Save filename w/o extention in $$QMAKE_ORIG_TARGET ------------
1228 project->variables()["QMAKE_ORIG_TARGET"] = project->variables()["TARGET"];
1229
1230 // TARGET (add extention to $$TARGET)
1231 //project->variables()["MSVCPROJ_DEFINES"].append(varGlue(".first() += project->first("TARGET_EXT");
1232
1233 // Init base class too -------------------------------------------
1234 MakefileGenerator::init();
1235
1236
1237 if ( msvcproj_project.isEmpty() )
1238 msvcproj_project = Option::output.name();
1239
1240 msvcproj_project = msvcproj_project.right( msvcproj_project.length() - msvcproj_project.findRev( "\\" ) - 1 );
1241 msvcproj_project = msvcproj_project.left( msvcproj_project.findRev( "." ) );
1242 msvcproj_project.replace(QRegExp("-"), "");
1243
1244 project->variables()["MSVCPROJ_PROJECT"].append(msvcproj_project);
1245 QStringList &proj = project->variables()["MSVCPROJ_PROJECT"];
1246
1247 for(it = proj.begin(); it != proj.end(); ++it)
1248 (*it).replace(QRegExp("\\.[a-zA-Z0-9_]*$"), "");
1249
1250 // SUBSYSTEM -----------------------------------------------------
1251 if ( !project->variables()["QMAKE_APP_FLAG"].isEmpty() ) {
1252 project->variables()["MSVCPROJ_TEMPLATE"].append("win32app" + project->first( "VCPROJ_EXTENSION" ) );
1253 if ( project->isActiveConfig("console") ) {
1254 project->variables()["MSVCPROJ_CONSOLE"].append("CONSOLE");
1255 project->variables()["MSVCPROJ_WINCONDEF"].append("_CONSOLE");
1256 project->variables()["MSVCPROJ_VCPROJTYPE"].append("0x0103");
1257 project->variables()["MSVCPROJ_SUBSYSTEM"].append("CONSOLE");
1258 } else {
1259 project->variables()["MSVCPROJ_CONSOLE"].clear();
1260 project->variables()["MSVCPROJ_WINCONDEF"].append("_WINDOWS");
1261 project->variables()["MSVCPROJ_VCPROJTYPE"].append("0x0101");
1262 project->variables()["MSVCPROJ_SUBSYSTEM"].append("WINDOWS");
1263 }
1264 } else {
1265 if ( project->isActiveConfig("dll") ) {
1266 project->variables()["MSVCPROJ_TEMPLATE"].append("win32dll" + project->first( "VCPROJ_EXTENSION" ) );
1267 } else {
1268 project->variables()["MSVCPROJ_TEMPLATE"].append("win32lib" + project->first( "VCPROJ_EXTENSION" ) );
1269 }
1270 }
1271
1272 // $$QMAKE.. -> $$MSVCPROJ.. -------------------------------------
1273 project->variables()["MSVCPROJ_LIBS"] += project->variables()["QMAKE_LIBS"];
1274 project->variables()["MSVCPROJ_LIBS"] += project->variables()["QMAKE_LIBS_WINDOWS"];
1275 project->variables()["MSVCPROJ_LFLAGS" ] += project->variables()["QMAKE_LFLAGS"];
1276 if ( !project->variables()["QMAKE_LIBDIR"].isEmpty() ) {
1277 QStringList strl = project->variables()["QMAKE_LIBDIR"];
1278 QStringList::iterator stri;
1279 for ( stri = strl.begin(); stri != strl.end(); ++stri ) {
1280 if ( !(*stri).startsWith("/LIBPATH:") )
1281 (*stri).prepend( "/LIBPATH:" );
1282 }
1283 project->variables()["MSVCPROJ_LFLAGS"] += strl;
1284 }
1285 project->variables()["MSVCPROJ_CXXFLAGS" ] += project->variables()["QMAKE_CXXFLAGS"];
1286 // We don't use this... Direct manipulation of compiler object
1287 //project->variables()["MSVCPROJ_DEFINES"].append(varGlue("DEFINES","/D ","" " /D ",""));
1288 //project->variables()["MSVCPROJ_DEFINES"].append(varGlue("PRL_EXPORT_DEFINES","/D ","" " /D ",""));
1289 QStringList &incs = project->variables()["INCLUDEPATH"];
1290 for(QStringList::Iterator incit = incs.begin(); incit != incs.end(); ++incit) {
1291 QString inc = (*incit);
1292 inc.replace(QRegExp("\""), "");
1293 project->variables()["MSVCPROJ_INCPATH"].append("/I" + inc );
1294 }
1295 project->variables()["MSVCPROJ_INCPATH"].append("/I" + specdir());
1296
1297 QString dest;
1298 project->variables()["MSVCPROJ_TARGET"] = project->first("TARGET");
1299 Option::fixPathToTargetOS(project->first("TARGET"));
1300 dest = project->first("TARGET") + project->first( "TARGET_EXT" );
1301 if ( project->first("TARGET").startsWith("$(QTDIR)") )
1302 dest.replace( QRegExp("\\$\\(QTDIR\\)"), getenv("QTDIR") );
1303 project->variables()["MSVCPROJ_TARGET"] = dest;
1304
1305 // DLL COPY ------------------------------------------------------
1306 if ( project->isActiveConfig("dll") && !project->variables()["DLLDESTDIR"].isEmpty() ) {
1307 QStringList dlldirs = project->variables()["DLLDESTDIR"];
1308 QString copydll("");
1309 QStringList::Iterator dlldir;
1310 for ( dlldir = dlldirs.begin(); dlldir != dlldirs.end(); ++dlldir ) {
1311 if ( !copydll.isEmpty() )
1312 copydll += " && ";
1313 copydll += "copy &quot;$(TargetPath)&quot; &quot;" + *dlldir + "&quot;";
1314 }
1315
1316 QString deststr( "Copy " + dest + " to " );
1317 for ( dlldir = dlldirs.begin(); dlldir != dlldirs.end(); ) {
1318 deststr += *dlldir;
1319 ++dlldir;
1320 if ( dlldir != dlldirs.end() )
1321 deststr += ", ";
1322 }
1323
1324 project->variables()["MSVCPROJ_COPY_DLL"].append( copydll );
1325 project->variables()["MSVCPROJ_COPY_DLL_DESC"].append( deststr );
1326 }
1327
1328 // ACTIVEQT ------------------------------------------------------
1329 if ( project->isActiveConfig("activeqt") ) {
1330 QString idl = project->variables()["QMAKE_IDL"].first();
1331 QString idc = project->variables()["QMAKE_IDC"].first();
1332 QString version = project->variables()["VERSION"].first();
1333 if ( version.isEmpty() )
1334 version = "1.0";
1335
1336 QString objdir = project->first( "OBJECTS_DIR" );
1337 project->variables()["MSVCPROJ_IDLSOURCES"].append( objdir + targetfilename + ".idl" );
1338 if ( project->isActiveConfig( "dll" ) ) {
1339 QString regcmd = "# Begin Special Build Tool\n"
1340 "TargetPath=" + targetfilename + "\n"
1341 "SOURCE=$(InputPath)\n"
1342 "PostBuild_Desc=Finalizing ActiveQt server...\n"
1343 "PostBuild_Cmds=" +
1344 idc + " %1 -idl " + objdir + targetfilename + ".idl -version " + version +
1345 "\t" + idl + " /nologo " + objdir + targetfilename + ".idl /tlb " + objdir + targetfilename + ".tlb" +
1346 "\t" + idc + " %1 /tlb " + objdir + targetfilename + ".tlb"
1347 "\tregsvr32 /s %1\n"
1348 "# End Special Build Tool";
1349
1350 QString executable = project->variables()["MSVCPROJ_TARGETDIRREL"].first() + "\\" + project->variables()["TARGET"].first();
1351 project->variables()["MSVCPROJ_COPY_DLL_REL"].append( regcmd.arg(executable).arg(executable).arg(executable) );
1352
1353 executable = project->variables()["MSVCPROJ_TARGETDIRDEB"].first() + "\\" + project->variables()["TARGET"].first();
1354 project->variables()["MSVCPROJ_COPY_DLL_DBG"].append( regcmd.arg(executable).arg(executable).arg(executable) );
1355 } else {
1356 QString regcmd = "# Begin Special Build Tool\n"
1357 "TargetPath=" + targetfilename + "\n"
1358 "SOURCE=$(InputPath)\n"
1359 "PostBuild_Desc=Finalizing ActiveQt server...\n"
1360 "PostBuild_Cmds="
1361 "%1 -dumpidl " + objdir + targetfilename + ".idl -version " + version +
1362 "\t" + idl + " /nologo " + objdir + targetfilename + ".idl /tlb " + objdir + targetfilename + ".tlb"
1363 "\t" + idc + " %1 /tlb " + objdir + targetfilename + ".tlb"
1364 "\t%1 -regserver\n"
1365 "# End Special Build Tool";
1366
1367 QString executable = project->variables()["MSVCPROJ_TARGETDIRREL"].first() + "\\" + project->variables()["TARGET"].first();
1368 project->variables()["MSVCPROJ_REGSVR_REL"].append( regcmd.arg(executable).arg(executable).arg(executable) );
1369
1370 executable = project->variables()["MSVCPROJ_TARGETDIRDEB"].first() + "\\" + project->variables()["TARGET"].first();
1371 project->variables()["MSVCPROJ_REGSVR_DBG"].append( regcmd.arg(executable).arg(executable).arg(executable) );
1372 }
1373 }
1374
1375 if ( !project->variables()["DEF_FILE"].isEmpty() )
1376 project->variables()["MSVCPROJ_LFLAGS"].append("/DEF:"+project->first("DEF_FILE"));
1377
1378 // FORMS ---------------------------------------------------------
1379 QStringList &list = project->variables()["FORMS"];
1380 for( it = list.begin(); it != list.end(); ++it ) {
1381 if ( QFile::exists( *it + ".h" ) )
1382 project->variables()["SOURCES"].append( *it + ".h" );
1383 }
1384
1385 project->variables()["QMAKE_INTERNAL_PRL_LIBS"] << "MSVCPROJ_LFLAGS" << "MSVCPROJ_LIBS";
1386
1387 // Verbose output if "-d -d"...
1388 outputVariables();
1389}
1390
1391// ------------------------------------------------------------------------------------------------
1392// ------------------------------------------------------------------------------------------------
1393
1394bool VcprojGenerator::openOutput(QFile &file) const
1395{
1396 QString outdir;
1397 if(!file.name().isEmpty()) {
1398 QFileInfo fi(file);
1399 if(fi.isDir())
1400 outdir = file.name() + QDir::separator();
1401 }
1402 if(!outdir.isEmpty() || file.name().isEmpty()) {
1403 QString ext = project->first("VCPROJ_EXTENSION");
1404 if(project->first("TEMPLATE") == "vcsubdirs")
1405 ext = project->first("VCSOLUTION_EXTENSION");
1406 file.setName(outdir + project->first("TARGET") + ext);
1407 }
1408 if(QDir::isRelativePath(file.name())) {
1409 file.setName( Option::fixPathToLocalOS(QDir::currentDirPath() + Option::dir_sep + fixFilename(file.name())) );
1410 }
1411 return Win32MakefileGenerator::openOutput(file);
1412}
1413
1414QString VcprojGenerator::fixFilename(QString ofile) const
1415{
1416 int slashfind = ofile.findRev('\\');
1417 if (slashfind == -1) {
1418 ofile = ofile.replace('-', '_');
1419 } else {
1420 int hypenfind = ofile.find('-', slashfind);
1421 while (hypenfind != -1 && slashfind < hypenfind) {
1422 ofile = ofile.replace(hypenfind, 1, '_');
1423 hypenfind = ofile.find('-', hypenfind + 1);
1424 }
1425 }
1426 return ofile;
1427}
1428
1429QString VcprojGenerator::findTemplate(QString file)
1430{
1431 QString ret;
1432 if(!QFile::exists((ret = file)) &&
1433 !QFile::exists((ret = QString(Option::mkfile::qmakespec + "/" + file))) &&
1434 !QFile::exists((ret = QString(getenv("QTDIR")) + "/mkspecs/win32-msvc.net/" + file)) &&
1435 !QFile::exists((ret = (QString(getenv("HOME")) + "/.tmake/" + file))))
1436 return "";
1437 debug_msg(1, "Generator: MSVC.NET: Found template \'%s\'", ret.latin1() );
1438 return ret;
1439}
1440
1441
1442void VcprojGenerator::processPrlVariable(const QString &var, const QStringList &l)
1443{
1444 if(var == "QMAKE_PRL_DEFINES") {
1445 QStringList &out = project->variables()["MSVCPROJ_DEFINES"];
1446 for(QStringList::ConstIterator it = l.begin(); it != l.end(); ++it) {
1447 if(out.findIndex((*it)) == -1)
1448 out.append((" /D " + *it ));
1449 }
1450 } else {
1451 MakefileGenerator::processPrlVariable(var, l);
1452 }
1453}
1454
1455void VcprojGenerator::outputVariables()
1456{
1457#if 0
1458 qDebug( "Generator: MSVC.NET: List of current variables:" );
1459 for ( QMap<QString, QStringList>::ConstIterator it = project->variables().begin(); it != project->variables().end(); ++it) {
1460 qDebug( "Generator: MSVC.NET: %s => %s", it.key().latin1(), it.data().join(" | ").latin1() );
1461 }
1462#endif
1463}
Note: See TracBrowser for help on using the repository browser.