[prev in list] [next in list] [prev in thread] [next in thread] 

List:       cmake
Subject:    Re: [CMake] Setting target properties
From:       Philip Lowman <philip () yhbt ! com>
Date:       2009-08-28 1:22:30
Message-ID: f168bb790908271822w2d44c720m990a577a244e2747 () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


On Thu, Aug 27, 2009 at 3:11 PM, Andrey Maslennikov <
andrew.maslennikov@gmail.com> wrote:

> My case: I have one file which can be compiled into 4 different binaries
> using macros. For this I use add_definitions() and remove_definitions()
> commands. But as I understand these commands has global effect in CMakeLists
> file. How can I define and undefine macros in *one* CMakeLists file?
>
> For this case more useful another command - set_target_properties() with
> property COMPILE_FLAGS. It really helped me, but I was confronted with
> difficulties in this way. I can't call it with 2 parameters, like
> set_target_properties( target PROPERTIES COMPILE_FLAGS -D__flag1__
> COMPILE_FLAGS -D__flag2__ ). In this case no keys were defined... It's very
> strange, because CMake's documentation present usage example with multiple
> properties in one command. I solved this issue with variable which contains
> all needed keys.


You could write a small CMakeLists function that uses get_target_property()
followed by
set_target_properties() to append flags to the COMPILE_FLAGS property.

Give this a shot:

function(append_compile_flags_to_target _target)
   get_target_property(_existing ${_target} COMPILE_FLAGS)
   if(_existing)
       set_target_properties(${_target} PROPERTIES COMPILE_FLAGS
"${_existing} ${ARGN}")
   else()
       set_target_properties(${_target} PROPERTIES COMPILE_FLAGS ${ARGN})
   endif()
endfunction()

Overall though I agree with you, it should be possible to append multiple
properties to the same set_target_properties() command.

-- 
Philip Lowman

[Attachment #5 (text/html)]

<div class="gmail_quote">On Thu, Aug 27, 2009 at 3:11 PM, Andrey Maslennikov <span \
dir="ltr">&lt;<a href="mailto:andrew.maslennikov@gmail.com">andrew.maslennikov@gmail.com</a>&gt;</span> \
wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, \
204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"> My case: I have one
file which can be compiled into 4 different binaries using macros. For
this I use add_definitions() and remove_definitions() commands. But as
I understand these commands has global effect in CMakeLists file. How can I
define and undefine macros in <i>one</i> CMakeLists file?<br><br>For this case more \
useful another command - set_target_properties() with property COMPILE_FLAGS. It \
really helped me, but I was confronted with difficulties in this way. I can&#39;t \
call it with 2 parameters, like set_target_properties( target PROPERTIES \
COMPILE_FLAGS -D__flag1__ COMPILE_FLAGS -D__flag2__ ). In this case no keys were \
defined... It&#39;s very strange, because CMake&#39;s documentation present usage \
example with multiple properties in one command. I solved this issue with variable \
which contains all needed keys.</blockquote> <div><br>You could write a small \
CMakeLists function that uses get_target_property() followed by \
<br>set_target_properties() to append flags to the COMPILE_FLAGS \
property.<br><br>Give this a shot:<br><br>function(append_compile_flags_to_target \
_target)<br>  get_target_property(_existing ${_target} COMPILE_FLAGS)<br>   \
if(_existing)<br>       set_target_properties(${_target} PROPERTIES COMPILE_FLAGS \
&quot;${_existing} ${ARGN}&quot;)<br>   else()<br>       \
set_target_properties(${_target} PROPERTIES COMPILE_FLAGS ${ARGN})<br>  \
endif()<br>endfunction()<br><br>Overall though I agree with you, it should be \
possible to append multiple properties to the same set_target_properties() \
command.<br><br></div></div>-- <br>Philip Lowman<br>



_______________________________________________
Powered by 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

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic