Skip to main content

A script that inserts a new c++ class in an existing CMake configuration.

Project description

CMake Class Creator

A script that inserts a new c++ class in an existing CMake configuration.

A class is composed of a header file and a source file. That's two files! And sometimes they have to be added to different folders as well! Adding classes and files can be tedious when using CMake. This project automates adding classes or single files to a cmake configuration.

How to install

The recommended way is to use pip: pip install CMake-Class-Creator

Please note that this module depends on a release candidate version op pyparsing, 3.0.0b1. So it is also recommended to install this in a virtual environment.

Optionally you can alias this command: alias cmcc=cmake_create_class

Easy insertion using references

There are (too many) ways to specify source files for CMake. Usually the sources are list variables defined with the set keyword. Sometimes the sources are defined directly in add_library or add_executable. In modern CMake there is also a target_sources statement.

So, you want to insert a new class, CMake Class Creator somehow must know how to insert it. The easiest way is to define a reference class.

Adding a class using a reference class

Suppose you want to insert a new class 'NewClass' next to 'ExistingClass':

$>cmcc <cmakelists> NewClass -rc ExistingClass

Executing this command will dump the updated cmakelists content to stdout, here you can check if the result is what you expect it to be.

When you approve of the changes, run the same command again with the -i option:

$>cmcc <cmakelists> NewClass -rc ExistingClass -i

Now the file contents of the cmakelists are updated. Your new class has been inserted!

Adding a single file using a reference file

It is also possible to add a single file using the -s option.

When you want to make a header only class for instance:

$>cmcc <cmakelists> New.hpp -s -rc Existing.hpp

Note that since we're dealing with single files, specifying the complete filename including the extension is required. But it is not required to specify the full path. In this example, Existing.hpp may be defined as <path>/Existing.hpp or just Existing.hpp. In case there is a path prefix, this will also be used for New.hpp.

When you approve of the changes, run the same command again with the -i option:

$>cmcc <cmakelists> New.hpp -s -rc Existing.hpp -i

Now the file contents of the cmakelists are updated. Your new file has been inserted!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

CMake-Class-Creator-0.1.6.tar.gz (23.6 kB view details)

Uploaded Source

Built Distribution

CMake_Class_Creator-0.1.6-py3-none-any.whl (25.1 kB view details)

Uploaded Python 3

File details

Details for the file CMake-Class-Creator-0.1.6.tar.gz.

File metadata

  • Download URL: CMake-Class-Creator-0.1.6.tar.gz
  • Upload date:
  • Size: 23.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.5

File hashes

Hashes for CMake-Class-Creator-0.1.6.tar.gz
Algorithm Hash digest
SHA256 cde6576baee155f4ddd57867cad61ee048dfbc54432a0ae89fa4b11cc05803c5
MD5 af18a46661b7e1844f4012d1ec073833
BLAKE2b-256 f7a9356ea47783cc4ed12a6e2aefffe7d42bcca5c06faf6b90cef409f63f5fd9

See more details on using hashes here.

File details

Details for the file CMake_Class_Creator-0.1.6-py3-none-any.whl.

File metadata

File hashes

Hashes for CMake_Class_Creator-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 d85911d058815e8ddcd7574cdcccf61ee3f97fca3ad84007a0595f6947c3f661
MD5 184319f53a973975e1005322c15416aa
BLAKE2b-256 5913bedc7372b718e109956103021ee856e03a3f2b3d4078ca9e5049bebc7fec

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page