Null alias targets?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Null alias targets?

Andrew White
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

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Null alias targets?

Marc CHEVRIER
Starting with CMake v3.11, it is now possible to aliasing an imported target. So you can have something like that:

if (BUILD_MY_LIB)
  add_library(my_lib SHARED ....)
  add_library(MY_NAMESPACE::mylib ALIAS my_lib)
else()
  add_library(system_lib SHARED IMPORTED GLOBAL)
  set_property(TARGET system_lib PROPERTY IMPORTED_LOCATION /path/to/system/lib)
  add_library(MY_NAMESPACE::mylib ALIAS system_lib) 
endif()

And, after you can use target MY_NAMESPACE::mylib transparently...


Le jeu. 14 juin 2018 à 06:53, Andrew White <[hidden email]> a écrit :
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

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake