Unity builds don't allow adding the same source file to two or more targets
The internal implementation of the unity build feature sets the HEADER_FILE_ONLY
source file property to true for each source file it incorporates into a unity build. If such source files are added to more than one target, only the first target gets the source included and the other targets miss out. A modified version of the same test case as used in #19946 (closed) demonstrates the problem:
cmake_minimum_required(VERSION 3.16)
project(unitybuild)
set(CMAKE_UNITY_BUILD YES)
add_library(checker ok1.cpp ok2.cpp)
add_library(anotherTarget ok1.cpp ok2.cpp) # This target ends up with no sources
This probably isn't a show-stopper for the CMake 3.16.0 release, but it does highlight a limitation of the current implementation which will affect some projects (e.g. those that build multiple variants of the same source file with different flags set at the target level).