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 toml lists in tool.scikit-build.cmake.define #874

Closed
alexreinking opened this issue Aug 23, 2024 · 4 comments · Fixed by #921
Closed

Allow toml lists in tool.scikit-build.cmake.define #874

alexreinking opened this issue Aug 23, 2024 · 4 comments · Fixed by #921
Milestone

Comments

@alexreinking
Copy link
Contributor

The following entry leads to a cryptic error:

[tool.scikit-build.cmake.define]
SOME_LIST = ["A", "B", "C"]

However, I believe it should be allowed. Simply join the entries with a ; and issue a warning if any entry already contains a ; (which would split the "item" in CMake-land).

I think the tangible UX improvement comes when the list entries are many or long:

[tool.scikit-build.cmake.define]
MY_PROJECT_ENABLE_COMPONENTS = [
    "FancyComponent",
    "OptionalDependency",
    "ObtuseComponentWithAReallyLongNameWhyDidAnyoneThinkThisWasAGoodIdea",
    "Foo",
]
@LecrisUT
Copy link
Collaborator

Sounds good, but instead of erroring out if an inner ; is present, I think it should escape each layer as the list is constructed, so as to allow passing list of lists.

@henryiii henryiii added this to the v0.11.0 milestone Aug 24, 2024
@alexreinking
Copy link
Contributor Author

@LecrisUT - does that work? I thought lists of lists weren't really a thing in CMake.

@LecrisUT
Copy link
Collaborator

Yeah, last I've encountered it was in a PR on Catch2. As long as you have the appropriate escaping it works. Don't remember how the "" had to be used for those though.

@alexreinking
Copy link
Contributor Author

So it does!

# test.cmake
cmake_minimum_required(VERSION 3.28)

set(compound "foo\\;bar" "baz" "quux\\;foo")

foreach (sublist IN LISTS compound)
   message(STATUS "!!!")
   foreach (item IN LISTS sublist)
     message(STATUS "${item}")
   endforeach ()
endforeach ()

Output:

$ cmake -P test.cmake
-- !!!
-- foo
-- bar
-- !!!
-- baz
-- !!!
-- quux
-- foo

alexreinking added a commit to alexreinking/scikit-build-core that referenced this issue Oct 1, 2024
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 a pull request may close this issue.

3 participants