[CMake] Null alias targets?

Andrew White andrew.white at audinate.com
Thu Jun 14 00:53:05 EDT 2018


I have a library that needs to be built on some platforms but on others is part of the OS.  I'd like to avoid putting "if platform" conditional code in the places it is used, but instead hide it away in my platform-specific code.

One way to do this is define a variable mylib_targetname in each platform and add ${mylib_targetname} as a dependency.  It can be defined on some platforms and undefined on others.

It feels cleaner if I could create an alias target MY_NAMESPACE::mylib and refer to that. This lets me define the dependency without making sure an environment variable is set, which feels more natural.  But in order to make this work I need a way to express that MY_NAMESPACE::mylib might be (legitimately) null on some platforms, and I can't figure out how to do this.

Any ideas?

--
Andrew



More information about the CMake mailing list