From 5a5ad8c0029ef9f9cb6ab3a1db309aff0d538828 Mon Sep 17 00:00:00 2001 From: Alexey Edelev Date: Tue, 17 May 2022 19:17:40 +0200 Subject: Add "content file" mode for the qt_internal_add_linker_version_script Add the support of pre-cooked content for the LD version script. The content can be generated without using the perl script at configure or build time. Change-Id: I1316e114a1d5550b2fdcf3482a51f336fb311a29 Reviewed-by: Axel Spoerl Reviewed-by: Alexandru Croitor --- cmake/QtBaseGlobalTargets.cmake | 1 + cmake/QtFlagHandlingHelpers.cmake | 65 ++++++++++++++++++++++++++++--------- cmake/QtGenerateVersionScript.cmake | 15 +++++++++ 3 files changed, 66 insertions(+), 15 deletions(-) create mode 100644 cmake/QtGenerateVersionScript.cmake diff --git a/cmake/QtBaseGlobalTargets.cmake b/cmake/QtBaseGlobalTargets.cmake index 7576c8fd7c..16a6ac9273 100644 --- a/cmake/QtBaseGlobalTargets.cmake +++ b/cmake/QtBaseGlobalTargets.cmake @@ -238,6 +238,7 @@ qt_copy_or_install(FILES cmake/QtGenerateExtPri.cmake cmake/QtGenerateLibHelpers.cmake cmake/QtGenerateLibPri.cmake + cmake/QtGenerateVersionScript.cmake cmake/QtGlobalStateHelpers.cmake cmake/QtHeadersClean.cmake cmake/QtInstallHelpers.cmake diff --git a/cmake/QtFlagHandlingHelpers.cmake b/cmake/QtFlagHandlingHelpers.cmake index b3d972bb37..43371cd176 100644 --- a/cmake/QtFlagHandlingHelpers.cmake +++ b/cmake/QtFlagHandlingHelpers.cmake @@ -1,14 +1,34 @@ # Copyright (C) 2022 The Qt Company Ltd. # SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +# This function generates LD version script for the target and uses it in the target linker line. +# Function has two modes dependending on the specified arguments. +# Arguments: +# PRIVATE_HEADERS specifies the list of header files that are used to generate +# Qt__PRIVATE_API section. Requires perl. +# PRIVATE_CONTENT_FILE specifies the pre-cooked content of Qt__PRIVATE_API section. +# Requires the content file available at build time. function(qt_internal_add_linker_version_script target) - qt_parse_all_arguments(arg "qt_internal_add_linker" "" "" "PRIVATE_HEADERS" ${ARGN}) + qt_parse_all_arguments(arg "qt_internal_add_linker_version_script" + "" + "PRIVATE_CONTENT_FILE" + "PRIVATE_HEADERS" + ${ARGN} + ) + + if(arg_PRIVATE_CONTENT_FILE AND arg_PRIVATE_HEADERS) + message(FATAL_ERROR "Both PRIVATE_CONTENT_FILE and PRIVATE_HEADERS are specified.") + endif() - if (TEST_ld_version_script) + if(TEST_ld_version_script) set(contents "Qt_${PROJECT_VERSION_MAJOR}_PRIVATE_API {\n qt_private_api_tag*;\n") - foreach(ph ${arg_PRIVATE_HEADERS}) - string(APPEND contents " @FILE:${ph}@\n") - endforeach() + if(arg_PRIVATE_HEADERS) + foreach(ph ${arg_PRIVATE_HEADERS}) + string(APPEND contents " @FILE:${ph}@\n") + endforeach() + else() + string(APPEND contents "@PRIVATE_CONTENT@") + endif() string(APPEND contents "};\n") set(current "Qt_${PROJECT_VERSION_MAJOR}") if (QT_NAMESPACE STREQUAL "") @@ -33,16 +53,31 @@ function(qt_internal_add_linker_version_script target) file(GENERATE OUTPUT "${infile}" CONTENT "${contents}") - qt_ensure_perl() - - set(generator_command "${HOST_PERL}" - "${QT_MKSPECS_DIR}/features/data/unix/findclasslist.pl" - "<" "${infile}" ">" "${outfile}" - ) - set(generator_dependencies - "${infile}" - "${QT_MKSPECS_DIR}/features/data/unix/findclasslist.pl" - ) + if(arg_PRIVATE_HEADERS) + qt_ensure_perl() + set(generator_command "${HOST_PERL}" + "${QT_MKSPECS_DIR}/features/data/unix/findclasslist.pl" + "<" "${infile}" ">" "${outfile}" + ) + set(generator_dependencies + "${infile}" + "${QT_MKSPECS_DIR}/features/data/unix/findclasslist.pl" + ) + else() + if(NOT arg_PRIVATE_CONTENT_FILE) + set(arg_PRIVATE_CONTENT_FILE "") + endif() + set(generator_command ${CMAKE_COMMAND} + "-DIN_FILE=${infile}" + "-DPRIVATE_CONTENT_FILE=${arg_PRIVATE_CONTENT_FILE}" + "-DOUT_FILE=${outfile}" + -P "${QT_CMAKE_DIR}/QtGenerateVersionScript.cmake" + ) + set(generator_dependencies + "${arg_PRIVATE_CONTENT_FILE}" + "${QT_CMAKE_DIR}/QtGenerateVersionScript.cmake" + ) + endif() add_custom_command( OUTPUT "${outfile}" diff --git a/cmake/QtGenerateVersionScript.cmake b/cmake/QtGenerateVersionScript.cmake new file mode 100644 index 0000000000..3e856169fe --- /dev/null +++ b/cmake/QtGenerateVersionScript.cmake @@ -0,0 +1,15 @@ +cmake_minimum_required(VERSION 3.16) + +if(EXISTS "${PRIVATE_CONTENT_FILE}") + file(READ "${PRIVATE_CONTENT_FILE}" PRIVATE_CONTENT) +endif() + +if(NOT EXISTS "${IN_FILE}") + message(FATAL_ERROR "Input file ${IN_FILE} doesn't exists") +endif() + +if(OUT_FILE STREQUAL "") + message(FATAL_ERROR "Output file is not specified") +endif() + +configure_file("${IN_FILE}" "${OUT_FILE}" @ONLY) -- cgit v1.2.3