[cmake-developers] [CMake] add_custom_command() OUTPUT does not accept generator expressions, why?

Petr Kmoch petr.kmoch at gmail.com
Wed Apr 6 08:02:07 EDT 2016


On 6 April 2016 at 09:51, Yves Frederix <yves.frederix+cmake at gmail.com>
wrote:

> [...]
> So, basically, a prerequisite for the above
> to work is that CMake behaves nicely for the following as well:
>
>   add_library(test_lib STATIC existing_file_$<CONFIG>.cpp)
>
> At this moment CMake supports generator expressions in the source
> list, so this "should" work. It does not in practice, however:
>
>   CMake Error in CMakeLists.txt:
>     Target "test_target" has source files which vary by configuration.
> This is
>     not supported by the "Visual Studio 14 2015" generator.
>
> Intuitively I understand why this is not supported (different
> configurations share the same project file in VS, so which source file
> would the project point to?) Is this also a technical limitation
> though? Or do VS project files (and other multiconfig generator
> project files such as xcode) support this setup but was it merely not
> implemented yet?
>

I don't know anything about XCode, unfortunately. However,  Visual Studio
definitely supports a form of varying the source file list of the project
between configurations. That's because a source file can be marked as
_excluded_ from build for a particular configuration. So the solution CMake
could use would be to add all source files from all configurations into the
project, but mark them as excluded from [in]appropriate configurations.

Petr
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake-developers/attachments/20160406/d24301ef/attachment.html>


More information about the cmake-developers mailing list