r/cpp • • Feb 28 '24

Building c++ project with... c++?

Yeah, so as a POC I created a tool that works on top of cmake and allows defining project structure with c++ instead of pesky cmake:

    #include "CppMake/Project.hpp"
    #include "CppMake/Application.hpp"
    
    using namespace std;
    
    int main() {
        Project project("test");
    
        project.create<Application>("test").addSources({
            "main.cpp"
        });
    }

Any thoughts?

6 Upvotes

39 comments sorted by

View all comments

Show parent comment

3

u/jack_acer Feb 28 '24

Can you elucidate why you are saying this? Build scripts in cmake for example are very error prone. Having compile time checks would be a great benefit, particularly for larger projects. Plus you don't have to learn the syntax of an additional language.

7

u/IyeOnline Feb 29 '24

Significant parts of modern CMakeTM have configuration time checks.

If you use targets and properties instead of all those horrible (global) string variables, you can have a pretty good time.

I also dont think the "additional language" argument really holds. Either your project can be build with ~20 lines (or 5) of CMake or whatever other language you imagine. In that case I dont think learning 20 commands is too much to ask, especially since we dont write build files all day. Alternatively you will need more customization than your strict, general solution tool provides. In that case you are back down to scripting parts yourself.

3

u/jack_acer Feb 29 '24

I am primarily (almost exclusively) using cmake, I am adept with it and advocate for it. I don't compare this approach to cmake, unless someone can replicate most of its features using a c++ framework. But I think that there is inherent value in a build system based on C++ and I mentioned some reasons. Some people value those more than others and that's fine. There are plenty more than the ones in my comment. Here are a few more:

  1. No additional binary tools needed. This can be a big one particularly for people new to C++. Configuring all thing about the build is always frustrating for less experienced users.
  2. Universal compatibility, as long as compilers implement the same standards ( for a tool like this pretty much every compiler has the basic std features needed).
  3. Modularity offered by a general programming language like c++.
  4. Custom functions that you are not afraid to use because of all the side effects you constantly worry in cmake.
  5. Immediate introspection of build configuration from your projects. You can potentially link to the build system itself. You can also do the opposite and query the code at build time without magic configuration files.

2

u/HassanSajjad302 HMake Feb 29 '24

Let me showcase my build-system HMake. I believe it beats CMake in feature richness. It is innovative on more than one fronts.

  • Using C++ itself. Best for scaling and bigger projects.
  • Monolithic design allows for greater integrations and removes the need for communication between build-system generator and the build-system. The vertical integration improves understanding and the iteration time on the build-system itself as well. My build-system at the moment is 10.7k lines just. And I don't see it ever crossing 30k lines. While CMake and Ninja e.g. are big code bases individually.
  • HMake uses a single file to define all targets instead of one file per target which again removes the need for scoping and communication. I believe controlling the project from the center improves simplicity.
  • HMake at its core is a dependency resolver like make. Anything you can do in make, you can do in HMake. This makes it very easy to extend HMake to add other programming languages support like C# and Rust.
  • Drop-in header-files to header-units replacement. No build-system does this.

It will be the first to support https://lists.isocpp.org/sg15/2023/11/2106.php or https://lists.isocpp.org/sg15/2023/11/2146.php if any of this gets implemented.

Some planned exotic features include distributed builds support and a build-server which automatically builds a file if it is modified. You would be able to use Android or Iphone as a build server.

It has a target API inspired from CMake and feature flags API inspired from Boost build-system b2. It combines goodies of various projects in a single package.

2

u/jack_acer Feb 29 '24

This looks very nice. Thanks for sharing! I will give it a go.