CMakePM: Fix compile for gcc 7

Due to a compiler bug the content of the raw string is
handled inside the preprocessor and the cmake comments
end up as being noticed as unknown preprocessor directives.

Change-Id: I3f235cfdd0799a6bb94743e2910663d9b0d3385d
Reviewed-by: Cristian Adam <cristian.adam@qt.io>
This commit is contained in:
Christian Stenger
2021-04-28 11:23:56 +02:00
parent a547b82075
commit ca04d9afcd

View File

@@ -166,35 +166,36 @@ static FilePath qmakeFromCMakeCache(const CMakeConfig &config)
if (!cmakeListTxt.open(QIODevice::WriteOnly)) { if (!cmakeListTxt.open(QIODevice::WriteOnly)) {
return FilePath(); return FilePath();
} }
cmakeListTxt.write(QByteArray(R"( // FIXME replace by raw string when gcc 8+ is minimum
cmake_minimum_required(VERSION 3.15) cmakeListTxt.write(QByteArray(
"cmake_minimum_required(VERSION 3.15)\n"
project(qmake-probe LANGUAGES NONE) "\n"
"project(qmake-probe LANGUAGES NONE)\n"
# Bypass Qt6's usage of find_dependency, which would require compiler "\n"
# and source code probing, which slows things unnecessarily "# Bypass Qt6's usage of find_dependency, which would require compiler\n"
file(WRITE "${CMAKE_SOURCE_DIR}/CMakeFindDependencyMacro.cmake" "# and source code probing, which slows things unnecessarily"
[=[ "file(WRITE \"${CMAKE_SOURCE_DIR}/CMakeFindDependencyMacro.cmake\"\n"
macro(find_dependency dep) "[=["
endmacro() " macro(find_dependency dep)\n"
]=]) " endmacro()\n"
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}") "]=])\n"
"set(CMAKE_MODULE_PATH \"${CMAKE_SOURCE_DIR}\")\n"
find_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED) "\n"
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core REQUIRED) "find_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED)\n"
"find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core REQUIRED)\n"
if (CMAKE_CROSSCOMPILING) "\n"
find_program(qmake_binary "if (CMAKE_CROSSCOMPILING)\n"
NAMES qmake qmake.bat " find_program(qmake_binary\n"
PATHS "${Qt${QT_VERSION_MAJOR}_DIR}/../../../bin" " NAMES qmake qmake.bat\n"
NO_DEFAULT_PATH) " PATHS \"${Qt${QT_VERSION_MAJOR}_DIR}/../../../bin\"\n"
file(WRITE "${CMAKE_SOURCE_DIR}/qmake-location.txt" "${qmake_binary}") " NO_DEFAULT_PATH)\n"
else() " file(WRITE \"${CMAKE_SOURCE_DIR}/qmake-location.txt\" \"${qmake_binary}\")\n"
file(GENERATE "else()\n"
OUTPUT "${CMAKE_SOURCE_DIR}/qmake-location.txt" " file(GENERATE\n"
CONTENT "$<TARGET_PROPERTY:Qt${QT_VERSION_MAJOR}::qmake,IMPORTED_LOCATION>") " OUTPUT \"${CMAKE_SOURCE_DIR}/qmake-location.txt\"\n"
endif() " CONTENT \"$<TARGET_PROPERTY:Qt${QT_VERSION_MAJOR}::qmake,IMPORTED_LOCATION>\")\n"
)")); "endif()\n"
));
cmakeListTxt.close(); cmakeListTxt.close();
SynchronousProcess cmake; SynchronousProcess cmake;