[CMake] set_target_properties versus set_source_files_properties

Michael Wild themiwi at gmail.com
Wed Sep 22 11:37:42 EDT 2010


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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 195 bytes
Desc: This is a digitally signed message part
URL: <http://www.cmake.org/pipermail/cmake/attachments/20100922/bf65d81d/attachment.pgp>


More information about the CMake mailing list