Git Product home page Git Product logo

Comments (3)

ttroy50 avatar ttroy50 commented on May 21, 2024

It provides an alternative way to reference a target name in other parts of your cmake files.

In that example you have

add_library(hello_library SHARED
    src/Hello.cpp
)
add_library(hello::library ALIAS hello_library)

hello::library refers to the same library as hello_library but gives it a different name.

One good use case that I have found for this is in the target_link_libraries command. If you use an alias target like

target_link_libraries(hello_binary
    PRIVATE
        hello::library
)

and some some reason the hello::library target doesn't exist you will get a failure. If instead you had used

target_link_libraries(hello_binary
    PRIVATE
        hello_library
)

And you didn't have a hello_library target, than you could accidentally link a library libhello_library.so that already exists on your filesystem.

from cmake-examples.

ttroy50 avatar ttroy50 commented on May 21, 2024

Here is a link to the cmake documentation on alias targets

https://cmake.org/cmake/help/latest/manual/cmake-buildsystem.7.html#alias-targets

from cmake-examples.

nevalsar avatar nevalsar commented on May 21, 2024

@ttroy50 I don't believe this is a valid use case for this feature... The accidental linking can directly be avoided using the original hello_library itself by linking it like so:

target_link_libraries(hello_binary
    PRIVATE
        hello_library::hello_library
)

If the target isn't found, this would fail (which is what we want) instead of looking for a library in the filesystem.

from cmake-examples.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.