Skip to content

Commit

Permalink
Projucer: Added an "add recommended warning flags" checkbox to the ex…
Browse files Browse the repository at this point in the history
…porters
  • Loading branch information
tpoole committed Jun 11, 2019
1 parent d4b7cce commit 1fd9c2f
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 9 deletions.
19 changes: 14 additions & 5 deletions extras/Projucer/Source/ProjectSaving/jucer_ProjectExport_Android.h
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ class AndroidProjectExporter : public ProjectExporter

void createConfigProperties (PropertyListBuilder& props) override
{
addRecommendedLLVMCompilerWarningsProperty (props);
addGCCOptimisationProperty (props);

props.add (new TextPropertyComponent (androidArchitectures, "Architectures", 256, false),
Expand Down Expand Up @@ -634,11 +635,19 @@ class AndroidProjectExporter : public ProjectExporter
if (getProject().getProjectType().isStaticLibrary())
mo << " targets \"" << getNativeModuleBinaryName (cfg) << "\"" << newLine;

mo << " arguments \"-DJUCE_BUILD_CONFIGURATION=" << cfg.getProductFlavourCMakeIdentifier() << "\""
<< ", \"-DCMAKE_CXX_FLAGS_" << (cfg.isDebug() ? "DEBUG" : "RELEASE")
<< "=-O" << cfg.getGCCOptimisationFlag() << "\""
<< ", \"-DCMAKE_C_FLAGS_" << (cfg.isDebug() ? "DEBUG" : "RELEASE")
<< "=-O" << cfg.getGCCOptimisationFlag() << "\"" << newLine;
mo << " arguments "
<< "\"-DJUCE_BUILD_CONFIGURATION=" << cfg.getProductFlavourCMakeIdentifier() << "\"";

mo << ", \"-DCMAKE_CXX_FLAGS_" << (cfg.isDebug() ? "DEBUG" : "RELEASE")
<< "=-O" << cfg.getGCCOptimisationFlag();

for (auto& flag : cfg.getRecommendedCompilerWarningFlags())
mo << " " << flag;

mo << "\""
<< ", \"-DCMAKE_C_FLAGS_" << (cfg.isDebug() ? "DEBUG" : "RELEASE")
<< "=-O" << cfg.getGCCOptimisationFlag()
<< "\"" << newLine;

mo << " }" << newLine;
mo << " }" << newLine << newLine;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ class CodeBlocksProjectExporter : public ProjectExporter

void createConfigProperties (PropertyListBuilder& props) override
{
addRecommendedLinuxCompilerWarningsProperty (props);
addGCCOptimisationProperty (props);

props.add (new ChoicePropertyComponent (architectureTypeValue, "Architecture",
Expand Down Expand Up @@ -401,6 +402,9 @@ class CodeBlocksProjectExporter : public ProjectExporter
if (auto* codeBlocksConfig = dynamic_cast<const CodeBlocksBuildConfiguration*> (&config))
flags.add (codeBlocksConfig->getArchitectureTypeString());

for (auto& recommended : config.getRecommendedCompilerWarningFlags())
flags.add (recommended);

flags.add ("-O" + config.getGCCOptimisationFlag());

if (config.isLinkTimeOptimisationEnabled())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class MakefileProjectExporter : public ProjectExporter

void createConfigProperties (PropertyListBuilder& props) override
{
addRecommendedLinuxCompilerWarningsProperty (props);
addGCCOptimisationProperty (props);

props.add (new ChoicePropertyComponent (architectureTypeValue, "Architecture",
Expand Down Expand Up @@ -521,6 +522,9 @@ class MakefileProjectExporter : public ProjectExporter
if (extra.isNotEmpty())
result.add (extra);

for (auto& recommended : config.getRecommendedCompilerWarningFlags())
result.add (recommended);

return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,7 @@ class XcodeProjectExporter : public ProjectExporter
void createConfigProperties (PropertyListBuilder& props) override
{
addXcodePluginInstallPathProperties (props);
addRecommendedLLVMCompilerWarningsProperty (props);
addGCCOptimisationProperty (props);

if (iOS)
Expand Down Expand Up @@ -1244,10 +1245,11 @@ class XcodeProjectExporter : public ProjectExporter
if (config.isFastMathEnabled())
s.set ("GCC_FAST_MATH", "YES");

auto extraFlags = owner.replacePreprocessorTokens (config, owner.getExtraCompilerFlagsString()).trim();
auto flags = (owner.replacePreprocessorTokens (config, owner.getExtraCompilerFlagsString())
+ " " + config.getRecommendedCompilerWarningFlags().joinIntoString (" ")).trim();

if (extraFlags.isNotEmpty())
s.set ("OTHER_CPLUSPLUSFLAGS", extraFlags.quoted());
if (flags.isNotEmpty())
s.set ("OTHER_CPLUSPLUSFLAGS", flags.quoted());

auto installPath = getInstallPathForConfiguration (config);

Expand Down
42 changes: 42 additions & 0 deletions extras/Projucer/Source/ProjectSaving/jucer_ProjectExporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -923,13 +923,26 @@ ProjectExporter::BuildConfiguration::BuildConfiguration (Project& p, const Value
configNameValue (config, Ids::name, getUndoManager(), "Build Configuration"),
targetNameValue (config, Ids::targetName, getUndoManager(), project.getProjectFilenameRootString()),
targetBinaryPathValue (config, Ids::binaryPath, getUndoManager()),
recommendedWarningsValue (config, Ids::recommendedWarnings, getUndoManager()),
optimisationLevelValue (config, Ids::optimisation, getUndoManager()),
linkTimeOptimisationValue (config, Ids::linkTimeOptimisation, getUndoManager(), ! isDebug()),
ppDefinesValue (config, Ids::defines, getUndoManager()),
headerSearchPathValue (config, Ids::headerPath, getUndoManager()),
librarySearchPathValue (config, Ids::libraryPath, getUndoManager()),
userNotesValue (config, Ids::userNotes, getUndoManager())
{
recommendedCompilerWarningFlags["LLVM"] = { "-Wall", "-Wshadow-all", "-Wshorten-64-to-32", "-Wstrict-aliasing", "-Wuninitialized", "-Wunused-parameter",
"-Wconversion", "-Wsign-compare", "-Wint-conversion", "-Wconditional-uninitialized", "-Woverloaded-virtual",
"-Wreorder", "-Wconstant-conversion", "-Wsign-conversion", "-Wunused-private-field", "-Wbool-conversion",
"-Wextra-semi", "-Wunreachable-code", "-Wzero-as-null-pointer-constant", "-Wcast-align",
"-Winconsistent-missing-destructor-override", "-Wshift-sign-overflow", "-Wnullable-to-nonnull-conversion",
"-Wno-missing-field-initializers", "-Wno-ignored-qualifiers" };
recommendedCompilerWarningFlags["GCC"] = { "-Wall", "-Wextra", "-Wstrict-aliasing", "-Wuninitialized", "-Wunused-parameter", "-Wsign-compare",
"-Woverloaded-virtual", "-Wreorder", "-Wsign-conversion", "-Wunreachable-code",
"-Wzero-as-null-pointer-constant", "-Wcast-align", "-Wno-implicit-fallthrough",
"-Wno-maybe-uninitialized", "-Wno-missing-field-initializers", "-Wno-ignored-qualifiers" };
recommendedCompilerWarningFlags["GCC-7"] = recommendedCompilerWarningFlags["GCC"];
recommendedCompilerWarningFlags["GCC-7"].add ("-Wno-strict-overflow");
}

ProjectExporter::BuildConfiguration::~BuildConfiguration()
Expand Down Expand Up @@ -961,6 +974,35 @@ void ProjectExporter::BuildConfiguration::addGCCOptimisationProperty (PropertyLi
"The optimisation level for this configuration");
}

void ProjectExporter::BuildConfiguration::addRecommendedLinuxCompilerWarningsProperty (PropertyListBuilder& props)
{
props.add (new ChoicePropertyComponent (recommendedWarningsValue, "Add Recommended Compiler Warning Flags",
{ "GCC", "GCC 7 and below", "LLVM", "Disabled" },
{ "GCC", "GCC-7", "LLVM", "" }),
"Enable this to add a set of recommended compiler warning flags.");
recommendedWarningsValue.setDefault ("");
}

void ProjectExporter::BuildConfiguration::addRecommendedLLVMCompilerWarningsProperty (PropertyListBuilder& props)
{
props.add (new ChoicePropertyComponent (recommendedWarningsValue, "Add Recommended Compiler Warning Flags",
{ "Enabled", "Disabled" },
{ "LLVM", "" }),
"Enable this to add a set of recommended compiler warning flags.");
recommendedWarningsValue.setDefault ("");
}

StringArray ProjectExporter::BuildConfiguration::getRecommendedCompilerWarningFlags() const
{
auto label = recommendedWarningsValue.get().toString();
auto it = recommendedCompilerWarningFlags.find (label);

if (it != recommendedCompilerWarningFlags.end())
return it->second;

return {};
}

void ProjectExporter::BuildConfiguration::createPropertyEditors (PropertyListBuilder& props)
{
if (exporter.supportsUserDefinedConfigurations())
Expand Down
7 changes: 6 additions & 1 deletion extras/Projucer/Source/ProjectSaving/jucer_ProjectExporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,9 @@ class ProjectExporter : private Value::Listener

//==============================================================================
void createPropertyEditors (PropertyListBuilder&);
void addRecommendedLinuxCompilerWarningsProperty (PropertyListBuilder&);
void addRecommendedLLVMCompilerWarningsProperty (PropertyListBuilder&);
StringArray getRecommendedCompilerWarningFlags() const;
void addGCCOptimisationProperty (PropertyListBuilder&);
void removeFromExporter();

Expand All @@ -281,10 +284,12 @@ class ProjectExporter : private Value::Listener
const ProjectExporter& exporter;

protected:
ValueWithDefault isDebugValue, configNameValue, targetNameValue, targetBinaryPathValue, optimisationLevelValue,
ValueWithDefault isDebugValue, configNameValue, targetNameValue, targetBinaryPathValue, recommendedWarningsValue, optimisationLevelValue,
linkTimeOptimisationValue, ppDefinesValue, headerSearchPathValue, librarySearchPathValue, userNotesValue;

private:
std::map<String, StringArray> recommendedCompilerWarningFlags;

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (BuildConfiguration)
};

Expand Down
1 change: 1 addition & 0 deletions extras/Projucer/Source/Utility/Helpers/jucer_PresetIDs.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ namespace Ids
DECLARE_ID (alwaysGenerateDebugSymbols);
DECLARE_ID (targetName);
DECLARE_ID (binaryPath);
DECLARE_ID (recommendedWarnings);
DECLARE_ID (optimisation);
DECLARE_ID (defines);
DECLARE_ID (headerPath);
Expand Down

0 comments on commit 1fd9c2f

Please sign in to comment.