# loki.transformations.build_system.plan module

Transformations to be used for exposing planned changes to the build system

class CMakePlanTransformation(rootpath=None)

  Bases: `Transformation`

  Gather the planning information from all `Item.trafo_data` to which this information is applied and allows writing a CMake plan file

  This requires that `FileWriteTransformation` has been applied in planning mode first.

  Applying this transformation to a `Item` updates internal lists:

  - `sources_to_transform`: The path of all source files that contain objects that are transformed by a Loki transformation in the pipeline

  - `sources_to_append`: The path of any new source files that exist as a consequence of the Loki transformation pipeline, e.g., transformed source files that are written.

  - `sources_to_remove`: The path of any existing source files that are to be removed from the compilation target. This includes all items that don’t have the `Item.replicate` property.

  The `Sourcefile.path` is used to determine the file path from which a Fortran sourcefile was read. New paths are provided in `item.trafo_data['FileWriteTransformation']['path']`.

  The method `write_plan()` allows to write the gathered information to a CMake file that can be included in the CMake scripts that build a library. The plan file is a CMake file defining three lists matching the above:

  - `LOKI_SOURCES_TO_TRANSFORM`: The list of files that are

      processed in the dependency graph

  - `LOKI_SOURCES_TO_APPEND`: The list of files that are created

      and have to be added to the build target as part of the processing

  - `LOKI_SOURCES_TO_REMOVE`: The list of files that are no longer

      required (because they have been replaced by transformed files) and should be removed from the build target.

  These lists are used by the Loki CMake wrappers (particularly `loki_transform_target`) to schedule the source updates and update the source lists of the CMake target object accordingly.

  Parameters:

    rootpath (str (optional)) – If given, all paths will be resolved relative to this root directory

  traverse_file_graph = True
  item_filter = None
  plan_file(sourcefile, **kwargs)

    Define the planning steps to apply for `Sourcefile` items.

    For transformations that modify the definitions or dependencies of `sourcefile` this should be implemented. It gets called via the dispatch method `apply()` if the optional `plan_mode` argument is set to True.

    Parameters:

      - sourcefile (`Sourcefile`) – The sourcefile to be transformed.

      - **kwargs (optional) – Keyword arguments for the transformation.

  write_plan(filepath)

    Write the CMake plan file to `filepath`