aboutsummaryrefslogtreecommitdiff
path: root/cmake/ProjReadme.cmake
blob: 7071a381e3cff2191f6853f56922d9a6d9cfd6b0 (plain)
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
#
# CMake script to modify README.md to create simpler README file
#
# This is equivalent to: fgrep -v "[!["
#

set(SourceFile "${PROJ_SOURCE_DIR}/README.md")
set(DestFile "${PROJ_SOURCE_DIR}/README")

# Below is based on https://stackoverflow.com/a/30227627

file(READ ${SourceFile} Contents)

# Set the variable "Esc" to the ASCII value 27 as a special escape value
string(ASCII 27 Esc)

# Turn the contents into a list of strings, each ending with Esc
string(REGEX REPLACE "\n" "${Esc};" ContentsAsList "${Contents}")

unset(ModifiedContents)
foreach(Line ${ContentsAsList})
  if(NOT "${Line}" MATCHES "\\[!\\[")
    # Swap the appended Esc character back out in favour of a line feed
    string(REGEX REPLACE "${Esc}" "\n" Line ${Line})
    set(ModifiedContents "${ModifiedContents}${Line}")
  endif()
endforeach()
file(WRITE ${DestFile} ${ModifiedContents})