Tools: Initializing C and C++ projects with cmake-init

Tools: Initializing C and C++ projects with cmake-init

Source: Dev.to

Just use the CMake project initializer ## What cmake-init can do ## A quick setup note for Ubuntu 24.04 When I was starting new C or C++ projects, my usual approach was either googling for a “C project template”, digging through my old templates saved on my PC (because I stored them, didn't I?) or just building a fresh project from scratch: like set up directories, add initial source files and write a simple CMake. After that, the project structure would evolve naturally as I added tests, CI/CD, and other features. This setup used to take a large chunk of my time, and sometimes configuring additional quality tools felt like a real challenge. Yet, I had never heard of any real shortcuts beyond reusing my old templates. Does it sound like you? If yes, I have something that will literally change how you kick off a new project. It turns out the ideal solution has been around for four years, but I somehow didn't know about it, and I only just discovered it now. Meet cmake-init — an awesome open-source project that can completely tale care of creating your C/C++ projects with a professional structure, ready-made CMake setup, testing, and more. With a very short setup (just answer a few simple questions) we receive a perfect C or C++ project structure with: It’s basically everything you need to start developing your project without wasting time on setup. What really surprised me was how smoothly it just worked. Usually, my experience with random open-source tools is that they require a fair bit of fighting before anything actually works. But this one just worked, effortlessly. The instruction mentions to install cmake-init via the pip install command, but Ubuntu 24.04 does not accept installing packages globally. To install cmake-init, I had to create a python virtual environment and install cmake-init inside it. My project didn't need python virtual environment, but you only need to run cmake-init once, so it's not a big cost for what you get. The new project created with cmake-init is here: mini_armv6_emulator. Templates let you quickly answer FAQs or store snippets for re-use. Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink. Hide child comments as well For further actions, you may consider blocking this person and/or reporting abuse COMMAND_BLOCK: kate@kate-Legion-Y540-15IRH-PG0:~$ pip install cmake-init error: externally-managed-environment × This environment is externally managed ╰─> To install Python packages system-wide, try apt install python3-xyz, where xyz is the package you are trying to install. If you wish to install a non-Debian-packaged Python package, create a virtual environment using python3 -m venv path/to/venv. Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make sure you have python3-full installed. If you wish to install a non-Debian packaged Python application, it may be easiest to use pipx install xyz, which will manage a virtual environment for you. Make sure you have pipx installed. See /usr/share/doc/python3.12/README.venv for more information. note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages. hint: See PEP 668 for the detailed specification. Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK: kate@kate-Legion-Y540-15IRH-PG0:~$ pip install cmake-init error: externally-managed-environment × This environment is externally managed ╰─> To install Python packages system-wide, try apt install python3-xyz, where xyz is the package you are trying to install. If you wish to install a non-Debian-packaged Python package, create a virtual environment using python3 -m venv path/to/venv. Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make sure you have python3-full installed. If you wish to install a non-Debian packaged Python application, it may be easiest to use pipx install xyz, which will manage a virtual environment for you. Make sure you have pipx installed. See /usr/share/doc/python3.12/README.venv for more information. note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages. hint: See PEP 668 for the detailed specification. COMMAND_BLOCK: kate@kate-Legion-Y540-15IRH-PG0:~$ pip install cmake-init error: externally-managed-environment × This environment is externally managed ╰─> To install Python packages system-wide, try apt install python3-xyz, where xyz is the package you are trying to install. If you wish to install a non-Debian-packaged Python package, create a virtual environment using python3 -m venv path/to/venv. Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make sure you have python3-full installed. If you wish to install a non-Debian packaged Python application, it may be easiest to use pipx install xyz, which will manage a virtual environment for you. Make sure you have pipx installed. See /usr/share/doc/python3.12/README.venv for more information. note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages. hint: See PEP 668 for the detailed specification. COMMAND_BLOCK: pip install cmake-init source myenv/bin/activate pip install cmake-init Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK: pip install cmake-init source myenv/bin/activate pip install cmake-init COMMAND_BLOCK: pip install cmake-init source myenv/bin/activate pip install cmake-init - Advanced CMake structure - Built-in versioning - Unit tests template - CI/CD on GitHub Actions running linters, coverage, sanitizers, and tests on Windows, Linux, and macOS - Debug and release builds - Doxygen documentation - Package manager integration