CMake with D support early snapshot

Trent Forkert trentforkert at gmail.com
Tue Apr 1 07:47:51 PDT 2014


On Tuesday, 1 April 2014 at 12:46:54 UTC, w0rp wrote:
> This is all very interesting. I have two questions.
>
> 1. Do you plan to get this merged back into CMake proper?

Ideally, yes. But things are still in early stages, and that is 
up to people who aren't me. Perhaps Ben can shed light on if 
Kitware wants something like this upstream. However, I 
effectively need CMake for a personal project, so I'll continue 
maintaining this even if Kitware refuses an upstream merge. Once 
things stabilize a bit more, I'll keep up-to-date binaries 
published, too.

> 2. Could I use it to handle my weird build process?
>
> At the moment I am working on something which requires
> a strange build process, and I have been struggling to
> implement it with existing build tools. First it needs to
> compile and run a D program, which generates .d and .cpp files. 
> Then,
> it needs to take all of those D and C++ sources and build one 
> library
> out of them. This all works, I just need to get a build tool 
> that
> does it all in one 'make' command or similar.

Yep, that sort of thing works:

CMakeLists.txt:

     cmake_minimum_required(VERSION 3.0)
     project(example D)

     add_executable(codegen codegen.d)
     add_custom_command(
         OUTPUT generated.d
         COMMAND codegen
     )
     add_library(generated generated.d)


codegen.d:
     import std.file;

     void main()
     {
         "generated.d".write(q{
             int myfunc()
             {
                 return 42;
             }
         });
     }

Then, to use CMake to generate Makefiles (or various other build 
systems) and build:

     mkdir ../path/to/builddir
     cd ../path/to/builddir
     cmake ../path/to/sourcedir
     make -j4

Luckily for you, an old pet project of mine does something 
similar to what you describe. I intend on reviving it in the near 
future, and moving from a hacky shell script build system to a 
CMake one. So, if something breaks, I'll be sure to fix it.

Be warned, however, that this project is still subject to 
significant changes. For instance, I'm in the process of 
replacing include_text_directories with 
include_directories(TEXT), and thus improving the way -J flags 
are managed. I'm sure other things will come up and need changed 
as we encounter bugs.

  - Trent


More information about the Digitalmars-d-announce mailing list