CMake/Tests/RunCMake/ExternalData/Semicolon2.cmake
Brad King 1823ab4d76 ExternalData: Preserve escaped semicolons during argument expansion
The CMake language implicitly flattens lists so a ";" in a list element
must be escaped with a backslash.  List expansion removes backslashes
escaping semicolons to leave raw semicolons in the values.  Teach
ExternalData_Add_Test and ExternalData_Expand_Arguments to re-escape
semicolons found in list elements so the resulting argument lists work
as if constructed directly by the set() command.

For example:

  ExternalData_Add_Test(Data NAME test1 COMMAND ... "a\\;b")
  ExternalData_Expand_Arguments(Data args2 "c\\;d")
  add_test(NAME test2 COMMAND ... ${args2})

should be equivalent to

  set(args1 "a\\;b")
  add_test(NAME test1 COMMAND ... ${args1})
  set(args2 "c\\;d")
  add_test(NAME test2 COMMAND ... ${args2})

which is equivalent to

  add_test(NAME test1 COMMAND ... "a;b")
  add_test(NAME test2 COMMAND ... "c;d")

Note that it is not possible to make ExternalData_Add_Test act exactly
like add_test when quoted arguments contain semicolons because the CMake
language flattens lists when constructing function ARGN values.  This
re-escape approach at least allows test arguments to have semicolons.

While at it, teach ExternalData APIs to not transform "DATA{...;...}"
arguments because the contained semicolons are non-sensical.

Suggested-by: Jean-Christophe Fillion-Robin <jchris.fillionr@kitware.com>
2013-03-12 16:33:19 -04:00

15 lines
524 B
CMake

include(ExternalData)
set(ExternalData_URL_TEMPLATES
"file:///${CMAKE_CURRENT_SOURCE_DIR}/%(algo)/%(hash)"
)
set(input Data.txt)
set(output ${CMAKE_CURRENT_BINARY_DIR}/Data.txt)
ExternalData_Expand_Arguments(Data args "DATA{${input}};a\\;b;c;d;DATA{${input}}")
set(expect "${output};a\\;b;c;d;${output}")
if("x${args}" STREQUAL "x${expect}")
message(STATUS "Data arguments correctly transformed!")
else()
message(FATAL_ERROR "Data arguments transformed to:\n ${args}\n"
"but we expected:\n ${expect}")
endif()