1 PROJECT(StringFileTest)
2 INCLUDE_DIRECTORIES(${StringFileTest_BINARY_DIR})
5 FILE(READ "${CMAKE_CURRENT_SOURCE_DIR}/InputFile.h.in" infile)
8 STRING(REGEX MATCH "[cC][mM][aA][kK][eE]" rmvar "CMake is great")
9 STRING(REGEX MATCHALL "[cC][mM][aA][kK][eE]" rmallvar "CMake is better than cmake or CMake")
10 STRING(REGEX REPLACE "[Aa][uU][tT][oO]([cC][oO][nN][fF]|[mM][aA][kK][eE])"
11 "CMake" rrepvar "People should use Autoconf and Automake")
12 STRING(COMPARE EQUAL "CMake" "Autoconf" nceqvar)
13 STRING(COMPARE EQUAL "CMake" "CMake" ceqvar)
14 STRING(COMPARE NOTEQUAL "CMake" "Autoconf" cneqvar)
15 STRING(COMPARE NOTEQUAL "CMake" "CMake" ncneqvar)
16 STRING(COMPARE LESS "before" "after" nclvar)
17 STRING(COMPARE LESS "max" "min" clvar)
18 STRING(COMPARE GREATER "before" "after" cgvar)
19 STRING(COMPARE GREATER "max" "min" ncgvar)
20 STRING(ASCII 67 109 97 107 101 savar)
21 STRING(TOUPPER "CMake" tuvar)
22 STRING(TOLOWER "CMake" tlvar)
25 SET(var "\\ \" \ \t \n \r \# \( \) \0")
26 MESSAGE("Output: [${var}]")
27 SET(var \\ \" \ \t \n \r \# \( \) \0)
28 MESSAGE("Output: [${var}]")
30 # Make-style unquoted argument test
31 SET(var $(VAR1)$(VAR2)/$(VAR3))
32 MESSAGE("Output: [${var}]")
33 STRING(COMPARE EQUAL "${var}" "$(VAR1)$(VAR2)/$(VAR3)" result)
35 MESSAGE(SEND_ERROR "Unquoted $(VAR) syntax is broken.")
38 # Make directories test
40 "${CMAKE_CURRENT_BINARY_DIR}/Includes"
41 "${CMAKE_CURRENT_BINARY_DIR}/Directory1"
42 "${CMAKE_CURRENT_BINARY_DIR}/Directory2"
45 # Write results to the file (test write file)
46 SET(file "${CMAKE_CURRENT_BINARY_DIR}/Includes/Values.h")
47 FILE(WRITE "${file}" "/* this file is generated */\n")
63 FILE(APPEND "${file}" "#define ${var} \"${${var}}\"\n")
66 # Test configuration of the string
69 STRING(CONFIGURE "${infile}" infile @ONLY)
71 # Write include file to a file
72 STRING(REGEX REPLACE "includefile" "${file}" outfile "${infile}")
73 FILE(WRITE "${CMAKE_CURRENT_BINARY_DIR}/OutputFile.h" "${outfile}")
76 FILE(GLOB_RECURSE src_files "${CMAKE_CURRENT_SOURCE_DIR}/*")
77 MESSAGE("Files in ${CMAKE_CURRENT_SOURCE_DIR} are ${src_files}")
78 SET(expr "${CMAKE_CURRENT_SOURCE_DIR}/[sS][!a-su-zA-Z0-9][^a-qs-zA-Z0-9]ing?ile*.cxx")
79 MESSAGE("Glob expression is [${expr}].")
80 FILE(GLOB src_files "${expr}")
81 MESSAGE("Globbed files [${src_files}].")
83 ADD_EXECUTABLE(StringFileTest ${src_files})
86 MESSAGE("Cheack if FOREACH with RANGE works")
87 MACRO(TEST_RANGE ARGS CHECK)
89 FOREACH(a RANGE ${ARGS})
92 MESSAGE("FOREACH with RANGE ${ARGS} produces ${r}")
93 IF("x${r}x" MATCHES "^x${CHECK}x$")
94 ELSE("x${r}x" MATCHES "^x${CHECK}x$")
95 MESSAGE(SEND_ERROR "The range resulted in: ${r} should be ${CHECK}")
96 ENDIF("x${r}x" MATCHES "^x${CHECK}x$")
98 TEST_RANGE("5" "0;1;2;3;4;5")
99 TEST_RANGE("3;5" "3;4;5")
100 TEST_RANGE("5;3" "5;4;3")
101 TEST_RANGE("3;10;2" "3;5;7;9")
102 TEST_RANGE("10;0;-3" "10;7;4;1")