Distinguish between Objective-C and Objective-C++ sources

Instead of lumping both Objective-C (.m) and Objective-C++ (.mm) sources
into the same pile, passing them on to the same compiler as for C++ (CXX),
with the C++ flags (CXXFLAGS), we follow Apple's lead and treat them as
variants of the C and C++ languages separately, so that Objective-C
sources are built with CC and with CFLAGS, and Objective-C++ sources
with CXX, and CXXFLAGS.

This lets us remove a lot of duplicated flags and definitions from the
QMAKE_OBJECTIVE_CFLAGS variable, which in 99% of the cases just matched
the C++ equivalent. The remaining Objective-C/C++ flags are added to
CFLAGS/CXXFLAGS, as the compiler will just ignore them when running in
C/C++ mode. This matches Xcode, which also doesn't have a separate build
setting for Objective-C/C++ flags.

The Makefile qmake generator has been rewritten to support Objective-C/C++
fully, by not assuming that we're just iterating over the C and C++
extensions when dealing with compilation rules, precompiled headers, etc.
There's some duplicated logic in this code, as inherent by qmake's already
duplicated code paths, but this can be cleaned up when C++11 support is
mandatory and we can use lambda functions.

Task-number: QTBUG-36575
Change-Id: I4f06576d5f49e939333a2e03d965da54119e5e31
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@theqtcompany.com>
This commit is contained in:
Tor Arne Vestbø 2015-10-02 13:54:33 +02:00 committed by Thiago Macieira
parent a3a7d485fa
commit 9ff1310af5
23 changed files with 138 additions and 173 deletions

3
configure vendored
View File

@ -318,7 +318,7 @@ macSDKify()
val=$(echo $sdk_val $(echo $val | cut -s -d ' ' -f 2-))
echo "$var=$val"
;;
QMAKE_CFLAGS=*|QMAKE_CXXFLAGS=*|QMAKE_OBJECTIVE_CFLAGS=*)
QMAKE_CFLAGS=*|QMAKE_CXXFLAGS=*)
echo "$line -isysroot $sysroot $version_min_flag"
;;
QMAKE_LFLAGS=*)
@ -6413,7 +6413,6 @@ if [ '!' -z "$W_FLAGS" ]; then
# add the user defined warning flags
QMakeVar add QMAKE_CFLAGS_WARN_ON "$W_FLAGS"
QMakeVar add QMAKE_CXXFLAGS_WARN_ON "$W_FLAGS"
QMakeVar add QMAKE_OBJECTIVE_CFLAGS_WARN_ON "$W_FLAGS"
fi
if [ "$XPLATFORM_MINGW" = "yes" ]; then

View File

@ -7,5 +7,4 @@ QMAKE_OBJCXXFLAGS_USE_PRECOMPILE = $$QMAKE_CFLAGS_USE_PRECOMPILE
QMAKE_XCODE_GCC_VERSION = com.apple.compilers.llvm.clang.1_0
QMAKE_CXXFLAGS += -stdlib=libc++
QMAKE_OBJECTIVE_CFLAGS += -stdlib=libc++
QMAKE_LFLAGS += -stdlib=libc++

View File

@ -12,14 +12,6 @@ include(gcc-base.conf)
QMAKE_COMPILER_DEFINES += __APPLE__ __GNUC__=4 __APPLE_CC__
QMAKE_OBJECTIVE_CFLAGS = $$QMAKE_CFLAGS
QMAKE_OBJECTIVE_CFLAGS_WARN_ON = $$QMAKE_CFLAGS_WARN_ON
QMAKE_OBJECTIVE_CFLAGS_WARN_OFF = $$QMAKE_CFLAGS_WARN_OFF
QMAKE_OBJECTIVE_CFLAGS_DEBUG = $$QMAKE_CFLAGS_DEBUG
QMAKE_OBJECTIVE_CFLAGS_RELEASE = $$QMAKE_CFLAGS_RELEASE
QMAKE_OBJECTIVE_CFLAGS_RELEASE_WITH_DEBUGINFO = $$QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO
QMAKE_OBJECTIVE_CFLAGS_HIDESYMS = $$QMAKE_CXXFLAGS_HIDESYMS
QMAKE_LFLAGS += -headerpad_max_install_names
QMAKE_LFLAGS_SHLIB += -single_module -dynamiclib

View File

@ -22,7 +22,7 @@ QMAKE_IOS_OBJ_CFLAGS += -Wno-deprecated-implementations -Wprotocol -Wno-select
# Set build flags
QMAKE_CFLAGS += $$QMAKE_IOS_CFLAGS
QMAKE_CXXFLAGS += $$QMAKE_IOS_CFLAGS $$QMAKE_IOS_CXXFLAGS
QMAKE_OBJECTIVE_CFLAGS += $$QMAKE_IOS_CFLAGS $$QMAKE_IOS_CXXFLAGS $$QMAKE_IOS_OBJ_CFLAGS
QMAKE_OBJECTIVE_CFLAGS += $$QMAKE_IOS_OBJ_CFLAGS
QMAKE_IOS_CFLAGS =
QMAKE_IOS_CXXFLAGS =

View File

@ -35,7 +35,6 @@ force_debug_info|debug: \
force_debug_info {
QMAKE_CFLAGS_RELEASE = $$QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO
QMAKE_CXXFLAGS_RELEASE = $$QMAKE_CXXFLAGS_RELEASE_WITH_DEBUGINFO
QMAKE_OBJECTIVE_CFLAGS_RELEASE = $$QMAKE_OBJECTIVE_CFLAGS_RELEASE_WITH_DEBUGINFO
QMAKE_LFLAGS_RELEASE = $$QMAKE_LFLAGS_RELEASE_WITH_DEBUGINFO
}
@ -51,13 +50,11 @@ optimize_full {
debug {
QMAKE_CFLAGS += $$QMAKE_CFLAGS_DEBUG
QMAKE_CXXFLAGS += $$QMAKE_CXXFLAGS_DEBUG
QMAKE_OBJECTIVE_CFLAGS += $$QMAKE_OBJECTIVE_CFLAGS_DEBUG
QMAKE_LFLAGS += $$QMAKE_LFLAGS_DEBUG
QMAKE_LIBFLAGS += $$QMAKE_LIBFLAGS_DEBUG
} else {
QMAKE_CFLAGS += $$QMAKE_CFLAGS_RELEASE
QMAKE_CXXFLAGS += $$QMAKE_CXXFLAGS_RELEASE
QMAKE_OBJECTIVE_CFLAGS += $$QMAKE_OBJECTIVE_CFLAGS_RELEASE
QMAKE_LFLAGS += $$QMAKE_LFLAGS_RELEASE
QMAKE_LIBFLAGS += $$QMAKE_LIBFLAGS_RELEASE
}
@ -107,7 +104,6 @@ c++11|c++14|c++1z {
!strict_c++:!isEmpty(QMAKE_CXXFLAGS_GNU$$cxxstd): cxxstd = GNU$$cxxstd
QMAKE_CXXFLAGS += $$eval(QMAKE_CXXFLAGS_$$cxxstd)
QMAKE_OBJECTIVE_CFLAGS += $$eval(QMAKE_CXXFLAGS_$$cxxstd)
QMAKE_LFLAGS += $$eval(QMAKE_LFLAGS_$$cxxstd)
unset(cxxstd)

View File

@ -25,7 +25,6 @@
QMAKE_CFLAGS += -fprofile-arcs -ftest-coverage
QMAKE_CXXFLAGS += -fprofile-arcs -ftest-coverage
QMAKE_OBJECTIVE_CFLAGS += -fprofile-arcs -ftest-coverage
QMAKE_LFLAGS += -fprofile-arcs -ftest-coverage
QMAKE_CLEAN += $(OBJECTS_DIR)*.gcno and $(OBJECTS_DIR)*.gcda

View File

@ -1,23 +1,10 @@
for(source, SOURCES) {
contains(source,.*\\.mm?$) {
warning(Objective-C source \'$$source\' found in SOURCES but should be in OBJECTIVE_SOURCES)
SOURCES -= $$source
OBJECTIVE_SOURCES += $$source
}
}
# Objective-C/C++ sources go in SOURCES, like all other sources
SOURCES += $$OBJECTIVE_SOURCES
isEmpty(QMAKE_OBJECTIVE_CC):QMAKE_OBJECTIVE_CC = $$QMAKE_CC
# Strip C/C++ flags from QMAKE_OBJECTIVE_CFLAGS just in case
QMAKE_OBJECTIVE_CFLAGS -= $$QMAKE_CFLAGS $$QMAKE_CXXFLAGS
OBJECTIVE_C_OBJECTS_DIR = $$OBJECTS_DIR
isEmpty(OBJECTIVE_C_OBJECTS_DIR):OBJECTIVE_C_OBJECTS_DIR = .
isEmpty(QMAKE_EXT_OBJECTIVE_C):QMAKE_EXT_OBJECTIVE_C = .mm .m
objective_c.dependency_type = TYPE_C
objective_c.variables = QMAKE_OBJECTIVE_CFLAGS
objective_c.commands = $$QMAKE_OBJECTIVE_CC -c $(QMAKE_COMP_QMAKE_OBJECTIVE_CFLAGS) $(DEFINES) $(INCPATH) ${QMAKE_FILE_IN} -o ${QMAKE_FILE_OUT}
objective_c.output = $$OBJECTIVE_C_OBJECTS_DIR/${QMAKE_FILE_BASE}$${first(QMAKE_EXT_OBJ)}
objective_c.input = OBJECTIVE_SOURCES
objective_c.name = Compile ${QMAKE_FILE_IN}
silent:objective_c.commands = @echo objective-c ${QMAKE_FILE_IN} && $$objective_c.commands
QMAKE_EXTRA_COMPILERS += objective_c
# Add Objective-C/C++ flags to C/C++ flags, the compiler can handle it
QMAKE_CFLAGS += $$QMAKE_OBJECTIVE_CFLAGS
QMAKE_CXXFLAGS += $$QMAKE_OBJECTIVE_CFLAGS

View File

@ -32,7 +32,6 @@ isEmpty(QMAKE_MAC_SDK.$${QMAKE_MAC_SDK}.version) {
!equals(MAKEFILE_GENERATOR, XCODE) {
QMAKE_CFLAGS += -isysroot $$QMAKE_MAC_SDK_PATH
QMAKE_CXXFLAGS += -isysroot $$QMAKE_MAC_SDK_PATH
QMAKE_OBJECTIVE_CFLAGS += -isysroot $$QMAKE_MAC_SDK_PATH
QMAKE_LFLAGS += -Wl,-syslibroot,$$QMAKE_MAC_SDK_PATH
}
@ -80,6 +79,5 @@ isEmpty(QMAKE_MAC_SDK.$${QMAKE_MAC_SDK}.platform_name) {
version_min_flag = -m$${version_identifier}-version-min=$$deployment_target
QMAKE_CFLAGS += $$version_min_flag
QMAKE_CXXFLAGS += $$version_min_flag
QMAKE_OBJECTIVE_CFLAGS += $$version_min_flag
QMAKE_LFLAGS += $$version_min_flag
}

View File

@ -7,6 +7,8 @@ QMAKE_DIRLIST_SEP = $$DIRLIST_SEPARATOR
QMAKE_EXT_C = .c
QMAKE_EXT_CPP = .cpp .cc .cxx
QMAKE_EXT_OBJC = .m
QMAKE_EXT_OBJCXX = .mm
QMAKE_EXT_CPP_MOC = .moc
QMAKE_EXT_H = .h .hpp .hh .hxx
QMAKE_EXT_H_MOC = .cpp

View File

@ -1,4 +1,3 @@
QMAKE_CFLAGS += $$QMAKE_CFLAGS_HIDESYMS
QMAKE_CXXFLAGS += $$QMAKE_CXXFLAGS_HIDESYMS
QMAKE_OBJECTIVE_CFLAGS += $$QMAKE_OBJECTIVE_CFLAGS_HIDESYMS
QMAKE_LFLAGS += $$QMAKE_LFLAGS_HIDESYMS

View File

@ -1,4 +1,3 @@
CONFIG -= warn_on
QMAKE_CFLAGS += $$QMAKE_CFLAGS_WARN_OFF
QMAKE_CXXFLAGS += $$QMAKE_CXXFLAGS_WARN_OFF
QMAKE_OBJECTIVE_CFLAGS += $$QMAKE_OBJECTIVE_CFLAGS_WARN_OFF

View File

@ -1,5 +1,4 @@
CONFIG -= warn_off
QMAKE_CFLAGS += $$QMAKE_CFLAGS_WARN_ON
QMAKE_CXXFLAGS += $$QMAKE_CXXFLAGS_WARN_ON
QMAKE_OBJECTIVE_CFLAGS += $$QMAKE_OBJECTIVE_CFLAGS_WARN_ON

View File

@ -14,7 +14,6 @@ include(../common/clang-mac.conf)
QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.7
QMAKE_CFLAGS += -arch i386
QMAKE_OBJECTIVE_CFLAGS += -arch i386
QMAKE_CXXFLAGS += -arch i386
QMAKE_LFLAGS += -arch i386

View File

@ -17,7 +17,6 @@ include(../common/g++-macx.conf)
QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.7
QMAKE_CFLAGS += -arch i386
QMAKE_OBJECTIVE_CFLAGS += -arch i386
QMAKE_CXXFLAGS += -arch i386
QMAKE_LFLAGS += -arch i386

View File

@ -34,14 +34,6 @@ QMAKE_CFLAGS_SSE4_2 += -msse4.2
QMAKE_CFLAGS_AVX += -mavx
QMAKE_CFLAGS_AVX2 += -march=core-avx2
QMAKE_OBJECTIVE_CC = clang
QMAKE_OBJECTIVE_CFLAGS = -pipe
QMAKE_OBJECTIVE_CFLAGS_WARN_ON = -Wall -W
QMAKE_OBJECTIVE_CFLAGS_WARN_OFF = -w
QMAKE_OBJECTIVE_CFLAGS_RELEASE = -Os
QMAKE_OBJECTIVE_CFLAGS_DEBUG = -g
QMAKE_OBJECTIVE_CFLAGS_HIDESYMS = -fvisibility=hidden
QMAKE_CXX = icpc
QMAKE_CXXFLAGS = $$QMAKE_CFLAGS
QMAKE_CXXFLAGS_DEPS = $$QMAKE_CFLAGS_DEPS

View File

@ -93,6 +93,5 @@ macx-xcode {
QMAKE_CFLAGS += $$arch_flags
QMAKE_CXXFLAGS += $$arch_flags
QMAKE_OBJECTIVE_CFLAGS += $$arch_flags
QMAKE_LFLAGS += $$arch_flags
}

View File

@ -417,20 +417,24 @@ public:
inline QString groupName() const { return group; }
inline QString compilerName() const { return compiler; }
inline bool isObjectOutput(const QString &file) const {
bool ret = object_output;
for(int i = 0; !ret && i < Option::c_ext.size(); ++i) {
if(file.endsWith(Option::c_ext.at(i))) {
ret = true;
break;
}
if (object_output)
return true;
if (file.endsWith(Option::objc_ext))
return true;
if (file.endsWith(Option::objcpp_ext))
return true;
for (int i = 0; i < Option::c_ext.size(); ++i) {
if (file.endsWith(Option::c_ext.at(i)))
return true;
}
for(int i = 0; !ret && i < Option::cpp_ext.size(); ++i) {
if(file.endsWith(Option::cpp_ext.at(i))) {
ret = true;
break;
}
for (int i = 0; i < Option::cpp_ext.size(); ++i) {
if (file.endsWith(Option::cpp_ext.at(i)))
return true;
}
return ret;
return false;
}
};
@ -490,9 +494,9 @@ static QString xcodeFiletypeForFilename(const QString &filename)
return "sourcecode.c.h";
}
if (filename.endsWith(QStringLiteral(".mm")))
if (filename.endsWith(Option::objcpp_ext))
return QStringLiteral("sourcecode.cpp.objcpp");
if (filename.endsWith(QStringLiteral(".m")))
if (filename.endsWith(Option::objc_ext))
return QStringLiteral("sourcecode.c.objc");
if (filename.endsWith(QStringLiteral(".framework")))
return QStringLiteral("wrapper.framework");

View File

@ -378,6 +378,13 @@ MakefileGenerator::init()
ProValueMap &v = project->variables();
v["QMAKE_BUILTIN_COMPILERS"] = ProStringList() << "C" << "CXX";
v["QMAKE_LANGUAGE_C"] = ProString("c");
v["QMAKE_LANGUAGE_CXX"] = ProString("c++");
v["QMAKE_LANGUAGE_OBJC"] = ProString("objective-c");
v["QMAKE_LANGUAGE_OBJCXX"] = ProString("objective-c++");
if (v["TARGET"].isEmpty())
warn_msg(WarnLogic, "TARGET is empty");
@ -1136,12 +1143,28 @@ MakefileGenerator::writeObj(QTextStream &t, const char *src)
<< " " << escapeDependencyPaths(findDependencies(srcf)).join(" \\\n\t\t");
ProKey comp;
for(QStringList::Iterator cppit = Option::cpp_ext.begin(); cppit != Option::cpp_ext.end(); ++cppit) {
if((*sit).endsWith((*cppit))) {
comp = "QMAKE_RUN_CXX";
break;
foreach (const ProString &compiler, project->values("QMAKE_BUILTIN_COMPILERS")) {
// Unfortunately we were not consistent about the C++ naming
ProString extensionSuffix = compiler;
if (extensionSuffix == "CXX")
extensionSuffix = ProString("CPP");
// Nor the C naming
ProString compilerSuffix = compiler;
if (compilerSuffix == "C")
compilerSuffix = ProString("CC");
foreach (const ProString &extension, project->values(ProKey("QMAKE_EXT_" + extensionSuffix))) {
if ((*sit).endsWith(extension)) {
comp = ProKey("QMAKE_RUN_" + compilerSuffix);
break;
}
}
if (!comp.isNull())
break;
}
if (comp.isEmpty())
comp = "QMAKE_RUN_CC";
if (!project->isEmpty(comp)) {

View File

@ -145,14 +145,16 @@ UnixMakefileGenerator::init()
MakefileGenerator::init();
QString comps[] = { "C", "CXX", "OBJC", "OBJCXX", QString() };
for(int i = 0; !comps[i].isNull(); i++) {
if (project->isActiveConfig("objective_c"))
project->values("QMAKE_BUILTIN_COMPILERS") << "OBJC" << "OBJCXX";
foreach (const ProString &compiler, project->values("QMAKE_BUILTIN_COMPILERS")) {
QString compile_flag = var("QMAKE_COMPILE_FLAG");
if(compile_flag.isEmpty())
compile_flag = "-c";
if(doPrecompiledHeaders() && !project->isEmpty("PRECOMPILED_HEADER")) {
QString pchFlags = var(ProKey("QMAKE_" + comps[i] + "FLAGS_USE_PRECOMPILE"));
QString pchFlags = var(ProKey("QMAKE_" + compiler + "FLAGS_USE_PRECOMPILE"));
QString pchBaseName;
if(!project->isEmpty("PRECOMPILED_DIR")) {
@ -179,22 +181,11 @@ UnixMakefileGenerator::init()
pchBaseName += project->first("QMAKE_PCH_OUTPUT_EXT").toQString();
pchBaseName += Option::dir_sep;
QString pchOutputFile;
if(comps[i] == "C") {
pchOutputFile = "c";
} else if(comps[i] == "CXX") {
pchOutputFile = "c++";
} else if(project->isActiveConfig("objective_c")) {
if(comps[i] == "OBJC")
pchOutputFile = "objective-c";
else if(comps[i] == "OBJCXX")
pchOutputFile = "objective-c++";
}
if(!pchOutputFile.isEmpty()) {
ProString language = project->first(ProKey("QMAKE_LANGUAGE_" + compiler));
if (!language.isEmpty()) {
pchFlags.replace("${QMAKE_PCH_OUTPUT}",
escapeFilePath(pchBaseName + pchOutputFile + headerSuffix));
escapeFilePath(pchBaseName + language + headerSuffix));
}
}
@ -202,23 +193,27 @@ UnixMakefileGenerator::init()
compile_flag += " " + pchFlags;
}
QString cflags;
if(comps[i] == "OBJC" || comps[i] == "OBJCXX")
cflags += " $(CFLAGS)";
else
cflags += " $(" + comps[i] + "FLAGS)";
compile_flag += cflags + " $(INCPATH)";
QString compilerExecutable;
if (compiler == "C" || compiler == "OBJC") {
compilerExecutable = "$(CC)";
compile_flag += " $(CFLAGS)";
} else {
compilerExecutable = "$(CXX)";
compile_flag += " $(CXXFLAGS)";
}
QString compiler = comps[i];
if (compiler == "C")
compiler = "CC";
compile_flag += " $(INCPATH)";
const ProKey runComp("QMAKE_RUN_" + compiler);
ProString compilerVariable = compiler;
if (compilerVariable == "C")
compilerVariable = ProString("CC");
const ProKey runComp("QMAKE_RUN_" + compilerVariable);
if(project->isEmpty(runComp))
project->values(runComp).append("$(" + compiler + ") " + compile_flag + " " + var("QMAKE_CC_O_FLAG") + "$obj $src");
const ProKey runCompImp("QMAKE_RUN_" + compiler + "_IMP");
project->values(runComp).append(compilerExecutable + " " + compile_flag + " " + var("QMAKE_CC_O_FLAG") + "$obj $src");
const ProKey runCompImp("QMAKE_RUN_" + compilerVariable + "_IMP");
if(project->isEmpty(runCompImp))
project->values(runCompImp).append("$(" + compiler + ") " + compile_flag + " " + var("QMAKE_CC_O_FLAG") + "\"$@\" \"$<\"");
project->values(runCompImp).append(compilerExecutable + " " + compile_flag + " " + var("QMAKE_CC_O_FLAG") + "\"$@\" \"$<\"");
}
if (project->isActiveConfig("mac") && !project->isEmpty("TARGET") &&
@ -306,10 +301,11 @@ UnixMakefileGenerator::init()
}
QStringList
&UnixMakefileGenerator::findDependencies(const QString &file)
&UnixMakefileGenerator::findDependencies(const QString &f)
{
QStringList &ret = MakefileGenerator::findDependencies(file);
QStringList &ret = MakefileGenerator::findDependencies(f);
if (doPrecompiledHeaders() && !project->isEmpty("PRECOMPILED_HEADER")) {
ProString file = f;
QString header_prefix;
if(!project->isEmpty("PRECOMPILED_DIR"))
header_prefix = project->first("PRECOMPILED_DIR").toQString();
@ -329,45 +325,33 @@ QStringList
QString header_suffix = project->isActiveConfig("clang_pch_style")
? project->first("QMAKE_PCH_OUTPUT_EXT").toQString() : "";
header_prefix += Option::dir_sep + project->first("QMAKE_PRECOMP_PREFIX");
for(QStringList::Iterator it = Option::c_ext.begin(); it != Option::c_ext.end(); ++it) {
if(file.endsWith(*it)) {
if(!project->isEmpty("QMAKE_CFLAGS_PRECOMPILE")) {
QString precomp_c_h = header_prefix + "c" + header_suffix;
if(!ret.contains(precomp_c_h))
ret += precomp_c_h;
}
if(project->isActiveConfig("objective_c")) {
if(!project->isEmpty("QMAKE_OBJCFLAGS_PRECOMPILE")) {
QString precomp_objc_h = header_prefix + "objective-c" + header_suffix;
if(!ret.contains(precomp_objc_h))
ret += precomp_objc_h;
}
if(!project->isEmpty("QMAKE_OBJCXXFLAGS_PRECOMPILE")) {
QString precomp_objcpp_h = header_prefix + "objective-c++" + header_suffix;
if(!ret.contains(precomp_objcpp_h))
ret += precomp_objcpp_h;
}
}
break;
}
}
for(QStringList::Iterator it = Option::cpp_ext.begin(); it != Option::cpp_ext.end(); ++it) {
if(file.endsWith(*it)) {
if(!project->isEmpty("QMAKE_CXXFLAGS_PRECOMPILE")) {
QString precomp_cpp_h = header_prefix + "c++" + header_suffix;
if(!ret.contains(precomp_cpp_h))
ret += precomp_cpp_h;
}
if(project->isActiveConfig("objective_c")) {
if(!project->isEmpty("QMAKE_OBJCXXFLAGS_PRECOMPILE")) {
QString precomp_objcpp_h = header_prefix + "objective-c++" + header_suffix;
if(!ret.contains(precomp_objcpp_h))
ret += precomp_objcpp_h;
}
}
break;
foreach (const ProString &compiler, project->values("QMAKE_BUILTIN_COMPILERS")) {
if (project->isEmpty(ProKey("QMAKE_" + compiler + "FLAGS_PRECOMPILE")))
continue;
ProString language = project->first(ProKey("QMAKE_LANGUAGE_" + compiler));
if (language.isEmpty())
continue;
// Unfortunately we were not consistent about the C++ naming
ProString extensionSuffix = compiler;
if (extensionSuffix == "CXX")
extensionSuffix = ProString("CPP");
foreach (const ProString &extension, project->values(ProKey("QMAKE_EXT_" + extensionSuffix))) {
if (!file.endsWith(extension.toQString()))
continue;
QString precompiledHeader = header_prefix + language + header_suffix;
if (!ret.contains(precompiledHeader))
ret += precompiledHeader;
goto foundPrecompiledDependency;
}
}
foundPrecompiledDependency:
; // Hurray!!
}
}
return ret;

View File

@ -1001,15 +1001,14 @@ UnixMakefileGenerator::writeMakeParts(QTextStream &t)
ProString header_suffix = project->isActiveConfig("clang_pch_style")
? project->first("QMAKE_PCH_OUTPUT_EXT") : "";
if(!project->isEmpty("QMAKE_CFLAGS_PRECOMPILE"))
precomp_files += precomph_out_dir + header_prefix + "c" + header_suffix;
if(!project->isEmpty("QMAKE_CXXFLAGS_PRECOMPILE"))
precomp_files += precomph_out_dir + header_prefix + "c++" + header_suffix;
if(project->isActiveConfig("objective_c")) {
if(!project->isEmpty("QMAKE_OBJCFLAGS_PRECOMPILE"))
precomp_files += precomph_out_dir + header_prefix + "objective-c" + header_suffix;
if(!project->isEmpty("QMAKE_OBJCXXFLAGS_PRECOMPILE"))
precomp_files += precomph_out_dir + header_prefix + "objective-c++" + header_suffix;
foreach (const ProString &compiler, project->values("QMAKE_BUILTIN_COMPILERS")) {
if (project->isEmpty(ProKey("QMAKE_" + compiler + "FLAGS_PRECOMPILE")))
continue;
ProString language = project->first(ProKey("QMAKE_LANGUAGE_" + compiler));
if (language.isEmpty())
continue;
precomp_files += precomph_out_dir + header_prefix + language + header_suffix;
}
}
t << "-$(DEL_FILE) " << escapeFilePaths(precomp_files).join(' ') << "\n\t";
@ -1064,17 +1063,16 @@ UnixMakefileGenerator::writeMakeParts(QTextStream &t)
if(doPrecompiledHeaders() && !project->isEmpty("PRECOMPILED_HEADER")) {
QString pchInput = project->first("PRECOMPILED_HEADER").toQString();
t << "###### Precompiled headers\n";
QString comps[] = { "C", "CXX", "OBJC", "OBJCXX", QString() };
for(int i = 0; !comps[i].isNull(); i++) {
QString pchFlags = var(ProKey("QMAKE_" + comps[i] + "FLAGS_PRECOMPILE"));
foreach (const ProString &compiler, project->values("QMAKE_BUILTIN_COMPILERS")) {
QString pchFlags = var(ProKey("QMAKE_" + compiler + "FLAGS_PRECOMPILE"));
if(pchFlags.isEmpty())
continue;
QString cflags;
if(comps[i] == "OBJC" || comps[i] == "OBJCXX")
if (compiler == "C" || compiler == "OBJC")
cflags += " $(CFLAGS)";
else
cflags += " $(" + comps[i] + "FLAGS)";
cflags += " $(CXXFLAGS)";
ProString pchBaseName = project->first("QMAKE_ORIG_TARGET");
ProString pchOutput;
@ -1102,21 +1100,13 @@ UnixMakefileGenerator::writeMakeParts(QTextStream &t)
ProString header_suffix = project->isActiveConfig("clang_pch_style")
? project->first("QMAKE_PCH_OUTPUT_EXT") : "";
pchOutput += Option::dir_sep;
QString pchOutputDir = pchOutput.toQString(), pchOutputFile;
QString pchOutputDir = pchOutput.toQString();
if(comps[i] == "C") {
pchOutputFile = "c";
} else if(comps[i] == "CXX") {
pchOutputFile = "c++";
} else if(project->isActiveConfig("objective_c")) {
if(comps[i] == "OBJC")
pchOutputFile = "objective-c";
else if(comps[i] == "OBJCXX")
pchOutputFile = "objective-c++";
}
if(pchOutputFile.isEmpty())
QString language = project->first(ProKey("QMAKE_LANGUAGE_" + compiler)).toQString();
if (language.isEmpty())
continue;
pchOutput += header_prefix + pchOutputFile + header_suffix;
pchOutput += header_prefix + language + header_suffix;
t << escapeDependencyPath(pchOutput) << ": " << escapeDependencyPath(pchInput) << ' '
<< escapeDependencyPaths(findDependencies(pchInput)).join(" \\\n\t\t")
@ -1126,14 +1116,14 @@ UnixMakefileGenerator::writeMakeParts(QTextStream &t)
.replace("${QMAKE_PCH_OUTPUT_BASE}", escapeFilePath(pchBaseName.toQString()))
.replace("${QMAKE_PCH_OUTPUT}", escapeFilePath(pchOutput.toQString()));
QString compiler;
if(comps[i] == "C" || comps[i] == "OBJC" || comps[i] == "OBJCXX")
compiler = "$(CC)";
QString compilerExecutable;
if (compiler == "C" || compiler == "OBJC")
compilerExecutable = "$(CC)";
else
compiler = "$(CXX)";
compilerExecutable = "$(CXX)";
// compile command
t << "\n\t" << compiler << cflags << " $(INCPATH) " << pchFlags << endl << endl;
t << "\n\t" << compilerExecutable << cflags << " $(INCPATH) " << pchFlags << endl << endl;
}
}

View File

@ -59,6 +59,8 @@ QStringList Option::h_ext;
QString Option::cpp_moc_ext;
QStringList Option::cpp_ext;
QStringList Option::c_ext;
QString Option::objc_ext;
QString Option::objcpp_ext;
QString Option::obj_ext;
QString Option::lex_ext;
QString Option::yacc_ext;
@ -465,6 +467,8 @@ bool Option::postProcessProject(QMakeProject *project)
Option::cpp_ext = project->values("QMAKE_EXT_CPP").toQStringList();
Option::h_ext = project->values("QMAKE_EXT_H").toQStringList();
Option::c_ext = project->values("QMAKE_EXT_C").toQStringList();
Option::objc_ext = project->first("QMAKE_EXT_OBJC").toQString();
Option::objcpp_ext = project->first("QMAKE_EXT_OBJCXX").toQString();
Option::res_ext = project->first("QMAKE_EXT_RES").toQString();
Option::pkgcfg_ext = project->first("QMAKE_EXT_PKGCONFIG").toQString();
Option::libtool_ext = project->first("QMAKE_EXT_LIBTOOL").toQString();

View File

@ -91,6 +91,8 @@ struct Option
static QStringList h_ext;
static QStringList cpp_ext;
static QStringList c_ext;
static QString objc_ext;
static QString objcpp_ext;
static QString cpp_moc_ext;
static QString obj_ext;
static QString lex_ext;

View File

@ -92,7 +92,7 @@ mac {
# don't know yet if the target that links to testlib will build under Xcode or not.
# The corresponding flags for the target lives in xctest.prf, where we do know.
QMAKE_LFLAGS += -F$${platform_dev_frameworks_path} -weak_framework XCTest
QMAKE_OBJECTIVE_CFLAGS += -F$${platform_dev_frameworks_path}
QMAKE_CXXFLAGS += -F$${platform_dev_frameworks_path}
MODULE_CONFIG += xctest
}
}