Understanding CMake Policy CMP0100: Processing Header Files with .hh Extension
Before CMake 3.17
- Files with the
.hh
extension were ignored. - By default,
AUTOMOC
andAUTOUIC
only processed header files ending with the.h
extension.
After CMake 3.17 (with CMP0100 enabled)
AUTOMOC
andAUTOUIC
now also process header files ending with the.hh
extension.
This policy provides more flexibility in how you name your header files while still being compatible with these tools.
- New Behavior (With CMP0100)
Process.hh
files alongside.h
files. - Default Behavior (Before CMP0100)
Ignore.hh
files. - Effect
EnablesAUTOMOC
andAUTOUIC
to process header files with the.hh
extension. - Introduced In
CMake 3.17 - Policy Name
CMP0100
Example 1: Enabling CMP0100
This example explicitly enables CMP0100 for a cleaner build without warnings.
cmake_policy(CMP0100 NEW)
# Rest of your CMakeLists.txt code
cmake_policy(CMP0100 NEW)
sets the policy CMP0100 to the new behavior, ensuringAUTOMOC
andAUTOUIC
process.hh
files.
Example 2: Handling the Warning (Without Enabling)
This example demonstrates how to silence the warning if you're not ready to enable CMP0100 yet or have specific reasons to keep the old behavior.
# Set the source file property to skip processing by AUTOMOC/AUTOUIC
set_property(SOURCE /path/to/your/file.hh PROPERTY SKIP_AUTOMOC ON)
# Rest of your CMakeLists.txt code
set_property(SOURCE /path/to/your/file.hh PROPERTY SKIP_AUTOMOC ON)
sets theSKIP_AUTOMOC
property for the specific header filefile.hh
. This tells CMake to exclude it from processing byAUTOMOC
. You can useSKIP_AUTOUIC
for similar exclusion withAUTOUIC
.
- If you have specific reasons to keep the old behavior (ignoring
.hh
files), use property exclusion (Example 2) to silence the warning for specific header files. However, consider updating your project to take advantage of the new behavior in the future. - If your project uses
.hh
header files and you're working with CMake 3.17 or later, enabling CMP0100 (Example 1) is recommended for better compatibility.
- Renaming Header Files
- If you're not strongly tied to the
.hh
extension, the simplest solution might be to rename your header files to the standard.h
extension. This ensures compatibility with both old and new CMake versions without needing policy changes.
- Excluding Specific Files (if needed)
- If some of your
.hh
files shouldn't be processed byAUTOMOC
orAUTOUIC
even with CMP0100 enabled, you can still utilize file property exclusion as shown in the previous example. This allows for granular control over which files are processed by these tools.
- Alternative Header Generation Tools
Remember, the best approach depends on your project's requirements and coding style. Consider factors like:
- Consistency and maintainability of your codebase
- Specific functionality required from
AUTOMOC
orAUTOUIC
- Compatibility needs (older vs. newer CMake versions)