diff options
author | Alexandru Croitor <alexandru.croitor@qt.io> | 2019-05-28 14:13:27 +0200 |
---|---|---|
committer | Alexandru Croitor <alexandru.croitor@qt.io> | 2019-05-28 14:04:31 +0000 |
commit | cae4c5c2cef9399193d6aa477565b86c5718570e (patch) | |
tree | 8ad4e314ca8b88c6a3800bfd82b28d2c2f315ab0 /cmake/QtBuild.cmake | |
parent | f96778dee27f10e84865c4b0a32ef333287c5fe7 (diff) |
Add some qtdeclarative related functions to QtBuild
QtQml uses QLALR to generate a grammar, but the qmake qlalr feature
seems to be a general one, so the corresponding CMake implementations
are kept in qtbase for now.
Change-Id: Ibe916878b18155ddc5bb08793dd2075ebfa8f282
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Reviewed-by: Qt CMake Build Bot
Diffstat (limited to 'cmake/QtBuild.cmake')
-rw-r--r-- | cmake/QtBuild.cmake | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/cmake/QtBuild.cmake b/cmake/QtBuild.cmake index ff2298f36b..acdeaaca95 100644 --- a/cmake/QtBuild.cmake +++ b/cmake/QtBuild.cmake @@ -1896,3 +1896,52 @@ macro(qt_find_apple_system_frameworks) find_library(FWWatchKit WatchKit) endif() endmacro() + +# Match the pattern 'regex' in 'input_line', replace the match with 'replacement' +# and set that result in 'out_var' in the parent scope. +function(qt_regex_match_and_get input_line regex replacement out_var) + string(REGEX MATCH "${regex}" match "${input_line}") + if(match) + string(REGEX REPLACE "${regex}" "${replacement}" match "${input_line}") + string(STRIP ${match} match) + set(${out_var} "${match}" PARENT_SCOPE) + endif() +endfunction() + +# Match 'regex' in a list of lines. When found, set the value to 'out_var' and break early. +function(qt_qlalr_find_option_in_list input_list regex out_var) + foreach(line ${input_list}) + qt_regex_match_and_get("${line}" "${regex}" "\\1" option) + if(option) + string(TOLOWER ${option} option) + set(${out_var} "${option}" PARENT_SCOPE) + return() + endif() + endforeach() + message(FATAL_ERROR "qt_qlalr_find_option_in_list: Could not extract ${out_var}") +endfunction() + +# Generate a few output files using qlalr, and assign those to 'consuming_target'. +# 'input_file_list' is a list of 'foo.g' file paths. +# 'flags' are extra flags to be passed to qlalr. +function(qt_process_qlalr input_file_list consuming_target flags) + foreach(input_file ${input_file_list}) + file(STRINGS ${input_file} input_file_lines) + qt_qlalr_find_option_in_list("${input_file_lines}" "^%parser(.+)" "parser") + qt_qlalr_find_option_in_list("${input_file_lines}" "^%decl(.+)" "decl") + qt_qlalr_find_option_in_list("${input_file_lines}" "^%impl(.+)" "impl") + get_filename_component(base_file_name ${input_file} NAME_WE) + + set(cpp_file "${parser}.cpp") + set(private_file "${parser}_p.h") + set(decl_file "${decl}") + set(impl_file "${impl}") + add_custom_command( + OUTPUT ${cpp_file} ${private_file} ${decl_file} ${impl_file} + COMMAND ${QT_CMAKE_EXPORT_NAMESPACE}::qlalr ${flags} ${input_file} + MAIN_DEPENDENCY ${input_file} + ) + target_sources(${consuming_target} PRIVATE ${cpp_file} ${impl_file}) + endforeach() +endfunction() + |