diff options
author | Alexandru Croitor <alexandru.croitor@qt.io> | 2020-06-18 11:53:52 +0200 |
---|---|---|
committer | Alexandru Croitor <alexandru.croitor@qt.io> | 2020-06-18 12:57:51 +0200 |
commit | 43b7a3693ea8c8ce05af8f42f8007c73e129aaf6 (patch) | |
tree | 9fe9ae34763207fd12d6ff3e46a4a0c868f7a105 /CMakeLists.txt | |
parent | 4a0429a82f83118707229fd7f9e089d397d21c6c (diff) |
CMake: Fix parsing of .gitmodules to be more robust
Fix empty lines in .gitmodules, rather than failing to configure
with an error message that the line is malformed.
Quote all relevant values, to avoid errors that string REGEX does
not have enough arguments in cases when the parsed content is
malformed.
Remove some dead code.
Change-Id: I300a76f82fe174290442c659ca2e84391db361a1
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r-- | CMakeLists.txt | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 98b44543..01fca842 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,21 +12,23 @@ enable_testing() set(qt_module_prop_prefix "__qt_prop_") function(extract_git_submodules out_module_list) - set(modules "") set(current_module "") set(module_list "") file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/.gitmodules" lines) foreach(line IN LISTS lines) - string(REGEX REPLACE "^\\[submodule \"([^\"]+)\"\\]$" "\\1" module ${line}) + # Skip empty lines. + if(NOT line) + continue() + endif() + string(REGEX REPLACE "^\\[submodule \"([^\"]+)\"\\]$" "\\1" module "${line}") if (NOT module STREQUAL line) - list(APPEND modules ${modules}) - set(current_module ${module}) - list(APPEND module_list ${module}) + set(current_module "${module}") + list(APPEND module_list "${module}") else() - string(REGEX REPLACE "^\t([^ =]+) *=.*$" "\\1" prop ${line}) + string(REGEX REPLACE "^\t([^ =]+) *=.*$" "\\1" prop "${line}") if (NOT prop STREQUAL line) - string(REGEX REPLACE "^[^=]+= *" "" value ${line}) - string(REPLACE " " ";" value ${value}) + string(REGEX REPLACE "^[^=]+= *" "" value "${line}") + string(REPLACE " " ";" value "${value}") set("${qt_module_prop_prefix}${current_module}_${prop}" "${value}" PARENT_SCOPE) else() message(FATAL_ERROR "Malformed line ${CMAKE_CURRENT_SOURCE_DIR}/.gitmodules: ${line}") |