aboutsummaryrefslogtreecommitdiffstats
path: root/cmake/QtDeclarativeSetup.cmake
diff options
context:
space:
mode:
Diffstat (limited to 'cmake/QtDeclarativeSetup.cmake')
-rw-r--r--cmake/QtDeclarativeSetup.cmake76
1 files changed, 48 insertions, 28 deletions
diff --git a/cmake/QtDeclarativeSetup.cmake b/cmake/QtDeclarativeSetup.cmake
index d8e4719dbf..165a71e09a 100644
--- a/cmake/QtDeclarativeSetup.cmake
+++ b/cmake/QtDeclarativeSetup.cmake
@@ -1,30 +1,58 @@
-# Generates a header file with a hash.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+# Create a header containing a hash that describes this library. For a
+# released version of Qt, we'll use the .tag file that is updated by git
+# archive with the tree hash. For unreleased versions, we'll ask git
+# rev-parse. If none of this works, we use CMake to hash all the files
+# in the src/qml/ directory.
+# Skip recreation of the hash when doing a developer build.
function(qt_declarative_write_tag_header target_name)
+ set(out_file "${CMAKE_CURRENT_BINARY_DIR}/qml_compile_hash_p.h")
+ if(FEATURE_developer_build AND EXISTS "${out_file}")
+ target_sources(${target_name} PRIVATE "${out_file}")
+ set_source_files_properties("${out_file}" PROPERTIES GENERATED TRUE)
+ return()
+ endif()
+
set(tag_file "${CMAKE_CURRENT_SOURCE_DIR}/../../.tag")
set(tag_contents "")
if(EXISTS "${tag_file}")
file(READ "${tag_file}" tag_contents)
+ string(STRIP "${tag_contents}" tag_contents)
endif()
- if(NOT tag_file STREQUAL "$Format:%H$")
+ find_program(git_path git)
+
+ if(tag_contents AND NOT tag_contents STREQUAL "$Format:%T$")
set(QML_COMPILE_HASH "${tag_contents}")
- string(STRIP "${QML_COMPILE_HASH}" QML_COMPILE_HASH)
- elseif(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/../../.git")
+ elseif(git_path AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/../../.git")
execute_process(
- COMMAND git rev-parse HEAD
+ COMMAND ${git_path} rev-parse HEAD
OUTPUT_VARIABLE QML_COMPILE_HASH
- OUTPUT_STRIP_TRAILING_WHITESPACE)
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
endif()
string(LENGTH "${QML_COMPILE_HASH}" QML_COMPILE_HASH_LENGTH)
- set(compile_hash_contents "// Generated file, DO NOT EDIT
- #define QML_COMPILE_HASH \"${QML_COMPILE_HASH}\"
- #define QML_COMPILE_HASH_LENGTH ${QML_COMPILE_HASH_LENGTH}"
- )
- set(compile_hash_output_path "${CMAKE_CURRENT_BINARY_DIR}/qml_compile_hash_p.h")
- file(GENERATE OUTPUT "${compile_hash_output_path}"
- CONTENT "${compile_hash_contents}")
-endfunction()
+ if(QML_COMPILE_HASH_LENGTH EQUAL 0)
+ set(sources_hash "")
+ file(GLOB_RECURSE qtqml_source_files "${CMAKE_CURRENT_SOURCE_DIR}/*")
+ foreach(file IN LISTS qtqml_source_files)
+ file(SHA1 ${file} file_hash)
+ string(APPEND sources_hash ${file_hash})
+ endforeach()
+ string(SHA1 QML_COMPILE_HASH "${sources_hash}")
+ endif()
-find_package(PythonInterp REQUIRED)
+ string(LENGTH "${QML_COMPILE_HASH}" QML_COMPILE_HASH_LENGTH)
+ if(QML_COMPILE_HASH_LENGTH GREATER 0)
+ configure_file("qml_compile_hash_p.h.in" "${out_file}")
+ else()
+ message(FATAL_ERROR "QML compile hash is empty! "
+ "You need either a valid git repository or a non-empty .tag file.")
+ endif()
+ target_sources(${target_name} PRIVATE "${out_file}")
+ set_source_files_properties("${out_file}" PROPERTIES GENERATED TRUE)
+endfunction()
# Generate a header file containing a regular expression jit table.
function(qt_declarative_generate_reg_exp_jit_tables consuming_target)
@@ -40,21 +68,13 @@ function(qt_declarative_generate_reg_exp_jit_tables consuming_target)
add_custom_command(
OUTPUT "${output_file}"
- COMMAND "${PYTHON_EXECUTABLE}" ${retgen_script_file} ${output_file}
+ COMMAND "${QT_INTERNAL_DECLARATIVE_PYTHON}" ${retgen_script_file} ${output_file}
MAIN_DEPENDENCY ${retgen_script_file}
+ VERBATIM
)
target_sources(${consuming_target} PRIVATE ${output_file})
target_include_directories(${consuming_target} PRIVATE $<BUILD_INTERFACE:${generate_dir}>)
-endfunction()
-
-function(qt_qml_find_python out_var_path out_var_found)
- find_program(QT_QML_PYTHON_PATH
- NAMES python python2 python3 py
- DOC "Qt Declarative python path")
- if(QT_QML_PYTHON_PATH)
- set(${out_var_path} "${QT_QML_PYTHON_PATH}" PARENT_SCOPE)
- set(${out_var_found} "TRUE" PARENT_SCOPE)
- else()
- set(${out_var_found} "FALSE" PARENT_SCOPE)
- endif()
+ set_source_files_properties(${output_file} PROPERTIES
+ GENERATED TRUE
+ _qt_non_module_header TRUE)
endfunction()