Cppmake 0.5 review

by rbytes.net on

Cppmake application is a front-end to make that builds C++ programs with less effort than writing makefiles manually. Building a C

License: GPL (GNU General Public License)
File size: 30K
Developer: Bitwiser Labs
0 stars award from rbytes.net

Cppmake application is a front-end to make that builds C++ programs with less effort than writing makefiles manually.

Building a C++ program with cppmake is similar to compiling a Java program. The idea is that you specify a classpath and cppmake will automatically find all the classes needed by your program. Once found, all of the classes are compiled and linked into an executable or library.

The benefits of using cppmake to build C++ programs include

- You don't have to write a makefile when you start a new project
- You don't have to maintain a makefile as your project evolves
- Header file dependencies are automatically kept up to date
- You can switch from one implementation of a group of classes to another on the fly by simply changing the classpath

Let's begin with an example. Suppose you want to build a program called joe and the main function is in joe.cpp. Your programs classes live in the current directory, ../../common, and /usr/src/base. The only thing you need to do is set the classpath (just like a java program) to ".:../../common:/usr/src/base" (unix/cygwin) or ".;....common;C:usrsrcbase" (windows). This tells cppmake to first search for classes in the current directory, then in ../../common and finally in /usr/src/base. You simply run cppmake on joe.cpp to build the executable.

$ cppmake --classpath ".:../../common:/usr/src/base" joe.cpp

The result of this command is an executable called joe. Cppmake figures out which classes on the classpath need to be included in the executable and defers the work of actually compiling and linking the executable to the make command. Therefore the next time you run cppmake, only files that need to be recompiled are recompiled.

Now let's do a more complicated example. Suppose you want to build the same program as in the previous example, but this time you want more control over the build. You want to explicitly name the executable joe.exe, you want output files to go in a directory called build, you want to specify the compiler as g++, you want to pass the -Wall -g compiler flags, and you want to link with the pthread library.

$ cppmake --classpath ".:../../common:/usr/src/base" -o joe.exe -d build -x g++ -f "-Wall -g" -l "-lpthread" joe.cpp

Most of these options can be given through environment variables as well as the command line. The following is equivalent to the previous example using bash.

$ export CLASSPATH=".:../../common:/usr/src/base"
$ export OUTPUT=joe.exe
$ export DIRECTORY=build
$ export CXX=g++
$ export CXXFLAGS="-Wall -g"
$ export LDFLAGS="-lpthread"
$ export CPPFILES="joe.cpp"
$ cppmake

When an option is given by both an environment variable and the command line, the command line option takes precedence. One exception to this rule is that C++ files can be given with the CPPFILES environment variable and the command line at the same time.

Cppmake can also be used to build libraries. The difference between building a library and an executable is that when building an executable you only want classes that are needed by the executable, but when you build a library you want all the C++ files on the classpath.

The --library option tells cppmake to include every C++ file found on the classpath in the build. You also have to pass your compiler specific linker options to build a library, cppmake will not know to give those options automatically because they are compiler specific. The following example creates a library on linux assuming CLASSPATH has already been set as in the previous example.

$ cppmake --library -o libjoe.so.1.1.1 -l"-shared -Wl-soname,libjoe.so.1"

The --clean option tells cppmake to remove all the object files and the output. The --help option prints a summary of all the options and exits.

Cppmake is written in python. You need python 2.3 or greater to use it.

Cppmake requires that your compiler supports the -I, -o, -c, and -MM options like GCC does.

Finally cppmake requires that you use a few common sense programming conventions that most C++ programmers already use anyway.

Associated source files and headers should have the same base name. For example if you declare a class in Bob.h then the method implementations should be in a file called Bob.cpp and in the same directory as Bob.h. If for some reason your source file and header can't have the same base name you must list that source file in CPPFILES or on the command line, cppmake will not be able to find it automatically.
When including headers include the file name relative to the classpath directory it lives in. For example if /usr/src/base is on the classpath and you want to include /usr/src/base/bob/Bob.h, then your include statement should be #include "bob/Bob.h".
Source files must have a normal C++ file extension such as .cpp, .cxx, .cc, .c++, .C or .c.

What's New in This Release:
This release significantly improves the built-in C preprocessor.
The rudimentary preprocessor offered in 0.4 has been overhauled to correctly handle nearly all conditional includes.
Most notably, complex #if and #elif conditional expressions are now evaluated correctly.
ISO C trigraph sequences are also now supported.

Cppmake 0.5 keywords