Suggestion: Enhance target_link_libraries To Allow Developers To Indicate Which Link Dependencies Are Targets
I develop in a rather large solution that has many dependencies. This solution can be configured based on options selected. From time to time, I run into cases, based on the selected options, where a solution will generate but targets will fail to link. This is usually caused by an improperly configured CMakeLists.txt blindly targeting a target that was never created, forcing target_link_libraries to add the argument to the link line. This is quite annoying as one would like CMake to fail fast and early so that the time spent building could be avoided.
add_executable(program main.cpp)
target_link_libraries(program PRIVATE some-target)
If some-target
is not defined, then, through the rules laid out by target_link_libraries, the some-target
identifier will be considered as a plain link library.
I could just use the add_dependencies command to force a generation error, but I feel this is not needed (already implicitly done anyway) and could be better resolved by enhancing target_link_libraries to call those items that are targets.
This even helps out in situations where if a target decides to modify its name, then all locations would have to be searched for to fix the issue. If it is known to be a target and could be marked appropriately, then CMake can easily just indicate those areas that need to be addressed.
Thanks for the consideration,
Ryan