Improve qconfig.cpp generation

We used to copy a qconfig.cpp.in file verbatim.
Add some plumbing to actually compute the strings and their lengths
as it is done in qtbase/configure.pri.

Also make sure to replace the hardcoded linux mkspec with one that is
automatically determined.

Of course both the detection of the mkspec, and the hardcoded strings
for include, lib, etc. should be fixed in the future.

This is a stepping stone to allow building a Qt application using
the qmake built by CMake.

Change-Id: I2e6754f44b20b09b09d14fd85785d56288e6517b
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
This commit is contained in:
Alexandru Croitor 2019-05-31 16:30:09 +02:00
parent b99e4387f6
commit d53f22e2fb
3 changed files with 70 additions and 49 deletions

View File

@ -64,33 +64,41 @@ SET(CMAKE_INSTALL_RPATH "${_default_install_rpath}" CACHE PATH "RPATH for instal
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
# Platform define path, etc.
set(QT_QMAKE_TARGET_MKSPEC "")
if(WIN32)
set(QT_DEFAULT_PLATFORM_DEFINITIONS UNICODE _UNICODE WIN32 _ENABLE_EXTENDED_ALIGNED_STORAGE)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
list(APPEND QT_DEFAULT_PLATFORM_DEFINITIONS WIN64 _WIN64)
endif()
if(MSVC)
set(QT_DEFAULT_PLATFORM_DEFINITION_DIR mkspecs/win32-msvc)
set(QT_QMAKE_TARGET_MKSPEC win32-msvc)
elseif(CLANG)
set(QT_DEFAULT_PLATFORM_DEFINITION_DIR mkspecs/win32-clang)
set(QT_QMAKE_TARGET_MKSPEC win32-clang)
elseif(MINGW)
set(QT_DEFAULT_PLATFORM_DEFINITION_DIR mkspecs/win32-g++)
set(QT_QMAKE_TARGET_MKSPEC win32-g++)
list(APPEND QT_DEFAULT_PLATFORM_DEFINITIONS _WIN32_WINNT=0x0601)
endif()
elseif(LINUX)
if(GCC)
set(QT_DEFAULT_PLATFORM_DEFINITION_DIR mkspecs/linux-g++)
set(QT_QMAKE_TARGET_MKSPEC linux-g++)
elseif(CLANG)
set(QT_DEFAULT_PLATFORM_DEFINITION_DIR mkspecs/linux-clang)
set(QT_QMAKE_TARGET_MKSPEC linux-clang)
endif()
elseif(ANDROID)
if(GCC)
set(QT_DEFAULT_PLATFORM_DEFINITION_DIR mkspecs/android-g++)
set(QT_QMAKE_TARGET_MKSPEC android-g++)
elseif(CLANG)
set(QT_DEFAULT_PLATFORM_DEFINITION_DIR mkspecs/android-clang)
set(QT_QMAKE_TARGET_MKSPEC android-clang)
endif()
elseif(APPLE)
set(QT_DEFAULT_PLATFORM_DEFINITION_DIR mkspecs/macx-clang)
set(QT_QMAKE_TARGET_MKSPEC macx-clang)
endif()
# TODO: Fixme to be correct.
set(QT_QMAKE_HOST_MKSPEC "${QT_QMAKE_TARGET_MKSPEC}")
if(QT_QMAKE_TARGET_MKSPEC)
set(QT_DEFAULT_PLATFORM_DEFINITION_DIR mkspecs/${QT_QMAKE_TARGET_MKSPEC})
endif()
if(NOT DEFINED QT_DEFAULT_PLATFORM_DEFINITIONS)
@ -2081,3 +2089,52 @@ function(qt_process_qlalr input_file_list consuming_target flags)
endforeach()
endfunction()
macro(qt_add_string_to_qconfig_cpp str)
string(LENGTH "${str}" length)
string(APPEND QT_CONFIG_STRS " \"${str}\\0\"\n")
string(APPEND QT_CONFIG_STR_OFFSETS " ${QT_CONFIG_STR_OFFSET},\n")
math(EXPR QT_CONFIG_STR_OFFSET "${QT_CONFIG_STR_OFFSET}+${length}+1")
endmacro()
function(qt_generate_qconfig_cpp)
set(QT_CONFIG_STR_OFFSET "0")
set(QT_CONFIG_STR_OFFSETS "")
set(QT_CONFIG_STRS "")
# Start first part.
qt_add_string_to_qconfig_cpp("doc")
qt_add_string_to_qconfig_cpp("include")
qt_add_string_to_qconfig_cpp("lib")
qt_add_string_to_qconfig_cpp("libexec")
qt_add_string_to_qconfig_cpp("bin")
qt_add_string_to_qconfig_cpp("plugins")
qt_add_string_to_qconfig_cpp("imports")
qt_add_string_to_qconfig_cpp("qml")
qt_add_string_to_qconfig_cpp(".")
qt_add_string_to_qconfig_cpp(".")
qt_add_string_to_qconfig_cpp("translations")
qt_add_string_to_qconfig_cpp("examples")
qt_add_string_to_qconfig_cpp("tests")
# Save first part.
set(QT_CONFIG_STR_OFFSETS_FIRST "${QT_CONFIG_STR_OFFSETS}")
set(QT_CONFIG_STRS_FIRST "${QT_CONFIG_STRS}")
# Start second part.
set(QT_CONFIG_STR_OFFSETS "")
set(QT_CONFIG_STRS "")
qt_add_string_to_qconfig_cpp("")
qt_add_string_to_qconfig_cpp("false")
qt_add_string_to_qconfig_cpp("bin")
qt_add_string_to_qconfig_cpp("lib")
qt_add_string_to_qconfig_cpp(".")
qt_add_string_to_qconfig_cpp("${QT_QMAKE_TARGET_MKSPEC}")
qt_add_string_to_qconfig_cpp("${QT_QMAKE_HOST_MKSPEC}")
# Save second part.
set(QT_CONFIG_STR_OFFSETS_SECOND "${QT_CONFIG_STR_OFFSETS}")
set(QT_CONFIG_STRS_SECOND "${QT_CONFIG_STRS}")
configure_file(global/qconfig.cpp.in global/qconfig.cpp @ONLY)
endfunction()

View File

@ -250,7 +250,7 @@ else()
target_compile_definitions(Core PUBLIC "QT_NAMESPACE=${QT_NAMESPACE}")
endif()
configure_file(global/qconfig.cpp.in global/qconfig.cpp)
qt_generate_qconfig_cpp()
# Handle QObject: Automoc does not work for this as it would
# require to spill internals into users:

View File

@ -7,51 +7,15 @@ static const char qt_configure_ext_prefix_path_str [12+256] = "qt_epfxpath=@CM
static const char qt_configure_host_prefix_path_str [12+256] = "qt_hpfxpath=@CMAKE_INSTALL_PREFIX@";
#endif
static const short qt_configure_str_offsets[] = {
0,
4,
12,
16,
24,
28,
36,
44,
48,
50,
52,
65,
74,
@QT_CONFIG_STR_OFFSETS_FIRST@
#ifdef QT_BUILD_QMAKE
80,
81,
87,
91,
95,
97,
107,
@QT_CONFIG_STR_OFFSETS_SECOND@
#endif
};
static const char qt_configure_strs[] =
"doc\0"
"include\0"
"lib\0"
"libexec\0"
"bin\0"
"plugins\0"
"imports\0"
"qml\0"
".\0"
".\0"
"translations\0"
"examples\0"
"tests\0"
@QT_CONFIG_STRS_FIRST@
#ifdef QT_BUILD_QMAKE
"\0"
"false\0"
"bin\0"
"lib\0"
".\0"
"linux-g++\0"
"linux-g++\0"
@QT_CONFIG_STRS_SECOND@
#endif
;
#define QT_CONFIGURE_SETTINGS_PATH "etc/xdg"