test: Add GTest printers for commonly used Qt types
[quassel.git] / cmake / GenerateQrc.cmake
1 # Generates a .qrc file named ${QRC_FILE} with path prefix ${PREFIX}, containing
2 # all files matching the glob ${PATTERNS} in the current working directory.
3 # This script is intended to be executed using the cmake -P syntax, so the
4 # arguments we're interested in start at ARGV3.
5
6 set(QRC_FILE ${CMAKE_ARGV3})
7 set(PREFIX   ${CMAKE_ARGV4})
8 set(PATTERNS ${CMAKE_ARGV5})
9
10 # Find all files matching PATTERNS in the current working directory
11 if (PATTERNS)
12     file(GLOB_RECURSE files RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${PATTERNS})
13 endif()
14
15 # Generate a temporary file first, so we don't touch the real thing unless something changed
16 set(qrc_tmp ${QRC_FILE}.tmp)
17 file(WRITE ${qrc_tmp} "<!DOCTYPE RCC>\n<RCC version=\"1.0\">\n<qresource prefix=\"/${PREFIX}\">\n")
18 foreach(file ${files})
19     # Record the timestamp of last modification so changes are detected
20     file(TIMESTAMP ${file} timestamp)
21     file(APPEND ${qrc_tmp} "    <file timestamp=\"${timestamp}\">${file}</file>\n")
22 endforeach()
23 file(APPEND ${qrc_tmp} "</qresource>\n</RCC>\n")
24
25 # Check if the newly generated file has the same contents (including timestamps) as the existing one.
26 # If the files are the same, don't touch the original to avoid useless rebuilds.
27 if (EXISTS ${QRC_FILE})
28     file(MD5 ${QRC_FILE} orig_sum)
29     file(MD5 ${qrc_tmp}  tmp_sum)
30     if (NOT orig_sum STREQUAL tmp_sum)
31         file(RENAME ${qrc_tmp} ${QRC_FILE})
32     else()
33         file(REMOVE ${qrc_tmp})
34     endif()
35 else()
36     file(RENAME ${qrc_tmp} ${QRC_FILE})
37 endif()