How to write a new generator?


I am looking into contributing and extending CMake with a new kind of generator for a Please build system ( I have been looking into the codebase but I am lost a bit. Namely, can you describe the architecture you use to create new generators? What are local and global generators used for? What is the difference?

Just taking a glance, it doesn’t look to me like Please is suitable backend. However, it’s only at a glance and you’ve not provided details into how you expect it to work, so feel free to correct me.

CMake has its own model of what targets are and how they interact. There’s almost certainly not a way to put something like this into a generated Please file other than as a series of commands to perform (i.e., c_library and cc_library are not usable in general):

add_library(foo STATIC
  impl.cxx # C++ code
  fort.f90 # some Fortran source code
    Some::Target # has complicated genex requirements

As for the question you asked:

  • local generators represent a build directory added by add_subdirectory and are “homes” for targets
  • the global generator coordinates all of the local generators to store global information and the like

Interesting you mention that. Although c_library or cc_library invoke “C compiler” or “C++ compiler” that does not have to be a strict rule as you can always configure what is executed. You can always go a layer below - meaning what that target does can be redefined.

In other words, if we need separate build definitions such that they map easily to CMake ones that is of no problem to create ones (all rules at the end call genrule or build_rule internal which are very generic)

I am not that well-versed in the internals of the build targets of CMake so I have no idea what add_library does internally with the different file types and file formats.

In fact, what are you searching to achieve?

From my quick lookup to, it is more a high-level build tool (so more or less equivalent, conceptually speaking, to CMake) than a low-level one like Makefile or Ninja.

So, as noted by @ben.boeckel, it will be very complex to do a correct matching of the concepts between the two tools. Except, as you note, to do a complete rewrite of the rules of builds in please.

The result will be a complex development of this generator, and what will be the added-value compared to Ninja for example?

From what I can tell, Please tries to isolate each command. Given that CMake currently has no model to inform any tool caring about such things what belongs in that isolated environment, I don’t know how well it could be leveraged without CMake developments.

build rules are Starlark (Python-like) functions and there will be support for plugins in the future, so it’s not that bad, IMO. Although matching the concepts be an impossible task it would mean that I can use

The general built-in definitions are here: