forked from Governikus/AusweisApp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tools.Libraries.cmake
43 lines (36 loc) · 1.7 KB
/
Tools.Libraries.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# This file will be included in Tools.cmake AND after Libraries.cmake
# So this file will be called two times and the check needs to respect that
# with a "VALIDATOR function" or "if(NOT VARIABLE)".
if(NOT TARGET format.qml)
set(QMLFORMAT_MIN_VERSION 6)
function(qmlformat_validator validator_result binary)
execute_process(COMMAND ${binary} --version OUTPUT_VARIABLE QMLFORMAT_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE)
string(REPLACE "qmlformat " "" QMLFORMAT_VERSION "${QMLFORMAT_VERSION}")
if("${QMLFORMAT_VERSION}" VERSION_LESS "${QMLFORMAT_MIN_VERSION}")
set(${validator_result} FALSE PARENT_SCOPE)
endif()
endfunction()
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.25")
set(VALIDATOR VALIDATOR qmlformat_validator)
endif()
find_program(QMLFORMAT qmlformat HINTS "${QT_INSTALL_ARCHDATA}/bin" ${VALIDATOR} CMAKE_FIND_ROOT_PATH_BOTH)
if(QMLFORMAT)
execute_process(COMMAND ${QMLFORMAT} --version OUTPUT_VARIABLE QMLFORMAT_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE)
string(REPLACE "qmlformat " "" QMLFORMAT_VERSION "${QMLFORMAT_VERSION}")
if("${QMLFORMAT_VERSION}" VERSION_LESS "${QMLFORMAT_MIN_VERSION}")
unset(QMLFORMAT CACHE) # let's retry later
else()
file(GLOB_RECURSE FILES_QML ${PROJECT_SOURCE_DIR}/*.qml)
set(FORMATTING_FILE ${PROJECT_BINARY_DIR}/formatting.files.qml)
file(WRITE ${FORMATTING_FILE} "")
foreach(file ${FILES_QML})
file(APPEND ${FORMATTING_FILE} ${file})
file(APPEND ${FORMATTING_FILE} "\n")
endforeach()
add_custom_target(format.qml
COMMAND ${CMAKE_COMMAND} -E echo Calling ${QMLFORMAT} in version ${QMLFORMAT_VERSION}
COMMAND ${QMLFORMAT} -F ${FORMATTING_FILE} SOURCES ${FILES_QML})
add_dependencies(format format.qml)
endif()
endif()
endif()