[CMake] set_target_properties versus set_source_files_properties

2010-09-22 Thread pellegrini

Hello everybody,

my question is in the title !

I want to create a fortran static library using the following set of g95 
compiler flags -O3 -std=f2003 -funroll-loops -msse2


If I use:

set_target_properties(my_static_lib PROPERTIES COMPILE_FLAGS -O3 
-std=f2003 -funroll-loops -msse2)

or
set_source_files_properties(${SRC_FILES} PROPERTIES COMPILE_FLAGS -O3 
-std=f2003 -funroll-loops -msse2)


where ${SRC_FILES} is the list of source files used to compile my static 
library, the result is the same when starting the make process.


So, in such a case is there a difference between those two functions ?

Another question I have is when applying one or the other function, this 
will duplicate some of the compiler flags (e.g. O3). The only way I 
found to avoid this is to do the following:


set(CMAKE_Fortran_FLAGS_RELEASE  )  
set_target_properties(crysfml PROPERTIES COMPILE_FLAGS -O3 -std=f2003 
-funroll-loops -msse2)


so everything looks as if by default the CMAKE_Fortran_FLAGS_RELEASE 
variable was set to -O3 and then, the value stored in the 
COMPILE_FLAGS variable was appended to it (so in that case -O3 + -O3 
-std=f2003 -funroll-loops -msse2 giving -O3 -O3 -std=f2003 
-funroll-loops -msse2). Am I right ?


thanks a lot

Eric

--
Eric Pellegrini
Calcul Scientifique
Insitut Laue-Langevin
Grenoble, France

___
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] set_target_properties versus set_source_files_properties

2010-09-22 Thread Michael Wild

On 22. Sep, 2010, at 14:09 , pellegrini wrote:

 Hello everybody,
 
 my question is in the title !
 
 I want to create a fortran static library using the following set of g95 
 compiler flags -O3 -std=f2003 -funroll-loops -msse2
 
 If I use:
 
 set_target_properties(my_static_lib PROPERTIES COMPILE_FLAGS -O3 -std=f2003 
 -funroll-loops -msse2)
 or
 set_source_files_properties(${SRC_FILES} PROPERTIES COMPILE_FLAGS -O3 
 -std=f2003 -funroll-loops -msse2)
 
 where ${SRC_FILES} is the list of source files used to compile my static 
 library, the result is the same when starting the make process.
 
 So, in such a case is there a difference between those two functions ?

Yes. The latter is if you need more fine-grained control (compile some files 
with other flags than the rest).

 
 Another question I have is when applying one or the other function, this will 
 duplicate some of the compiler flags (e.g. O3). The only way I found to avoid 
 this is to do the following:
 
 set(CMAKE_Fortran_FLAGS_RELEASE  )  
 set_target_properties(crysfml PROPERTIES COMPILE_FLAGS -O3 -std=f2003 
 -funroll-loops -msse2)
 
 so everything looks as if by default the CMAKE_Fortran_FLAGS_RELEASE variable 
 was set to -O3 and then, the value stored in the COMPILE_FLAGS variable was 
 appended to it (so in that case -O3 + -O3 -std=f2003 -funroll-loops 
 -msse2 giving -O3 -O3 -std=f2003 -funroll-loops -msse2). Am I right ?

Yes. RTFMing tells me:

$ cmake --help-property COMPILE_FLAGS
cmake version 2.8.2
  COMPILE_FLAGS
   Additional flags to use when compiling this target's sources.

   The COMPILE_FLAGS property sets additional compiler flags used to
   build sources within the target.  Use COMPILE_DEFINITIONS to pass
   additional preprocessor definitions

So, it says that the flags are appended to the standard flags.

 
 thanks a lot
 
 Eric

BTW: You shouldn't set -O3, -funroll-loops and -msse2 in COMPILE_FLAGS, since 
those are optimization flags. You should set them when you run cmake in 
CMAKE_Fortran_FLAGS_RELEASE.

Michael

--
There is always a well-known solution to every human problem -- neat, 
plausible, and wrong.
H. L. Mencken



PGP.sig
Description: This is a digitally signed message part
___
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] set_target_properties versus set_source_files_properties

2010-09-22 Thread Michael Wild

On 22. Sep, 2010, at 17:49 , pellegrini wrote:

 Michael Wild a écrit :
 On 22. Sep, 2010, at 14:09 , pellegrini wrote:
 
  
 Hello everybody,
 
 my question is in the title !
 
 I want to create a fortran static library using the following set of g95 
 compiler flags -O3 -std=f2003 -funroll-loops -msse2
 
 If I use:
 
 set_target_properties(my_static_lib PROPERTIES COMPILE_FLAGS -O3 
 -std=f2003 -funroll-loops -msse2)
 or
 set_source_files_properties(${SRC_FILES} PROPERTIES COMPILE_FLAGS -O3 
 -std=f2003 -funroll-loops -msse2)
 
 where ${SRC_FILES} is the list of source files used to compile my static 
 library, the result is the same when starting the make process.
 
 So, in such a case is there a difference between those two functions ?

 
 Yes. The latter is if you need more fine-grained control (compile some files 
 with other flags than the rest).
 
  
 Another question I have is when applying one or the other function, this 
 will duplicate some of the compiler flags (e.g. O3). The only way I found 
 to avoid this is to do the following:
 
 set(CMAKE_Fortran_FLAGS_RELEASE  )  
 set_target_properties(crysfml PROPERTIES COMPILE_FLAGS -O3 -std=f2003 
 -funroll-loops -msse2)
 
 so everything looks as if by default the CMAKE_Fortran_FLAGS_RELEASE 
 variable was set to -O3 and then, the value stored in the COMPILE_FLAGS 
 variable was appended to it (so in that case -O3 + -O3 -std=f2003 
 -funroll-loops -msse2 giving -O3 -O3 -std=f2003 -funroll-loops -msse2). 
 Am I right ?

 
 Yes. RTFMing tells me:
 
 $ cmake --help-property COMPILE_FLAGS
 cmake version 2.8.2
  COMPILE_FLAGS
   Additional flags to use when compiling this target's sources.
 
   The COMPILE_FLAGS property sets additional compiler flags used to
   build sources within the target.  Use COMPILE_DEFINITIONS to pass
   additional preprocessor definitions
 
 So, it says that the flags are appended to the standard flags.
 
  
 thanks a lot
 
 Eric

 
 BTW: You shouldn't set -O3, -funroll-loops and -msse2 in COMPILE_FLAGS, 
 since those are optimization flags. You should set them when you run cmake 
 in CMAKE_Fortran_FLAGS_RELEASE.
 
 Michael
 
  
 
 thanks Michael fore the hint.
 
 So you mean that I should better write something like this if I really want 
 to reset the compiler flags for the different kind of build (Debug, Release 
 ...):
 
 if(CMAKE_BUILD_TYPE strequal Release)
 
 set(CMAKE_Fortran_FLAGS_RELEASE  )
 set_target_properties(crysfml PROPERTIES COMPILE_Fortran_FLAGS_RELEASE -O3 
 -std=f2003 -funroll-loops -msse2)
 
 elseif(CMAKE_BUILD_TYPE strequal Debug)
 
 set(CMAKE_Fortran_FLAGS_DEBUG  )  
 set_target_properties(crysfml PROPERTIES COMPILE_Fortran_FLAGS_DEBUG -O3 
 -std=f2003 -funroll-loops -msse2)
 
 end()
 
 instead of using the COMPILE_FLAGS ?
 
 Eric

I'd suggest to leave it to the user, don't set those flags in the 
CMakeLists.txt at all. If you absolutely must/want to, remove the conditionals, 
the variables themselves act as conditionals in the sense that CMake only 
uses them for the corresponding configuration type. Your approach breaks down 
for multi-config IDE's (such as Visual Studio, Xcode etc.), where 
CMAKE_BUILD_TYPE is irrelevant. Also, it's not a good idea to just set them 
like you do, since it's very surprising for users if their changes in the cache 
don't have any effect.

The only reasonable way to really override the default compiler flags is 
probably to provide your own Compiler/*-Fortran.cmake files and set 
CMAKE_MODULE_PATH accordingly before the project() (or enable_language()) call 
that activates Fortran support.

Michael

--
There is always a well-known solution to every human problem -- neat, 
plausible, and wrong.
H. L. Mencken



PGP.sig
Description: This is a digitally signed message part
___
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