MantisBT - CMake
View Issue Details
0015493CMakeCMakepublic2015-04-03 10:582015-11-02 09:13
Aleksey Konovalov 
Brad King 
normalminoralways
closedfixed 
 
CMake 3.3CMake 3.3 
0015493: incorrect file parsing, if it has a BOM-header
The #include directive in the first line of the c/c++ source file is ignored if the file contains a BOM-header. In this case, the file depend.make is not included this header file and its dependencies.

My patch fixes this problem:

From 281e67e98961c1b2dcf0979dc3a38d5a1fa0b42a Mon Sep 17 00:00:00 2001
From: Aleksey Konovalov <konovalov.aleks@gmail.com>
Date: Fri, 3 Apr 2015 17:38:11 +0300
Subject: [PATCH] Skipping BOM-header while parsing a C-source

---
 Source/cmDependsC.cxx | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/Source/cmDependsC.cxx b/Source/cmDependsC.cxx
index 63d8fa6..60937b6 100644
--- a/Source/cmDependsC.cxx
+++ b/Source/cmDependsC.cxx
@@ -242,6 +242,9 @@ bool cmDependsC::WriteDependencies(const std::set<std::string>& sources,
           cmsys::ifstream fin(fullName.c_str());
           if(fin)
             {
+ // Skip BOM-header if it exists
+ cmsys::FStream::ReadBOM(fin);
+
             // Add this file as a dependency.
             dependencies.insert(fullName);
 
--
1.8.1.4

Attached file cmake_test.zip contains test-project. File test.cpp contains BOM-header in first line. CMake ignores this #include directive and does not add test.h to depend.make. Because of this, compilation does not occur when you modify test.h
current depend.make content:
---------------------------------------------------------------
# CMAKE generated file: DO NOT EDIT!
# Generated by "Unix Makefiles" Generator, CMake Version 2.8

CMakeFiles/test.dir/test.cpp.o: ../test.cpp

---------------------------------------------------------------

expected depend.make content:
---------------------------------------------------------------
# CMAKE generated file: DO NOT EDIT!
# Generated by "Unix Makefiles" Generator, CMake Version 3.2

CMakeFiles/test.dir/test.cpp.o: ../test.cpp
CMakeFiles/test.dir/test.cpp.o: ../test.h


---------------------------------------------------------------
No tags attached.
zip cmake_test.zip (376) 2015-04-03 10:58
https://public.kitware.com/Bug/file/5419/cmake_test.zip
Issue History
2015-04-03 10:58Aleksey KonovalovNew Issue
2015-04-03 10:58Aleksey KonovalovFile Added: cmake_test.zip
2015-04-03 13:24Brad KingNote Added: 0038396
2015-04-03 13:25Brad KingAssigned To => Brad King
2015-04-03 13:25Brad KingStatusnew => resolved
2015-04-03 13:25Brad KingResolutionopen => fixed
2015-04-03 13:25Brad KingFixed in Version => CMake 3.3
2015-04-03 13:25Brad KingTarget Version => CMake 3.3
2015-11-02 09:13Robert MaynardNote Added: 0039757
2015-11-02 09:13Robert MaynardStatusresolved => closed

Notes
(0038396)
Brad King   
2015-04-03 13:24   
Thanks. I made a change similar to yours and added a test case:

 Makefile: Tolerate a BOM while scanning source dependencies
 http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=af924827 [^]
(0039757)
Robert Maynard   
2015-11-02 09:13   
Closing resolved issues that have not been updated in more than 4 months.