View Issue Details Jump to Notes ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0008362CMakeCMakepublic2009-01-11 07:042011-01-18 11:52
ReporterJelle Geerts 
Assigned ToBrad King 
PrioritynormalSeveritymajorReproducibilityalways
StatusclosedResolutionduplicate 
PlatformOSOS Version
Product VersionCMake-2-6 
Target VersionFixed in Version 
Summary0008362: cmake fails executing the command in link.txt with continuation characters in CMAKE_C_FLAGS
DescriptionFor example:
set( CMAKE_C_FLAGS "-ansi \
    -pedantic" )

This would generate:
path_to_gcc.exe -ansi \
    -pedantic CMakeFiles\test.dir\src\main.c.obj -o _build\bin\test.exe -Wl,--out-implib,_build\lib\libtest.dll.a -Wl,--major-image-version,0,--minor-image-version,0

Now, the command 'cmake.exe -E cmake_link_script CMakeFiles\pkeep.dir\link.txt'
fails, it only executes the first line, 'path_to_gcc.exe -ansi \'.

Tested on WinXP SP3.
TagsNo tags attached.
Attached Files

 Relationships
duplicate of 0006493closedStephen Kelly configuration dependent COMPILE_FLAGS for SET_TARGET_PROPERTIES 

  Notes
(0014530)
Brad King (manager)
2009-01-12 08:59

Continuation characters in flags is not a supported use case. If the flags are generated by something else, use string(REGEX REPLACE) to remove them.
(0014596)
Jelle Geerts (reporter)
2009-01-17 08:43

It's not about the continuation characters, but it's about the newline characters. The command in link.txt may not have newline characters because cmake only executes the first line.

Might this be an issue to look into?
(0014597)
Brad King (manager)
2009-01-17 09:02

What is your use case for this? Why does the _link_ command line ever need a newline in it?
(0014598)
Jelle Geerts (reporter)
2009-01-17 09:04

Because having newlines inside the 'set( CMAKE_C_FLAGS' part improves the maintainability of the CMakeLists.txt file.

Example:
set( CMAKE_C_FLAGS "-ansi -Wall -Wextra -Werror -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -Wnested-externs -Wstrict-prototypes -Wbad-function-cast -Wformat=2 -pedantic -Wa,--fatal-warnings" )
Versus:
set( CMAKE_C_FLAGS "-ansi -Wall -Wextra -Werror -Wshadow
-Wpointer-arith -Wcast-align -Wwrite-strings -Wmissing-prototypes
-Wmissing-declarations -Wredundant-decls -Wnested-externs
-Wstrict-prototypes -Wbad-function-cast -Wformat=2 -pedantic
-Wa,--fatal-warnings" )
(0014599)
Brad King (manager)
2009-01-17 11:07

I see. Unfortunately the flags were introduced _really_ early in CMake, before we had the convention of semi-colon separated lists. Otherwise you could just write the above code without the quotes. A while back I started working on a COMPILE_OPTIONS feature which is like flags but uses modern CMake conventions. I don't know when I'll get back to it.

Meanwhile, you can use the string(REPLACE) command to remove the newlines:

string(REPLACE "\n" " " CMAKE_C_FLAGS "
-ansi -Wall -Wextra -Werror -Wshadow
-Wpointer-arith -Wcast-align -Wwrite-strings -Wmissing-prototypes
-Wmissing-declarations -Wredundant-decls -Wnested-externs
-Wstrict-prototypes -Wbad-function-cast -Wformat=2 -pedantic
-Wa,--fatal-warnings
")

or create a macro to help you

macro(add_flags var)
  foreach(flag ${ARGN})
    set(${var} "${${var}} ${flag}")
  endforeach(flag)
endmacro(add_flags)

add_flags(CMAKE_C_FLAGS
  -ansi -Wall -Wextra -Werror -Wshadow
  -Wpointer-arith -Wcast-align -Wwrite-strings -Wmissing-prototypes
  -Wmissing-declarations -Wredundant-decls -Wnested-externs
  -Wstrict-prototypes -Wbad-function-cast -Wformat=2 -pedantic
  -Wa,--fatal-warnings
  )

The macro can be more efficient like this:

macro(add_flags var)
  string(REPLACE ";" " " _flags "${ARGN}")
  set(${var} "${${var}} ${_flags}")
endmacro(add_flags)
(0021205)
Göran Uddeborg (reporter)
2010-07-01 07:40

It would certainly be very nice if this could be fixed without extra local code like add_flags. Coming from Make previously, we hit this almost immediately. In our makefiles we always put the values of variables on several lines when there were many of them.
(0024860)
David Cole (manager)
2011-01-18 11:17

Looking at "older" "feedback" status bugs today... is this still an issue that we want to address moving forward? If so, please remove the "feedback" status and just set it to "assigned"... If not, please resolve it.

Thanks.
(0024875)
Brad King (manager)
2011-01-18 11:52

Closing as duplicate of 0006493 because the solution is the same: a future COMPILE_OPTIONS property. Please visit that issue and click the "Monitor" button to get further updates.

 Issue History
Date Modified Username Field Change
2009-01-11 07:04 Jelle Geerts New Issue
2009-01-11 20:29 Bill Hoffman Status new => assigned
2009-01-11 20:29 Bill Hoffman Assigned To => Brad King
2009-01-12 08:59 Brad King Note Added: 0014530
2009-01-12 08:59 Brad King Status assigned => closed
2009-01-12 08:59 Brad King Resolution open => won't fix
2009-01-17 08:43 Jelle Geerts Note Added: 0014596
2009-01-17 08:43 Jelle Geerts Status closed => feedback
2009-01-17 08:43 Jelle Geerts Resolution won't fix => reopened
2009-01-17 09:02 Brad King Note Added: 0014597
2009-01-17 09:04 Jelle Geerts Note Added: 0014598
2009-01-17 11:07 Brad King Note Added: 0014599
2010-07-01 07:40 Göran Uddeborg Note Added: 0021205
2011-01-18 11:17 David Cole Note Added: 0024860
2011-01-18 11:51 Brad King Relationship added duplicate of 0006493
2011-01-18 11:52 Brad King Note Added: 0024875
2011-01-18 11:52 Brad King Status feedback => closed
2011-01-18 11:52 Brad King Resolution reopened => duplicate


Copyright © 2000 - 2018 MantisBT Team