summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2015-04-06 12:58:17 (GMT)
committerCMake Topic Stage <kwrobot@kitware.com>2015-04-06 12:58:17 (GMT)
commitb9c1eb4dcc801ea0a8f3f33aec58c5f9ab04026e (patch)
tree5586d3fceb7d2fdfb0e277a63c71e2705940edee
parent9ddbacdb74c7f3daf824decee9a1d900ddb44744 (diff)
parentaf924827120f39f1a7a940bc3f6bc487665145d9 (diff)
downloadCMake-b9c1eb4dcc801ea0a8f3f33aec58c5f9ab04026e.zip
CMake-b9c1eb4dcc801ea0a8f3f33aec58c5f9ab04026e.tar.gz
CMake-b9c1eb4dcc801ea0a8f3f33aec58c5f9ab04026e.tar.bz2
Merge topic 'makefile-depscan-BOM'
af924827 Makefile: Tolerate a BOM while scanning source dependencies (#15493)
-rw-r--r--Source/cmDependsC.cxx21
-rw-r--r--Tests/RunCMake/CommandLine/RunCMakeTest.cmake26
-rw-r--r--Tests/RunCMake/CommandLine/cmake_depends-check.cmake13
-rw-r--r--Tests/RunCMake/CommandLine/cmake_depends-stdout.txt1
-rw-r--r--Tests/RunCMake/CommandLine/cmake_depends/test.c2
-rw-r--r--Tests/RunCMake/CommandLine/cmake_depends/test.h1
-rw-r--r--Tests/RunCMake/CommandLine/cmake_depends/test_UTF-16LE.hbin0 -> 58 bytes
7 files changed, 58 insertions, 6 deletions
diff --git a/Source/cmDependsC.cxx b/Source/cmDependsC.cxx
index 63d8fa6..6cdd4c1 100644
--- a/Source/cmDependsC.cxx
+++ b/Source/cmDependsC.cxx
@@ -242,13 +242,22 @@ bool cmDependsC::WriteDependencies(const std::set<std::string>& sources,
cmsys::ifstream fin(fullName.c_str());
if(fin)
{
- // Add this file as a dependency.
- dependencies.insert(fullName);
+ cmsys::FStream::BOM bom = cmsys::FStream::ReadBOM(fin);
+ if(bom == cmsys::FStream::BOM_None ||
+ bom == cmsys::FStream::BOM_UTF8)
+ {
+ // Add this file as a dependency.
+ dependencies.insert(fullName);
- // Scan this file for new dependencies. Pass the directory
- // containing the file to handle double-quote includes.
- std::string dir = cmSystemTools::GetFilenamePath(fullName);
- this->Scan(fin, dir.c_str(), fullName);
+ // Scan this file for new dependencies. Pass the directory
+ // containing the file to handle double-quote includes.
+ std::string dir = cmSystemTools::GetFilenamePath(fullName);
+ this->Scan(fin, dir.c_str(), fullName);
+ }
+ else
+ {
+ // Skip file with encoding we do not implement.
+ }
}
}
}
diff --git a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake
index a9c49e7..e8b4584 100644
--- a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake
+++ b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake
@@ -80,3 +80,29 @@ run_cmake(D_nested_cache)
set(RunCMake_TEST_OPTIONS
"-DFOO:STRING=-DBAR:BOOL=BAZ")
run_cmake(D_typed_nested_cache)
+
+function(run_cmake_depends)
+ set(RunCMake_TEST_SOURCE_DIR "${RunCMake_SOURCE_DIR}/cmake_depends")
+ set(RunCMake_TEST_BINARY_DIR "${RunCMake_BINARY_DIR}/cmake_depends-build")
+ set(RunCMake_TEST_NO_CLEAN 1)
+ file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
+ file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
+ file(WRITE "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/DepTarget.dir/DependInfo.cmake" "
+set(CMAKE_DEPENDS_LANGUAGES \"C\")
+set(CMAKE_DEPENDS_CHECK_C
+ \"${RunCMake_TEST_SOURCE_DIR}/test.c\"
+ \"${RunCMake_TEST_BINARY_DIR}/CMakeFiles/DepTarget.dir/test.c.o\"
+ )
+")
+ file(WRITE "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/CMakeDirectoryInformation.cmake" "
+set(CMAKE_RELATIVE_PATH_TOP_SOURCE \"${RunCMake_TEST_SOURCE_DIR}\")
+set(CMAKE_RELATIVE_PATH_TOP_BINARY \"${RunCMake_TEST_BINARY_DIR}\")
+")
+ run_cmake_command(cmake_depends ${CMAKE_COMMAND} -E cmake_depends
+ "Unix Makefiles"
+ ${RunCMake_TEST_SOURCE_DIR} ${RunCMake_TEST_SOURCE_DIR}
+ ${RunCMake_TEST_BINARY_DIR} ${RunCMake_TEST_BINARY_DIR}
+ ${RunCMake_TEST_BINARY_DIR}/CMakeFiles/DepTarget.dir/DependInfo.cmake
+ )
+endfunction()
+run_cmake_depends()
diff --git a/Tests/RunCMake/CommandLine/cmake_depends-check.cmake b/Tests/RunCMake/CommandLine/cmake_depends-check.cmake
new file mode 100644
index 0000000..031478b
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/cmake_depends-check.cmake
@@ -0,0 +1,13 @@
+set(depend_make "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/DepTarget.dir/depend.make")
+if(EXISTS "${depend_make}")
+ file(READ "${depend_make}" depend_make_content)
+ string(REGEX REPLACE "\n+$" "" depend_make_content "${depend_make_content}")
+ if(NOT depend_make_content MATCHES "
+CMakeFiles/DepTarget.dir/test.c.o: .*/Tests/RunCMake/CommandLine/cmake_depends/test.c
+CMakeFiles/DepTarget.dir/test.c.o: .*/Tests/RunCMake/CommandLine/cmake_depends/test.h$")
+ string(REPLACE "\n" "\n " depend_make_content " ${depend_make_content}")
+ set(RunCMake_TEST_FAILED "depend.make does not have expected content:\n${depend_make_content}")
+ endif()
+else()
+ set(RunCMake_TEST_FAILED "depend.make missing:\n ${depend_make}")
+endif()
diff --git a/Tests/RunCMake/CommandLine/cmake_depends-stdout.txt b/Tests/RunCMake/CommandLine/cmake_depends-stdout.txt
new file mode 100644
index 0000000..8fe092b
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/cmake_depends-stdout.txt
@@ -0,0 +1 @@
+^Scanning dependencies of target DepTarget$
diff --git a/Tests/RunCMake/CommandLine/cmake_depends/test.c b/Tests/RunCMake/CommandLine/cmake_depends/test.c
new file mode 100644
index 0000000..92c056f
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/cmake_depends/test.c
@@ -0,0 +1,2 @@
+#include "test.h"
+#include "test_UTF-16LE.h"
diff --git a/Tests/RunCMake/CommandLine/cmake_depends/test.h b/Tests/RunCMake/CommandLine/cmake_depends/test.h
new file mode 100644
index 0000000..fd87388
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/cmake_depends/test.h
@@ -0,0 +1 @@
+void test(void) {}
diff --git a/Tests/RunCMake/CommandLine/cmake_depends/test_UTF-16LE.h b/Tests/RunCMake/CommandLine/cmake_depends/test_UTF-16LE.h
new file mode 100644
index 0000000..bf56ec6
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/cmake_depends/test_UTF-16LE.h
Binary files differ