MantisBT - CMake
View Issue Details
0014858CMakeCMakepublic2014-04-01 11:512014-10-06 10:33
Michael Priestman 
Brad King 
normalminoralways
closedfixed 
x64Windows7
CMake 2.8.12.2 
CMake 3.1CMake 3.1 
0014858: Flags specified for the compiler do not stay together during processing.
I want to enable code analysis in Visual Studio. To do this, you add the following flags to the compiler:

/analyze /analyze:log output.xml

When I try to do this with the following snippet of CMake:

set(CMAKE_C_FLAGS "/analyze /analyze:log output.xml")

It mangles the arguments. Firstly, it puts quotes around the "log" part, and secondly, the "output.xml" does not follow immediately after the "/analyze:log" argument, which is a compile error.

I have had this working in a previous version of CMake; I think it worked in version 2.8.9, but stopped working in (I think) 2.8.12.
Attached files reproduce the problem with Visual Studio 11 generator.

Generate Visual Studio 11 solution and try to build. You'll get a compile error saying /analyze:log requires an argument.
No tags attached.
zip CMakeAnalyzeError.zip (483) 2014-04-01 11:51
https://public.kitware.com/Bug/file/5118/CMakeAnalyzeError.zip
Issue History
2014-04-01 11:51Michael PriestmanNew Issue
2014-04-01 11:51Michael PriestmanFile Added: CMakeAnalyzeError.zip
2014-04-01 13:07Brad KingNote Added: 0035608
2014-04-01 13:17Brad KingNote Added: 0035609
2014-04-01 13:21Michael PriestmanNote Added: 0035610
2014-04-01 14:25Brad KingNote Added: 0035611
2014-04-01 14:37Michael PriestmanNote Added: 0035612
2014-04-01 14:37Michael PriestmanNote Edited: 0035612bug_revision_view_page.php?bugnote_id=35612#r1430
2014-04-02 09:24Brad KingNote Added: 0035621
2014-04-03 13:26Brad KingAssigned To => Brad King
2014-04-03 13:26Brad KingStatusnew => resolved
2014-04-03 13:26Brad KingResolutionopen => fixed
2014-04-03 13:26Brad KingFixed in Version => CMake 3.1
2014-04-03 13:26Brad KingTarget Version => CMake 3.1
2014-10-06 10:33Robert MaynardNote Added: 0036963
2014-10-06 10:33Robert MaynardStatusresolved => closed

Notes
(0035608)
Brad King   
2014-04-01 13:07   
In CMake 2.8.9 these flags would have been passed through raw to the project file AdditionalOptions setting. Since then this post-2.8.9 commit:

 VS11: Generate flag tables from MSBuild V110 tool files
 http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=9b2dda5d [^]

introduced the proper mapping from flags to project file settings. Clearly something goes wrong with the mapping for this flag.
(0035609)
Brad King   
2014-04-01 13:17   
The option mapping code parses and handles one flag at a time:

 http://cmake.org/gitweb?p=cmake.git;a=blob;f=Source/cmVisualStudioGeneratorOptions.cxx;hb=v2.8.12.2#l138 [^]
 http://cmake.org/gitweb?p=cmake.git;a=blob;f=Source/cmIDEOptions.cxx;hb=v2.8.12.2#l34 [^]

The string "/analyze:log output.xml" is actually two flags that need to be paired together. This is the first such flag I've seen.
(0035610)
Michael Priestman   
2014-04-01 13:21   
Yep, it is a pretty special case where there are two options that need to go together. This page details all the /analyze options for Visual Studio 11:

http://msdn.microsoft.com/en-us/library/ms173498%28v=vs.110%29.aspx [^]
(0035611)
Brad King   
2014-04-01 14:25   
AFAICT the /analyze options are only available through the IDE with VS Enterprise Team Developer to which I do not have access. How are

 /analyze:WX-
 /analyze:quiet
 /analyze:stacksize number
 /analyze:max_paths number
 /analyze:only

each represented in .vcxproj files? I especially need help with the stacksize and max_paths cases because they also require a separate argument like "log".
(0035612)
Michael Priestman   
2014-04-01 14:37   
In the UI, you can only enable or disable code analysis. You don't have access to the extended options. Enabling Code Analysis adds the indicated lines to the vcxproj file:

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    <LinkIncremental>true</LinkIncremental>
--> <RunCodeAnalysis>true</RunCodeAnalysis> <--
  </PropertyGroup>

and

  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    <ClCompile>
      <PrecompiledHeader>Use</PrecompiledHeader>
      <WarningLevel>Level3</WarningLevel>
      <Optimization>Disabled</Optimization>
      <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <SDLCheck>true</SDLCheck>
--> <EnablePREfast>true</EnablePREfast> <--
    </ClCompile>
    <Link>
      <SubSystem>Console</SubSystem>
      <GenerateDebugInformation>true</GenerateDebugInformation>
    </Link>
  </ItemDefinitionGroup>

I think all the other options, such as the log and stacksize need to be passed in to the compiler on the command line. When I added the "/analyze:log" option to the project, I got the following in the project file under the ClCompile section shown above:

    <ClCompile>
      <PrecompiledHeader>Use</PrecompiledHeader>
      <WarningLevel>Level3</WarningLevel>
      <Optimization>Disabled</Optimization>
      <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <SDLCheck>true</SDLCheck>
      <EnablePREfast>true</EnablePREfast>
--> <AdditionalOptions>/analyze:log output.xml %(AdditionalOptions)</AdditionalOptions> <--
    </ClCompile>

I hope this helps...

(0035621)
Brad King   
2014-04-02 09:24   
Okay, this should fix all the /analyze options:

 cmIDEOptions: Factor FlagMap update out to separate method
 http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=f2a3dd9d [^]

 VS: Support mapping flags with values following separately
 http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=650199e7 [^]

 VS: Fix /analyze:log flag mapping
 http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=e8633e66 [^]
(0036963)
Robert Maynard   
2014-10-06 10:33   
Closing resolved issues that have not been updated in more than 4 months.