Skip to content
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

allow integers as CMakeToolchain.preprocessor_definitions #8645

Merged

Conversation

memsharded
Copy link
Member

Changelog: Feature: Allow integers as preprocessor_definitions in CMakeToolchain.
Docs: Omit

Close #8632

tc.preprocessor_definitions.debug["MYDEFINE_CONFIG"] = "MYDEF_DEBUG"
tc.preprocessor_definitions.release["MYDEFINE_CONFIG"] = "MYDEF_RELEASE"
tc.preprocessor_definitions.debug["MYDEFINEINT_CONFIG"] = 421
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need this? I though you planned to remove that

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have not yet fully decided, on one hand it is clear there is demand, on the other, it could be a pure build-system thing, and Conan agnostic about it. In the meantime, it totally makes sense that users want to provide integer preprocessor definitions, as they are very common. Maybe @guiserle could elaborate a bit further about their use case, and why such preprocessor definitions are not integrated in the build system scripts directly.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First of all, thanks a lot for considering my request.

My use case is to define configuration values for libraries such as FreeRTOS or MCU SDK packages. Currently we define conan options for such values and pass those values to cmake on conan build() method. However that means for every configuration value (and these libraries have lots of them) we need to add logic on both conanfile.py and cmake files.

On top of that we are using Clion as IDE and we need to add these cmake variables (and others such as version numbers) on the IDE project settings manually. I was thinking about setting these values directly on generate() method so they would all be included in toolchain file and it would only be necessary to add the toolchain as value for CMAKE_TOOLCHAIN_FILE.

If that is not the intended use case for the generate method and this should be implemented on another way, I will understand it. Also I have considered the implementation of a custom generator for my particular use case if necessary

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am going to merge this, seems a valid use case, thanks for the feedback.

Just beware that self.options are also always strings, even if you defined them as option: [1, 2, 3], internally, they are always strings. So you might need to convert it to ints, if you use it from there like cmake.preprocessor_defintions["MYDEF"] = int(self.options.myoption)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's great. Thanks for taking my use case into account!

@memsharded memsharded merged commit 1a6d990 into conan-io:develop Mar 21, 2021
@memsharded memsharded deleted the feature/toolchain_cmake_preprocesor_int branch March 21, 2021 22:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[feature] allow for non-string configuration-specific preprocesor definitions on CMakeToolchain
3 participants