I dont quite get the application of alias expressions. I understand that I can write something like this
cmake_minimum_required(VERSION 3.5.1 FATAL_ERROR)
project(myLibs)
add_library(${PROJECT_NAME} src/test.cpp)
add_library(myLibs::myLibs ALIAS ${PROJECT_NAME})
...
and then use
target_link_libraries(${TARGET_NAME}
myLibs::myLibs
in another file to link the library to some executable, etc.
but why would I do that? I might as well skip the alias definition and just use the targetname of the built library directly
target_link_libraries(${TARGET_NAME}
myLibs
- Can anyone explain to me why aliases exist
- why do they employ the :: syntax? is the alias not completely arbitrary?
Taking your
add_library()
example, the CMake target's name would e.g. directly be linked to the target's output file names.So
ALIAS
targets are mainly used to give the target a more spelling or structured name by e.g. adding a "namespace".The
cmake-developer
documentation gives the following advice on namespaces: