qt5base-lts/mkspecs/features/moc.prf
Thiago Macieira da04322b4c Make moc obey the preprocessor environment variable for include paths
C preprocessors augment their standard list of include paths from the
environment: Unix preprocessors use $C_INCLUDE_PATH (for C) and
$CPLUS_INCLUDE_PATH (for C++), plus CPATH for both, whereas MSVC uses
the an environment variable simply called "INCLUDE". Handling this for
MSVC is particularly important because the VCVARSALL.BAT script sets the
necessary #include paths in the environment for important things.
Without that being parsed, moc won't find some #defines, like
WINAPI_DESKTOP_FAMILY.

[ChangeLog][moc] qmake and moc now cooperate to use the Visual Studio
environment variables (set by the VCVARSALL.BAT script) to find system
include files. A possible consequence is that moc parses application
headers slightly differently, depending on #if conditions that depended
on macros that previous versions had not seen #define'd. Implementers of
other buildsystems are advised to pass the --compiler-flavor=msvc option
to moc.

Change-Id: I7e06274214d1939b0124e5b4bf169cceaef9ca46
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
2016-07-20 02:54:09 +00:00

106 lines
4.1 KiB
Plaintext

#global defaults
qtPrepareTool(QMAKE_MOC, moc)
isEmpty(MOC_DIR):MOC_DIR = .
isEmpty(QMAKE_H_MOD_MOC):QMAKE_H_MOD_MOC = moc_
isEmpty(QMAKE_EXT_CPP_MOC):QMAKE_EXT_CPP_MOC = .moc
MOC_INCLUDEPATH =
for (inc, INCLUDEPATH): \
MOC_INCLUDEPATH += $$absolute_path($$inc, $$_PRO_FILE_PWD_)
!no_include_pwd:!isEqual(OUT_PWD, $$_PRO_FILE_PWD_): \
MOC_INCLUDEPATH += .
MOC_INCLUDEPATH = $$QMAKESPEC $$_PRO_FILE_PWD_ $$MOC_INCLUDEPATH $$QMAKE_DEFAULT_INCDIRS
# On Windows, put the includes into a .inc file which moc will read, if the project
# has too many includes. We do this to overcome a command-line limit on Win < XP
WIN_INCLUDETEMP=
win32:count(MOC_INCLUDEPATH, 40, >) {
WIN_INCLUDETEMP = $$MOC_DIR/mocinclude.opt
WIN_INCLUDETEMP_CONT =
for (inc, MOC_INCLUDEPATH): \
WIN_INCLUDETEMP_CONT += -I$$inc
write_file($$absolute_path($$WIN_INCLUDETEMP, $$OUT_PWD), WIN_INCLUDETEMP_CONT)|error("Aborting.")
}
# QNX's compiler sets "gcc" config, but does not support the -dM option;
# iOS builds are multi-arch, so this feature cannot possibly work.
if(gcc|intel_icl|msvc):!rim_qcc:!ios {
moc_predefs.CONFIG = no_link
gcc: moc_predefs.commands = $$QMAKE_CXX $$QMAKE_CXXFLAGS -dM -E -o ${QMAKE_FILE_OUT} ${QMAKE_FILE_IN}
else:intel_icl: moc_predefs.commands = $$QMAKE_CXX $$QMAKE_CXXFLAGS -QdM -P -Fi${QMAKE_FILE_OUT} ${QMAKE_FILE_IN}
else:msvc {
moc_predefs.commands += $$QMAKE_CXX -Bx$$shell_path($$[QT_INSTALL_BINS/get]/qmake) $$QMAKE_CXXFLAGS -E ${QMAKE_FILE_IN} 2>NUL >${QMAKE_FILE_OUT}
} else: error("Oops, I messed up")
moc_predefs.output = $$MOC_DIR/moc_predefs.h
moc_predefs.input = MOC_PREDEF_FILE
silent: moc_predefs.commands = @echo generating $$moc_predefs.output$$escape_expand(\n\t)@$$moc_predefs.commands
QMAKE_EXTRA_COMPILERS += moc_predefs
MOC_PREDEF_FILE = $$[QT_HOST_DATA/src]/mkspecs/features/data/dummy.cpp
}
defineReplace(mocCmdBase) {
!isEmpty(WIN_INCLUDETEMP) {
incvar = @$$WIN_INCLUDETEMP
} else {
incvar =
for (inc, MOC_INCLUDEPATH): \
incvar += -I$$shell_quote($$inc)
incvar += $$QMAKE_FRAMEWORKPATH_FLAGS
}
RET = $$QMAKE_MOC $(DEFINES)
msvc: RET += --compiler-flavor=msvc
isEmpty(MOC_PREDEF_FILE): RET += $$join(QMAKE_COMPILER_DEFINES, " -D", -D)
else: RET += --include $$moc_predefs.output
RET += $$incvar $$QMAKE_MOC_OPTIONS
return($$RET)
}
#moc headers
moc_header.CONFIG = moc_verify
moc_header.dependency_type = TYPE_C
moc_header.commands = ${QMAKE_FUNC_mocCmdBase} ${QMAKE_FILE_IN} -o ${QMAKE_FILE_OUT}
moc_header.output = $$MOC_DIR/$${QMAKE_H_MOD_MOC}${QMAKE_FILE_BASE}$${first(QMAKE_EXT_CPP)}
moc_header.input = HEADERS
moc_header.variable_out = SOURCES
moc_header.name = MOC ${QMAKE_FILE_IN}
moc_header.depends += $$WIN_INCLUDETEMP $$moc_predefs.output
silent:moc_header.commands = @echo moc ${QMAKE_FILE_IN} && $$moc_header.commands
QMAKE_EXTRA_COMPILERS += moc_header
INCREDIBUILD_XGE += moc_header
#moc sources
moc_source.CONFIG = no_link moc_verify
moc_source.dependency_type = TYPE_C
moc_source.commands = ${QMAKE_FUNC_mocCmdBase} ${QMAKE_FILE_IN} -o ${QMAKE_FILE_OUT}
moc_source.output = $$MOC_DIR/$${QMAKE_CPP_MOD_MOC}${QMAKE_FILE_BASE}$${QMAKE_EXT_CPP_MOC}
moc_source.input = SOURCES OBJECTIVE_SOURCES
moc_source.name = MOC ${QMAKE_FILE_IN}
moc_source.depends += $$WIN_INCLUDETEMP $$moc_predefs.output
silent:moc_source.commands = @echo moc ${QMAKE_FILE_IN} && $$moc_source.commands
QMAKE_EXTRA_COMPILERS += moc_source
INCREDIBUILD_XGE += moc_source
#make sure we can include these files
INCLUDEPATH += $$absolute_path($$MOC_DIR, $$OUT_PWD)
#auto depend on moc
!no_mocdepend {
moc_source.depends += $$QMAKE_MOC_EXE
moc_header.depends += $$QMAKE_MOC_EXE
}
#generate a mocclean
build_pass|isEmpty(BUILDS):mocclean.depends = compiler_moc_header_clean compiler_moc_source_clean
else:mocclean.CONFIG += recursive
QMAKE_EXTRA_TARGETS += mocclean
#generate a mocables
build_pass|isEmpty(BUILDS):mocables.depends = compiler_moc_header_make_all compiler_moc_source_make_all
else:mocables.CONFIG += recursive
QMAKE_EXTRA_TARGETS += mocables