Merge topic 'configure_file-unicode'

98383f80 Unicode: check encoding of files given to configure_file.
This commit is contained in:
Brad King 2014-03-20 09:22:28 -04:00 committed by CMake Topic Stage
commit 565213c1fd
25 changed files with 69 additions and 0 deletions

View File

@ -3526,6 +3526,20 @@ int cmMakefile::ConfigureFile(const char* infile, const char* outfile,
return 0;
}
cmsys::FStream::BOM bom = cmsys::FStream::ReadBOM(fin);
if(bom != cmsys::FStream::BOM_None &&
bom != cmsys::FStream::BOM_UTF8)
{
cmOStringStream e;
e << "File starts with a Byte-Order-Mark that is not UTF-8:\n "
<< sinfile;
this->IssueMessage(cmake::FATAL_ERROR, e.str());
return 0;
}
// rewind to copy BOM to output file
fin.seekg(0);
// now copy input to output and expand variables in the
// input file at the same time
std::string inLine;

View File

@ -96,6 +96,7 @@ add_RunCMake_test(TargetPolicies)
add_RunCMake_test(alias_targets)
add_RunCMake_test(interface_library)
add_RunCMake_test(no_install_prefix)
add_RunCMake_test(configure_file)
find_package(Qt4 QUIET)
find_package(Qt5Core QUIET)

View File

@ -0,0 +1,3 @@
cmake_minimum_required(VERSION 3.0)
project(${RunCMake_TEST} NONE)
include(${RunCMake_TEST}.cmake)

View File

@ -0,0 +1,2 @@
configure_file(NO-BOM.txt.in ${CMAKE_CURRENT_BINARY_DIR}/NO-BOM.txt)

View File

@ -0,0 +1 @@
Hello World

View File

@ -0,0 +1,8 @@
include(RunCMake)
run_cmake(NO-BOM)
run_cmake(UTF8-BOM)
run_cmake(UTF16LE-BOM)
run_cmake(UTF16BE-BOM)
run_cmake(UTF32LE-BOM)
run_cmake(UTF32BE-BOM)

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1,6 @@
CMake Error at UTF16BE-BOM.cmake:2 \(configure_file\):
File starts with a Byte-Order-Mark that is not UTF-8:
.*/Tests/RunCMake/configure_file/UTF16BE-BOM.txt.in
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)

View File

@ -0,0 +1,2 @@
configure_file(UTF16BE-BOM.txt.in ${CMAKE_CURRENT_BINARY_DIR}/UTF16BE-BOM.txt)

Binary file not shown.

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1,6 @@
CMake Error at UTF16LE-BOM.cmake:2 \(configure_file\):
File starts with a Byte-Order-Mark that is not UTF-8:
.*/Tests/RunCMake/configure_file/UTF16LE-BOM.txt.in
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)

View File

@ -0,0 +1,2 @@
configure_file(UTF16LE-BOM.txt.in ${CMAKE_CURRENT_BINARY_DIR}/UTF16LE-BOM.txt)

Binary file not shown.

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1,6 @@
CMake Error at UTF32BE-BOM.cmake:2 \(configure_file\):
File starts with a Byte-Order-Mark that is not UTF-8:
.*/Tests/RunCMake/configure_file/UTF32BE-BOM.txt.in
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)

View File

@ -0,0 +1,2 @@
configure_file(UTF32BE-BOM.txt.in ${CMAKE_CURRENT_BINARY_DIR}/UTF32BE-BOM.txt)

Binary file not shown.

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1,6 @@
CMake Error at UTF32LE-BOM.cmake:2 \(configure_file\):
File starts with a Byte-Order-Mark that is not UTF-8:
.*/Tests/RunCMake/configure_file/UTF32LE-BOM.txt.in
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)

View File

@ -0,0 +1,2 @@
configure_file(UTF32LE-BOM.txt.in ${CMAKE_CURRENT_BINARY_DIR}/UTF32LE-BOM.txt)

Binary file not shown.

View File

@ -0,0 +1,2 @@
configure_file(UTF8-BOM.txt.in ${CMAKE_CURRENT_BINARY_DIR}/UTF8-BOM.txt)

View File

@ -0,0 +1 @@
Hello World

View File

@ -329,6 +329,7 @@ fi
KWSYS_CXX_SOURCES="\
Directory \
EncodingCXX \
FStream \
Glob \
RegularExpression \
SystemTools"