Is the -m32 flag being provided as a default by cmake, or are you specifying it yourself ? If the latter, then maybe it has been added to the COMPILE_DEFINITIONS property instead of the CMAKE_C_FLAGS variable. I have seen CMakeList.txt files use add_definitions(-m32) rather than adding it to the CMAKE_C_FLAGS variable. That would explain why explicitly setting CMAKE_C_FLAGS wasn't removing it. Also, is it C files or C++ files that are being compiled, because C++ files use CMAKE_CXX_FLAGS instead of CMAKE_C_FLAGS.<br>
<br><div class="gmail_quote">On 8 September 2011 18:16, David Dunkle <span dir="ltr"><<a href="mailto:ddunkle@arxan.com">ddunkle@arxan.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div link="blue" vlink="purple" lang="EN-US"><div><p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">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 <FLAGS> below. The code below is in the CMakeLists.txt of the subdirectory that switches to the new compiler.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">Now I need to build on a new platform, which involves adding only one new compiler flag (-m32) to compiler A. Unfortunately, the –m32 is picked up by the <FLAGS> below and passed to compiler B, which does not support this flag, and gives an error.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">So, I am trying to figure out if I can modify the existing code to remove the –m32 from <FLAGS> 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’s necessary.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">While conceptually removing one –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 –m32 or I can substitute the new flags completely.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">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 <FLAGS>, possibly because its occurring long after the project is established. Can I get_target_property on COMPILER_FLAGS and modify that? <u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">The second option almost works, but I can’t figure out how to obtain the –DDEBUG option that is currently established with set_target_properties, as described below.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">-David<u></u><u></u></span></p><p class="MsoNormal">
<span style="font-size: 11pt; color: rgb(31, 73, 125);"><u></u> <u></u></span></p><p class="MsoNormal"><b><span style="font-size: 10pt;">From:</span></b><span style="font-size: 10pt;"> Glenn Coombs [mailto:<a href="mailto:glenn.coombs@gmail.com" target="_blank">glenn.coombs@gmail.com</a>] <br>
<b>Sent:</b> Thursday, September 08, 2011 3:15 AM<br><b>To:</b> David Dunkle<br><b>Cc:</b> David Cole; <a href="mailto:cmake@cmake.org" target="_blank">cmake@cmake.org</a><div><div></div><div class="h5"><br><b>Subject:</b> Re: [CMake] novice question: modification of FLAGS rule variable?<u></u><u></u></div>
</div></span></p><div><div></div><div class="h5"><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal" style="margin-bottom: 12pt;">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). Why do you need to mess with the <FLAGS> part of the compile command ? Can't you add extra compiler command flags like this:<br>
<br> set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -myFlag")<br><br>or even replace the default flags entirely like this:<br><br> set(CMAKE_C_FLAGS "-foo")<br><br>I'm not sure what you are trying to achieve. Can you explain in a bit more detail ?<br>
<br>--<br>Glenn<u></u><u></u></p><div><p class="MsoNormal">On 8 September 2011 04:35, David Dunkle <<a href="mailto:ddunkle@arxan.com" target="_blank">ddunkle@arxan.com</a>> wrote:<u></u><u></u></p><div><div><p class="MsoNormal">
<span style="font-size: 11pt; color: rgb(31, 73, 125);">Thanks, Glenn. That almost works. However, the values of <FLAGS> is hard to construct in this case. It looks something like this:</span><u></u><u></u></p><p class="MsoNormal">
<span style="font-size: 11pt; color: rgb(31, 73, 125);"> </span><u></u><u></u></p><p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">add_library(mylib, STATIC, ${files})</span><u></u><u></u></p><p class="MsoNormal">
<span style="font-size: 11pt; color: rgb(31, 73, 125);">set_target_properties(mylib</span><u></u><u></u></p><p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);"> PROPERTIES PREFIX “”</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);"> COMPILE_FLAGS ${target_compiler_flags})</span><u></u><u></u></p><p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">add_library(mylibd, STATIC, ${files})</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">set_target_properties(mylibd,</span><u></u><u></u></p><p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);"> PROPERTIES PREFIX “”</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);"> COMPILE_FLAGS “-DDEBUG ${target_compiler_flags}”)</span><u></u><u></u></p><div><p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">…</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">set(CMAKE_C_COMPILE_OBJECT "${target_compiler} -c <FLAGS> -o <OBJECT>")</span><u></u><u></u></p><p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);"> </span><u></u><u></u></p>
</div><p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">I can replace <FLAGS> with ${target_compiler_flags} yielding this:</span><u></u><u></u></p><p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">set(CMAKE_C_COMPILE_OBJECT “${target_compiler} –c ${target_compiler_flags} –o <OBJECT>”)</span><u></u><u></u></p><p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">but then the –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 –DDEBUG to the compile of one and not the other.</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);"> </span><u></u><u></u></p><p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">-David</span><u></u><u></u></p><p class="MsoNormal">
<span style="font-size: 11pt; color: rgb(31, 73, 125);"> </span><u></u><u></u></p><p class="MsoNormal"><b><span style="font-size: 10pt;">From:</span></b><span style="font-size: 10pt;"> 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><u></u><u></u></p>
<div><div><p class="MsoNormal"> <u></u><u></u></p><p class="MsoNormal" style="margin-bottom: 12pt;">What you can do however is set the variable which uses the <FLAGS> definition, i.e. CMAKE_C_COMPILE_OBJECT in your example. I have a CMakeLists.txt file where I override the default assembler flags:<br>
<br>set(CMAKE_ASM-ATT_COMPILE_OBJECT "<CMAKE_ASM-ATT_COMPILER> ${ASM_SYS_FLAGS} -o <OBJECT> <SOURCE>")<br><br>to use what is set in my ASM_SYS_FLAGS variable instead of the default <FLAGS> one. 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. Also, I think that later changes to the ASM_SYS_FLAGS variable are ignored.<br>
<br>--<br>Glenn<u></u><u></u></p><div><p class="MsoNormal">On 5 September 2011 19:53, David Cole <<a href="mailto:david.cole@kitware.com" target="_blank">david.cole@kitware.com</a>> wrote:<u></u><u></u></p><div><div>
<p class="MsoNormal">On Mon, Sep 5, 2011 at 1:31 PM, David Dunkle <<a href="mailto:ddunkle@arxan.com" target="_blank">ddunkle@arxan.com</a>> wrote:<br>> Is it possible to read and to set a property/rule variable like <FLAGS>?<br>
> What syntax would I use to do that? I mean <FLAGS> as it, for example,<br>> appears here:<br>><br>><br>><br>> set(CMAKE_C_COMPILE_OBJECT "${target_compiler} -c <FLAGS> -o <OBJECT>")<br>
><br>><br>><br>> For example can I do something like this (this is pseudo code)?<br>><br>><br>><br>> #read<br>><br>> set(MY_FLAGS, ${<FLAGS>} );<br>><br>><br>><br>> …<br>><br>
><br>><br>> #set<br>><br>> set(<FLAGS>, ${MY_FLAGS});<br>><br>><br>><br>> In the documentation, here:<br>><br>><br>><br>> <a href="http://cmake.org/Wiki/CMake_Useful_Variables#Expansion_Rules" target="_blank">http://cmake.org/Wiki/CMake_Useful_Variables#Expansion_Rules</a><br>
><br>><br>><br>> it hints at this being possible but doesn’t explain, at least not so that I<br>> understand.<br>><br>><br>><br>> Thanks,<br>><br>> -David<br>><br>><br>><br>><br>
><u></u><u></u></p></div></div><p class="MsoNormal">> _______________________________________________<br>> Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>><br>> Visit other Kitware open-source projects at<br>
> <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:<br>> <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><br>><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 "CMAKE_CXX_FLAGS" which eventually get<br>
translated into the substitution that CMake performs, but you cannot<br>alter "<FLAGS>" 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><u></u><u></u></p></div><p class="MsoNormal"> <u></u><u></u></p>
</div></div></div></div></div><p class="MsoNormal"><u></u> <u></u></p></div></div></div></div></blockquote></div><br>