<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=us-ascii"><meta name=Generator content="Microsoft Word 14 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p.MsoAcetate, li.MsoAcetate, div.MsoAcetate
        {mso-style-priority:99;
        mso-style-link:"Balloon Text Char";
        margin:0in;
        margin-bottom:.0001pt;
        font-size:8.0pt;
        font-family:"Tahoma","sans-serif";}
span.EmailStyle17
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
span.BalloonTextChar
        {mso-style-name:"Balloon Text Char";
        mso-style-priority:99;
        mso-style-link:"Balloon Text";
        font-family:"Tahoma","sans-serif";}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-US link=blue vlink=purple><div class=WordSection1><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>I inherited this cmake build that builds a complex project with a fairly large directory tree. Part way through it switches compilers, with code similar to what is below, and builds a few subdirectories using the new compilers. The compiler flags for the original compilers (compiler A) bleeds through to the new compilers (compiler B), because of the &lt;FLAGS&gt; below. The code below is in the CMakeLists.txt of the subdirectory that switches to the new compiler.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p>&nbsp;</o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Now I need to build on a new platform, which involves adding only one new compiler flag (-m32) to compiler A. Unfortunately, the &#8211;m32 is picked up by the &lt;FLAGS&gt; below and passed to compiler B, which does not support this flag, and gives an error.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p>&nbsp;</o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>So, I am trying to figure out if I can modify the existing code to remove the &#8211;m32 from &lt;FLAGS&gt; for compiler B, or if I need to basically rewrite the compiler B part of the build so that the subdirectories using compiler B are a separate cmake project. The rewrite idea is hard to justify in schedule sense to remove one flag, and I have to be sure it&#8217;s necessary.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p>&nbsp;</o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>While conceptually removing one &#8211;m32 flag seems simple, I am having a very hard time figuring out how to do it in cmake. Removing the single flag from compiler B can take two forms, as we have discussed. I can obtain the existing flags and remove the &#8211;m32 or I can substitute the new flags completely.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p>&nbsp;</o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>The removal option has not worked so far, possibly because this removal is occurring in a subdirectory of the original long after the project is established, and possibly because I am not sure which variable to modify. The CMAKE_C_FLAGS is already modified in this case, to no effect on &lt;FLAGS&gt;, possibly because its occurring long after the project is established. Can I get_target_property on COMPILER_FLAGS and modify that? <o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p>&nbsp;</o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>The second option almost works, but &nbsp;I can&#8217;t figure out how to obtain the &#8211;DDEBUG option that is currently established with set_target_properties, as described below.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p>&nbsp;</o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>-David<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p>&nbsp;</o:p></span></p><p class=MsoNormal><b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>From:</span></b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'> Glenn Coombs [mailto:glenn.coombs@gmail.com] <br><b>Sent:</b> Thursday, September 08, 2011 3:15 AM<br><b>To:</b> David Dunkle<br><b>Cc:</b> David Cole; cmake@cmake.org<br><b>Subject:</b> Re: [CMake] novice question: modification of FLAGS rule variable?<o:p></o:p></span></p><p class=MsoNormal><o:p>&nbsp;</o:p></p><p class=MsoNormal style='margin-bottom:12.0pt'>The set_target_properties() of COMPILE_FLAGS allows you to add the -DDEBUG just for the mylibd target (although you should really use the COMPILE_DEFINITIONS property for preprocessor symbols).&nbsp; Why do you need to mess with the &lt;FLAGS&gt; part of the compile command ?&nbsp; Can't you add extra compiler command flags like this:<br><br>&nbsp;&nbsp;&nbsp; set(CMAKE_C_FLAGS &quot;${CMAKE_C_FLAGS} -myFlag&quot;)<br><br>or even replace the default flags entirely like this:<br><br>&nbsp;&nbsp;&nbsp; set(CMAKE_C_FLAGS &quot;-foo&quot;)<br><br>I'm not sure what you are trying to achieve.&nbsp; Can you explain in a bit more detail ?<br><br>--<br>Glenn<o:p></o:p></p><div><p class=MsoNormal>On 8 September 2011 04:35, David Dunkle &lt;<a href="mailto:ddunkle@arxan.com">ddunkle@arxan.com</a>&gt; wrote:<o:p></o:p></p><div><div><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:11.0pt;color:#1F497D'>Thanks, Glenn. That almost works. However, the values of &lt;FLAGS&gt; is hard to construct in this case. It looks something like this:</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:11.0pt;color:#1F497D'>&nbsp;</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:11.0pt;color:#1F497D'>add_library(mylib, STATIC, ${files})</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:11.0pt;color:#1F497D'>set_target_properties(mylib</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:11.0pt;color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PROPERTIES PREFIX &#8220;&#8221;</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:11.0pt;color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; COMPILE_FLAGS ${target_compiler_flags})</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:11.0pt;color:#1F497D'>add_library(mylibd, STATIC, ${files})</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:11.0pt;color:#1F497D'>set_target_properties(mylibd,</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:11.0pt;color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PROPERTIES PREFIX &#8220;&#8221;</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:11.0pt;color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; COMPILE_FLAGS &#8220;-DDEBUG ${target_compiler_flags}&#8221;)</span><o:p></o:p></p><div><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:11.0pt;color:#1F497D'>&#8230;</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:11.0pt;color:#1F497D'>set(CMAKE_C_COMPILE_OBJECT &quot;${target_compiler} -c &lt;FLAGS&gt; -o &lt;OBJECT&gt;&quot;)</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:11.0pt;color:#1F497D'>&nbsp;</span><o:p></o:p></p></div><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:11.0pt;color:#1F497D'>I can replace &lt;FLAGS&gt; with ${target_compiler_flags} yielding this:</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:11.0pt;color:#1F497D'>&nbsp;</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:11.0pt;color:#1F497D'>set(CMAKE_C_COMPILE_OBJECT &#8220;${target_compiler} &#8211;c ${target_compiler_flags} &#8211;o &lt;OBJECT&gt;&#8221;)</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:11.0pt;color:#1F497D'>&nbsp;</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:11.0pt;color:#1F497D'>but then the &#8211;DDEBUG is missing for the build of mylibd. I guess both mylibd and mylib use CMAKE_C_COMPILE_OBJECT and I need a way to pass the &#8211;DDEBUG to the compile of one and not the other.</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:11.0pt;color:#1F497D'>&nbsp;</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:11.0pt;color:#1F497D'>-David</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:11.0pt;color:#1F497D'>&nbsp;</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><b><span style='font-size:10.0pt'>From:</span></b><span style='font-size:10.0pt'> Glenn Coombs [mailto:<a href="mailto:glenn.coombs@gmail.com" target="_blank">glenn.coombs@gmail.com</a>] <br><b>Sent:</b> Wednesday, September 07, 2011 4:19 AM<br><b>To:</b> David Cole<br><b>Cc:</b> David Dunkle; <a href="mailto:cmake@cmake.org" target="_blank">cmake@cmake.org</a><br><b>Subject:</b> Re: [CMake] novice question: modification of FLAGS rule variable?</span><o:p></o:p></p><div><div><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'>&nbsp;<o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;margin-bottom:12.0pt'>What you can do however is set the variable which uses the &lt;FLAGS&gt; definition, i.e. CMAKE_C_COMPILE_OBJECT in your example.&nbsp; I have a CMakeLists.txt file where I override the default assembler flags:<br><br>set(CMAKE_ASM-ATT_COMPILE_OBJECT &quot;&lt;CMAKE_ASM-ATT_COMPILER&gt; ${ASM_SYS_FLAGS} -o &lt;OBJECT&gt; &lt;SOURCE&gt;&quot;)<br><br>to use what is set in my ASM_SYS_FLAGS variable instead of the default &lt;FLAGS&gt; one.&nbsp; I'm not sure but I think you are supposed to set these sort of variables early on in a CMakeList.txt before the project() or enable_language() commands.&nbsp; Also, I think that later changes to the ASM_SYS_FLAGS variable are ignored.<br><br>--<br>Glenn<o:p></o:p></p><div><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'>On 5 September 2011 19:53, David Cole &lt;<a href="mailto:david.cole@kitware.com" target="_blank">david.cole@kitware.com</a>&gt; wrote:<o:p></o:p></p><div><div><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'>On Mon, Sep 5, 2011 at 1:31 PM, David Dunkle &lt;<a href="mailto:ddunkle@arxan.com" target="_blank">ddunkle@arxan.com</a>&gt; wrote:<br>&gt; Is it possible to read and to set a property/rule variable like &lt;FLAGS&gt;?<br>&gt; What syntax would I use to do that? I mean &lt;FLAGS&gt; as it, for example,<br>&gt; appears here:<br>&gt;<br>&gt;<br>&gt;<br>&gt; set(CMAKE_C_COMPILE_OBJECT &quot;${target_compiler} -c &lt;FLAGS&gt; -o &lt;OBJECT&gt;&quot;)<br>&gt;<br>&gt;<br>&gt;<br>&gt; For example can I do something like this (this is pseudo code)?<br>&gt;<br>&gt;<br>&gt;<br>&gt; #read<br>&gt;<br>&gt; set(MY_FLAGS, &nbsp;${&lt;FLAGS&gt;} );<br>&gt;<br>&gt;<br>&gt;<br>&gt; &#8230;<br>&gt;<br>&gt;<br>&gt;<br>&gt; #set<br>&gt;<br>&gt; set(&lt;FLAGS&gt;, ${MY_FLAGS});<br>&gt;<br>&gt;<br>&gt;<br>&gt; In the documentation, here:<br>&gt;<br>&gt;<br>&gt;<br>&gt; <a href="http://cmake.org/Wiki/CMake_Useful_Variables#Expansion_Rules" target="_blank">http://cmake.org/Wiki/CMake_Useful_Variables#Expansion_Rules</a><br>&gt;<br>&gt;<br>&gt;<br>&gt; it hints at this being possible but doesn&#8217;t explain, at least not so that I<br>&gt; understand.<br>&gt;<br>&gt;<br>&gt;<br>&gt; Thanks,<br>&gt;<br>&gt; -David<br>&gt;<br>&gt;<br>&gt;<br>&gt;<br>&gt;<o:p></o:p></p></div></div><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'>&gt; _______________________________________________<br>&gt; Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>&gt;<br>&gt; Visit other Kitware open-source projects at<br>&gt; <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>&gt;<br>&gt; Please keep messages on-topic and check the CMake FAQ at:<br>&gt; <a href="http://www.cmake.org/Wiki/CMake_FAQ" target="_blank">http://www.cmake.org/Wiki/CMake_FAQ</a><br>&gt;<br>&gt; Follow this link to subscribe/unsubscribe:<br>&gt; <a href="http://www.cmake.org/mailman/listinfo/cmake" target="_blank">http://www.cmake.org/mailman/listinfo/cmake</a><br>&gt;<br><br>The wiki page is simply misleading. You cannot set those from the<br>CMake language. CMake decides on their values in internal code, and<br>then substitutes appropriately when generating make files or<br>solution/project files for the build system.<br><br>You can set things the &quot;CMAKE_CXX_FLAGS&quot; which eventually get<br>translated into the substitution that CMake performs, but you cannot<br>alter &quot;&lt;FLAGS&gt;&quot; in the rules variables.<br><br><br>HTH,<br>David<br>_______________________________________________<br>Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br><br>Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br><br>Please keep messages on-topic and check the CMake FAQ at: <a href="http://www.cmake.org/Wiki/CMake_FAQ" target="_blank">http://www.cmake.org/Wiki/CMake_FAQ</a><br><br>Follow this link to subscribe/unsubscribe:<br><a href="http://www.cmake.org/mailman/listinfo/cmake" target="_blank">http://www.cmake.org/mailman/listinfo/cmake</a><o:p></o:p></p></div><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'>&nbsp;<o:p></o:p></p></div></div></div></div></div><p class=MsoNormal><o:p>&nbsp;</o:p></p></div></body></html>