CMAKE_VERIFY_INTERFACE_HEADER_SETS does not see add_compile_definitions
While trying the new verify header sets option I was met with a barrage of compile errors for missing definitions these definitions were defined in the CMakeLists.txt file for each component of the repo to be added regardless of outcome (or in 1-2 cases if your machine met some criteria)
a minimal reproducible example is below if you download this: min1.zip and run
export CMAKE_BIN=path/to/cmake
export CC=clang
export CXX=clang++
${CMAKE_BIN} -DCMAKE_VERIFY_INTERFACE_HEADER_SETS=ON -DCMAKE_EXPORT_COMPILE_COMMANDS=ON .
and then open the generated compile_commands.json
you will notice that -DFOO_BAR (which was defined in CMakeLists.txt) is missing from the header verification target, where if you generate the project for a release or debug build, it is present.
here's the generated compile_commands.json
[
{
"directory": "/root/minimal/minimal",
"command": "/usr/local/bin/clang++ -DFOO_BAR -I/root/minimal/minimal/. -o CMakeFiles/blah.dir/blah.cpp.o -c /root/minimal/minimal/blah.cpp",
"file": "/root/minimal/minimal/blah.cpp"
},
{
"directory": "/root/minimal/minimal",
"command": "/usr/local/bin/clang++ -I/root/minimal/minimal/. -x c++ -o CMakeFiles/blah_verify_interface_header_sets.dir/blah_verify_interface_header_sets/blah.h.cxx.o -c /root/minimal/minimal/blah_verify_interface_header_sets/bla h.h.cxx",
"file": "/root/minimal/minimal/blah_verify_interface_header_sets/blah.h.cxx"
}
]
ADDENDUM: Here's the files
CMakeLists.txt
cmake_minimum_required(VERSION 3.24.0)
project(MINIMAL)
add_library(blah blah.cpp)
add_compile_definitions(FOO_BAR)
target_include_directories(blah PUBLIC .)
target_sources(blah PUBLIC
FILE_SET internal_h_files
TYPE HEADERS
BASE_DIRS .
FILES blah.h)
#set_property(TARGET blah PROPERTY EXPORT_COMPILE_COMMANDS FALSE)
blah.cpp
#include <blah.h>
#include <iostream>
int ab(int a, int b)
{
return a + b;
}
blah.h
int ab(int a, int b);
Edited by Brad King