diff options
author | Joerg Bornemann <joerg.bornemann@qt.io> | 2020-06-05 10:10:50 +0200 |
---|---|---|
committer | Joerg Bornemann <joerg.bornemann@qt.io> | 2020-06-09 21:04:26 +0200 |
commit | 2a767ab4bb7de8c29d2a8365212244ed944e9aeb (patch) | |
tree | d02b1d45bb0bcd7a313baaac8c57a86c999ea658 /cmake/QtGenerateLibPri.cmake | |
parent | d2833a3ce5af725d66ef9338f2a61b766dd3cb2d (diff) |
CMake: Fix libraries in qt_lib_XXX_private.pri files for NMC
qmake_use.prf understands the _DEBUG and _RELEASE suffixes for
QMAKE_LIBS_XXX entries. The CMake configuration "Debug" is considered
for the _DEBUG entries, "Release" and "RelWithDebInfo" for _RELEASE.
The qt_lib_XXX_private.pri files are now generated in multiple steps:
1. The QT_LIBS_XXX information is generated per $<CONFIG> and written to
.cmake files.
2. A preliminary qt_lib_XXX_private.pri file is generated, containing
only configuration-independent data.
3. A custom command runs the QtGenerateLibPri.cmake script that combines
the files from step 1 and 2 into the final qt_lib_XXX_private.pri
file.
The same is done for mkspecs/qmodule.pri.
To be able to trigger custom commands from header modules, which are
interface libraries, we introduce one XXX_timestamp ALL target per
header module that creates a timestamp file. To that XXX_timestamp
target we add the pri file generation target as dependency.
Fixes: QTBUG-84348
Change-Id: I610f279e37feeb7eceb9ef20b3ddfecff8cfbf81
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'cmake/QtGenerateLibPri.cmake')
-rw-r--r-- | cmake/QtGenerateLibPri.cmake | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/cmake/QtGenerateLibPri.cmake b/cmake/QtGenerateLibPri.cmake new file mode 100644 index 0000000000..d335924c1d --- /dev/null +++ b/cmake/QtGenerateLibPri.cmake @@ -0,0 +1,84 @@ +# Generate a qt_lib_XXX.pri file. +# +# This file is to be used in CMake script mode with the following variables set: +# IN_FILES: path to the qt_lib_XXX.cmake files +# OUT_FILE: path to the generated qt_lib_XXX.pri file +# CONFIGS: the configurations Qt is being built with +# +# QMAKE_LIBS_XXX values are split into QMAKE_LIBS_XXX_DEBUG and QMAKE_LIBS_XXX_RELEASE if +# debug_and_release was detected. The CMake configuration "Debug" is considered for the _DEBUG +# values. The first config that is not "Debug" is treated as _RELEASE. + +cmake_policy(SET CMP0057 NEW) + +# Create a qmake-style list from the passed arguments and store it in ${out_var}. +function(qmake_list out_var) + set(result "") + + # Surround values that contain spaces with double quotes. + foreach(v ${ARGN}) + if(v MATCHES " ") + set(v "\"${v}\"") + endif() + list(APPEND result ${v}) + endforeach() + + list(JOIN result " " result) + set(${out_var} ${result} PARENT_SCOPE) +endfunction() + +list(POP_FRONT IN_FILES in_pri_file) +file(READ ${in_pri_file} content) +string(APPEND content "\n") +foreach(in_file ${IN_FILES}) + include(${in_file}) +endforeach() +list(REMOVE_DUPLICATES known_libs) + +set(is_debug_and_release FALSE) +if("Debug" IN_LIST CONFIGS AND ("Release" IN_LIST CONFIGS OR "RelWithDebInfo" IN_LIST CONFIGS)) + set(is_debug_and_release TRUE) + set(release_configs ${CONFIGS}) + list(REMOVE_ITEM release_configs "Debug") + list(GET release_configs 0 release_cfg) + string(TOUPPER "${release_cfg}" release_cfg) +endif() + +foreach(lib ${known_libs}) + set(configuration_independent_infixes LIBDIR INCDIR DEFINES) + + if(is_debug_and_release) + set(value_debug ${QMAKE_LIBS_${lib}_DEBUG}) + set(value_release ${QMAKE_LIBS_${lib}_${release_cfg}}) + if(value_debug STREQUAL value_release) + if(value_debug) + qmake_list(value_debug ${value_debug}) + string(APPEND content "QMAKE_LIBS_${lib} = ${value_debug}\n") + endif() + else() + if(value_debug) + qmake_list(value_debug ${value_debug}) + string(APPEND content "QMAKE_LIBS_${lib}_DEBUG = ${value_debug}\n") + endif() + if(value_release) + qmake_list(value_release ${value_release}) + string(APPEND content "QMAKE_LIBS_${lib}_RELEASE = ${value_release}\n") + endif() + endif() + else() + list(APPEND configuration_independent_infixes LIBS) + endif() + + # The remaining values are considered equal for all configurations. + # Pick the first configuration and use its values. + list(GET CONFIGS 0 cfg) + string(TOUPPER ${cfg} cfg) + foreach(infix ${configuration_independent_infixes}) + set(value ${QMAKE_${infix}_${lib}_${cfg}}) + if(value) + qmake_list(value ${value}) + string(APPEND content "QMAKE_${infix}_${lib} = ${value}\n") + endif() + endforeach() +endforeach() +file(WRITE "${OUT_FILE}" "${content}") |