2003-07-10 22:29:30 +04:00
|
|
|
PROJECT(StringFileTest)
|
|
|
|
INCLUDE_DIRECTORIES(${StringFileTest_BINARY_DIR})
|
|
|
|
|
2003-07-21 21:48:18 +04:00
|
|
|
# Read file test
|
2003-07-10 22:29:30 +04:00
|
|
|
FILE(READ "${CMAKE_CURRENT_SOURCE_DIR}/InputFile.h.in" infile)
|
2003-07-21 21:48:18 +04:00
|
|
|
|
|
|
|
# String test
|
2003-07-10 22:29:30 +04:00
|
|
|
STRING(REGEX MATCH "[cC][mM][aA][kK][eE]" rmvar "CMake is great")
|
|
|
|
STRING(REGEX MATCHALL "[cC][mM][aA][kK][eE]" rmallvar "CMake is better than cmake or CMake")
|
|
|
|
STRING(REGEX REPLACE "[Aa][uU][tT][oO]([cC][oO][nN][fF]|[mM][aA][kK][eE])"
|
|
|
|
"CMake" rrepvar "People should use Autoconf and Automake")
|
|
|
|
STRING(COMPARE EQUAL "CMake" "Autoconf" nceqvar)
|
|
|
|
STRING(COMPARE EQUAL "CMake" "CMake" ceqvar)
|
|
|
|
STRING(COMPARE NOTEQUAL "CMake" "Autoconf" cneqvar)
|
|
|
|
STRING(COMPARE NOTEQUAL "CMake" "CMake" ncneqvar)
|
|
|
|
STRING(COMPARE LESS "before" "after" nclvar)
|
|
|
|
STRING(COMPARE LESS "max" "min" clvar)
|
|
|
|
STRING(COMPARE GREATER "before" "after" cgvar)
|
|
|
|
STRING(COMPARE GREATER "max" "min" ncgvar)
|
|
|
|
STRING(ASCII 67 109 97 107 101 savar)
|
|
|
|
STRING(TOUPPER "CMake" tuvar)
|
|
|
|
STRING(TOLOWER "CMake" tlvar)
|
|
|
|
|
2003-07-21 21:48:18 +04:00
|
|
|
# Escaping test
|
|
|
|
SET(var "\\ \" \ \t \n \r \# \( \) \0")
|
2003-07-23 17:10:39 +04:00
|
|
|
MESSAGE("Output: [${var}]")
|
2003-07-21 21:48:18 +04:00
|
|
|
SET(var \\ \" \ \t \n \r \# \( \) \0)
|
2003-07-23 17:10:39 +04:00
|
|
|
MESSAGE("Output: [${var}]")
|
2003-07-21 21:48:18 +04:00
|
|
|
|
|
|
|
# Make directories test
|
|
|
|
FILE(MAKE_DIRECTORY
|
|
|
|
"${CMAKE_CURRENT_BINARY_DIR}/Includes"
|
|
|
|
"${CMAKE_CURRENT_BINARY_DIR}/Directory1"
|
|
|
|
"${CMAKE_CURRENT_BINARY_DIR}/Directory2"
|
|
|
|
)
|
2003-07-10 22:29:30 +04:00
|
|
|
|
2003-07-21 21:48:18 +04:00
|
|
|
# Write results to the file (test write file)
|
2003-07-10 22:29:30 +04:00
|
|
|
SET(file "${CMAKE_CURRENT_BINARY_DIR}/Includes/Values.h")
|
|
|
|
FILE(WRITE "${file}" "/* this file is generated */\n")
|
|
|
|
FOREACH(var
|
|
|
|
rmvar
|
|
|
|
rmallvar
|
|
|
|
rrepvar
|
|
|
|
nceqvar
|
|
|
|
ceqvar
|
|
|
|
cneqvar
|
|
|
|
ncneqvar
|
|
|
|
nclvar
|
|
|
|
clvar
|
|
|
|
cgvar
|
|
|
|
ncgvar
|
|
|
|
savar
|
|
|
|
tuvar
|
|
|
|
tlvar)
|
2003-07-17 22:56:44 +04:00
|
|
|
FILE(APPEND "${file}" "#define ${var} \"${${var}}\"\n")
|
2003-07-10 22:29:30 +04:00
|
|
|
ENDFOREACH(var)
|
|
|
|
|
2003-07-21 21:48:18 +04:00
|
|
|
# Write include file to a file
|
2003-07-10 22:29:30 +04:00
|
|
|
STRING(REGEX REPLACE "includefile" "${file}" outfile "${infile}")
|
|
|
|
FILE(WRITE "${CMAKE_CURRENT_BINARY_DIR}/OutputFile.h" "${outfile}")
|
|
|
|
|
2003-07-21 21:48:18 +04:00
|
|
|
# Test file glob
|
2003-07-21 23:29:29 +04:00
|
|
|
FILE(GLOB_RECURSE src_files "${CMAKE_CURRENT_SOURCE_DIR}/*")
|
2003-07-23 17:10:39 +04:00
|
|
|
MESSAGE("Files in ${CMAKE_CURRENT_SOURCE_DIR} are ${src_files}")
|
|
|
|
SET(expr "${CMAKE_CURRENT_SOURCE_DIR}/[sS][!a-su-zA-Z0-9][^a-qs-zA-Z0-9]ing?ile*.cxx")
|
|
|
|
MESSAGE("Glob expression is [${expr}].")
|
|
|
|
FILE(GLOB src_files "${expr}")
|
|
|
|
MESSAGE("Globbed files [${src_files}].")
|
2003-07-21 21:48:18 +04:00
|
|
|
|
|
|
|
ADD_EXECUTABLE(StringFileTest ${src_files})
|