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

[feature] CMakeToolchain: improve tc.blocks interface #14640

Closed
1 task
jcar87 opened this issue Sep 1, 2023 · 0 comments · Fixed by #14731
Closed
1 task

[feature] CMakeToolchain: improve tc.blocks interface #14640

jcar87 opened this issue Sep 1, 2023 · 0 comments · Fixed by #14731
Assignees
Milestone

Comments

@jcar87
Copy link
Contributor

jcar87 commented Sep 1, 2023

What is your suggestion?

The contents of conan_toolchain.cmake consist of a set of logical blocks that are controlled via https://docs.conan.io/2/reference/tools/cmake/cmaketoolchain.html#customizing-the-content-blocks

currently, it is possible to remove blocks, or add/replace with new templates. But if we want to "choose" which blocks to keep, it isn't as easy, as removing is only possible if the names are known beforehand.

use case:

  • user would like to keep the find paths (CMAKE_PREFIX_PATH and so on), but nothing else, as the user already has pre-existing CMake toolchain files that they must use

The only way of doing it today is by knowing the names of all existing blocks:

    def generate(self):
        tc = CMakeToolchain(self)
        self.output.warning(f"Blocks: {tc.blocks}")
        for block in ["user_toolchain", "generic_system", "compilers", "android_system",
                    "apple_system", "fpic", "arch_flags", "linker_scripts", "libcxx",
                    "vs_runtime", "cppstd", "parallel", "extra_flags",
                    "cmake_flags_init", "try_compile", "pkg_config", "rpath", "shared", "output_dirs"]:
            tc.blocks.remove(block)
        tc.generate()

It would be good if this could be simplified, to something like:

for block in tc.block.names():
    if name != "find_paths":
        tc.block.remove(block)

which would cause the conan_toolchain.cmake file to be generated with only the selected contents.

We should also be aware that this would make the names of the blocks part of the API - renaming blocks could be a breaking change, so may want to settle on an interface that is robust to changes in a way that future Conan updates don't break recipes

Have you read the CONTRIBUTING guide?

  • I've read the CONTRIBUTING guide
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.

2 participants