I’m creating a Pong game project with a dependency on a Github project called EnTT, a header-only library. Previously, I manually downloaded and installed EnTT in /usr/local, and included it with find_package(EnTT), which worked.
Now I want to replace find_package with FetchContent_Declare(entt). I have the following:
The build step fails because of errors generated in the EnTT header file, due to the compile options (such as sign-conversion errors). So the EnTT files need to be compiled without the target_compile_options above. I don’t understand why they are compiled with these options even though it is applied to the pong target. Is it possible to set different compile options for this dependency?
If it is indeed header-only, the EnTT headers are not compiled on their own. They are inheriting the options from those given to your sources (which then include the header). I think what probably changed is that EnTT::EnTT is not hiding warnings behind -isystem. Can you try setting the SYSTEM property on EnTT::EnTT to see if that hides the warnings again?
FetchContent_Declare(entt
PREFIX dependencies/EnTT
GIT_REPOSITORY https://github.com/skypjack/entt.git
GIT_TAG v3.12.0
SYSTEM
)
So you’re right, the issue was that the header files were not treated as system headers.
I noted that the SYSTEM property is only available in CMake version 3.25 and up. My package manager contains version 3.18, and I’d like to continue using that one if possible. Would it be possible to set this property on the target in an earlier version, without SYSTEM?
The set_property method does not work, since EnTT::EnTT is an alias, and set_property may not be used on aliases. Same for set_target_properties. So it seems SYSTEM is the only way. Thank you for your help.
The set_property function does not work since EnTT::EnTT is an alias, and set_property does not work on aliases. Same for set_target_properties. So it seems SYSTEM is the only way. Thanks for your help.