Create Library - nenetto/CMakeTemplates GitHub Wiki
This tutorial explain how to create a CMake structure similar to CMake tutorials but using CMakeTemplates.
IMPORTANT: This tutorial is exactly the same as executable tutorial, so images are the same. Just change Executable
word by Library
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 library 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 library template. The trick part is this program runs on CMake, so we will need CMake Configure in order to create our library template.
Steps
- First, we will decide a cool name for the library , for example...
MyAwesomeFirstLibrary
- Follow the instructions on Configure & Generate
- This time, your repository source will be the folder called
CMakeProject
- This time, your repository source will be the folder called
- 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
PROJECT_TYPE
: Change toLibrary
because we want to create an libraryPROJECT_NAME_DEFAULT
: Change to your executable nameMyAwesomeFirstLibrary
SOURCE_DIR_DEFAULT
: This is where source template for your Library will be created. This option will be a folder with the same name of your LibraryMyAwesomeFirstLibrary
into your SuperBuild Project where you want to include itMyAwesomeSuperBuild
- Click on Configure and close CMake, it is done!
Now you created successfully your first project for an Library. 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 library's nameMyAwesomeFirstLibrary
. Navigates inside to the CMake folder
MyAwesomeSuperBuild\MyAwesomeFirstLibrary\CMake
- Here, copy the file
TemplateCreator-internal.cmake
to yourProjects
folder but change the name for your Library's:MyAwesomeSuperBuild\MyAwesomeFirstLibrary\CMake\TemplateCreator-internal.cmake
toMyAwesomeSuperBuild\Projects\MyAwesomeFirstLibrary.cmake
. This tells to your SuperBuild that the project exists and the source is in theMyAwesomeFirstLibrary
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 Library. If you want to add new header files or source (c/cpp) files, do it inside your source folder MyAwesomeFirstLibrary/inc
and MyAwesomeFirstLibrary/src