CMake does not allow duplicate target names. The rationale is given in the docs for the CMP0002 policy :
- Unique names can be unambiguously specified both in CMake code and command line commands.
- Logical names are used by the Xcode and VS IDE generators to create meaningful project names for purposes.
You might be trying to install CMP0002 on an OLD (made with cmake_policy(SET CMP0002 OLD) ), which would at least get rid of the CMake error, but I would recommend against this - it certainly will not work for MSVC / Xcode .
The only option that I can see, in addition to unique names for manual encoding, is to write a CMake function that generates a unique name for the "control" target - for example, it can add the name of the target to be verified, giving way to names such as check_my_lib_one , check_my_exe_one , etc. .d.
This function can also be used to collect a list of all registered instances of check_<Target> and add them to a single target named check , which each subordinate check_<Target> will call, so running make check launches them all.
Fraser
source share