Skip to content

The CMake Project Generator is an automated Python script for quickly creating ready-to-use C++ and Qt project templates.

Notifications You must be signed in to change notification settings

Aram-Vn/CMakeProjectGenerator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CMake Project Generator for C++ and Qt

The CMake Project Generator is a Python-based tool that automates the setup of C++ and Qt projects using CMake. It provides a consistent project structure and ready-to-use configuration files, letting you focus on coding instead of boilerplate setup.

Scripts

  • cppinit: Generates the necessary files and directory structure for a new C++ project.
  • add_to_path.py: Copies the CMakeProjectGenerator.py script to a ~/scripts directory and updates your PATH environment variable to include this directory, allowing you to run the script from anywhere.

Dependencies

  • Python 3.x
  • CMake 3.16+
  • A C++17 capable compiler -For qtinit: Qt5 or Qt6 development packages (qtbase5-dev on Ubuntu, or Qt SDK installed manually)

Features

  • Generates CMakeLists.txt for the project root and test directories.
  • reates a main.cpp file, a header file, and a source file.
  • Configures .gitignore and .clang-format files for Git and code formatting.
  • For Qt projects: sets up MainWindow.h/.cpp, QApplication, Q_OBJECT macro, and a build system ready for Qt5/Qt6.
  • ntegrates with your shell (add_to_path.py) so scripts can be run from anywhere.

Adding to PATH

The add_to_path.py script copies a specified script (for example cppinit) to the ~/scripts directory and adds this directory to your PATH environment variable, so you can execute the script from anywhere in the terminal. If this is the first run, the add_to_path.py script will also copy itself to the ~/scripts directory, removing the .py extension.

Steps

if is first run

  1. Ensure both scripts are in the same directory.
  2. Run the add_to_path.py script with the name of the script you want to copy:
./add_to_path.py cppinit

# or

python add_to_path.py cppinit

This script will:

  • Copy cppinit to ~/scripts.
  • Check if ~/scripts is already in your PATH and add it to your .bashrc or .zshrc file if it is not.
  • Instruct you to source your shell configuration file to update the PATH in the current session.

Now you can run cppinit from any directory

cppinit <project_name>

Using add_to_path.py After the First Run

After the first run, the add_to_path.py script is copied to the ~/scripts directory without the .py extension, allowing you to call it from anywhere:

add_to_path <script_name>

For example, to copy another script from any directory named new_script to the ~/scripts directory, so you can use it from anywhere:

add_to_path new_script

cppinit

With Project Name Argument

To use the cppinit, simply run the Python script with the project name as an argument:

./cppinit <project_name>

# or 

python cppinit <project_name>

Without Project Name Argument

or If you run the script without providing a project name as an argument, it will prompt you to enter the project name

./cppinit

# or 

python cppinit

You will then be prompted to enter the project name manually. After providing the project name, the script will proceed to create the project directory and files as usual.

Example

./cppinit
Please enter project name:
<project_name>

Result Structure

<project_name>/
├── main.cpp
│
├── .clang-format
│
├── .gitignore
│
├── CMakeLists.txt
│
├── build/
│
├── include/
│   └── <project_name>.h
│
├── src/
│   └── <project_name>.cpp
│
└── tests/
    ├── <project_name>_test.cpp
    └── CMakeLists.txt

Example Workflow

  1. Generate a project:
cppinit MyProject
  1. Navigate to your project directory:
cd MyProject
  1. Build the project:
cd build
cmake ..
cmake --build .

qtinit

qtinit With Project Name Argument

To use the cppinit, simply run the Python script with the project name as an argument:

./qtinit <project_name>

# or 

python qtinit <project_name>

qtinit Without Project Name Argument

or If you run the script without providing a project name as an argument, it will prompt you to enter the project name

./qtinit

# or 

python qtinit

You will then be prompted to enter the project name manually. After providing the project name, the script will proceed to create the project directory and files as usual.

qtinit Example

./qtinit
Please enter project name:
<project_name>

Result Structure

<project_name>/
├── main.cpp
├── .clang-format
├── .gitignore
├── CMakeLists.txt
├── build/
├── include/
│   └── MainWindow.h
└── src/
    └── MainWindow.cpp

qtinit Example Workflow

  1. Generate a project:
cppinit MyProject
  1. Navigate to your project directory:
cd MyProject
  1. Build the project:
cd build
cmake ..
cmake --build .

With this setup, you can now generate either plain C++ projects (cppinit) or Qt Widgets projects (qtinit), both ready to build immediately.

About

The CMake Project Generator is an automated Python script for quickly creating ready-to-use C++ and Qt project templates.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages