View Issue Details Jump to Notes ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0014858CMakeCMakepublic2014-04-01 11:512014-10-06 10:33
ReporterMichael Priestman 
Assigned ToBrad King 
PrioritynormalSeverityminorReproducibilityalways
StatusclosedResolutionfixed 
Platformx64OSWindowsOS Version7
Product VersionCMake 2.8.12.2 
Target VersionCMake 3.1Fixed in VersionCMake 3.1 
Summary0014858: Flags specified for the compiler do not stay together during processing.
DescriptionI 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.
Steps To ReproduceAttached 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.
TagsNo tags attached.
Attached Fileszip file icon CMakeAnalyzeError.zip [^] (483 bytes) 2014-04-01 11:51

 Relationships

  Notes
(0035608)
Brad King (manager)
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 (manager)
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 (reporter)
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 (manager)
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 (reporter)
2014-04-01 14:37
edited on: 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 (manager)
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 (manager)
2014-10-06 10:33

Closing resolved issues that have not been updated in more than 4 months.

 Issue History
Date Modified Username Field Change
2014-04-01 11:51 Michael Priestman New Issue
2014-04-01 11:51 Michael Priestman File Added: CMakeAnalyzeError.zip
2014-04-01 13:07 Brad King Note Added: 0035608
2014-04-01 13:17 Brad King Note Added: 0035609
2014-04-01 13:21 Michael Priestman Note Added: 0035610
2014-04-01 14:25 Brad King Note Added: 0035611
2014-04-01 14:37 Michael Priestman Note Added: 0035612
2014-04-01 14:37 Michael Priestman Note Edited: 0035612
2014-04-02 09:24 Brad King Note Added: 0035621
2014-04-03 13:26 Brad King Assigned To => Brad King
2014-04-03 13:26 Brad King Status new => resolved
2014-04-03 13:26 Brad King Resolution open => fixed
2014-04-03 13:26 Brad King Fixed in Version => CMake 3.1
2014-04-03 13:26 Brad King Target Version => CMake 3.1
2014-10-06 10:33 Robert Maynard Note Added: 0036963
2014-10-06 10:33 Robert Maynard Status resolved => closed


Copyright © 2000 - 2018 MantisBT Team