2011-04-27 10:05:43 +00:00
/****************************************************************************
* *
2015-01-28 08:44:43 +00:00
* * Copyright ( C ) 2015 The Qt Company Ltd .
* * Contact : http : //www.qt.io/licensing/
2011-04-27 10:05:43 +00:00
* *
* * This file is part of the qmake application of the Qt Toolkit .
* *
2014-08-21 13:51:22 +00:00
* * $ QT_BEGIN_LICENSE : LGPL21 $
2012-09-19 12:28:29 +00:00
* * Commercial License Usage
* * Licensees holding valid commercial Qt licenses may use this file in
* * accordance with the commercial license agreement provided with the
* * Software or , alternatively , in accordance with the terms contained in
2015-01-28 08:44:43 +00:00
* * a written agreement between you and The Qt Company . For licensing terms
* * and conditions see http : //www.qt.io/terms-conditions. For further
* * information use the contact form at http : //www.qt.io/contact-us.
2012-09-19 12:28:29 +00:00
* *
2011-04-27 10:05:43 +00:00
* * GNU Lesser General Public License Usage
2012-09-19 12:28:29 +00:00
* * Alternatively , this file may be used under the terms of the GNU Lesser
2014-08-21 13:51:22 +00:00
* * General Public License version 2.1 or version 3 as published by the Free
* * Software Foundation and appearing in the file LICENSE . LGPLv21 and
* * LICENSE . LGPLv3 included in the packaging of this file . Please review the
* * following information to ensure the GNU Lesser General Public License
* * requirements will be met : https : //www.gnu.org/licenses/lgpl.html and
* * http : //www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
2012-09-19 12:28:29 +00:00
* *
2015-01-28 08:44:43 +00:00
* * As a special exception , The Qt Company gives you certain additional
* * rights . These rights are described in The Qt Company LGPL Exception
2011-04-27 10:05:43 +00:00
* * version 1.1 , included in the file LGPL_EXCEPTION . txt in this package .
* *
* * $ QT_END_LICENSE $
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
# include "msvc_vcproj.h"
# include "option.h"
# include "xmloutput.h"
# include <qdir.h>
# include <qdiriterator.h>
# include <qcryptographichash.h>
# include <qregexp.h>
# include <qhash.h>
# include <quuid.h>
# include <stdlib.h>
2012-04-25 14:55:28 +00:00
# include <qlinkedlist.h>
2011-04-27 10:05:43 +00:00
//#define DEBUG_SOLUTION_GEN
QT_BEGIN_NAMESPACE
// Filter GUIDs (Do NOT change these!) ------------------------------
const char _GUIDSourceFiles [ ] = " {4FC737F1-C7A5-4376-A066-2A32D752A2FF} " ;
const char _GUIDHeaderFiles [ ] = " {93995380-89BD-4b04-88EB-625FBE52EBFB} " ;
const char _GUIDGeneratedFiles [ ] = " {71ED8ED8-ACB9-4CE9-BBE1-E00B30144E11} " ;
const char _GUIDResourceFiles [ ] = " {D9D6E242-F8AF-46E4-B9FD-80ECBC20BA3E} " ;
const char _GUIDLexYaccFiles [ ] = " {E12AE0D2-192F-4d59-BD23-7D3FA58D3183} " ;
const char _GUIDTranslationFiles [ ] = " {639EADAA-A684-42e4-A9AD-28FC9BCB8F7C} " ;
const char _GUIDFormFiles [ ] = " {99349809-55BA-4b9d-BF79-8FDBB0286EB3} " ;
const char _GUIDExtraCompilerFiles [ ] = " {E0D8C965-CC5F-43d7-AD63-FAEF0BBC0F85} " ;
2013-02-11 23:25:23 +00:00
const char _GUIDDeploymentFiles [ ] = " {D9D6E243-F8AF-46E4-B9FD-80ECBC20BA3E} " ;
2015-03-20 09:58:02 +00:00
const char _GUIDDistributionFiles [ ] = " {B83CAF91-C7BF-462F-B76C-EA11631F866C} " ;
2011-04-27 10:05:43 +00:00
QT_END_NAMESPACE
# ifdef Q_OS_WIN32
# include <qt_windows.h>
# include <windows/registry_p.h>
QT_BEGIN_NAMESPACE
2012-09-20 08:18:37 +00:00
struct DotNetCombo {
2011-04-27 10:05:43 +00:00
DotNET version ;
const char * versionStr ;
const char * regKey ;
} dotNetCombo [ ] = {
2015-04-17 09:53:28 +00:00
{ NET2015 , " MSVC.NET 2015 (14.0) " , " Software \\ Microsoft \\ VisualStudio \\ 14.0 \\ Setup \\ VC \\ ProductDir " } ,
2013-07-02 11:48:08 +00:00
{ NET2013 , " MSVC.NET 2013 (12.0) " , " Software \\ Microsoft \\ VisualStudio \\ 12.0 \\ Setup \\ VC \\ ProductDir " } ,
{ NET2013 , " MSVC.NET 2013 Express Edition (12.0) " , " Software \\ Microsoft \\ VCExpress \\ 12.0 \\ Setup \\ VC \\ ProductDir " } ,
2012-09-21 14:28:11 +00:00
{ NET2012 , " MSVC.NET 2012 (11.0) " , " Software \\ Microsoft \\ VisualStudio \\ 11.0 \\ Setup \\ VC \\ ProductDir " } ,
{ NET2012 , " MSVC.NET 2012 Express Edition (11.0) " , " Software \\ Microsoft \\ VCExpress \\ 11.0 \\ Setup \\ VC \\ ProductDir " } ,
2011-04-27 10:05:43 +00:00
{ NET2010 , " MSVC.NET 2010 (10.0) " , " Software \\ Microsoft \\ VisualStudio \\ 10.0 \\ Setup \\ VC \\ ProductDir " } ,
{ NET2010 , " MSVC.NET 2010 Express Edition (10.0) " , " Software \\ Microsoft \\ VCExpress \\ 10.0 \\ Setup \\ VC \\ ProductDir " } ,
{ NET2008 , " MSVC.NET 2008 (9.0) " , " Software \\ Microsoft \\ VisualStudio \\ 9.0 \\ Setup \\ VC \\ ProductDir " } ,
{ NET2008 , " MSVC.NET 2008 Express Edition (9.0) " , " Software \\ Microsoft \\ VCExpress \\ 9.0 \\ Setup \\ VC \\ ProductDir " } ,
{ NET2005 , " MSVC.NET 2005 (8.0) " , " Software \\ Microsoft \\ VisualStudio \\ 8.0 \\ Setup \\ VC \\ ProductDir " } ,
{ NET2005 , " MSVC.NET 2005 Express Edition (8.0) " , " Software \\ Microsoft \\ VCExpress \\ 8.0 \\ Setup \\ VC \\ ProductDir " } ,
{ NET2003 , " MSVC.NET 2003 (7.1) " , " Software \\ Microsoft \\ VisualStudio \\ 7.1 \\ Setup \\ VC \\ ProductDir " } ,
{ NET2002 , " MSVC.NET 2002 (7.0) " , " Software \\ Microsoft \\ VisualStudio \\ 7.0 \\ Setup \\ VC \\ ProductDir " } ,
{ NETUnknown , " " , " " } ,
} ;
QT_END_NAMESPACE
# endif
QT_BEGIN_NAMESPACE
2013-12-26 14:04:29 +00:00
DotNET which_dotnet_version ( const QByteArray & preferredVersion = QByteArray ( ) )
2011-04-27 10:05:43 +00:00
{
# ifndef Q_OS_WIN32
2013-12-26 14:04:29 +00:00
Q_UNUSED ( preferredVersion ) ;
2011-04-27 10:05:43 +00:00
return NET2002 ; // Always generate 7.0 versions on other platforms
# else
// Only search for the version once
static DotNET current_version = NETUnknown ;
if ( current_version ! = NETUnknown )
return current_version ;
// Fallback to .NET 2002
current_version = NET2002 ;
2013-10-29 15:09:18 +00:00
const DotNetCombo * lowestInstalledVersion = 0 ;
2012-04-10 16:46:06 +00:00
QHash < DotNET , QString > installPaths ;
2011-04-27 10:05:43 +00:00
int installed = 0 ;
int i = 0 ;
for ( ; dotNetCombo [ i ] . version ; + + i ) {
2015-12-05 18:09:15 +00:00
QString path = qt_readRegistryKey ( HKEY_LOCAL_MACHINE , dotNetCombo [ i ] . regKey ,
KEY_WOW64_32KEY ) ;
2012-04-10 16:46:06 +00:00
if ( ! path . isEmpty ( ) & & installPaths . value ( dotNetCombo [ i ] . version ) ! = path ) {
2013-10-29 15:09:18 +00:00
lowestInstalledVersion = & dotNetCombo [ i ] ;
installPaths . insert ( lowestInstalledVersion - > version , path ) ;
2011-04-27 10:05:43 +00:00
+ + installed ;
2013-10-29 15:09:18 +00:00
current_version = lowestInstalledVersion - > version ;
2013-12-26 14:04:29 +00:00
if ( QByteArray ( lowestInstalledVersion - > versionStr ) . contains ( preferredVersion ) ) {
installed = 1 ;
break ;
}
2011-04-27 10:05:43 +00:00
}
}
if ( installed < 2 )
return current_version ;
// More than one version installed, search directory path
QString paths = qgetenv ( " PATH " ) ;
2013-10-29 15:09:18 +00:00
const QStringList pathlist = paths . split ( QLatin1Char ( ' ; ' ) ) ;
foreach ( const QString & path , pathlist ) {
for ( i = 0 ; dotNetCombo [ i ] . version ; + + i ) {
const QString productPath = installPaths . value ( dotNetCombo [ i ] . version ) ;
if ( productPath . isEmpty ( ) )
continue ;
2014-01-06 09:04:23 +00:00
if ( path . startsWith ( productPath , Qt : : CaseInsensitive ) ) {
current_version = dotNetCombo [ i ] . version ;
return current_version ;
}
2011-04-27 10:05:43 +00:00
}
}
2013-10-29 15:09:18 +00:00
warn_msg ( WarnLogic , " Generator: MSVC.NET: Found more than one version of Visual Studio, but "
" none in your PATH. Falling back to lowest version (%s) " ,
qPrintable ( lowestInstalledVersion - > versionStr ) ) ;
2011-04-27 10:05:43 +00:00
return current_version ;
# endif
} ;
// Flatfile Tags ----------------------------------------------------
const char _slnHeader70 [ ] = " Microsoft Visual Studio Solution File, Format Version 7.00 " ;
const char _slnHeader71 [ ] = " Microsoft Visual Studio Solution File, Format Version 8.00 " ;
const char _slnHeader80 [ ] = " Microsoft Visual Studio Solution File, Format Version 9.00 "
" \n # Visual Studio 2005 " ;
const char _slnHeader90 [ ] = " Microsoft Visual Studio Solution File, Format Version 10.00 "
" \n # Visual Studio 2008 " ;
const char _slnHeader100 [ ] = " Microsoft Visual Studio Solution File, Format Version 11.00 "
" \n # Visual Studio 2010 " ;
2012-09-21 14:28:11 +00:00
const char _slnHeader110 [ ] = " Microsoft Visual Studio Solution File, Format Version 12.00 "
" \n # Visual Studio 2012 " ;
2013-07-02 11:48:08 +00:00
const char _slnHeader120 [ ] = " Microsoft Visual Studio Solution File, Format Version 12.00 "
" \n # Visual Studio 2013 " ;
2015-04-17 09:53:28 +00:00
const char _slnHeader140 [ ] = " Microsoft Visual Studio Solution File, Format Version 12.00 "
" \n # Visual Studio 2015 " ;
2011-04-27 10:05:43 +00:00
// The following UUID _may_ change for later servicepacks...
// If so we need to search through the registry at
// HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\7.0\Projects
// to find the subkey that contains a "PossibleProjectExtension"
// containing "vcproj"...
// Use the hardcoded value for now so projects generated on other
// platforms are actually usable.
const char _slnMSVCvcprojGUID [ ] = " {8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942} " ;
const char _slnProjectBeg [ ] = " \n Project( \" " ;
const char _slnProjectMid [ ] = " \" ) = " ;
const char _slnProjectEnd [ ] = " \n EndProject " ;
const char _slnGlobalBeg [ ] = " \n Global " ;
const char _slnGlobalEnd [ ] = " \n EndGlobal " ;
2013-10-08 06:22:51 +00:00
const char _slnSolutionConf [ ] = " \n \t GlobalSection(SolutionConfigurationPlatforms) = preSolution "
" \n \t \t Debug|Win32 = Debug|Win32 "
" \n \t \t Release|Win32 = Release|Win32 "
2011-04-27 10:05:43 +00:00
" \n \t EndGlobalSection " ;
2013-05-13 12:02:39 +00:00
const char _slnProjDepBeg [ ] = " \n \t ProjectSection(ProjectDependencies) = postProject " ;
const char _slnProjDepEnd [ ] = " \n \t EndProjectSection " ;
2013-10-08 06:22:51 +00:00
const char _slnProjConfBeg [ ] = " \n \t GlobalSection(ProjectConfigurationPlatforms) = postSolution " ;
2011-04-27 10:05:43 +00:00
const char _slnProjRelConfTag1 [ ] = " .Release|%1.ActiveCfg = Release| " ;
const char _slnProjRelConfTag2 [ ] = " .Release|%1.Build.0 = Release| " ;
2016-03-22 06:28:38 +00:00
const char _slnProjRelConfTag3 [ ] = " .Release|%1.Deploy.0 = Release| " ;
2011-04-27 10:05:43 +00:00
const char _slnProjDbgConfTag1 [ ] = " .Debug|%1.ActiveCfg = Debug| " ;
const char _slnProjDbgConfTag2 [ ] = " .Debug|%1.Build.0 = Debug| " ;
2016-03-22 06:28:38 +00:00
const char _slnProjDbgConfTag3 [ ] = " .Debug|%1.Deploy.0 = Debug| " ;
2011-04-27 10:05:43 +00:00
const char _slnProjConfEnd [ ] = " \n \t EndGlobalSection " ;
const char _slnExtSections [ ] = " \n \t GlobalSection(ExtensibilityGlobals) = postSolution "
" \n \t EndGlobalSection "
" \n \t GlobalSection(ExtensibilityAddIns) = postSolution "
" \n \t EndGlobalSection " ;
// ------------------------------------------------------------------
VcprojGenerator : : VcprojGenerator ( )
: Win32MakefileGenerator ( ) ,
2011-05-05 08:51:27 +00:00
is64Bit ( false ) ,
2011-04-27 10:05:43 +00:00
projectWriter ( 0 )
{
}
VcprojGenerator : : ~ VcprojGenerator ( )
{
delete projectWriter ;
}
bool VcprojGenerator : : writeMakefile ( QTextStream & t )
{
initProject ( ) ; // Fills the whole project with proper data
// Generate solution file
if ( project - > first ( " TEMPLATE " ) = = " vcsubdirs " ) {
if ( ! project - > isActiveConfig ( " build_pass " ) ) {
debug_msg ( 1 , " Generator: MSVC.NET: Writing solution file " ) ;
writeSubDirs ( t ) ;
} else {
debug_msg ( 1 , " Generator: MSVC.NET: Not writing solution file for build_pass configs " ) ;
}
return true ;
} else
// Generate single configuration project file
if ( project - > first ( " TEMPLATE " ) = = " vcapp " | |
project - > first ( " TEMPLATE " ) = = " vclib " ) {
if ( ! project - > isActiveConfig ( " build_pass " ) ) {
debug_msg ( 1 , " Generator: MSVC.NET: Writing single configuration project file " ) ;
XmlOutput xmlOut ( t ) ;
projectWriter - > write ( xmlOut , vcProject ) ;
}
return true ;
}
return project - > isActiveConfig ( " build_pass " ) ;
}
bool VcprojGenerator : : writeProjectMakefile ( )
{
QTextStream t ( & Option : : output ) ;
// Check if all requirements are fulfilled
if ( ! project - > values ( " QMAKE_FAILED_REQUIREMENTS " ) . isEmpty ( ) ) {
fprintf ( stderr , " Project file not generated because all requirements not met: \n \t %s \n " ,
var ( " QMAKE_FAILED_REQUIREMENTS " ) . toLatin1 ( ) . constData ( ) ) ;
return true ;
}
// Generate project file
if ( project - > first ( " TEMPLATE " ) = = " vcapp " | |
project - > first ( " TEMPLATE " ) = = " vclib " ) {
if ( ! mergedProjects . count ( ) ) {
warn_msg ( WarnLogic , " Generator: MSVC.NET: no single configuration created, cannot output project! " ) ;
return false ;
}
debug_msg ( 1 , " Generator: MSVC.NET: Writing project file " ) ;
VCProject mergedProject ;
for ( int i = 0 ; i < mergedProjects . count ( ) ; + + i ) {
VCProjectSingleConfig * singleProject = & ( mergedProjects . at ( i ) - > vcProject ) ;
mergedProject . SingleProjects + = * singleProject ;
for ( int j = 0 ; j < singleProject - > ExtraCompilersFiles . count ( ) ; + + j ) {
const QString & compilerName = singleProject - > ExtraCompilersFiles . at ( j ) . Name ;
if ( ! mergedProject . ExtraCompilers . contains ( compilerName ) )
mergedProject . ExtraCompilers + = compilerName ;
}
}
if ( mergedProjects . count ( ) > 1 & &
mergedProjects . at ( 0 ) - > vcProject . Name = =
mergedProjects . at ( 1 ) - > vcProject . Name )
mergedProjects . at ( 0 ) - > writePrlFile ( ) ;
2012-09-06 10:21:38 +00:00
mergedProject . Name = project - > first ( " QMAKE_PROJECT_NAME " ) . toQString ( ) ;
2011-04-27 10:05:43 +00:00
mergedProject . Version = mergedProjects . at ( 0 ) - > vcProject . Version ;
2013-12-29 12:54:48 +00:00
mergedProject . SdkVersion = mergedProjects . at ( 0 ) - > vcProject . SdkVersion ;
2012-09-06 10:21:38 +00:00
mergedProject . ProjectGUID = project - > isEmpty ( " QMAKE_UUID " ) ? getProjectUUID ( ) . toString ( ) . toUpper ( ) : project - > first ( " QMAKE_UUID " ) . toQString ( ) ;
mergedProject . Keyword = project - > first ( " VCPROJ_KEYWORD " ) . toQString ( ) ;
2011-04-27 10:05:43 +00:00
mergedProject . SccProjectName = mergedProjects . at ( 0 ) - > vcProject . SccProjectName ;
mergedProject . SccLocalPath = mergedProjects . at ( 0 ) - > vcProject . SccLocalPath ;
mergedProject . PlatformName = mergedProjects . at ( 0 ) - > vcProject . PlatformName ;
XmlOutput xmlOut ( t ) ;
projectWriter - > write ( xmlOut , mergedProject ) ;
return true ;
} else if ( project - > first ( " TEMPLATE " ) = = " vcsubdirs " ) {
return writeMakefile ( t ) ;
}
return false ;
}
struct VcsolutionDepend {
QString uuid ;
QString vcprojFile , orig_target , target ;
Target targetType ;
QStringList dependencies ;
} ;
2012-01-30 14:16:50 +00:00
/* Disable optimization in getProjectUUID() due to a compiler
* bug in MSVC 2010 that causes ASSERT : " &other != this " in the QString
* copy constructor for non - empty file names at :
* filename . isEmpty ( ) ? project - > first ( " QMAKE_MAKEFILE " ) : filename */
# ifdef Q_CC_MSVC
# pragma optimize( "g", off )
# pragma warning ( disable : 4748 )
# endif
2011-04-27 10:05:43 +00:00
QUuid VcprojGenerator : : getProjectUUID ( const QString & filename )
{
bool validUUID = true ;
// Read GUID from variable-space
2012-09-06 10:21:38 +00:00
QUuid uuid = project - > first ( " GUID " ) . toQString ( ) ;
2011-04-27 10:05:43 +00:00
// If none, create one based on the MD5 of absolute project path
if ( uuid . isNull ( ) | | ! filename . isEmpty ( ) ) {
2014-11-24 15:02:38 +00:00
QString abspath = Option : : fixPathToTargetOS (
filename . isEmpty ( ) ? project - > first ( " QMAKE_MAKEFILE " ) . toQString ( ) : filename ) ;
2013-08-13 20:38:45 +00:00
QByteArray digest = QCryptographicHash : : hash ( abspath . toUtf8 ( ) , QCryptographicHash : : Sha1 ) ;
2011-04-27 10:05:43 +00:00
memcpy ( ( unsigned char * ) ( & uuid ) , digest . constData ( ) , sizeof ( QUuid ) ) ;
validUUID = ! uuid . isNull ( ) ;
uuid . data4 [ 0 ] = ( uuid . data4 [ 0 ] & 0x3F ) | 0x80 ; // UV_DCE variant
uuid . data3 = ( uuid . data3 & 0x0FFF ) | ( QUuid : : Name < < 12 ) ;
}
// If still not valid, generate new one, and suggest adding to .pro
if ( uuid . isNull ( ) | | ! validUUID ) {
uuid = QUuid : : createUuid ( ) ;
fprintf ( stderr ,
" qmake couldn't create a GUID based on filepath, and we couldn't \n find a valid GUID in the .pro file (Consider adding \n 'GUID = %s' to the .pro file) \n " ,
uuid . toString ( ) . toUpper ( ) . toLatin1 ( ) . constData ( ) ) ;
}
// Store GUID in variable-space
2012-09-06 10:21:38 +00:00
project - > values ( " GUID " ) = ProStringList ( uuid . toString ( ) . toUpper ( ) ) ;
2011-04-27 10:05:43 +00:00
return uuid ;
}
2012-01-30 14:16:50 +00:00
# ifdef Q_CC_MSVC
# pragma optimize( "g", on )
# endif
2011-04-27 10:05:43 +00:00
QUuid VcprojGenerator : : increaseUUID ( const QUuid & id )
{
QUuid result ( id ) ;
qint64 dataFirst = ( result . data4 [ 0 ] < < 24 ) +
( result . data4 [ 1 ] < < 16 ) +
( result . data4 [ 2 ] < < 8 ) +
result . data4 [ 3 ] ;
qint64 dataLast = ( result . data4 [ 4 ] < < 24 ) +
( result . data4 [ 5 ] < < 16 ) +
( result . data4 [ 6 ] < < 8 ) +
result . data4 [ 7 ] ;
if ( ! ( dataLast + + ) )
dataFirst + + ;
result . data4 [ 0 ] = uchar ( ( dataFirst > > 24 ) & 0xff ) ;
result . data4 [ 1 ] = uchar ( ( dataFirst > > 16 ) & 0xff ) ;
result . data4 [ 2 ] = uchar ( ( dataFirst > > 8 ) & 0xff ) ;
result . data4 [ 3 ] = uchar ( dataFirst & 0xff ) ;
result . data4 [ 4 ] = uchar ( ( dataLast > > 24 ) & 0xff ) ;
result . data4 [ 5 ] = uchar ( ( dataLast > > 16 ) & 0xff ) ;
result . data4 [ 6 ] = uchar ( ( dataLast > > 8 ) & 0xff ) ;
result . data4 [ 7 ] = uchar ( dataLast & 0xff ) ;
return result ;
}
2014-04-02 15:16:33 +00:00
QString VcprojGenerator : : retrievePlatformToolSet ( ) const
{
// The PlatformToolset string corresponds to the name of a directory in
// $(VCTargetsPath)\Platforms\{Win32,x64,...}\PlatformToolsets
// e.g. v90, v100, v110, v110_xp, v120_CTP_Nov, v120, or WindowsSDK7.1
// This environment variable may be set by a commandline build
// environment such as the Windows SDK command prompt
QByteArray envVar = qgetenv ( " PlatformToolset " ) ;
if ( ! envVar . isEmpty ( ) )
return envVar ;
2014-04-02 14:56:15 +00:00
QString suffix ;
2014-04-23 05:54:12 +00:00
if ( project - > isActiveConfig ( " winphone " ) )
suffix = ' _ ' + project - > first ( " WINTARGET_VER " ) . toQString ( ) . toLower ( ) ;
2014-04-02 14:56:15 +00:00
else if ( project - > first ( " QMAKE_TARGET_OS " ) = = " xp " )
suffix = " _xp " ;
2014-04-02 15:16:33 +00:00
switch ( vcProject . Configuration . CompilerVersion )
{
case NET2012 :
2014-04-02 14:56:15 +00:00
return QStringLiteral ( " v110 " ) + suffix ;
2014-04-02 15:16:33 +00:00
case NET2013 :
2014-04-02 14:56:15 +00:00
return QStringLiteral ( " v120 " ) + suffix ;
2015-04-17 09:53:28 +00:00
case NET2015 :
return QStringLiteral ( " v140 " ) + suffix ;
2014-04-02 15:16:33 +00:00
default :
return QString ( ) ;
}
}
2014-10-21 11:47:16 +00:00
bool VcprojGenerator : : isStandardSuffix ( const QString & suffix ) const
{
if ( ! project - > values ( " QMAKE_APP_FLAG " ) . isEmpty ( ) ) {
if ( suffix . compare ( " exe " , Qt : : CaseInsensitive ) = = 0 )
return true ;
} else if ( project - > isActiveConfig ( " shared " ) ) {
if ( suffix . compare ( " dll " , Qt : : CaseInsensitive ) = = 0 )
return true ;
} else {
if ( suffix . compare ( " lib " , Qt : : CaseInsensitive ) = = 0 )
return true ;
}
return false ;
}
2015-04-21 13:43:29 +00:00
ProString VcprojGenerator : : firstInputFileName ( const ProString & extraCompilerName ) const
{
foreach ( const ProString & var , project - > values ( ProKey ( extraCompilerName + " .input " ) ) ) {
const ProStringList & files = project - > values ( var . toKey ( ) ) ;
if ( ! files . isEmpty ( ) )
return files . first ( ) ;
}
return ProString ( ) ;
}
QString VcprojGenerator : : firstExpandedOutputFileName ( const ProString & extraCompilerName )
{
const ProString firstOutput = project - > first ( ProKey ( extraCompilerName + " .output " ) ) ;
return replaceExtraCompilerVariables ( firstOutput . toQString ( ) ,
firstInputFileName ( extraCompilerName ) . toQString ( ) ,
QString ( ) , NoShell ) ;
}
2012-04-25 14:55:28 +00:00
ProStringList VcprojGenerator : : collectDependencies ( QMakeProject * proj , QHash < QString , QString > & projLookup ,
QHash < QString , QString > & projGuids ,
QHash < VcsolutionDepend * , QStringList > & extraSubdirs ,
QHash < QString , VcsolutionDepend * > & solution_depends ,
QList < VcsolutionDepend * > & solution_cleanup ,
QTextStream & t ,
QHash < QString , ProStringList > & subdirProjectLookup ,
const ProStringList & allDependencies )
2011-04-27 10:05:43 +00:00
{
2012-04-25 14:55:28 +00:00
QLinkedList < QPair < QString , ProStringList > > collectedSubdirs ;
ProStringList tmp_proj_subdirs = proj - > values ( " SUBDIRS " ) ;
ProStringList projectsInProject ;
2011-04-27 10:05:43 +00:00
for ( int x = 0 ; x < tmp_proj_subdirs . size ( ) ; + + x ) {
2012-09-06 10:21:38 +00:00
ProString tmpdir = tmp_proj_subdirs . at ( x ) ;
const ProKey tmpdirConfig ( tmpdir + " .CONFIG " ) ;
2011-11-01 09:40:31 +00:00
if ( ! proj - > isEmpty ( tmpdirConfig ) ) {
2012-09-06 10:21:38 +00:00
const ProStringList config = proj - > values ( tmpdirConfig ) ;
2011-11-01 09:40:31 +00:00
if ( config . contains ( QStringLiteral ( " no_default_target " ) ) )
continue ; // Ignore this sub-dir
}
2012-09-06 10:21:38 +00:00
const ProKey fkey ( tmpdir + " .file " ) ;
const ProKey skey ( tmpdir + " .subdir " ) ;
if ( ! proj - > isEmpty ( fkey ) ) {
if ( ! proj - > isEmpty ( skey ) )
2011-04-27 10:05:43 +00:00
warn_msg ( WarnLogic , " Cannot assign both file and subdir for subdir %s " ,
tmpdir . toLatin1 ( ) . constData ( ) ) ;
2012-09-06 10:21:38 +00:00
tmpdir = proj - > first ( fkey ) ;
} else if ( ! proj - > isEmpty ( skey ) ) {
tmpdir = proj - > first ( skey ) ;
2011-04-27 10:05:43 +00:00
}
2012-04-25 14:55:28 +00:00
projectsInProject . append ( tmpdir ) ;
collectedSubdirs . append ( qMakePair ( tmpdir . toQString ( ) , proj - > values ( ProKey ( tmp_proj_subdirs . at ( x ) + " .depends " ) ) ) ) ;
projLookup . insert ( tmp_proj_subdirs . at ( x ) . toQString ( ) , tmpdir . toQString ( ) ) ;
2011-04-27 10:05:43 +00:00
}
2012-04-25 14:55:28 +00:00
QLinkedListIterator < QPair < QString , ProStringList > > collectedIt ( collectedSubdirs ) ;
while ( collectedIt . hasNext ( ) ) {
QPair < QString , ProStringList > subdir = collectedIt . next ( ) ;
QString profile = subdir . first ;
2014-11-24 15:02:38 +00:00
QFileInfo fi ( fileInfo ( Option : : normalizePath ( profile ) ) ) ;
2012-04-25 14:55:28 +00:00
if ( fi . exists ( ) ) {
if ( fi . isDir ( ) ) {
if ( ! profile . endsWith ( Option : : dir_sep ) )
profile + = Option : : dir_sep ;
profile + = fi . baseName ( ) + Option : : pro_ext ;
QString profileKey = fi . absoluteFilePath ( ) ;
2014-11-24 15:02:38 +00:00
fi = QFileInfo ( fileInfo ( Option : : normalizePath ( profile ) ) ) ;
2012-04-25 14:55:28 +00:00
if ( ! fi . exists ( ) )
continue ;
projLookup . insert ( profileKey , fi . absoluteFilePath ( ) ) ;
}
QString oldpwd = qmake_getpwd ( ) ;
2013-02-27 18:12:02 +00:00
QString oldoutpwd = Option : : output_dir ;
2012-04-25 14:55:28 +00:00
QMakeProject tmp_proj ;
QString dir = fi . absolutePath ( ) , fn = fi . fileName ( ) ;
if ( ! dir . isEmpty ( ) ) {
if ( ! qmake_setpwd ( dir ) )
fprintf ( stderr , " Cannot find directory: %s " , dir . toLatin1 ( ) . constData ( ) ) ;
}
2013-10-07 16:53:49 +00:00
Option : : output_dir = Option : : globals - > shadowedPath ( QDir : : cleanPath ( dir ) ) ;
2012-04-25 14:55:28 +00:00
if ( tmp_proj . read ( fn ) ) {
// Check if all requirements are fulfilled
if ( ! tmp_proj . isEmpty ( " QMAKE_FAILED_REQUIREMENTS " ) ) {
fprintf ( stderr , " Project file(%s) not added to Solution because all requirements not met: \n \t %s \n " ,
fn . toLatin1 ( ) . constData ( ) , tmp_proj . values ( " QMAKE_FAILED_REQUIREMENTS " ) . join ( " " ) . toLatin1 ( ) . constData ( ) ) ;
qmake_setpwd ( oldpwd ) ;
2013-02-27 18:12:02 +00:00
Option : : output_dir = oldoutpwd ;
2012-04-25 14:55:28 +00:00
continue ;
}
if ( tmp_proj . first ( " TEMPLATE " ) = = " vcsubdirs " ) {
ProStringList tmpList = collectDependencies ( & tmp_proj , projLookup , projGuids , extraSubdirs , solution_depends , solution_cleanup , t , subdirProjectLookup , subdir . second ) ;
subdirProjectLookup . insert ( subdir . first , tmpList ) ;
} else {
ProStringList tmpList ;
tmpList + = subdir . second ;
tmpList + = allDependencies ;
// Initialize a 'fake' project to get the correct variables
// and to be able to extract all the dependencies
Option : : QMAKE_MODE old_mode = Option : : qmake_mode ;
Option : : qmake_mode = Option : : QMAKE_GENERATE_NOTHING ;
VcprojGenerator tmp_vcproj ;
tmp_vcproj . setNoIO ( true ) ;
tmp_vcproj . setProjectFile ( & tmp_proj ) ;
Option : : qmake_mode = old_mode ;
// We assume project filename is [QMAKE_PROJECT_NAME].vcproj
2015-02-06 14:30:02 +00:00
QString vcproj = tmp_vcproj . project - > first ( " QMAKE_PROJECT_NAME " ) + project - > first ( " VCPROJ_EXTENSION " ) ;
2015-11-27 18:03:37 +00:00
QString vcprojDir = Option : : output_dir ;
2012-04-25 14:55:28 +00:00
// If file doesn't exsist, then maybe the users configuration
// doesn't allow it to be created. Skip to next...
if ( ! exists ( vcprojDir + Option : : dir_sep + vcproj ) ) {
2015-11-27 18:03:37 +00:00
warn_msg ( WarnLogic , " Ignored (not found) '%s' " , QString ( vcprojDir + Option : : dir_sep + vcproj ) . toLatin1 ( ) . constData ( ) ) ;
goto nextfile ; // # Dirty!
2012-04-25 14:55:28 +00:00
}
VcsolutionDepend * newDep = new VcsolutionDepend ;
newDep - > vcprojFile = vcprojDir + Option : : dir_sep + vcproj ;
2015-02-06 14:30:02 +00:00
newDep - > orig_target = tmp_proj . first ( " QMAKE_ORIG_TARGET " ) . toQString ( ) ;
2012-04-25 14:55:28 +00:00
newDep - > target = tmp_proj . first ( " MSVCPROJ_TARGET " ) . toQString ( ) . section ( Option : : dir_sep , - 1 ) ;
newDep - > targetType = tmp_vcproj . projectTarget ;
newDep - > uuid = tmp_proj . isEmpty ( " QMAKE_UUID " ) ? getProjectUUID ( Option : : fixPathToLocalOS ( vcprojDir + QDir : : separator ( ) + vcproj ) ) . toString ( ) . toUpper ( ) : tmp_proj . first ( " QMAKE_UUID " ) . toQString ( ) ;
// We want to store it as the .lib name.
if ( newDep - > target . endsWith ( " .dll " ) )
newDep - > target = newDep - > target . left ( newDep - > target . length ( ) - 3 ) + " lib " ;
2013-10-24 20:52:14 +00:00
projGuids . insert ( newDep - > orig_target , newDep - > target ) ;
2012-04-25 14:55:28 +00:00
2015-12-04 11:25:12 +00:00
if ( tmpList . size ( ) ) {
const ProStringList depends = tmpList ;
2012-04-25 14:55:28 +00:00
foreach ( const ProString & dep , depends ) {
QString depend = dep . toQString ( ) ;
if ( ! projGuids [ depend ] . isEmpty ( ) ) {
newDep - > dependencies < < projGuids [ depend ] ;
} else if ( subdirProjectLookup [ projLookup [ depend ] ] . size ( ) > 0 ) {
ProStringList tmpLst = subdirProjectLookup [ projLookup [ depend ] ] ;
foreach ( const ProString & tDep , tmpLst ) {
QString tmpDep = tDep . toQString ( ) ;
newDep - > dependencies < < projGuids [ projLookup [ tmpDep ] ] ;
}
} else {
2015-12-04 11:25:12 +00:00
extraSubdirs . insert ( newDep , tmpList . toQStringList ( ) ) ;
2012-04-25 14:55:28 +00:00
newDep - > dependencies . clear ( ) ;
break ;
}
}
}
// All ActiveQt Server projects are dependent on idc.exe
if ( tmp_proj . values ( " CONFIG " ) . contains ( " qaxserver " ) )
newDep - > dependencies < < " idc.exe " ;
// Add all unknown libs to the deps
QStringList where = QStringList ( ) < < " QMAKE_LIBS " < < " QMAKE_LIBS_PRIVATE " ;
if ( ! tmp_proj . isEmpty ( " QMAKE_INTERNAL_PRL_LIBS " ) )
where = tmp_proj . values ( " QMAKE_INTERNAL_PRL_LIBS " ) . toQStringList ( ) ;
for ( QStringList : : ConstIterator wit = where . begin ( ) ;
wit ! = where . end ( ) ; + + wit ) {
const ProStringList & l = tmp_proj . values ( ProKey ( * wit ) ) ;
for ( ProStringList : : ConstIterator it = l . begin ( ) ; it ! = l . end ( ) ; + + it ) {
2015-12-04 11:15:54 +00:00
const QString opt = fixLibFlag ( * it ) . toQString ( ) ;
2012-04-25 14:55:28 +00:00
if ( ! opt . startsWith ( " / " ) & & // Not a switch
opt ! = newDep - > target & & // Not self
opt ! = " opengl32.lib " & & // We don't care about these libs
opt ! = " glu32.lib " & & // to make depgen alittle faster
opt ! = " kernel32.lib " & &
opt ! = " user32.lib " & &
opt ! = " gdi32.lib " & &
opt ! = " comdlg32.lib " & &
opt ! = " advapi32.lib " & &
opt ! = " shell32.lib " & &
opt ! = " ole32.lib " & &
opt ! = " oleaut32.lib " & &
opt ! = " uuid.lib " & &
opt ! = " imm32.lib " & &
opt ! = " winmm.lib " & &
opt ! = " wsock32.lib " & &
opt ! = " ws2_32.lib " & &
opt ! = " winspool.lib " & &
opt ! = " delayimp.lib " )
{
newDep - > dependencies < < opt . section ( Option : : dir_sep , - 1 ) ;
}
}
}
# ifdef DEBUG_SOLUTION_GEN
qDebug ( " Deps for %20s: [%s] " , newDep - > target . toLatin1 ( ) . constData ( ) , newDep - > dependencies . join ( " :: " ) . toLatin1 ( ) . constData ( ) ) ;
# endif
solution_cleanup . append ( newDep ) ;
solution_depends . insert ( newDep - > target , newDep ) ;
}
nextfile :
qmake_setpwd ( oldpwd ) ;
2013-02-27 18:12:02 +00:00
Option : : output_dir = oldoutpwd ;
2012-04-25 14:55:28 +00:00
}
}
}
return projectsInProject ;
2011-04-27 10:05:43 +00:00
}
void VcprojGenerator : : writeSubDirs ( QTextStream & t )
{
// Check if all requirements are fulfilled
if ( ! project - > values ( " QMAKE_FAILED_REQUIREMENTS " ) . isEmpty ( ) ) {
fprintf ( stderr , " Project file not generated because all requirements not met: \n \t %s \n " ,
var ( " QMAKE_FAILED_REQUIREMENTS " ) . toLatin1 ( ) . constData ( ) ) ;
return ;
}
2013-12-26 14:04:29 +00:00
switch ( which_dotnet_version ( project - > first ( " MSVC_VER " ) . toLatin1 ( ) ) ) {
2015-04-17 09:53:28 +00:00
case NET2015 :
t < < _slnHeader140 ;
2015-09-05 09:38:56 +00:00
break ;
2013-07-02 11:48:08 +00:00
case NET2013 :
t < < _slnHeader120 ;
break ;
2012-09-21 14:28:11 +00:00
case NET2012 :
t < < _slnHeader110 ;
break ;
2011-04-27 10:05:43 +00:00
case NET2010 :
t < < _slnHeader100 ;
break ;
case NET2008 :
t < < _slnHeader90 ;
break ;
case NET2005 :
t < < _slnHeader80 ;
break ;
case NET2003 :
t < < _slnHeader71 ;
break ;
case NET2002 :
t < < _slnHeader70 ;
break ;
default :
t < < _slnHeader70 ;
warn_msg ( WarnLogic , " Generator: MSVC.NET: Unknown version (%d) of MSVC detected for .sln " , which_dotnet_version ( ) ) ;
break ;
}
QHash < QString , VcsolutionDepend * > solution_depends ;
QList < VcsolutionDepend * > solution_cleanup ;
// Make sure that all temp projects are configured
// for release so that the depends are created
// without the debug <lib>dxxx.lib name mangling
2012-09-05 16:29:19 +00:00
QString old_after_vars = Option : : globals - > postcmds ;
Option : : globals - > postcmds . append ( " \n CONFIG+=release " ) ;
2011-04-27 10:05:43 +00:00
2012-04-25 14:55:28 +00:00
QHash < QString , QString > profileLookup ;
QHash < QString , QString > projGuids ;
QHash < VcsolutionDepend * , QStringList > extraSubdirs ;
QHash < QString , ProStringList > subdirProjectLookup ;
collectDependencies ( project , profileLookup , projGuids , extraSubdirs , solution_depends , solution_cleanup , t , subdirProjectLookup ) ;
2011-04-27 10:05:43 +00:00
2013-05-13 12:02:39 +00:00
// write out projects
for ( QList < VcsolutionDepend * > : : Iterator it = solution_cleanup . begin ( ) ; it ! = solution_cleanup . end ( ) ; + + it ) {
2015-02-06 14:30:02 +00:00
// ### quoting rules?
2013-05-13 12:02:39 +00:00
t < < _slnProjectBeg < < _slnMSVCvcprojGUID < < _slnProjectMid
< < " \" " < < ( * it ) - > orig_target < < " \" , \" " < < ( * it ) - > vcprojFile
< < " \" , \" " < < ( * it ) - > uuid < < " \" " ;
debug_msg ( 1 , " Project %s has dependencies: %s " , ( * it ) - > target . toLatin1 ( ) . constData ( ) , ( * it ) - > dependencies . join ( " " ) . toLatin1 ( ) . constData ( ) ) ;
bool hasDependency = false ;
for ( QStringList : : iterator dit = ( * it ) - > dependencies . begin ( ) ; dit ! = ( * it ) - > dependencies . end ( ) ; + + dit ) {
if ( VcsolutionDepend * vc = solution_depends [ * dit ] ) {
if ( ! hasDependency ) {
hasDependency = true ;
t < < _slnProjDepBeg ;
}
t < < " \n \t \t " < < vc - > uuid < < " = " < < vc - > uuid ;
}
}
if ( hasDependency )
t < < _slnProjDepEnd ;
t < < _slnProjectEnd ;
}
2012-04-25 14:55:28 +00:00
t < < _slnGlobalBeg ;
2011-04-27 10:05:43 +00:00
2012-04-25 14:55:28 +00:00
QHashIterator < VcsolutionDepend * , QStringList > extraIt ( extraSubdirs ) ;
while ( extraIt . hasNext ( ) ) {
extraIt . next ( ) ;
foreach ( const QString & depend , extraIt . value ( ) ) {
if ( ! projGuids [ depend ] . isEmpty ( ) ) {
extraIt . key ( ) - > dependencies < < projGuids [ depend ] ;
} else if ( ! profileLookup [ depend ] . isEmpty ( ) ) {
if ( ! projGuids [ profileLookup [ depend ] ] . isEmpty ( ) )
extraIt . key ( ) - > dependencies < < projGuids [ profileLookup [ depend ] ] ;
2011-04-27 10:05:43 +00:00
}
}
}
2011-05-05 08:51:27 +00:00
QString slnConf = _slnSolutionConf ;
2013-02-11 22:44:39 +00:00
if ( ! project - > isEmpty ( " VCPROJ_ARCH " ) ) {
2016-02-04 14:12:03 +00:00
slnConf . replace ( QLatin1String ( " |Win32 " ) , " | " + project - > first ( " VCPROJ_ARCH " ) ) ;
2013-02-11 22:44:39 +00:00
} else if ( ! project - > isEmpty ( " CE_SDK " ) & & ! project - > isEmpty ( " CE_ARCH " ) ) {
2012-05-18 18:00:23 +00:00
QString slnPlatform = QString ( " | " ) + project - > values ( " CE_SDK " ) . join ( ' ' ) + " ( " + project - > first ( " CE_ARCH " ) + " ) " ;
2016-02-04 14:12:03 +00:00
slnConf . replace ( QLatin1String ( " |Win32 " ) , slnPlatform ) ;
2011-05-05 08:51:27 +00:00
} else if ( is64Bit ) {
2016-02-04 14:12:03 +00:00
slnConf . replace ( QLatin1String ( " |Win32 " ) , QLatin1String ( " |x64 " ) ) ;
2011-04-27 10:05:43 +00:00
}
2011-05-05 08:51:27 +00:00
t < < slnConf ;
2011-04-27 10:05:43 +00:00
// Restore previous after_user_var options
2012-09-05 16:29:19 +00:00
Option : : globals - > postcmds = old_after_vars ;
2011-04-27 10:05:43 +00:00
t < < _slnProjConfBeg ;
for ( QList < VcsolutionDepend * > : : Iterator it = solution_cleanup . begin ( ) ; it ! = solution_cleanup . end ( ) ; + + it ) {
2011-05-05 08:51:27 +00:00
QString platform = is64Bit ? " x64 " : " Win32 " ;
2012-01-31 17:36:18 +00:00
QString xplatform = platform ;
2013-02-11 22:44:39 +00:00
if ( ! project - > isEmpty ( " VCPROJ_ARCH " ) ) {
xplatform = project - > first ( " VCPROJ_ARCH " ) . toQString ( ) ;
} else if ( ! project - > isEmpty ( " CE_SDK " ) & & ! project - > isEmpty ( " CE_ARCH " ) ) {
2012-05-18 18:00:23 +00:00
xplatform = project - > values ( " CE_SDK " ) . join ( ' ' ) + " ( " + project - > first ( " CE_ARCH " ) + " ) " ;
2013-02-11 22:44:39 +00:00
}
2012-01-31 17:36:18 +00:00
if ( ! project - > isHostBuild ( ) )
platform = xplatform ;
t < < " \n \t \t " < < ( * it ) - > uuid < < QString ( _slnProjDbgConfTag1 ) . arg ( xplatform ) < < platform ;
t < < " \n \t \t " < < ( * it ) - > uuid < < QString ( _slnProjDbgConfTag2 ) . arg ( xplatform ) < < platform ;
2016-03-22 06:28:38 +00:00
if ( ! project - > isEmpty ( " CE_SDK " ) & & ! project - > isEmpty ( " CE_ARCH " ) )
t < < " \n \t \t " < < ( * it ) - > uuid < < QString ( _slnProjDbgConfTag3 ) . arg ( xplatform ) < < platform ;
2012-01-31 17:36:18 +00:00
t < < " \n \t \t " < < ( * it ) - > uuid < < QString ( _slnProjRelConfTag1 ) . arg ( xplatform ) < < platform ;
t < < " \n \t \t " < < ( * it ) - > uuid < < QString ( _slnProjRelConfTag2 ) . arg ( xplatform ) < < platform ;
2016-03-22 06:28:38 +00:00
if ( ! project - > isEmpty ( " CE_SDK " ) & & ! project - > isEmpty ( " CE_ARCH " ) )
t < < " \n \t \t " < < ( * it ) - > uuid < < QString ( _slnProjRelConfTag3 ) . arg ( xplatform ) < < platform ;
2011-04-27 10:05:43 +00:00
}
t < < _slnProjConfEnd ;
t < < _slnExtSections ;
t < < _slnGlobalEnd ;
while ( ! solution_cleanup . isEmpty ( ) )
delete solution_cleanup . takeFirst ( ) ;
}
// ------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------
bool VcprojGenerator : : hasBuiltinCompiler ( const QString & file )
{
// Source files
for ( int i = 0 ; i < Option : : cpp_ext . count ( ) ; + + i )
if ( file . endsWith ( Option : : cpp_ext . at ( i ) ) )
return true ;
for ( int i = 0 ; i < Option : : c_ext . count ( ) ; + + i )
if ( file . endsWith ( Option : : c_ext . at ( i ) ) )
return true ;
if ( file . endsWith ( " .rc " )
| | file . endsWith ( " .idl " ) )
return true ;
return false ;
}
void VcprojGenerator : : init ( )
{
2011-05-05 08:51:27 +00:00
is64Bit = ( project - > first ( " QMAKE_TARGET.arch " ) = = " x86_64 " ) ;
2011-04-27 10:05:43 +00:00
projectWriter = createProjectWriter ( ) ;
if ( project - > first ( " TEMPLATE " ) = = " vcsubdirs " ) //too much work for subdirs
return ;
debug_msg ( 1 , " Generator: MSVC.NET: Initializing variables " ) ;
// this should probably not be here, but I'm using it to wrap the .t files
if ( project - > first ( " TEMPLATE " ) = = " vcapp " )
project - > values ( " QMAKE_APP_FLAG " ) . append ( " 1 " ) ;
else if ( project - > first ( " TEMPLATE " ) = = " vclib " )
project - > values ( " QMAKE_LIB_FLAG " ) . append ( " 1 " ) ;
processVars ( ) ;
2015-03-31 15:34:18 +00:00
// set /VERSION for EXE/DLL header
ProString major_minor = project - > first ( " VERSION_PE_HEADER " ) ;
if ( major_minor . isEmpty ( ) ) {
ProString version = project - > first ( " VERSION " ) ;
if ( ! version . isEmpty ( ) ) {
int firstDot = version . indexOf ( " . " ) ;
int secondDot = version . indexOf ( " . " , firstDot + 1 ) ;
major_minor = version . left ( secondDot ) ;
}
2011-04-27 10:05:43 +00:00
}
2015-03-31 15:34:18 +00:00
if ( ! major_minor . isEmpty ( ) )
project - > values ( " QMAKE_LFLAGS " ) . append ( " /VERSION: " + major_minor ) ;
2011-04-27 10:05:43 +00:00
MakefileGenerator : : init ( ) ;
2014-11-12 17:11:43 +00:00
// $$QMAKE.. -> $$MSVCPROJ.. -------------------------------------
const ProStringList & incs = project - > values ( " INCLUDEPATH " ) ;
for ( ProStringList : : ConstIterator incit = incs . begin ( ) ; incit ! = incs . end ( ) ; + + incit ) {
QString inc = ( * incit ) . toQString ( ) ;
2015-02-06 14:30:02 +00:00
project - > values ( " MSVCPROJ_INCPATH " ) . append ( " -I " + escapeFilePath ( inc ) ) ;
2014-11-12 17:11:43 +00:00
}
QString dest = Option : : fixPathToTargetOS ( project - > first ( " TARGET " ) . toQString ( ) ) + project - > first ( " TARGET_EXT " ) ;
project - > values ( " MSVCPROJ_TARGET " ) = ProStringList ( dest ) ;
// DLL COPY ------------------------------------------------------
if ( project - > isActiveConfig ( " dll " ) & & ! project - > values ( " DLLDESTDIR " ) . isEmpty ( ) ) {
const ProStringList & dlldirs = project - > values ( " DLLDESTDIR " ) ;
QString copydll ( " " ) ;
ProStringList : : ConstIterator dlldir ;
for ( dlldir = dlldirs . begin ( ) ; dlldir ! = dlldirs . end ( ) ; + + dlldir ) {
if ( ! copydll . isEmpty ( ) )
copydll + = " && " ;
2015-02-06 14:30:02 +00:00
copydll + = " copy \" $(TargetPath) \" " + escapeFilePath ( * dlldir ) ;
2014-11-12 17:11:43 +00:00
}
QString deststr ( " Copy " + dest + " to " ) ;
for ( dlldir = dlldirs . begin ( ) ; dlldir ! = dlldirs . end ( ) ; ) {
deststr + = * dlldir ;
+ + dlldir ;
if ( dlldir ! = dlldirs . end ( ) )
deststr + = " , " ;
}
project - > values ( " MSVCPROJ_COPY_DLL " ) . append ( copydll ) ;
project - > values ( " MSVCPROJ_COPY_DLL_DESC " ) . append ( deststr ) ;
}
2011-04-27 10:05:43 +00:00
2014-11-12 13:14:59 +00:00
#if 0
// Verbose output if "-d -d"...
qDebug ( " Generator: MSVC.NET: List of current variables: " ) ;
for ( ProValueMap : : ConstIterator it = project - > variables ( ) . begin ( ) ; it ! = project - > variables ( ) . end ( ) ; + + it )
qDebug ( " Generator: MSVC.NET: %s => %s " , qPrintable ( it . key ( ) . toQString ( ) ) , qPrintable ( it . value ( ) . join ( " | " ) ) ) ;
# endif
2011-04-27 10:05:43 +00:00
// Figure out what we're trying to build
if ( project - > first ( " TEMPLATE " ) = = " vcapp " ) {
projectTarget = Application ;
} else if ( project - > first ( " TEMPLATE " ) = = " vclib " ) {
if ( project - > isActiveConfig ( " staticlib " ) ) {
2015-02-06 14:30:02 +00:00
project - > values ( " QMAKE_LIBS " ) + = project - > values ( " RES_FILE " ) ;
2011-04-27 10:05:43 +00:00
projectTarget = StaticLib ;
} else
projectTarget = SharedLib ;
}
// Setup PCH variables
2012-09-06 10:21:38 +00:00
precompH = project - > first ( " PRECOMPILED_HEADER " ) . toQString ( ) ;
precompCPP = project - > first ( " PRECOMPILED_SOURCE " ) . toQString ( ) ;
2011-04-27 10:05:43 +00:00
usePCH = ! precompH . isEmpty ( ) & & project - > isActiveConfig ( " precompile_header " ) ;
if ( usePCH ) {
precompHFilename = fileInfo ( precompH ) . fileName ( ) ;
// Created files
2015-02-06 14:30:02 +00:00
QString origTarget = project - > first ( " QMAKE_ORIG_TARGET " ) . toQString ( ) ;
2011-04-27 10:05:43 +00:00
precompObj = origTarget + Option : : obj_ext ;
precompPch = origTarget + " .pch " ;
// Add PRECOMPILED_HEADER to HEADERS
if ( ! project - > values ( " HEADERS " ) . contains ( precompH ) )
project - > values ( " HEADERS " ) + = precompH ;
// Return to variable pool
2012-09-06 10:21:38 +00:00
project - > values ( " PRECOMPILED_OBJECT " ) = ProStringList ( precompObj ) ;
project - > values ( " PRECOMPILED_PCH " ) = ProStringList ( precompPch ) ;
2011-04-27 10:05:43 +00:00
autogenPrecompCPP = precompCPP . isEmpty ( ) & & project - > isActiveConfig ( " autogen_precompile_source " ) ;
if ( autogenPrecompCPP ) {
precompCPP = precompH
+ ( Option : : cpp_ext . count ( ) ? Option : : cpp_ext . at ( 0 ) : QLatin1String ( " .cpp " ) ) ;
project - > values ( " GENERATED_SOURCES " ) + = precompCPP ;
} else if ( ! precompCPP . isEmpty ( ) ) {
project - > values ( " SOURCES " ) + = precompCPP ;
}
}
// Add all input files for a custom compiler into a map for uniqueness,
// unless the compiler is configure as a combined stage, then use the first one
2012-09-06 10:21:38 +00:00
foreach ( const ProString & quc , project - > values ( " QMAKE_EXTRA_COMPILERS " ) ) {
const ProStringList & invar = project - > values ( ProKey ( quc + " .input " ) ) ;
const QString compiler_out = project - > first ( ProKey ( quc + " .output " ) ) . toQString ( ) ;
for ( ProStringList : : ConstIterator iit = invar . constBegin ( ) ; iit ! = invar . constEnd ( ) ; + + iit ) {
ProStringList fileList = project - > values ( ( * iit ) . toKey ( ) ) ;
2011-04-27 10:05:43 +00:00
if ( ! fileList . isEmpty ( ) ) {
2012-09-06 10:21:38 +00:00
if ( project - > values ( ProKey ( quc + " .CONFIG " ) ) . indexOf ( " combine " ) ! = - 1 )
fileList . erase ( fileList . begin ( ) + 1 , fileList . end ( ) ) ;
for ( ProStringList : : ConstIterator fit = fileList . constBegin ( ) ; fit ! = fileList . constEnd ( ) ; + + fit ) {
QString file = ( * fit ) . toQString ( ) ;
if ( verifyExtraCompiler ( quc , file ) ) {
2011-04-27 10:05:43 +00:00
if ( ! hasBuiltinCompiler ( file ) ) {
2012-09-06 10:21:38 +00:00
extraCompilerSources [ file ] + = quc . toQString ( ) ;
2011-04-27 10:05:43 +00:00
} else {
QString out = Option : : fixPathToTargetOS ( replaceExtraCompilerVariables (
2014-11-20 15:20:16 +00:00
compiler_out , file , QString ( ) , NoShell ) , false ) ;
2012-09-06 10:21:38 +00:00
extraCompilerSources [ out ] + = quc . toQString ( ) ;
2011-04-27 10:05:43 +00:00
extraCompilerOutputs [ out ] = QStringList ( file ) ; // Can only have one
}
}
}
}
}
}
#if 0 // Debugging
Q_FOREACH ( QString aKey , extraCompilerSources . keys ( ) ) {
qDebug ( " Extracompilers for %s are (%s) " , aKey . toLatin1 ( ) . constData ( ) , extraCompilerSources . value ( aKey ) . join ( " , " ) . toLatin1 ( ) . constData ( ) ) ;
}
Q_FOREACH ( QString aKey , extraCompilerOutputs . keys ( ) ) {
qDebug ( " Object mapping for %s is (%s) " , aKey . toLatin1 ( ) . constData ( ) , extraCompilerOutputs . value ( aKey ) . join ( " , " ) . toLatin1 ( ) . constData ( ) ) ;
}
qDebug ( " " ) ;
# endif
}
bool VcprojGenerator : : mergeBuildProject ( MakefileGenerator * other )
{
if ( ! other | | ! other - > projectFile ( ) ) {
warn_msg ( WarnLogic , " VcprojGenerator: Cannot merge null project. " ) ;
return false ;
}
if ( other - > projectFile ( ) - > first ( " MAKEFILE_GENERATOR " ) ! = project - > first ( " MAKEFILE_GENERATOR " ) ) {
warn_msg ( WarnLogic , " VcprojGenerator: Cannot merge other types of projects! (ignored) " ) ;
return false ;
}
VcprojGenerator * otherVC = static_cast < VcprojGenerator * > ( other ) ;
mergedProjects + = otherVC ;
return true ;
}
void VcprojGenerator : : initProject ( )
{
// Initialize XML sub elements
// - Do this first since project elements may need
// - to know of certain configuration options
initConfiguration ( ) ;
initRootFiles ( ) ;
initSourceFiles ( ) ;
initHeaderFiles ( ) ;
initGeneratedFiles ( ) ;
initLexYaccFiles ( ) ;
initTranslationFiles ( ) ;
initFormFiles ( ) ;
initResourceFiles ( ) ;
2015-03-20 09:58:02 +00:00
initDistributionFiles ( ) ;
2011-04-27 10:05:43 +00:00
initExtraCompilerOutputs ( ) ;
// Own elements -----------------------------
2015-02-06 14:30:02 +00:00
vcProject . Name = project - > first ( " QMAKE_ORIG_TARGET " ) . toQString ( ) ;
2013-12-26 14:04:29 +00:00
switch ( which_dotnet_version ( project - > first ( " MSVC_VER " ) . toLatin1 ( ) ) ) {
2015-04-17 09:53:28 +00:00
case NET2015 :
vcProject . Version = " 14.00 " ;
break ;
2013-07-02 11:48:08 +00:00
case NET2013 :
2014-01-06 20:48:48 +00:00
vcProject . Version = " 12.00 " ;
2013-07-02 11:48:08 +00:00
break ;
2012-09-21 14:28:11 +00:00
case NET2012 :
2014-01-06 20:48:48 +00:00
vcProject . Version = " 11.00 " ;
2012-09-21 14:28:11 +00:00
break ;
2011-04-27 10:05:43 +00:00
case NET2010 :
vcProject . Version = " 10.00 " ;
break ;
case NET2008 :
vcProject . Version = " 9,00 " ;
break ;
case NET2005 :
//### using ',' because of a bug in 2005 B2
//### VS uses '.' or ',' depending on the regional settings! Using ',' always works.
vcProject . Version = " 8,00 " ;
break ;
case NET2003 :
vcProject . Version = " 7.10 " ;
break ;
case NET2002 :
vcProject . Version = " 7.00 " ;
break ;
default :
vcProject . Version = " 7.00 " ;
warn_msg ( WarnLogic , " Generator: MSVC.NET: Unknown version (%d) of MSVC detected for .vcproj " , which_dotnet_version ( ) ) ;
break ;
}
2012-09-06 10:21:38 +00:00
vcProject . Keyword = project - > first ( " VCPROJ_KEYWORD " ) . toQString ( ) ;
2013-02-11 22:44:39 +00:00
if ( ! project - > isEmpty ( " VCPROJ_ARCH " ) ) {
vcProject . PlatformName = project - > first ( " VCPROJ_ARCH " ) . toQString ( ) ;
} else if ( project - > isHostBuild ( ) | | project - > isEmpty ( " CE_SDK " ) | | project - > isEmpty ( " CE_ARCH " ) ) {
2011-05-05 08:51:27 +00:00
vcProject . PlatformName = ( is64Bit ? " x64 " : " Win32 " ) ;
2011-04-27 10:05:43 +00:00
} else {
2012-05-18 18:00:23 +00:00
vcProject . PlatformName = project - > values ( " CE_SDK " ) . join ( ' ' ) + " ( " + project - > first ( " CE_ARCH " ) + " ) " ;
2011-04-27 10:05:43 +00:00
}
2013-12-29 12:54:48 +00:00
vcProject . SdkVersion = project - > first ( " WINSDK_VER " ) . toQString ( ) ;
2011-04-27 10:05:43 +00:00
// These are not used by Qt, but may be used by customers
2012-09-06 10:21:38 +00:00
vcProject . SccProjectName = project - > first ( " SCCPROJECTNAME " ) . toQString ( ) ;
vcProject . SccLocalPath = project - > first ( " SCCLOCALPATH " ) . toQString ( ) ;
2011-04-27 10:05:43 +00:00
vcProject . flat_files = project - > isActiveConfig ( " flat " ) ;
}
void VcprojGenerator : : initConfiguration ( )
{
// Initialize XML sub elements
// - Do this first since main configuration elements may need
// - to know of certain compiler/linker options
VCConfiguration & conf = vcProject . Configuration ;
2014-09-12 15:34:57 +00:00
conf . suppressUnknownOptionWarnings = project - > isActiveConfig ( " suppress_vcproj_warnings " ) ;
2013-12-26 14:04:29 +00:00
conf . CompilerVersion = which_dotnet_version ( project - > first ( " MSVC_VER " ) . toLatin1 ( ) ) ;
2011-04-27 10:05:43 +00:00
2015-09-17 16:06:57 +00:00
if ( conf . CompilerVersion > = NET2012 ) {
conf . WinRT = project - > isActiveConfig ( " winrt " ) ;
if ( conf . WinRT ) {
conf . WinPhone = project - > isActiveConfig ( " winphone " ) ;
// Saner defaults
conf . compiler . UsePrecompiledHeader = pchNone ;
conf . compiler . CompileAsWinRT = _False ;
conf . linker . GenerateWindowsMetadata = _False ;
}
}
2011-04-27 10:05:43 +00:00
initCompilerTool ( ) ;
// Only on configuration per build
bool isDebug = project - > isActiveConfig ( " debug " ) ;
if ( projectTarget = = StaticLib )
initLibrarianTool ( ) ;
else {
2013-11-18 20:39:08 +00:00
conf . linker . GenerateDebugInformation = project - > isActiveConfig ( " debug_info " ) ? _True : _False ;
2011-04-27 10:05:43 +00:00
initLinkerTool ( ) ;
}
2013-06-18 06:58:31 +00:00
initManifestTool ( ) ;
2011-04-27 10:05:43 +00:00
initResourceTool ( ) ;
initIDLTool ( ) ;
// Own elements -----------------------------
2012-09-06 10:21:38 +00:00
ProString temp = project - > first ( " BuildBrowserInformation " ) ;
2011-04-27 10:05:43 +00:00
switch ( projectTarget ) {
case SharedLib :
conf . ConfigurationType = typeDynamicLibrary ;
break ;
case StaticLib :
conf . ConfigurationType = typeStaticLibrary ;
break ;
case Application :
default :
conf . ConfigurationType = typeApplication ;
break ;
}
2012-09-06 10:21:38 +00:00
conf . OutputDirectory = project - > first ( " DESTDIR " ) . toQString ( ) ;
2011-04-27 10:05:43 +00:00
if ( conf . OutputDirectory . isEmpty ( ) )
conf . OutputDirectory = " . \\ " ;
if ( ! conf . OutputDirectory . endsWith ( " \\ " ) )
conf . OutputDirectory + = ' \\ ' ;
if ( conf . CompilerVersion > = NET2010 ) {
2014-04-02 15:16:33 +00:00
conf . PlatformToolSet = retrievePlatformToolSet ( ) ;
2014-10-21 11:47:16 +00:00
const QFileInfo targetInfo = fileInfo ( project - > first ( " MSVCPROJ_TARGET " ) . toQString ( ) ) ;
conf . PrimaryOutput = targetInfo . completeBaseName ( ) ;
const QString targetSuffix = targetInfo . suffix ( ) ;
if ( ! isStandardSuffix ( targetSuffix ) )
conf . PrimaryOutputExtension = ' . ' + targetSuffix ;
2011-04-27 10:05:43 +00:00
}
2012-05-18 18:00:23 +00:00
conf . Name = project - > values ( " BUILD_NAME " ) . join ( ' ' ) ;
2011-04-27 10:05:43 +00:00
if ( conf . Name . isEmpty ( ) )
conf . Name = isDebug ? " Debug " : " Release " ;
conf . ConfigurationName = conf . Name ;
2013-02-11 22:44:39 +00:00
if ( ! project - > isEmpty ( " VCPROJ_ARCH " ) ) {
conf . Name + = " | " + project - > first ( " VCPROJ_ARCH " ) ;
} else if ( project - > isHostBuild ( ) | | project - > isEmpty ( " CE_SDK " ) | | project - > isEmpty ( " CE_ARCH " ) ) {
2011-05-05 08:51:27 +00:00
conf . Name + = ( is64Bit ? " |x64 " : " |Win32 " ) ;
2011-04-27 10:05:43 +00:00
} else {
2012-05-18 18:00:23 +00:00
conf . Name + = " | " + project - > values ( " CE_SDK " ) . join ( ' ' ) + " ( " + project - > first ( " CE_ARCH " ) + " ) " ;
2011-04-27 10:05:43 +00:00
}
conf . ATLMinimizesCRunTimeLibraryUsage = ( project - > first ( " ATLMinimizesCRunTimeLibraryUsage " ) . isEmpty ( ) ? _False : _True ) ;
conf . BuildBrowserInformation = triState ( temp . isEmpty ( ) ? ( short ) unset : temp . toShort ( ) ) ;
temp = project - > first ( " CharacterSet " ) ;
2013-12-10 22:27:31 +00:00
conf . CharacterSet = charSet ( temp . isEmpty ( ) ? short ( conf . WinRT ? charSetUnicode : charSetNotSet ) : temp . toShort ( ) ) ;
2012-09-06 10:21:38 +00:00
conf . DeleteExtensionsOnClean = project - > first ( " DeleteExtensionsOnClean " ) . toQString ( ) ;
2011-04-27 10:05:43 +00:00
conf . ImportLibrary = conf . linker . ImportLibrary ;
2012-09-06 10:21:38 +00:00
conf . IntermediateDirectory = project - > first ( " OBJECTS_DIR " ) . toQString ( ) ;
2011-04-27 10:05:43 +00:00
conf . WholeProgramOptimization = conf . compiler . WholeProgramOptimization ;
temp = project - > first ( " UseOfATL " ) ;
if ( ! temp . isEmpty ( ) )
conf . UseOfATL = useOfATL ( temp . toShort ( ) ) ;
temp = project - > first ( " UseOfMfc " ) ;
if ( ! temp . isEmpty ( ) )
conf . UseOfMfc = useOfMfc ( temp . toShort ( ) ) ;
// Configuration does not need parameters from
// these sub XML items;
initCustomBuildTool ( ) ;
initPreBuildEventTools ( ) ;
initPostBuildEventTools ( ) ;
2013-02-11 23:25:23 +00:00
// Only deploy for CE and WinRT projects
2013-10-02 12:26:46 +00:00
if ( ( ! project - > isHostBuild ( ) & & ! project - > isEmpty ( " CE_SDK " ) & & ! project - > isEmpty ( " CE_ARCH " ) )
2013-02-11 23:25:23 +00:00
| | conf . WinRT )
2011-04-27 10:05:43 +00:00
initDeploymentTool ( ) ;
2014-02-11 11:49:18 +00:00
initWinDeployQtTool ( ) ;
2011-04-27 10:05:43 +00:00
initPreLinkEventTools ( ) ;
2013-04-09 12:32:06 +00:00
if ( ! isDebug )
2011-04-27 10:05:43 +00:00
conf . compiler . PreprocessorDefinitions + = " NDEBUG " ;
}
void VcprojGenerator : : initCompilerTool ( )
{
2012-09-06 10:21:38 +00:00
QString placement = project - > first ( " OBJECTS_DIR " ) . toQString ( ) ;
2011-04-27 10:05:43 +00:00
if ( placement . isEmpty ( ) )
placement = " . \\ " ;
VCConfiguration & conf = vcProject . Configuration ;
2012-01-06 15:40:27 +00:00
if ( conf . CompilerVersion > = NET2010 ) {
// adjust compiler tool defaults for VS 2010 and above
conf . compiler . Optimization = optimizeDisabled ;
}
2011-04-27 10:05:43 +00:00
conf . compiler . AssemblerListingLocation = placement ;
conf . compiler . ObjectFile = placement ;
conf . compiler . ExceptionHandling = ehNone ;
// PCH
if ( usePCH ) {
conf . compiler . UsePrecompiledHeader = pchUseUsingSpecific ;
conf . compiler . PrecompiledHeaderFile = " $(IntDir) \\ " + precompPch ;
2012-09-06 10:21:38 +00:00
conf . compiler . PrecompiledHeaderThrough = project - > first ( " PRECOMPILED_HEADER " ) . toQString ( ) ;
conf . compiler . ForcedIncludeFiles = project - > values ( " PRECOMPILED_HEADER " ) . toQStringList ( ) ;
2011-04-27 10:05:43 +00:00
if ( conf . CompilerVersion < = NET2003 ) {
// Minimal build option triggers an Internal Compiler Error
// when used in conjunction with /FI and /Yu, so remove it
// ### work-around for a VS 2003 bug. Move to some prf file or remove completely.
project - > values ( " QMAKE_CFLAGS_DEBUG " ) . removeAll ( " -Gm " ) ;
project - > values ( " QMAKE_CFLAGS_DEBUG " ) . removeAll ( " /Gm " ) ;
project - > values ( " QMAKE_CXXFLAGS_DEBUG " ) . removeAll ( " -Gm " ) ;
project - > values ( " QMAKE_CXXFLAGS_DEBUG " ) . removeAll ( " /Gm " ) ;
}
}
conf . compiler . parseOptions ( project - > values ( " QMAKE_CXXFLAGS " ) ) ;
if ( project - > isActiveConfig ( " windows " ) )
conf . compiler . PreprocessorDefinitions + = " _WINDOWS " ;
else if ( project - > isActiveConfig ( " console " ) )
conf . compiler . PreprocessorDefinitions + = " _CONSOLE " ;
2012-09-06 10:21:38 +00:00
conf . compiler . PreprocessorDefinitions + = project - > values ( " DEFINES " ) . toQStringList ( ) ;
conf . compiler . PreprocessorDefinitions + = project - > values ( " PRL_EXPORT_DEFINES " ) . toQStringList ( ) ;
2011-04-27 10:05:43 +00:00
conf . compiler . parseOptions ( project - > values ( " MSVCPROJ_INCPATH " ) ) ;
}
void VcprojGenerator : : initLibrarianTool ( )
{
VCConfiguration & conf = vcProject . Configuration ;
conf . librarian . OutputFile = " $(OutDir) \\ " ;
2012-09-06 10:21:38 +00:00
conf . librarian . OutputFile + = project - > first ( " MSVCPROJ_TARGET " ) . toQString ( ) ;
conf . librarian . AdditionalOptions + = project - > values ( " QMAKE_LIBFLAGS " ) . toQStringList ( ) ;
2011-04-27 10:05:43 +00:00
}
2013-06-18 06:58:31 +00:00
void VcprojGenerator : : initManifestTool ( )
{
VCManifestTool & tool = vcProject . Configuration . manifestTool ;
const ProString tmplt = project - > first ( " TEMPLATE " ) ;
if ( ( tmplt = = " vclib "
& & ! project - > isActiveConfig ( " embed_manifest_dll " )
& & ! project - > isActiveConfig ( " static " ) )
| | ( tmplt = = " vcapp "
& & ! project - > isActiveConfig ( " embed_manifest_exe " ) ) ) {
tool . EmbedManifest = _False ;
}
}
2011-04-27 10:05:43 +00:00
void VcprojGenerator : : initLinkerTool ( )
{
VCConfiguration & conf = vcProject . Configuration ;
conf . linker . parseOptions ( project - > values ( " QMAKE_LFLAGS " ) ) ;
if ( ! project - > values ( " DEF_FILE " ) . isEmpty ( ) )
2012-09-06 10:21:38 +00:00
conf . linker . ModuleDefinitionFile = project - > first ( " DEF_FILE " ) . toQString ( ) ;
2011-04-27 10:05:43 +00:00
2015-10-27 14:13:34 +00:00
static const char * const lflags [ ] = { " QMAKE_LIBS " , " QMAKE_LIBS_PRIVATE " , 0 } ;
for ( int i = 0 ; lflags [ i ] ; i + + ) {
foreach ( const ProString & lib , fixLibFlags ( lflags [ i ] ) ) {
if ( lib . startsWith ( " /LIBPATH: " ) )
conf . linker . AdditionalLibraryDirectories < < lib . mid ( 9 ) . toQString ( ) ;
else
conf . linker . AdditionalDependencies < < lib . toQString ( ) ;
2011-04-27 10:05:43 +00:00
}
}
conf . linker . OutputFile = " $(OutDir) \\ " ;
2012-09-06 10:21:38 +00:00
conf . linker . OutputFile + = project - > first ( " MSVCPROJ_TARGET " ) . toQString ( ) ;
2011-04-27 10:05:43 +00:00
}
void VcprojGenerator : : initResourceTool ( )
{
VCConfiguration & conf = vcProject . Configuration ;
2015-05-27 20:31:21 +00:00
ProStringList rcDefines = project - > values ( " RC_DEFINES " ) ;
if ( rcDefines . size ( ) > 0 )
conf . resource . PreprocessorDefinitions = rcDefines . toQStringList ( ) ;
else
conf . resource . PreprocessorDefinitions = conf . compiler . PreprocessorDefinitions ;
2011-04-27 10:05:43 +00:00
2012-12-06 15:29:30 +00:00
foreach ( const ProString & path , project - > values ( " RC_INCLUDEPATH " ) ) {
QString fixedPath = fileFixify ( path . toQString ( ) ) ;
if ( fileInfo ( fixedPath ) . isRelative ( ) ) {
2016-01-19 07:55:32 +00:00
if ( fixedPath = = QLatin1String ( " . " ) )
2012-12-06 15:29:30 +00:00
fixedPath = QStringLiteral ( " $(ProjectDir) " ) ;
else
fixedPath . prepend ( QStringLiteral ( " $(ProjectDir) \\ " ) ) ;
}
conf . resource . AdditionalIncludeDirectories < < escapeFilePath ( fixedPath ) ;
}
2011-04-27 10:05:43 +00:00
// We need to add _DEBUG for the debug version of the project, since the normal compiler defines
// do not contain it. (The compiler defines this symbol automatically, which is wy we don't need
// to add it for the compiler) However, the resource tool does not do this.
if ( project - > isActiveConfig ( " debug " ) )
conf . resource . PreprocessorDefinitions + = " _DEBUG " ;
2014-12-02 10:20:43 +00:00
if ( conf . CompilerVersion < NET2010 & & project - > isActiveConfig ( " staticlib " ) )
2011-04-27 10:05:43 +00:00
conf . resource . ResourceOutputFileName = " $(OutDir) \\ $(InputName).res " ;
}
void VcprojGenerator : : initIDLTool ( )
{
}
void VcprojGenerator : : initCustomBuildTool ( )
{
}
void VcprojGenerator : : initPreBuildEventTools ( )
{
}
void VcprojGenerator : : initPostBuildEventTools ( )
{
VCConfiguration & conf = vcProject . Configuration ;
if ( ! project - > values ( " QMAKE_POST_LINK " ) . isEmpty ( ) ) {
QStringList cmdline = VCToolBase : : fixCommandLine ( var ( " QMAKE_POST_LINK " ) ) ;
conf . postBuild . CommandLine = cmdline ;
conf . postBuild . Description = cmdline . join ( QLatin1String ( " \r \n " ) ) ;
conf . postBuild . ExcludedFromBuild = _False ;
}
QString signature = ! project - > isEmpty ( " SIGNATURE_FILE " ) ? var ( " SIGNATURE_FILE " ) : var ( " DEFAULT_SIGNATURE " ) ;
bool useSignature = ! signature . isEmpty ( ) & & ! project - > isActiveConfig ( " staticlib " ) & &
2012-01-31 17:36:18 +00:00
! project - > isHostBuild ( ) & & ! project - > isEmpty ( " CE_SDK " ) & & ! project - > isEmpty ( " CE_ARCH " ) ;
2011-04-27 10:05:43 +00:00
if ( useSignature ) {
conf . postBuild . CommandLine . prepend (
2015-02-06 14:30:02 +00:00
QLatin1String ( " signtool sign /F " ) + escapeFilePath ( signature ) + QLatin1String ( " \" $(TargetPath) \" " ) ) ;
2011-04-27 10:05:43 +00:00
conf . postBuild . ExcludedFromBuild = _False ;
}
if ( ! project - > values ( " MSVCPROJ_COPY_DLL " ) . isEmpty ( ) ) {
conf . postBuild . Description + = var ( " MSVCPROJ_COPY_DLL_DESC " ) ;
conf . postBuild . CommandLine + = var ( " MSVCPROJ_COPY_DLL " ) ;
conf . postBuild . ExcludedFromBuild = _False ;
}
}
void VcprojGenerator : : initDeploymentTool ( )
{
VCConfiguration & conf = vcProject . Configuration ;
2013-02-11 23:25:23 +00:00
QString targetPath ;
if ( conf . WinRT ) {
vcProject . DeploymentFiles . Name = " Deployment Files " ;
vcProject . DeploymentFiles . ParseFiles = _False ;
vcProject . DeploymentFiles . Filter = " deploy " ;
vcProject . DeploymentFiles . Guid = _GUIDDeploymentFiles ;
} else {
targetPath = project - > values ( " deploy.path " ) . join ( ' ' ) ;
if ( targetPath . isEmpty ( ) )
targetPath = QString ( " %CSIDL_PROGRAM_FILES% \\ " ) + project - > first ( " TARGET " ) ;
if ( targetPath . endsWith ( " / " ) | | targetPath . endsWith ( " \\ " ) )
targetPath . chop ( 1 ) ;
2016-03-22 06:28:38 +00:00
conf . deployment . RemoteDirectory = targetPath ;
2013-02-11 23:25:23 +00:00
}
2015-03-16 13:15:27 +00:00
ProStringList dllPaths = project - > values ( " QMAKE_DLL_PATHS " ) ;
2011-04-27 10:05:43 +00:00
// Only deploy Qt libs for shared build
2015-08-06 13:13:58 +00:00
if ( ! dllPaths . isEmpty ( ) & &
! ( conf . WinRT & & project - > first ( " MSVC_VER " ) . toQString ( ) = = " 14.0 " ) ) {
2012-07-12 18:33:25 +00:00
// FIXME: This code should actually resolve the libraries from all Qt modules.
2012-09-06 10:21:38 +00:00
ProStringList arg = project - > values ( " QMAKE_LIBS " ) + project - > values ( " QMAKE_LIBS_PRIVATE " ) ;
for ( ProStringList : : ConstIterator it = arg . constBegin ( ) ; it ! = arg . constEnd ( ) ; + + it ) {
2015-03-16 13:15:27 +00:00
QString dllName = ( * it ) . toQString ( ) ;
dllName . replace ( QLatin1Char ( ' \\ ' ) , QLatin1Char ( ' / ' ) ) ;
// LIBPATH isn't relevant for deployment
if ( dllName . startsWith ( QLatin1String ( " /LIBPATH: " ) ) )
continue ;
// We want to deploy .dlls not .libs
if ( dllName . endsWith ( QLatin1String ( " .lib " ) ) )
dllName . replace ( dllName . length ( ) - 3 , 3 , QLatin1String ( " dll " ) ) ;
// Use only the file name and check in Qt's install path and LIBPATHs to check for existence
dllName . remove ( 0 , dllName . lastIndexOf ( QLatin1Char ( ' / ' ) ) + 1 ) ;
QFileInfo info ;
foreach ( const ProString & dllPath , dllPaths ) {
QString absoluteDllFilePath = dllPath . toQString ( ) ;
if ( ! absoluteDllFilePath . endsWith ( QLatin1Char ( ' / ' ) ) )
absoluteDllFilePath + = QLatin1Char ( ' / ' ) ;
absoluteDllFilePath + = dllName ;
info = QFileInfo ( absoluteDllFilePath ) ;
if ( info . exists ( ) )
break ;
}
2011-04-27 10:05:43 +00:00
2015-03-16 13:15:27 +00:00
if ( ! info . exists ( ) )
continue ;
if ( conf . WinRT ) {
QString absoluteFilePath ( QDir : : toNativeSeparators ( info . absoluteFilePath ( ) ) ) ;
vcProject . DeploymentFiles . addFile ( absoluteFilePath ) ;
} else {
conf . deployment . AdditionalFiles + = info . fileName ( )
+ " | " + QDir : : toNativeSeparators ( info . absolutePath ( ) )
+ " | " + targetPath
+ " |0; " ;
2011-04-27 10:05:43 +00:00
}
}
}
2013-02-11 23:25:23 +00:00
if ( ! conf . WinRT ) {
// C-runtime deployment
QString runtime = project - > values ( " QT_CE_C_RUNTIME " ) . join ( QLatin1Char ( ' ' ) ) ;
if ( ! runtime . isEmpty ( ) & & ( runtime ! = QLatin1String ( " no " ) ) ) {
QString runtimeVersion = QLatin1String ( " msvcr " ) ;
ProString mkspec = project - > first ( " QMAKESPEC " ) ;
if ( ! mkspec . isEmpty ( ) ) {
if ( mkspec . endsWith ( " 2008 " ) )
runtimeVersion . append ( " 90 " ) ;
else
runtimeVersion . append ( " 80 " ) ;
if ( project - > isActiveConfig ( " debug " ) )
runtimeVersion . append ( " d " ) ;
runtimeVersion . append ( " .dll " ) ;
if ( runtime = = " yes " ) {
// Auto-find C-runtime
QString vcInstallDir = qgetenv ( " VCINSTALLDIR " ) ;
if ( ! vcInstallDir . isEmpty ( ) ) {
vcInstallDir + = " \\ ce \\ dll \\ " ;
vcInstallDir + = project - > values ( " CE_ARCH " ) . join ( QLatin1Char ( ' ' ) ) ;
2016-01-19 13:22:28 +00:00
if ( ! QFileInfo : : exists ( vcInstallDir + QDir : : separator ( ) + runtimeVersion ) )
2013-02-11 23:25:23 +00:00
runtime . clear ( ) ;
else
runtime = vcInstallDir ;
}
2011-04-27 10:05:43 +00:00
}
}
2013-02-11 23:25:23 +00:00
if ( ! runtime . isEmpty ( ) & & runtime ! = QLatin1String ( " yes " ) ) {
conf . deployment . AdditionalFiles + = runtimeVersion
+ " | " + QDir : : toNativeSeparators ( runtime )
+ " | " + targetPath
+ " |0; " ;
}
2011-04-27 10:05:43 +00:00
}
}
2015-05-26 15:32:47 +00:00
foreach ( const ProString & item , project - > values ( " INSTALLS " ) ) {
2011-04-27 10:05:43 +00:00
// get item.path
2012-09-06 10:21:38 +00:00
QString devicePath = project - > first ( ProKey ( item + " .path " ) ) . toQString ( ) ;
2013-02-11 23:25:23 +00:00
if ( ! conf . WinRT ) {
if ( devicePath . isEmpty ( ) )
devicePath = targetPath ;
// check if item.path is relative (! either /,\ or %)
if ( ! ( devicePath . at ( 0 ) = = QLatin1Char ( ' / ' )
| | devicePath . at ( 0 ) = = QLatin1Char ( ' \\ ' )
| | devicePath . at ( 0 ) = = QLatin1Char ( ' % ' ) ) ) {
// create output path
2014-11-24 15:02:38 +00:00
devicePath = Option : : fixPathToTargetOS ( targetPath + QLatin1Char ( ' \\ ' ) + devicePath ) ;
2013-02-11 23:25:23 +00:00
}
2011-04-27 10:05:43 +00:00
}
2012-07-02 13:21:15 +00:00
// foreach d in item.files
2012-09-06 10:21:38 +00:00
foreach ( const ProString & src , project - > values ( ProKey ( item + " .files " ) ) ) {
2011-04-27 10:05:43 +00:00
QString itemDevicePath = devicePath ;
2014-11-24 15:02:38 +00:00
QString source = Option : : normalizePath ( src . toQString ( ) ) ;
2011-04-27 10:05:43 +00:00
QString nameFilter ;
QFileInfo info ( source ) ;
QString searchPath ;
if ( info . isDir ( ) ) {
nameFilter = QLatin1String ( " * " ) ;
itemDevicePath + = " \\ " + info . fileName ( ) ;
searchPath = info . absoluteFilePath ( ) ;
} else {
2014-11-24 15:02:38 +00:00
nameFilter = info . fileName ( ) ;
2011-04-27 10:05:43 +00:00
searchPath = info . absolutePath ( ) ;
}
int pathSize = searchPath . size ( ) ;
QDirIterator iterator ( searchPath , QStringList ( ) < < nameFilter
, QDir : : Files | QDir : : NoDotAndDotDot | QDir : : NoSymLinks
, QDirIterator : : Subdirectories ) ;
// foreach dirIterator-entry in d
while ( iterator . hasNext ( ) ) {
iterator . next ( ) ;
2013-02-11 23:25:23 +00:00
if ( conf . WinRT ) {
2014-11-24 15:02:38 +00:00
QString absoluteItemFilePath = Option : : fixPathToTargetOS ( QFileInfo ( iterator . filePath ( ) ) . absoluteFilePath ( ) ) ;
2013-02-11 23:25:23 +00:00
vcProject . DeploymentFiles . addFile ( absoluteItemFilePath ) ;
} else {
2014-11-24 15:02:38 +00:00
QString absoluteItemPath = Option : : fixPathToTargetOS ( QFileInfo ( iterator . filePath ( ) ) . absolutePath ( ) ) ;
2013-02-11 23:25:23 +00:00
// Identify if it is just another subdir
int diffSize = absoluteItemPath . size ( ) - pathSize ;
// write out rules
conf . deployment . AdditionalFiles + = iterator . fileName ( )
+ " | " + absoluteItemPath
+ " | " + itemDevicePath + ( diffSize ? ( absoluteItemPath . right ( diffSize ) ) : QLatin1String ( " " ) )
+ " |0; " ;
}
2011-04-27 10:05:43 +00:00
}
}
2013-02-11 23:25:23 +00:00
if ( conf . WinRT ) {
vcProject . DeploymentFiles . Project = this ;
vcProject . DeploymentFiles . Config = & ( vcProject . Configuration ) ;
}
2011-04-27 10:05:43 +00:00
}
}
2014-02-11 11:49:18 +00:00
void VcprojGenerator : : initWinDeployQtTool ( )
{
VCConfiguration & conf = vcProject . Configuration ;
conf . windeployqt . ExcludedFromBuild = true ;
if ( project - > isActiveConfig ( " windeployqt " ) ) {
conf . windeployqt . Record = QStringLiteral ( " $(TargetName).windeployqt.$(Platform).$(Configuration) " ) ;
2015-03-27 14:56:37 +00:00
const QString commandLine = MakefileGenerator : : shellQuote ( QDir : : toNativeSeparators ( project - > first ( " QMAKE_WINDEPLOYQT " ) . toQString ( ) ) )
+ QLatin1Char ( ' ' ) + project - > values ( " WINDEPLOYQT_OPTIONS " ) . join ( QLatin1Char ( ' ' ) ) ;
// Visual Studio copies all files to be deployed into the MSIL directory
// and then invokes MDILXapCompile on it, which checks for managed code and
// translates it into native code. The problem is that all entries of the
// package will be copied into the MSIL directly, losing the subdirectory
// structure (for instance for plugins). However, the MDILXapCompile call
// itself contains the original subdirectories as parameters and hence the
// call fails.
// Neither there is a way to disable this behavior for Windows Phone, nor
2016-01-04 14:27:16 +00:00
// to influence the parameters. Hence the only way to get a build
2015-03-27 14:56:37 +00:00
// done is to recreate the directory structure manually by invoking
// windeployqt a second time, so that the MDILXapCompile call succeeds and
// deployment continues.
2016-01-04 14:27:16 +00:00
if ( conf . WinPhone ) {
2015-03-27 14:56:37 +00:00
conf . windeployqt . CommandLine = commandLine
+ QStringLiteral ( " -list relative -dir \" $(MSBuildProjectDirectory) \\ " )
+ var ( " OBJECTS_DIR " )
+ QStringLiteral ( " MSIL \" \" $(OutDir) \\ $(TargetName).exe \" " )
+ QLatin1String ( " && " ) ;
}
conf . windeployqt . CommandLine + = commandLine
2014-02-11 11:49:18 +00:00
+ QStringLiteral ( " -list relative -dir \" $(MSBuildProjectDirectory) \" \" $(OutDir) \\ $(TargetName).exe \" > " )
+ MakefileGenerator : : shellQuote ( conf . windeployqt . Record ) ;
conf . windeployqt . config = & vcProject . Configuration ;
conf . windeployqt . ExcludedFromBuild = false ;
}
}
2011-04-27 10:05:43 +00:00
void VcprojGenerator : : initPreLinkEventTools ( )
{
VCConfiguration & conf = vcProject . Configuration ;
if ( ! project - > values ( " QMAKE_PRE_LINK " ) . isEmpty ( ) ) {
QStringList cmdline = VCToolBase : : fixCommandLine ( var ( " QMAKE_PRE_LINK " ) ) ;
conf . preLink . CommandLine = cmdline ;
conf . preLink . Description = cmdline . join ( QLatin1String ( " \r \n " ) ) ;
conf . preLink . ExcludedFromBuild = _False ;
}
}
void VcprojGenerator : : initRootFiles ( )
{
// Note: Root files do _not_ have any filter name, filter nor GUID!
vcProject . RootFiles . addFiles ( project - > values ( " RC_FILE " ) ) ;
vcProject . RootFiles . Project = this ;
vcProject . RootFiles . Config = & ( vcProject . Configuration ) ;
}
void VcprojGenerator : : initSourceFiles ( )
{
vcProject . SourceFiles . Name = " Source Files " ;
vcProject . SourceFiles . Filter = " cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx " ;
vcProject . SourceFiles . Guid = _GUIDSourceFiles ;
vcProject . SourceFiles . addFiles ( project - > values ( " SOURCES " ) ) ;
vcProject . SourceFiles . Project = this ;
vcProject . SourceFiles . Config = & ( vcProject . Configuration ) ;
}
void VcprojGenerator : : initHeaderFiles ( )
{
vcProject . HeaderFiles . Name = " Header Files " ;
vcProject . HeaderFiles . Filter = " h;hpp;hxx;hm;inl;inc;xsd " ;
vcProject . HeaderFiles . Guid = _GUIDHeaderFiles ;
vcProject . HeaderFiles . addFiles ( project - > values ( " HEADERS " ) ) ;
if ( usePCH ) // Generated PCH cpp file
vcProject . HeaderFiles . addFile ( precompH ) ;
vcProject . HeaderFiles . Project = this ;
vcProject . HeaderFiles . Config = & ( vcProject . Configuration ) ;
// vcProject.HeaderFiles.CustomBuild = mocHdr;
// addMocArguments(vcProject.HeaderFiles);
}
void VcprojGenerator : : initGeneratedFiles ( )
{
vcProject . GeneratedFiles . Name = " Generated Files " ;
vcProject . GeneratedFiles . Filter = " cpp;c;cxx;moc;h;def;odl;idl;res; " ;
vcProject . GeneratedFiles . Guid = _GUIDGeneratedFiles ;
// ### These cannot have CustomBuild (mocSrc)!!
vcProject . GeneratedFiles . addFiles ( project - > values ( " GENERATED_SOURCES " ) ) ;
vcProject . GeneratedFiles . addFiles ( project - > values ( " GENERATED_FILES " ) ) ;
vcProject . GeneratedFiles . addFiles ( project - > values ( " IDLSOURCES " ) ) ;
2013-07-02 12:44:53 +00:00
if ( project - > values ( " RC_FILE " ) . isEmpty ( ) )
vcProject . GeneratedFiles . addFiles ( project - > values ( " RES_FILE " ) ) ;
2011-04-27 10:05:43 +00:00
if ( ! extraCompilerOutputs . isEmpty ( ) )
vcProject . GeneratedFiles . addFiles ( extraCompilerOutputs . keys ( ) ) ;
vcProject . GeneratedFiles . Project = this ;
vcProject . GeneratedFiles . Config = & ( vcProject . Configuration ) ;
// vcProject.GeneratedFiles.CustomBuild = mocSrc;
}
void VcprojGenerator : : initLexYaccFiles ( )
{
vcProject . LexYaccFiles . Name = " Lex / Yacc Files " ;
vcProject . LexYaccFiles . ParseFiles = _False ;
vcProject . LexYaccFiles . Filter = " l;y " ;
vcProject . LexYaccFiles . Guid = _GUIDLexYaccFiles ;
vcProject . LexYaccFiles . addFiles ( project - > values ( " LEXSOURCES " ) ) ;
vcProject . LexYaccFiles . addFiles ( project - > values ( " YACCSOURCES " ) ) ;
vcProject . LexYaccFiles . Project = this ;
vcProject . LexYaccFiles . Config = & ( vcProject . Configuration ) ;
}
void VcprojGenerator : : initTranslationFiles ( )
{
vcProject . TranslationFiles . Name = " Translation Files " ;
vcProject . TranslationFiles . ParseFiles = _False ;
vcProject . TranslationFiles . Filter = " ts;xlf " ;
vcProject . TranslationFiles . Guid = _GUIDTranslationFiles ;
vcProject . TranslationFiles . addFiles ( project - > values ( " TRANSLATIONS " ) ) ;
vcProject . TranslationFiles . Project = this ;
vcProject . TranslationFiles . Config = & ( vcProject . Configuration ) ;
}
void VcprojGenerator : : initFormFiles ( )
{
vcProject . FormFiles . Name = " Form Files " ;
vcProject . FormFiles . ParseFiles = _False ;
vcProject . FormFiles . Filter = " ui " ;
vcProject . FormFiles . Guid = _GUIDFormFiles ;
vcProject . FormFiles . addFiles ( project - > values ( " FORMS " ) ) ;
vcProject . FormFiles . Project = this ;
vcProject . FormFiles . Config = & ( vcProject . Configuration ) ;
}
void VcprojGenerator : : initResourceFiles ( )
{
vcProject . ResourceFiles . Name = " Resource Files " ;
vcProject . ResourceFiles . ParseFiles = _False ;
vcProject . ResourceFiles . Filter = " qrc;* " ; //"rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;ts;xlf;qrc";
vcProject . ResourceFiles . Guid = _GUIDResourceFiles ;
// Bad hack, please look away -------------------------------------
2012-05-18 18:00:23 +00:00
QString rcc_dep_cmd = project - > values ( " rcc.depend_command " ) . join ( ' ' ) ;
2011-04-27 10:05:43 +00:00
if ( ! rcc_dep_cmd . isEmpty ( ) ) {
2012-09-06 10:21:38 +00:00
ProStringList qrc_files = project - > values ( " RESOURCES " ) ;
2011-04-27 10:05:43 +00:00
QStringList deps ;
if ( ! qrc_files . isEmpty ( ) ) {
for ( int i = 0 ; i < qrc_files . count ( ) ; + + i ) {
char buff [ 256 ] ;
2014-11-20 15:20:16 +00:00
QString dep_cmd = replaceExtraCompilerVariables (
rcc_dep_cmd , qrc_files . at ( i ) . toQString ( ) , QString ( ) , LocalShell ) ;
2011-04-27 10:05:43 +00:00
dep_cmd = Option : : fixPathToLocalOS ( dep_cmd , true , false ) ;
if ( canExecute ( dep_cmd ) ) {
dep_cmd . prepend ( QLatin1String ( " cd " )
+ escapeFilePath ( Option : : fixPathToLocalOS ( Option : : output_dir , false ) )
+ QLatin1String ( " && " ) ) ;
if ( FILE * proc = QT_POPEN ( dep_cmd . toLatin1 ( ) . constData ( ) , " r " ) ) {
QString indeps ;
while ( ! feof ( proc ) ) {
int read_in = ( int ) fread ( buff , 1 , 255 , proc ) ;
if ( ! read_in )
break ;
indeps + = QByteArray ( buff , read_in ) ;
}
QT_PCLOSE ( proc ) ;
if ( ! indeps . isEmpty ( ) )
deps + = fileFixify ( indeps . replace ( ' \n ' , ' ' ) . simplified ( ) . split ( ' ' ) ,
2015-04-13 19:18:36 +00:00
FileFixifyFromOutdir ) ;
2011-04-27 10:05:43 +00:00
}
}
}
vcProject . ResourceFiles . addFiles ( deps ) ;
}
}
// You may look again --------------------------------------------
vcProject . ResourceFiles . addFiles ( project - > values ( " RESOURCES " ) ) ;
vcProject . ResourceFiles . Project = this ;
vcProject . ResourceFiles . Config = & ( vcProject . Configuration ) ;
}
2015-03-20 09:58:02 +00:00
void VcprojGenerator : : initDistributionFiles ( )
{
vcProject . DistributionFiles . Name = " Distribution Files " ;
vcProject . DistributionFiles . ParseFiles = _False ;
vcProject . DistributionFiles . Filter = " * " ;
vcProject . DistributionFiles . Guid = _GUIDDistributionFiles ;
vcProject . DistributionFiles . addFiles ( project - > values ( " DISTFILES " ) ) ;
vcProject . DistributionFiles . Project = this ;
vcProject . DistributionFiles . Config = & ( vcProject . Configuration ) ;
}
2011-04-27 10:05:43 +00:00
void VcprojGenerator : : initExtraCompilerOutputs ( )
{
2012-09-06 10:21:38 +00:00
ProStringList otherFilters ;
2011-04-27 10:05:43 +00:00
otherFilters < < " FORMS "
< < " GENERATED_FILES "
< < " GENERATED_SOURCES "
< < " HEADERS "
< < " IDLSOURCES "
< < " LEXSOURCES "
< < " RC_FILE "
< < " RESOURCES "
< < " RES_FILE "
< < " SOURCES "
< < " TRANSLATIONS "
< < " YACCSOURCES " ;
2012-09-06 10:21:38 +00:00
const ProStringList & quc = project - > values ( " QMAKE_EXTRA_COMPILERS " ) ;
for ( ProStringList : : ConstIterator it = quc . begin ( ) ; it ! = quc . end ( ) ; + + it ) {
ProString extracompilerName = project - > first ( ProKey ( * it + " .name " ) ) ;
2011-04-27 10:05:43 +00:00
if ( extracompilerName . isEmpty ( ) )
extracompilerName = ( * it ) ;
// Create an extra compiler filter and add the files
VCFilter extraCompile ;
2012-09-06 10:21:38 +00:00
extraCompile . Name = extracompilerName . toQString ( ) ;
2011-04-27 10:05:43 +00:00
extraCompile . ParseFiles = _False ;
extraCompile . Filter = " " ;
extraCompile . Guid = QString ( _GUIDExtraCompilerFiles ) + " - " + ( * it ) ;
// If the extra compiler has a variable_out set the output file
// is added to an other file list, and does not need its own..
2015-04-21 13:43:29 +00:00
bool addOnInput = hasBuiltinCompiler ( firstExpandedOutputFileName ( * it ) ) ;
2012-09-06 10:21:38 +00:00
const ProString & tmp_other_out = project - > first ( ProKey ( * it + " .variable_out " ) ) ;
2011-04-27 10:05:43 +00:00
if ( ! tmp_other_out . isEmpty ( ) & & ! addOnInput )
continue ;
if ( ! addOnInput ) {
2012-09-06 10:21:38 +00:00
QString tmp_out = project - > first ( ProKey ( * it + " .output " ) ) . toQString ( ) ;
if ( project - > values ( ProKey ( * it + " .CONFIG " ) ) . indexOf ( " combine " ) ! = - 1 ) {
2011-04-27 10:05:43 +00:00
// Combined output, only one file result
2014-11-20 15:20:16 +00:00
extraCompile . addFile ( Option : : fixPathToTargetOS (
replaceExtraCompilerVariables ( tmp_out , QString ( ) , QString ( ) , NoShell ) , false ) ) ;
2011-04-27 10:05:43 +00:00
} else {
// One output file per input
2012-09-06 10:21:38 +00:00
const ProStringList & tmp_in = project - > values ( project - > first ( ProKey ( * it + " .input " ) ) . toKey ( ) ) ;
2011-04-27 10:05:43 +00:00
for ( int i = 0 ; i < tmp_in . count ( ) ; + + i ) {
2012-09-06 10:21:38 +00:00
const QString & filename = tmp_in . at ( i ) . toQString ( ) ;
2011-04-27 10:05:43 +00:00
if ( extraCompilerSources . contains ( filename ) )
2014-11-20 15:20:16 +00:00
extraCompile . addFile ( Option : : fixPathToTargetOS (
replaceExtraCompilerVariables ( filename , tmp_out , QString ( ) , NoShell ) , false ) ) ;
2011-04-27 10:05:43 +00:00
}
}
} else {
// In this case we the outputs have a built-in compiler, so we cannot add the custom
// build steps there. So, we turn it around and add it to the input files instead,
// provided that the input file variable is not handled already (those in otherFilters
// are handled, so we avoid them).
2012-09-06 10:21:38 +00:00
const ProStringList & inputVars = project - > values ( ProKey ( * it + " .input " ) ) ;
foreach ( const ProString & inputVar , inputVars ) {
2011-04-27 10:05:43 +00:00
if ( ! otherFilters . contains ( inputVar ) ) {
2012-09-06 10:21:38 +00:00
const ProStringList & tmp_in = project - > values ( inputVar . toKey ( ) ) ;
2011-04-27 10:05:43 +00:00
for ( int i = 0 ; i < tmp_in . count ( ) ; + + i ) {
2012-09-06 10:21:38 +00:00
const QString & filename = tmp_in . at ( i ) . toQString ( ) ;
2011-04-27 10:05:43 +00:00
if ( extraCompilerSources . contains ( filename ) )
2014-11-20 15:20:16 +00:00
extraCompile . addFile ( Option : : fixPathToTargetOS (
replaceExtraCompilerVariables ( filename , QString ( ) , QString ( ) , NoShell ) , false ) ) ;
2011-04-27 10:05:43 +00:00
}
}
}
}
extraCompile . Project = this ;
extraCompile . Config = & ( vcProject . Configuration ) ;
vcProject . ExtraCompilersFiles . append ( extraCompile ) ;
}
}
// ------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------
VCProjectWriter * VcprojGenerator : : createProjectWriter ( )
{
return new VCProjectWriter ;
}
2014-11-20 15:20:16 +00:00
QString VcprojGenerator : : replaceExtraCompilerVariables (
const QString & var , const QStringList & in , const QStringList & out , ReplaceFor forShell )
2011-04-27 10:05:43 +00:00
{
2014-11-20 15:20:16 +00:00
QString ret = MakefileGenerator : : replaceExtraCompilerVariables ( var , in , out , forShell ) ;
2011-04-27 10:05:43 +00:00
2012-09-06 10:21:38 +00:00
ProStringList & defines = project - > values ( " VCPROJ_MAKEFILE_DEFINES " ) ;
2011-04-27 10:05:43 +00:00
if ( defines . isEmpty ( ) )
defines . append ( varGlue ( " PRL_EXPORT_DEFINES " , " -D " , " -D " , " " ) +
varGlue ( " DEFINES " , " -D " , " -D " , " " ) ) ;
2016-02-04 14:12:03 +00:00
ret . replace ( QLatin1String ( " $(DEFINES) " ) , defines . first ( ) . toQString ( ) ) ;
2011-04-27 10:05:43 +00:00
2012-09-06 10:21:38 +00:00
ProStringList & incpath = project - > values ( " VCPROJ_MAKEFILE_INCPATH " ) ;
2011-04-27 10:05:43 +00:00
if ( incpath . isEmpty ( ) & & ! this - > var ( " MSVCPROJ_INCPATH " ) . isEmpty ( ) )
incpath . append ( this - > var ( " MSVCPROJ_INCPATH " ) ) ;
2016-02-04 14:12:03 +00:00
ret . replace ( QLatin1String ( " $(INCPATH) " ) , incpath . join ( ' ' ) ) ;
2011-04-27 10:05:43 +00:00
return ret ;
}
bool VcprojGenerator : : openOutput ( QFile & file , const QString & /*build*/ ) const
{
QString outdir ;
if ( ! file . fileName ( ) . isEmpty ( ) ) {
QFileInfo fi ( fileInfo ( file . fileName ( ) ) ) ;
if ( fi . isDir ( ) )
outdir = file . fileName ( ) + QDir : : separator ( ) ;
}
if ( ! outdir . isEmpty ( ) | | file . fileName ( ) . isEmpty ( ) ) {
2012-09-06 10:21:38 +00:00
ProString ext = project - > first ( " VCPROJ_EXTENSION " ) ;
2011-04-27 10:05:43 +00:00
if ( project - > first ( " TEMPLATE " ) = = " vcsubdirs " )
ext = project - > first ( " VCSOLUTION_EXTENSION " ) ;
2015-02-06 14:30:02 +00:00
ProString outputName = project - > first ( " TARGET " ) ;
2011-04-27 10:05:43 +00:00
if ( ! project - > first ( " MAKEFILE " ) . isEmpty ( ) )
outputName = project - > first ( " MAKEFILE " ) ;
file . setFileName ( outdir + outputName + ext ) ;
}
return Win32MakefileGenerator : : openOutput ( file , QString ( ) ) ;
}
QT_END_NAMESPACE