In the worst case, some of your features will just not work if those packages are not found, with no explanation whatsoever. Sure, having optional dependencies is nice, but skipping on REQUIRED is not the way you want to do it. Instead set properties on the targets via target_link_libraries and its siblings target_compile_definitions, target_include_directories and target_compile_options and “inherit” those properties via target_link_libraries from different modules. In short: Do not use the old functions that force properties down the file hierarchy such as include_directories.
I have written about this before, and this is still my number one tip on CMake. Model dependencies with target_link_libraries
Number four will surprise you! Let’s hop right in: Tip #1
We are doing one of those list posts again! This time, I will share some tips and insights on better CMake.