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

docs for CMakeToolchain blocks select() and iteration #3384

Merged
merged 1 commit into from
Sep 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions reference/tools/cmake/cmaketoolchain.rst
Original file line number Diff line number Diff line change
Expand Up @@ -338,15 +338,43 @@ and added in this order:
Customizing the content blocks
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Every block can be customized in different ways:
Every block can be customized in different ways (recall to call ``tc.generate()`` after the customization):

.. code:: python

# remove an existing block
# tc.generate() should be called at the end of every one

# remove an existing block, the generated conan_toolchain.cmake
# will not contain code for that block at all
def generate(self):
tc = CMakeToolchain(self)
tc.blocks.remove("generic_system")

# remove several blocks
def generate(self):
tc = CMakeToolchain(self)
tc.blocks.remove("generic_system", "cmake_flags_init")

# keep one block, remove all the others
# If you want to generate conan_toolchain.cmake with only that
# block
def generate(self):
tc = CMakeToolchain(self)
tc.blocks.select("generic_system")

# keep several blocks, remove the other blocks
def generate(self):
tc = CMakeToolchain(self)
tc.blocks.select("generic_system", "cmake_flags_init")

# iterate blocks
def generate(self):
tc = CMakeToolchain(self)
for block_name in tc.blocks.keys():
# do something with block_name
for block_name, block in tc.blocks.items():
# do something with block_name and block

# modify the template of an existing block
def generate(self):
tc = CMakeToolchain(self)
Expand Down