MantisBT - CMake
View Issue Details
0015826CMakeCMakepublic2015-11-02 10:412016-06-10 14:31
Edward Rudd 
Kitware Robot 
normalminoralways
closedmoved 
 
 
0015826: target_compile_options de-duplicates flags but some repeats matter
So, I'm trying to build up a project via CMake that targets emscripten/asm.js Generally everything works great except for ONE thing that I'm trying to do. Pass custom emcc specific compile options. Emcc has compile options in the form of "-s USE_BLAH=2" . Generally these are used only as link options which doing this

target_link_libraries(MyTarget "-s USE_ZLIB=1" "-s USE_SDL=2" "-s ASSERTIONS=2") works fine. and the produced options has the options unquoted.

  em++ -s USE_ZLIB=1 -s USE_SDL=2 -s ASSERTIONS=2 -g -o MyTarget.js @CMakeFiles/MyTarget.dir/linklibs.rsp

However when applying them to compile options it breaks apart. e.g.

target_compile_options(MyTarget PRIVATE "-s USE_ZLIB=1" "-s USE_SDL=2")

CXX_FLAGS = "-s USE_ZLIB=1" "-s USE_SDL=2" -g @CMakeFiles/MyTarget.dir/includes_CXX.rsp

which emcc/em++ do not see the quoted argument as the option correctly and things do not work.

If I don't quote them then the produced output is further incorrect

target_compile_options(MyTarget PRIVATE -s USE_ZLIB=1 -s USE_SDL=2)

CXX_FLAGS = -s USE_ZLIB=1 USE_SDL=2 -g @CMakeFiles/MyTarget.dir/includes_CXX.rsp

Only one "-s" is produced!
No tags attached.
Issue History
2015-11-02 10:41Edward RuddNew Issue
2016-01-19 01:19Anil AltinayNote Added: 0040255
2016-01-19 10:28Brad KingNote Added: 0040260
2016-01-19 10:28Brad KingSummaryhandling quoting for compile options. => target_compile_options de-duplicates flags but some repeats matter
2016-01-19 10:33Brad KingNote Added: 0040261
2016-01-19 16:29Anil AltinayNote Edited: 0040255bug_revision_view_page.php?bugnote_id=40255#r2004
2016-01-20 15:33Stephen KellyNote Added: 0040276
2016-01-20 16:05Brad KingNote Added: 0040277
2016-06-10 14:29Kitware RobotNote Added: 0042876
2016-06-10 14:29Kitware RobotStatusnew => resolved
2016-06-10 14:29Kitware RobotResolutionopen => moved
2016-06-10 14:29Kitware RobotAssigned To => Kitware Robot
2016-06-10 14:31Kitware RobotStatusresolved => closed

Notes
(0040255)
Anil Altinay   
2016-01-19 01:19   
(edited on: 2016-01-19 16:29)
target_compile_options(..) get rid of same flags. In my case

target_compile_options(schedRandomizePercentage PRIVATE -mllvm -sched-randomize -mllvm -sched-randomize-percentage=100)

It tries to execute second flag without -mllvm but that is not what I want. I have tried following tricks to go around the problem but none of them worked.

______________TRICKS______________
1. Using PUBLIC instead of PRIVATE
2. Using semicolon instead of space between flags
3. Separating same flags into different commands like the following.

target_compile_options(schedRandomizePercentage PRIVATE -mllvm -sched-randomize)

target_compile_options(schedRandomizePercentage PRIVATE -mllvm -sched-randomize-percentage=100)

(0040260)
Brad King   
2016-01-19 10:28   
Re 0015826:0040255: I think that is the underlying problem and so I've updated the summary accordingly. The latter approach in the description is the intended interface.
(0040261)
Brad King   
2016-01-19 10:33   
It appears that the implementation intentionally removes duplicate options. See the "uniqueOptions" set here:

 https://cmake.org/gitweb?p=cmake.git;a=blob;f=Source/cmGeneratorTarget.cxx;hb=v3.4.1#l2346 [^]

Steve, was your intention here to avoid duplicates caused by collection of options repeated in multiple dependencies? That seems tricky to reconcile with these paired options.
(0040276)
Stephen Kelly   
2016-01-20 15:33   
Yes, I think that was my intention there. It seems to have been that way since it was introduced. I think the de-duplication was just intended to follow the pattern which include directories and compile definitions follow, but that doesn't may not make sense for compile options indeed.
(0040277)
Brad King   
2016-01-20 16:05   
Re 0015826:0040276: Thanks. The de-duplication is nice when flags are repeated only because they come from different targets that happen to provide the same flags in their INTERFACE_COMPILE_OPTIONS. However:

- Options specified within a single target's property should not be de-duplicated because repeats may be intentional
- Grouped options must be retained or de-dupliated together

We have at least these cases:

  "-option" "-unrelated-option"
  "-option" "value-to-option" [maybe-more-values]
  "-option with space"

Right now we have no way to tell the first two cases apart. We offer no way to encode the grouping information because we treat options with spaces as single options that happen to have spaces.
(0042876)
Kitware Robot   
2016-06-10 14:29   
Resolving issue as `moved`.

This issue tracker is no longer used. Further discussion of this issue may take place in the current CMake Issues page linked in the banner at the top of this page.