generator-cmake

A simple but powerful CMake buildsystem generator


Keywords
yeoman-generator
License
MIT
Install
npm install generator-cmake@0.1.2

Documentation

CMake Yeoman generator

This simple Yeoman generator creates a C++ project with CMake and Hunter for librairies management. It You can install yeoman with :

npm install -g yo

next, install this generator :

npm install -g generator-cmake

now all you have to do is call the generator :

mkdir my-project
cd my-project
yo cmake

Project architecture

Here is an explanation of the whole project architecture generated :

project
β”‚   README.md
β”‚   LICENSE    
β”‚   project.code-workspace    # VS Code workspace file
β”‚   CMakeLists.txt            # Main CMakeLists
β”‚   .gitignore
β”‚   .gitattributes
β”‚   .clang-tidy               # clang-tidy config
β”‚   .clang-format             # clang-format config
β”‚   
└───cmake
β”‚   β”‚   BuildSystem.cmake  
β”‚   β”‚   HunterGate.cmake
β”‚   β”‚   HunterLibs.cmake      # main hunter librairies
β”‚   β”‚   Install.cmake
β”‚   
└───external
β”‚   β”‚   lib1                  # legacy libraires
β”‚   β”‚   lib2
β”‚   β”‚   CMakeLists.txt        # external librairies CMake  
β”‚
└───main
β”‚   β”‚   myexe                 # an executable
β”‚   β”‚   mylib                 # a librairy
β”‚   β”‚   CMakeLists.txt        # project CMake
β”‚
└───resources
β”‚   β”‚   install
β”‚   β”‚   β”‚   InstallIcon.png   # installer icon
β”‚
└───test
β”‚   β”‚   myexe                 # executable tests
β”‚   β”‚   mylib                 # lib tests
β”‚   β”‚   CMakeLists.txt        # testing CMakeLists

Usage with VSCode

I created this generator to fit perfectly in the VS Code environment. However, you need a setup executed first if you want your VS Code to understance the CMake and C++ syntax.

VSCode setup for CMake + C++

I recommend the installation of three extensions for working in this kind of project :

  • CMake by twxs
  • CMake Tools by vector-of-bool
  • C/C++ by Microsoft

Once done you can open the project, VS Code should be able to recognize the CMake project and compile it.

Working with the project

Open the .code-workspace file with VS Code. Once asked, choose your compiler kit and VSCode will configure your project for it.

A press on Shift + F7 will open the menu that will allow you to build a custom target.

A press on F5 will launch the debug. Depending on your platform, select Windows or GDB and configure your launch.json.