-
Notifications
You must be signed in to change notification settings - Fork 996
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[bug] Issues with configuration-specific preprocesor definitions in CMakeToolchain #8284
Comments
Conan 2 looks like already using conan/conan/tools/cmake/toolchain/toolchain.py Lines 114 to 116 in 20517df
However, the first behavior is not yet supported as shown in the code above. |
Hi all I am having a look at this. tc.preprocessor_definitions["NOVALUE_DEF"] = None And it will be mapped to Because having a value should be harmless, such definition would only be used as |
Users who need a definition without a value likely do not care what the exact value is. They just want the definition present. The current design forces those users to arbitrarily come up with a value. I would say this is more of a UX improvement than a bug. It caters to the full range of compiler use cases. In summary, while functional, the proposed change would improve ease of use. It handles an additional compiler syntax variation, reducing the configuration burden on users. BTW, the three major compilers (MSVC, GCC, Clang) default to defining macros as 1 when no value is specified. I think 1 would be more appropriate than None in this case. Also, when users convert their build script to use CMakeToolchain, the actual compile arguments might differ as those no-value definitions are now given values. This might not affect output, but it could invalidate compiler caches like ccache. |
The UX improvement should be easy, proposed in #15545. Could you please check that this is the intended behavior? |
Hi Memsharded, |
#15545 merged for next 2.1 |
First of all, it is not possible to specify just a preprocessor definition without value.
we have to provide some value:
this may not work for all the cases as sometimes the preprocessor just checks if a flag is defined or not and does not care about the value.
Next for the above code the following will be generated in a toolchain file:
the problem is that the flag is always defined. In order to fix this
add_compile_definitions()
should be used (yeah, I know it was added in CMake 3.12):add_compile_definitions($<$<CONFIG:debug>:gsl_CONFIG_CONTRACT_CHECKING_AUDIT>)
or
add_compile_definitions($<$<CONFIG:debug>:gsl_CONFIG_CONTRACT_CHECKING_AUDIT=1>)
Unfortunatelly,
add_definitions()
seems to not support this syntax.To summarize:
add_compile_definitions()
The text was updated successfully, but these errors were encountered: