[cmake-developers] target sources property

Brad King brad.king at kitware.com
Fri Oct 11 09:02:20 EDT 2013


On 10/10/2013 08:55 PM, Stephen Kelly wrote:
> Brad King <brad.king at ...> writes:
>> I just checked the VS 6, 9 and 11 IDEs and it is possible to mark
>> a source file as excluded from certain configurations.  Those versions
>> represent all the VS generators.

If listing all sources and marking each one excluded in specific
configurations is sufficient to implement this feature then it
should work for VS.

>> Perhaps for Xcode we can generate wrapper sources that conditionally
>> #include the real source based on the configuration. 
> 
> While that would work for source files, it will not work for object files.
> 
>  add_library(obj OBJECT obj.cpp)
>  add_library(iface INTERFACE)
>  set_property(TARGET iface PROPERTY 
>    INTERFACE_SOURCES $<TARGET_PROPERTY:obj,SOURCES>)
>  
>  add_executable(user main.cpp)
>  target_link_libraries(user iface)
> 
> I'm sure that can work for makefile generators. Can it work for VS
> generators? Given that it will not work for Xcode, can we forego the
> #include workaround and simply exclude Xcode from the INTERFACE_SOURCES feature?

As a last resort with a note in the documentation, and a warning at
generate time, yes.  Can you compute the set of sources and objects
for all configurations before generating any config, and for those
that are the same across all configs do not do any special markings
and put it in Xcode too?  Then things would work except in the true
per-config source file case.

-Brad



More information about the cmake-developers mailing list