2021-07-30

Conditionally run CMake's CHECK_TYPE_SIZE

Is there a way to conditionally run CMake's CHECK_TYPE_SIZE command? CHECK_TYPE_SIZE is great for figuring out what the size of a struct is, but the problem is that over time someone might modify the header file with the struct to add new fields. Seems like it's an accident waiting to happen when someone updates the struct but forgets (or doesn't know to) blow away the CMake cache. Yes, you could put a note next to the struct to do a cache wipe if updated, but that doesn't really help when you have a multi-person project and someone else updated the header file.

I tried to do an unset(HAS_MYVAR CACHE) but that didn't seem to work as the function doesn't appear to be re-run. Any ideas?

CODE:

CHECK_TYPE_SIZE("my_struct_t" MY_STRUCT_SIZE)
message("Struct size is ${MY_STRUCT_SIZE})
$ cmake -S . -B /tmp/test
...
Struct size is 40
...

$ cd /tmp/test
$ make 
... (no message output) [expected]
$ <mod stuct size>
$ make
...
$ <Check size of ${MY_STRUCT_SIZE} - not changed>


from Recent Questions - Stack Overflow https://ift.tt/3j4bKA2
https://ift.tt/eA8V8J

No comments:

Post a Comment