[cmake-developers] [Discussion] Add python support for CMakeLists
Stephen Kelly
steveire at gmail.com
Mon Jan 16 17:12:55 EST 2017
Florent Castelli wrote:
> Well, CMake scripts can be written in a somewhat declarative form now.
> What prevents this now is that a lot of people use indirections
> everywhere. For example: add_library(foo STATIC ${SRCS}) If it was a plain
> list, any decent IDE would be able to parse this and add another file to
> the list easily. If some commands allowed more expressive alternative
> forms, it would definitely improve the situation:
>
> add_library(foo STATIC
> bar1.c
> bar2.c
> WINDOWS
> windows-specific.c
> APPLE
> apple-specific.m
> )
It's up to users to use generator expressions instead of if(WIN32) or
whatever:
add_library(foo
foo.cpp
$<$<PLATFORM_ID:Windows>:foo_win.cpp>
)
This has been possible for years and was designed with IDEs in mind:
http://public.kitware.com/pipermail/cmake-developers/2014-September/023042.html
> I find that most of the conditionals are just to create the list of
> sources per platform and then the list of dependencies. It’s certainly
> possible to use generator expressions for some cases, but they don’t have
> the prettiest syntax around, and maybe also not access to all the local
> variables that you need to pick the right files.
You should be able to put any configure-time variable through the generator
expressions $<BOOL> or $<STREQUAL> to make them genex-compatible.
Thanks,
Steve.
More information about the cmake-developers
mailing list