Target visibility controls (who may depend on a target)


I am trying to figure out if CMake has a feature to control the visibility of a target, as in what other target may depend on target.
This is the target visibility concept of Bazel: 顯示設定  |  Bazel

I am working in a large C++ codebase with many targets owned by different teams and it is hard to enforce functional/technical dependencies between them.

It could look something like that:


// Would configure successfully
target_link_libraries(B A)

// Would not configure and print an error message
target_link_libraries(C A)
-> CMake: The target A cannot be used by target C, it is only visible from target B

Is something like that possible with CMake?

Thank you.

Not today; that would be a new feature.

The closest we have is Compatible Interface Properties which might suffice for this.

Thank you for the reply, I was not aware of this feature.
Unfortunately I don’t think it can be used for this use case since a target might be visible to more than one other targets, it will be hard to achieved with bool or simple string matching.
What is the process to request a new feature?

A new issue: