MantisBT - CMake
View Issue Details
0015211CMakeCMakepublic2014-10-18 16:522015-04-06 09:07
Timo Korthals 
 
highmajoralways
closedno change required 
amd64Ubuntu14.04.1
CMake 2.8.12.2 
 
0015211: Faulty parsing of variables with multi-line content
cmake (above 2.8.7 up to master/head) fails to parse variables which have more than two lines (and therefore two 'newline' character) in it. The outcome of it is, that the project is unmakeable, because of the faulty produced makefiles.

As a minimal example I define multiple include directories in the variable "GCC_INCLUDES" and hand it over to "include_directories", which produces the "CXX_FLAGS" in "flags.make".
I give you first an working example with the corresponding output file, and then an example with the faulty output:

Working "CMakeLists.txt"
-----------------------START
  cmake_minimum_required(VERSION 2.8.7 FATAL_ERROR)
  project ("helloWorld")
  set(GCC_INCLUDES "/test1\n/test2")
  include_directories(
      ${GCC_INCLUDES}
  )
  add_executable("helloWorld" main.cpp)
-----------------------END

Correct outputfile "CMakeFiles/helloWorld.dir/flags.make"
-----------------------START
# CMAKE generated file: DO NOT EDIT!
# Generated by "Unix Makefiles" Generator, CMake Version 2.8

# compile CXX with /usr/bin/c++
CXX_FLAGS = -I/test1 -I/test2

  CXX_DEFINES =
-----------------------END

Faulty "CMakeLists.txt"
-----------------------START
  cmake_minimum_required(VERSION 2.8.7 FATAL_ERROR)
  project ("helloWorld")
  set(GCC_INCLUDES "/test1\n/test2\n/test3")
  include_directories(
      ${GCC_INCLUDES}
  )
  add_executable("helloWorld" main.cpp)
-----------------------END

Faulty outputfile "CMakeFiles/helloWorld.dir/flags.make"
-----------------------START
# CMAKE generated file: DO NOT EDIT!
# Generated by "Unix Makefiles" Generator, CMake Version 2.8

# compile CXX with /usr/bin/c++
CXX_FLAGS = -I/test1 -I/test2
/test3 -I/test3

CXX_DEFINES =
-----------------------END
Use the CMakeLists.txt files in the section "Description" and run "cmake ." to produce the error message.

Example "main.cpp"
-----------------------START
#include <iostream>

using namespace std;

int main(void) {
 cout << "Hallo World" << endl;
 return 0;
}
-----------------------END
I tested the following cmake versions

OS: Ubuntu 12.04.4; cmake 2.8.7
Result: No parsing error

OS: Ubuntu 14.04.1; cmake 2.8.7
Result: No parsing error

OS: Ubuntu 14.04.1; cmake 2.12.2
Result: ERROR

OS: Ubuntu 14.04.1; cmake master/head (commit d4525d7288ef935ee8b9d8cf338763498850364f)
Result: ERROR
No tags attached.
Issue History
2014-10-18 16:52Timo KorthalsNew Issue
2014-10-20 09:11Brad KingNote Added: 0037052
2014-10-20 09:12Brad KingNote Added: 0037053
2014-10-20 09:12Brad KingStatusnew => resolved
2014-10-20 09:12Brad KingResolutionopen => no change required
2015-04-06 09:07Robert MaynardNote Added: 0038424
2015-04-06 09:07Robert MaynardStatusresolved => closed

Notes
(0037052)
Brad King   
2014-10-20 09:11   
The CMake language does not separate arguments on newlines in evaluated variables, only on semicolons:

 http://www.cmake.org/cmake/help/v3.0/manual/cmake-language.7.html#lists [^]

The include_directories() command does not try to parse multiple lines either. If you have some source of information that produces one include directory on each line then it is up to you to parse it before passing to include_directories() in the documented way. You could use the string() command for that, for example.
(0037053)
Brad King   
2014-10-20 09:12   
If you need further help please ask on the mailing list:

 http://www.cmake.org/mailman/listinfo/cmake [^]
(0038424)
Robert Maynard   
2015-04-06 09:07   
Closing resolved issues that have not been updated in more than 4 months.