[CMake] Default source properties and get_property plus LANGUAGE source propery has no effect.

Michael Wild themiwi at gmail.com
Fri Mar 4 08:09:23 EST 2011


On 03/04/2011 01:56 PM, Orcun Gokbulut wrote:
> Hi everybody,
> 
> I came across two problems when I was porting our project build system to
> cmake.
> 
> The first program that I encounter is I can not compile generated source
> files with extension other than default c/c++ extensions.
> 
> 
> I have tried;
> 
> 
> set_property (SOURCE ZEPortalMap.h.zpp PROPERTY LANGUAGE CXX)
> 
> 
> and this
> 
> 
> SET (CMAKE_CXX_SOURCE_FILE_EXTENSIONS ${CMAKE_CXX_SOURCE_FILE_EXTENSIONS}
> zpp)
> 
> 
> but they do not work. File's build tool property in visual studio is still
> custom build tool instead of c++ compiler.
> 

have you tried set_source_files_properties()? And if the source is
generated, why don't you use a standard extension then? After all, it's
under your control...

> 
> While I was investigating the problem I came across another problem; I can
> not read default values of a source property. In more generic terms value of
> a source file property (I don't known whether this applies to
> target/directory/global properties) is not defined unless it is defined by a
> set command. However, those properties has build in default values that are
> also overwritten by set functions. So there is no way of getting default
> values of these properties.
> 
> The statements,
> 
> get_property (Result SOURCE ZEPortalMap.h PROPERTY COMPILE_FLAGS)
> message (${Result})
> 
> returns this error message
> 
> CMake Error at Source/ZEMap/ZEPortalMap/CMakeLists.txt:23 (message):
> 
>  message called with incorrect number of arguments
> 
> 
> However if I do this;
> 
> 
> set_property (SOURCE ZEPortalMap.h PROPERTY COMPILE_FLAGS "-blabla")
> get_property (Result SOURCE ZEPortalMap.h PROPERTY COMPILE_FLAGS)
> 
> message (${Result})
> 
> I get:
> -blabla
> 
> on the output. In sort, cmake does not setup default properties for source
> files. (maybe for targets, directories, etc. I did not tested)
> 
> This causes (or can cause) problems for generic build system macros. Generic
> macros can not depend on reading current value of a source/target/directory
> properties because that property may not  be instantiated by set function.
> 
> Of course I know that this problem can be functionality by design.


These kinds of properties (AFAIK except the read-only ones) are never
initialized with the defaults. If you create such a generic macro, you
should always first call get_property(... PROPERTY ... DEFINED) to see
whether the property is actually defined.


HTH

Michael


More information about the CMake mailing list