A lightweight scaffolding tool designed to quickly generate a modern, standard C++ project structure.
Available in both Bash (Linux/macOS) and Python (Cross-platform/Windows) versions, this tool automatically configures the CMake build system and prepares the environment for Neovim (LSP) development out of the box.
- Standard Directory Structure: Automatically creates
src,include,build, anddatadirectories. - Modern CMake Configuration:
- Defaults to C++17 standard.
- Auto-discovery: Automatically scans
srcfor all.cppfiles (no need to manually edit CMakeLists.txt when adding files). - Correctly configures header file paths (
target_include_directories).
- LSP/Neovim Ready:
- Automatically generates
compile_commands.json. - Creates a symbolic link to the project root, ensuring
clangdorcclsworks immediately.
- Automatically generates
- Code Formatting: Generates a pre-configured
.clang-formatfile (LLVM style).
Choose the script that best fits your operating system.
Fast and dependency-free for Unix-like systems.
-
Make executable:
chmod +x creat_c_project.sh
-
Run the script:
./creat_c_project.sh MyAwesomeProject
Ideal for Windows users or those requiring cross-platform compatibility. It handles Windows symlink permissions gracefully (falling back to file copying if necessary).
- Run the script:
python creat_c_project.py MyAwesomeProject
The script generates the following file tree:
MyAwesomeProject/
├── build/ # CMake intermediate build files
├── data/ # Data files storage
├── include/ # Header files (.h / .hpp)
├── src/ # Source files (.cpp)
│ └── main.cpp # Automatically generated entry point
├── .clang-format # Code formatting rules
├── CMakeLists.txt # Modern CMake configuration
└── compile_commands.json # (Symlink) For LSP navigation/completion
The generated CMakeLists.txt uses GLOB_RECURSE with CONFIGURE_DEPENDS. This means when you add new .cpp files to the src/ directory, CMake will detect them automatically during the next build—no manual file listing required.
Immediately after creating the directories, the script runs cmake .. in the build folder to generate compile_commands.json. It then symlinks (or copies on restricted Windows environments) this file to the project root.
This ensures that Neovim (via coc.nvim, nvim-lspconfig, etc.) or VSCode provides code completion and definition jumping immediately upon opening the project.
Once generated, you can start developing right away:
cd MyAwesomeProject
# Build
cmake --build build
# Run
./build/MyAwesomeProject # Linux/macOS
# .\build\Debug\MyAwesomeProject.exe # Windows- CMake: 3.10 or higher.
- C++ Compiler: GCC, Clang, or MSVC.
- Python: (Only if using the Python script) Python 3.6+.
MIT License