[CMake] novice question: modification of FLAGS rule variable?
David Dunkle
ddunkle at arxan.com
Thu Sep 8 13:16:13 EDT 2011
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.
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.
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.
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.
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?
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.
-David
From: Glenn Coombs [mailto:glenn.coombs at gmail.com]
Sent: Thursday, September 08, 2011 3:15 AM
To: David Dunkle
Cc: David Cole; cmake at cmake.org
Subject: Re: [CMake] novice question: modification of FLAGS rule variable?
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:
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -myFlag")
or even replace the default flags entirely like this:
set(CMAKE_C_FLAGS "-foo")
I'm not sure what you are trying to achieve. Can you explain in a bit more detail ?
--
Glenn
On 8 September 2011 04:35, David Dunkle <ddunkle at arxan.com<mailto:ddunkle at arxan.com>> wrote:
Thanks, Glenn. That almost works. However, the values of <FLAGS> is hard to construct in this case. It looks something like this:
add_library(mylib, STATIC, ${files})
set_target_properties(mylib
PROPERTIES PREFIX ""
COMPILE_FLAGS ${target_compiler_flags})
add_library(mylibd, STATIC, ${files})
set_target_properties(mylibd,
PROPERTIES PREFIX ""
COMPILE_FLAGS "-DDEBUG ${target_compiler_flags}")
...
set(CMAKE_C_COMPILE_OBJECT "${target_compiler} -c <FLAGS> -o <OBJECT>")
I can replace <FLAGS> with ${target_compiler_flags} yielding this:
set(CMAKE_C_COMPILE_OBJECT "${target_compiler} -c ${target_compiler_flags} -o <OBJECT>")
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.
-David
From: Glenn Coombs [mailto:glenn.coombs at gmail.com<mailto:glenn.coombs at gmail.com>]
Sent: Wednesday, September 07, 2011 4:19 AM
To: David Cole
Cc: David Dunkle; cmake at cmake.org<mailto:cmake at cmake.org>
Subject: Re: [CMake] novice question: modification of FLAGS rule variable?
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:
set(CMAKE_ASM-ATT_COMPILE_OBJECT "<CMAKE_ASM-ATT_COMPILER> ${ASM_SYS_FLAGS} -o <OBJECT> <SOURCE>")
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.
--
Glenn
On 5 September 2011 19:53, David Cole <david.cole at kitware.com<mailto:david.cole at kitware.com>> wrote:
On Mon, Sep 5, 2011 at 1:31 PM, David Dunkle <ddunkle at arxan.com<mailto:ddunkle at arxan.com>> wrote:
> Is it possible to read and to set a property/rule variable like <FLAGS>?
> What syntax would I use to do that? I mean <FLAGS> as it, for example,
> appears here:
>
>
>
> set(CMAKE_C_COMPILE_OBJECT "${target_compiler} -c <FLAGS> -o <OBJECT>")
>
>
>
> For example can I do something like this (this is pseudo code)?
>
>
>
> #read
>
> set(MY_FLAGS, ${<FLAGS>} );
>
>
>
> ...
>
>
>
> #set
>
> set(<FLAGS>, ${MY_FLAGS});
>
>
>
> In the documentation, here:
>
>
>
> http://cmake.org/Wiki/CMake_Useful_Variables#Expansion_Rules
>
>
>
> it hints at this being possible but doesn't explain, at least not so that I
> understand.
>
>
>
> Thanks,
>
> -David
>
>
>
>
>
> _______________________________________________
> Powered by www.kitware.com<http://www.kitware.com>
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake
>
The wiki page is simply misleading. You cannot set those from the
CMake language. CMake decides on their values in internal code, and
then substitutes appropriately when generating make files or
solution/project files for the build system.
You can set things the "CMAKE_CXX_FLAGS" which eventually get
translated into the substitution that CMake performs, but you cannot
alter "<FLAGS>" in the rules variables.
HTH,
David
_______________________________________________
Powered by www.kitware.com<http://www.kitware.com>
Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20110908/52447232/attachment.htm>
More information about the CMake
mailing list