Skip to content

Non-global alias not visible in subdirectory

Consider the following minimal project which demonstrates the problem:

CMakeLists.txt:

cmake_minimum_required(VERSION 3.18)
project(localalias)

find_program(BASH_EXE bash REQUIRED)

add_executable(bash IMPORTED)
add_executable(bash::bash ALIAS bash)

set_target_properties(bash PROPERTIES IMPORTED_LOCATION "${BASH_EXE}")

get_target_property(isGlobal bash::bash ALIAS_GLOBAL)
message("from top --> isGlobal = ${isGlobal}")   # Prints expected output

add_subdirectory(subA)

subA/CMakeLists.txt:

get_target_property(isGlobal bash::bash ALIAS_GLOBAL)   # Unexpected error on this line, bash::bash unknown target
message("from subdir --> isGlobal = ${isGlobal}")

The bash::bash alias is non-global. It should still be visible in a subdirectory of the scope in which it is defined, but the above project demonstrates that this is not the case. It leads to output like the following:

from top --> isGlobal = FALSE
CMake Error at subA/CMakeLists.txt:1 (get_target_property):
  get_target_property() called with non-existent target "bash::bash".


from subdir --> isGlobal = FALSE
-- Configuring incomplete, errors occurred!

I am also surprised that execution continues past the first error, which should be fatal. Some experiments with modified versions of the example using only global targets and CMake 3.17 suggests that there are pre-existing causes of this though. It may be historical that some errors effectively only give SEND_ERROR behavior rather than FATAL_ERROR. Mentioning it now just for context, it probably deserves its own separate issue if it isn't something directly related to the new non-global alias feature.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information