Re: [CMake] Different CMAKE_CXX_FLAGS for different executables

2011-03-30 Thread Michael Hertling
On 03/25/2011 03:36 PM, David Doria wrote:
 Could you post the output of make VERBOSE=1?

 On *nix, the following CMakeLists.txt works as expected:
 The output of make VERBOSE=1 contains:

 .../c++ -DUNIX -o .../SetTargetProperties.cxx.o -c 
 .../SetTargetProperties.cxx
 
 It is working properly now. I must not have done a 'make clean'.
 
 BTW, preprocessor definitions like -DUNIX should be set via the
 COMPILE_DEFINITIONS properties instead of the COMPILE_FLAGS ones.
 
 It seems to generate exactly the same thing if I use
 
 set_target_properties(CompilerFlags PROPERTIES COMPILE_FLAGS -DUNIX)
 
 and
 
 set_target_properties(CompilerFlags PROPERTIES COMPILE_DEFINITIONS UNIX)
 
 After reading the documentation you set certainly sounds like I should
 use the COMPILE_DEFINITIONS version, but is there a difference?
 
 Thanks again,
 
 David

For simple defines, i.e. without = sign, COMPILE_FLAGS with -D and
COMPILE_DEFINITIONS without -D should act equivalently. However, the
latter cares about the correct escaping for more complex definitions,
i.e. -DXYZ=\...\ and the like. Furthermore, COMPILE_DEFINITIONS has
configuration-specific variants and is also available as a directory
property. Finally, it is list-oriented while COMPILE_FLAGS is space-
separated. Thus, COMPILE_DEFINITIONS is preferable for preprocessor
definitions while COMPILE_FLAGS should be reserved for non-define
flags - as long as it doesn't become obsolete anyway due to the
envisaged COMPILE_OPTIONS property [1].

Regards,

Michael

[1] http://public.kitware.com/Bug/view.php?id=6493#c13821
___
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


Re: [CMake] Different CMAKE_CXX_FLAGS for different executables

2011-03-25 Thread David Doria
 Could you post the output of make VERBOSE=1?

 On *nix, the following CMakeLists.txt works as expected:
 The output of make VERBOSE=1 contains:

 .../c++ -DUNIX -o .../SetTargetProperties.cxx.o -c 
 .../SetTargetProperties.cxx

It is working properly now. I must not have done a 'make clean'.

 BTW, preprocessor definitions like -DUNIX should be set via the
 COMPILE_DEFINITIONS properties instead of the COMPILE_FLAGS ones.

It seems to generate exactly the same thing if I use

set_target_properties(CompilerFlags PROPERTIES COMPILE_FLAGS -DUNIX)

and

set_target_properties(CompilerFlags PROPERTIES COMPILE_DEFINITIONS UNIX)

After reading the documentation you set certainly sounds like I should
use the COMPILE_DEFINITIONS version, but is there a difference?

Thanks again,

David
___
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


[CMake] Different CMAKE_CXX_FLAGS for different executables

2011-03-24 Thread David Doria
Is there a way to explicitly set the CMAKE_CXX_FLAGS for a particular
executable? That is, if I set CMAKE_CXX_FLAGS and then have a
add_executable line, then change CMAKE_CXX_FLAGS and then have another
add_executable, will the first set of CMAKE_CXX_FLAGS be applied to
the first executable and the second set of CMAKE_CXX_FLAGS be applied
to the second executable?

I guess my confusion is that I don't understand how CMake variables are cached.

Each time I modify the variable, should I do it using

SET(CMAKE_CXX_FLAGS some flags)

or

SET(CMAKE_CXX_FLAGS some flags CACHE STRING compiler flags)

?

In this example: http://codepad.org/PGJRBjss the messages are actually
not displayed at all, which is only adding to my confusion :)

Any comments on this?

Thanks,

David
___
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


Re: [CMake] Different CMAKE_CXX_FLAGS for different executables

2011-03-24 Thread David Doria
On Thu, Mar 24, 2011 at 10:44 AM, David Doria daviddo...@gmail.com wrote:
 Is there a way to explicitly set the CMAKE_CXX_FLAGS for a particular
 executable? That is, if I set CMAKE_CXX_FLAGS and then have a
 add_executable line, then change CMAKE_CXX_FLAGS and then have another
 add_executable, will the first set of CMAKE_CXX_FLAGS be applied to
 the first executable and the second set of CMAKE_CXX_FLAGS be applied
 to the second executable?

 I guess my confusion is that I don't understand how CMake variables are 
 cached.

 Each time I modify the variable, should I do it using

 SET(CMAKE_CXX_FLAGS some flags)

 or

 SET(CMAKE_CXX_FLAGS some flags CACHE STRING compiler flags)

 ?

 In this example: http://codepad.org/PGJRBjss the messages are actually
 not displayed at all, which is only adding to my confusion :)

 Any comments on this?

 Thanks,

 David


Scratch that last part, I was looking in the wrong place in my IDE.
The output is:

Using flags
Using flags

when I would expect:

Using flags Flags1
Using flags Flags2

Can anyone explain this?

David
___
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


Re: [CMake] Different CMAKE_CXX_FLAGS for different executables

2011-03-24 Thread Yuri Timenkov
Use COMPILE_FLAGS target property. Like this:

set_target_properties(Exec2 PROPERTIES COMPILE_FLAGS /flag1 /flag2)

You can see full list of properties in CMake documentation. Note that
compiler flags may be also set for particular source file with
set_source_files_properties command.

On Thu, Mar 24, 2011 at 5:44 PM, David Doria daviddo...@gmail.com wrote:

 Is there a way to explicitly set the CMAKE_CXX_FLAGS for a particular
 executable? That is, if I set CMAKE_CXX_FLAGS and then have a
 add_executable line, then change CMAKE_CXX_FLAGS and then have another
 add_executable, will the first set of CMAKE_CXX_FLAGS be applied to
 the first executable and the second set of CMAKE_CXX_FLAGS be applied
 to the second executable?

 I guess my confusion is that I don't understand how CMake variables are
 cached.

 Each time I modify the variable, should I do it using

 SET(CMAKE_CXX_FLAGS some flags)

 or

 SET(CMAKE_CXX_FLAGS some flags CACHE STRING compiler flags)

 ?

 In this example: http://codepad.org/PGJRBjss the messages are actually
 not displayed at all, which is only adding to my confusion :)

 Any comments on this?

 Thanks,

 David
 ___
 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

___
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

Re: [CMake] Different CMAKE_CXX_FLAGS for different executables

2011-03-24 Thread David Doria
On Thu, Mar 24, 2011 at 11:31 AM, Yuri Timenkov y...@timenkov.ru wrote:
 Use COMPILE_FLAGS target property. Like this:

 set_target_properties(Exec2 PROPERTIES COMPILE_FLAGS /flag1 /flag2)

 You can see full list of properties in CMake documentation. Note that
 compiler flags may be also set for particular source file with
 set_source_files_properties command.

Hi Yuri,

I tried a CMakeLists.txt file like this:

cmake_minimum_required(VERSION 2.6)
PROJECT(SetTargetProperties)
ADD_EXECUTABLE(SetTargetProperties SetTargetProperties.cxx)
set_target_properties(SetTargetProperties PROPERTIES COMPILE_FLAGS -DUNIX)

Then I ran:

make VERBOSE=1

and I don't see anything in the output that indicates that this flag
was passed, but I also don't see the call to g++ at all. How would I
check that this worked correctly?

Thanks for your help so far,

David
___
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


Re: [CMake] Different CMAKE_CXX_FLAGS for different executables

2011-03-24 Thread Michael Hertling
On 03/24/2011 03:44 PM, David Doria wrote:
 Is there a way to explicitly set the CMAKE_CXX_FLAGS for a particular
 executable? That is, if I set CMAKE_CXX_FLAGS and then have a
 add_executable line, then change CMAKE_CXX_FLAGS and then have another
 add_executable, will the first set of CMAKE_CXX_FLAGS be applied to
 the first executable and the second set of CMAKE_CXX_FLAGS be applied
 to the second executable?

AFAIK, CMAKE_CXX_FLAGS et al. are special in as much as the last value
they receive within a CMakeLists.txt file is effective for all targets
defined in that file, i.e. they undergo a kind of lazy evaluation. So,
the answer to your question is: No, you can't specify CMAKE_CXX_FLAGS
individually for targets within the same CMakeLists.txt, but you can
specify them per directory, i.e. individually in each CMakeLists.txt.
Nevertheless, CMAKE_CXX_FLAGS should be considered as project-wide
settings, IMO.

 I guess my confusion is that I don't understand how CMake variables are 
 cached.
 
 Each time I modify the variable, should I do it using
 
 SET(CMAKE_CXX_FLAGS some flags)
 
 or
 
 SET(CMAKE_CXX_FLAGS some flags CACHE STRING compiler flags)
 
 ?

See [1] for a consideration of SET() w.r.t. the cache and scopes.

 In this example: http://codepad.org/PGJRBjss [...]

ATM, that site seems to be offline. Could you post the example here?

Regards,

Michael

[1] http://www.mail-archive.com/cmake@cmake.org/msg29869.html et seq.
___
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


Re: [CMake] Different CMAKE_CXX_FLAGS for different executables

2011-03-24 Thread Michael Hertling
On 03/24/2011 11:39 PM, David Doria wrote:
 On Thu, Mar 24, 2011 at 11:31 AM, Yuri Timenkov y...@timenkov.ru wrote:
 Use COMPILE_FLAGS target property. Like this:

 set_target_properties(Exec2 PROPERTIES COMPILE_FLAGS /flag1 /flag2)

 You can see full list of properties in CMake documentation. Note that
 compiler flags may be also set for particular source file with
 set_source_files_properties command.
 
 Hi Yuri,
 
 I tried a CMakeLists.txt file like this:
 
 cmake_minimum_required(VERSION 2.6)
 PROJECT(SetTargetProperties)
 ADD_EXECUTABLE(SetTargetProperties SetTargetProperties.cxx)
 set_target_properties(SetTargetProperties PROPERTIES COMPILE_FLAGS -DUNIX)
 
 Then I ran:
 
 make VERBOSE=1
 
 and I don't see anything in the output that indicates that this flag
 was passed, but I also don't see the call to g++ at all. How would I
 check that this worked correctly?

Could you post the output of make VERBOSE=1?

On *nix, the following CMakeLists.txt works as expected:

cmake_minimum_required(VERSION 2.6)
PROJECT(SetTargetProperties)
FILE(WRITE ${CMAKE_BINARY_DIR}/SetTargetProperties.cxx
int main(){return 0;}\n)
ADD_EXECUTABLE(SetTargetProperties SetTargetProperties.cxx)
set_target_properties(SetTargetProperties PROPERTIES COMPILE_FLAGS -DUNIX)

The output of make VERBOSE=1 contains:

 .../c++ -DUNIX -o .../SetTargetProperties.cxx.o -c .../SetTargetProperties.cxx

BTW, preprocessor definitions like -DUNIX should be set via the
COMPILE_DEFINITIONS properties instead of the COMPILE_FLAGS ones.

Regards,

Michael
___
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