Create Executable - nenetto/CMakeTemplates GitHub Wiki

This tutorial explain how to create a CMake structure similar to CMake tutorials but using CMakeTemplates.

Starting point

Let say you have your SuperBuild project already created. For tutorial purposes we will use the previous SuperBuild that we created in previous tutorial lesson. This project was called MyAwesomeSuperBuild, and right now has nothing useful inside.

Now you want to develop a new executable that will be part of your SuperBuild project. For this purpose, we will use CMakeProject. Important: This project is NOT a template, it is a program to create your executable template. The trick part is this program runs on CMake, so we will need CMake Configure in order to create our executable template.

Steps

  • First, we will decide a cool name for the executable, for example... MyAwesomeFirstExecutable
  • Follow the instructions on Configure & Generate
    • This time, your repository source will be the folder called CMakeProject

CMakeProjectConfigure

  • Binary folder can be anywhere in your computer. It does not matter really.
  • Before click on Configure button again, we need to set three options for our project
    1. PROJECT_TYPE: Change to Executable because we want to create an executable
    2. PROJECT_NAME_DEFAULT: Change to your executable name MyAwesomeFirstExecutable
    3. SOURCE_DIR_DEFAULT: This is where source template for your Executable will be created. This option will be a folder with the same name of your executable MyAwesomeFirstExecutable into your SuperBuild Project where you want to include it MyAwesomeSuperBuild

NewExecutable

  • Click on Configure and close CMake, it is done!

Now you created successfully your first project for an executable. We need to do something else, in order your SuperBuild can "see" the change and add it as a subproject.

  • Go to your MyAwesomeSuperBuild folder, and there you will see a new folder with your executable's name MyAwesomeFirstExecutable. Navigates inside to the CMake folder
MyAwesomeSuperBuild\MyAwesomeFirstExecutable\CMake
  • Here, copy the file TemplateCreator-internal.cmake to your Projects folder but change the name for your Executable's: MyAwesomeSuperBuild\MyAwesomeFirstExecutable\CMake\TemplateCreator-internal.cmake to MyAwesomeSuperBuild\Projects\MyAwesomeFirstExecutable.cmake. This tells to your SuperBuild that the project exists and the source is in the MyAwesomeFirstExecutable folder

Now you can start working. The template has a main function and some example functions. Uses the public header and the cpp for develop your own executable. If you want to add new header files or source (c/cpp) files, do it inside your source folder MyAwesomeFirstExecutable/inc and MyAwesomeFirstExecutable/src