示例#1
0
void MSBuildQbsProductProject::addItemDefGroup(const Project &project,
                                               const ProductData &productData)
{
    const auto properties = productData.moduleProperties();

    const bool consoleApp = productData.properties().value(QStringLiteral("consoleApplication"))
            .toBool();
    const bool debugBuild = properties.getModuleProperty(QStringLiteral("qbs"),
                                                         QStringLiteral("debugInformation"))
            .toBool();
    const auto optimizationLevel = properties.getModuleProperty(QStringLiteral("qbs"),
                                                                QStringLiteral("optimization"))
            .toString();
    const auto warningLevel = properties.getModuleProperty(QStringLiteral("qbs"),
                                                           QStringLiteral("warningLevel"))
            .toString();

    const auto includePaths = QStringList()
            << properties.getModulePropertiesAsStringList(QStringLiteral("cpp"),
                                                          QStringLiteral("includePaths"))
            << properties.getModulePropertiesAsStringList(QStringLiteral("cpp"),
                                                          QStringLiteral("systemIncludePaths"));
    const auto cppDefines = properties.getModulePropertiesAsStringList(
                QStringLiteral("cpp"), QStringLiteral("defines"));

    const auto sep = Internal::HostOsInfo::pathListSeparator(Internal::HostOsInfo::HostOsWindows);

    auto itemDefGroup = new MSBuildItemDefinitionGroup(this);
    itemDefGroup->setCondition(MSBuildUtils::buildTaskCondition(project));

    auto compile = new MSBuildClCompile(itemDefGroup);

    // C++ - General
    compile->appendProperty(QStringLiteral("AdditionalIncludeDirectories"),
                            includePaths.join(sep)
                                + sep
                                + QStringLiteral("%(AdditionalIncludeDirectories)"));
    if (warningLevel == QStringLiteral("none"))
        compile->appendProperty(QStringLiteral("WarningLevel"),
                                QStringLiteral("TurnOffAllWarnings"));
    else if (warningLevel == QStringLiteral("all"))
        compile->appendProperty(QStringLiteral("WarningLevel"),
                                QStringLiteral("EnableAllWarnings"));
    else
        compile->appendProperty(QStringLiteral("WarningLevel"),
                                QStringLiteral("Level3")); // this is VS default.

    // C++ - Optimization
    compile->appendProperty(QStringLiteral("Optimization"),
                            optimizationLevel == QStringLiteral("none")
                                ? QStringLiteral("Disabled")
                                : QStringLiteral("MaxSpeed"));

    // C++ - Preprocessor
    compile->appendProperty(QStringLiteral("PreprocessorDefinitions"),
                            cppDefines.join(sep)
                                + sep
                                + QStringLiteral("%(PreprocessorDefinitions)"));

    // C++ - Code Generation
    compile->appendProperty(QStringLiteral("RuntimeLibrary"), debugBuild
                            ? QStringLiteral("MultiThreadedDebugDLL")
                            : QStringLiteral("MultiThreadedDLL"));

    auto link = new MSBuildLink(itemDefGroup);

    // Linker - General
    link->appendProperty(QStringLiteral("AdditionalLibraryDirectories"),
        properties.getModulePropertiesAsStringList(QStringLiteral("cpp"),
                                                   QStringLiteral("libraryPaths")).join(sep));

    // Linker - Input
    link->appendProperty(QStringLiteral("AdditionalDependencies"),
        properties.getModulePropertiesAsStringList(QStringLiteral("cpp"),
                                                   QStringLiteral("staticLibraries")).join(sep)
                                            + sep + QStringLiteral("%(AdditionalDependencies)"));

    // Linker - Debugging
    link->appendProperty(QStringLiteral("GenerateDebugInformation"),
                         debugBuild ? QStringLiteral("true") : QStringLiteral("false"));

    // Linker - System
    link->appendProperty(QStringLiteral("SubSystem"),
                         consoleApp ? QStringLiteral("Console") : QStringLiteral("Windows"));
    const auto subsysVersion = properties.getModuleProperty(
                QStringLiteral("cpp"), QStringLiteral("minimumWindowsVersion")).toString();
    if (!subsysVersion.isEmpty())
        link->appendProperty(QStringLiteral("MinimumRequiredVersion"),
                             subsystemVersion(subsysVersion));

    // Linker - Optimization
    link->appendProperty(QStringLiteral("OptimizeReferences"),
                         debugBuild ? QStringLiteral("false") : QStringLiteral("true"));
}