UNITY_BUILD ignores HEADER_FILE_ONLY source file property
If a source file already has the HEADER_FILE_ONLY
source property set to true, that source file should be excluded from the unity build. As of CMake 3.16.0-rc3, this is not the case. A simple demonstrator project that verifies the issue:
CMakeLists.txt:
cmake_minimum_required(VERSION 3.16)
project(unitybuild)
set(CMAKE_UNITY_BUILD YES)
add_library(checker ok1.cpp ok2.cpp notOk.cpp)
set_source_files_properties(notOk.cpp PROPERTIES HEADER_FILE_ONLY TRUE)
ok1.cpp
#define ok1_added 1
int ok1() { return 23; } // Just to ensure there's something to compile, prevents warnings
ok2.cpp
#define ok2_added 1
int ok2() { return 57; } // Just to ensure there's something to compile, prevents warnings
notOk.cpp
#if defined(ok1_added) || defined(ok2_added)
#error Was not excluded from unity build
#endif
int notOk() { return 3; } // Just to ensure there's something to compile, prevents warnings