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

dynamic_project_options: #239

Open
samwhitlock opened this issue Sep 2, 2023 · 1 comment
Open

dynamic_project_options: #239

samwhitlock opened this issue Sep 2, 2023 · 1 comment

Comments

@samwhitlock
Copy link

samwhitlock commented Sep 2, 2023

Either something is fundamentally broken with dynamic_project_options or I'm sorely misunderstanding how to use it.

My understanding of the intent is as follows:

  • Create an option called OPT_${option_name} that is configurable afterward running CMake (e.g. through ccmake).
  • Use the option named OPT_${option_name} if it is specified (usually through the cmake command line).
  • Else pick either the developer or user value for that value, which is determined based on whether ENABLE_DEVELOPER_MODE is toggled.

What am I seeing in the error?

This is the sample CMake file I used, which is just a slightly modified version of the example one in the dynamic project options file.

CMakeLists.txt

If I invoke it like this:

cmake -S . -B ./build -G Ninja -DOPT_GCC_WARNINGS="-Wdouble-conversion"

I'd expect there to be an option called OPT_GCC_WARNINGS with that given value (and a user default of "-WBaz" based on the lack of developer options being enabled).

If I invoke it without the OPT_GCC_WARNINGS on the command line, I would expect there to be no option available (based on the cmake_dependent_option use in DynamicProjectOptions), but that a hidden one be populated with the value "-WBaz". Instead, I find an option called OPT_GCC_WARNINGS that has the value OFF.

I suspect that either I misunderstand how to use this tool properly, or that this worked at one point but some subtle CMake variable creation behavior changed recently and broke it (and maybe I'm the only one to use this dynamic macro?).

I'm happy to help test this out further. I was hoping to just submit a PR, but I'm really stuck on this so I don't have a solution yet.

Upvote & Fund

  • I am using Polar.sh so you can upvote and help fund this issue. The funding is received once the issue is completed & confirmed by you.

  • Thank you in advance for helping prioritize & fund our backlog.

Fund with Polar
@samwhitlock
Copy link
Author

I'm maintaining the fix in my fork, if anyone is interested: https://github.com/samwhitlock/project_options/blob/f0bd6e275b4c2922878b05e5c7010fa0a1930147/src/DynamicProjectOptions.cmake#L236

In short, there cmake_dependent_option sets the option to a BOOL if the guard list (ENABLE_DEVELOPER_MODE in this case) is set. This means that if developer mode is on, this effectively just turns the option into a bool, not defaulting it to the developer default. If the guard is false, then this works just fine.

I'm frankly not sure if cmake_dependent_option is the way to go here, vs. a regular option defaulting to the selecting default based on the mode.

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

No branches or pull requests

1 participant