How to Create a New Application using cmake

From KratosWiki
Jump to: navigation, search

Using Cmake the creation of new application is a straightforward task. As an example we will create here an app that is empty.


Downloading the ' files to create your standard directories

You can find a model for the structure of your application inside the file. You just have to take care to change the name of your application in the files it appears in and to start inserting your own elements, utilities etc. like in a standard, already existing application.

To begin with uncompress this folder into the applications folder. Inside of it you will find the following main parts:

  • . This file will be copied later to the KratosMultyphisics folder so that the application can be run when called in the script of your problem.
  • TestApplication.cpp and TestApplication.h plus several folders including the utilities, elements, etc.
  • cMakeLists.txt . Here you must include the source files that you want to be compiled.

The next step is telling Kratos that we want to include and compile this application .

Modifying and renaming the test_files into the desired name

We created a simple linux script to make automatic the name change (see lines below).

In order to use the script follow the following steps

  • download and extract the file into a temporary directory (say /home/username/temp)
  • download and extract the script into the same directory
  • extract the zip files
  • edit the file "" and select the name you want to provide. You need to provide lowercase,uppercase and mixed versions of the name
  • launch the ".sh" file by typing "sh" at the command line
  • copy the modified application directory in "kratos/applications"
  • compile and go!

understanding what is automatically performed

In order to understand what is done by the automatic script, we should consider that the following operations are needed to change the name:

If your new application name is newname you have firstly to change the name of the following files:

 test_application.h    ----> newname_application.h
 test_application.cpp    ----> newname_application.cpp
 test_python_application.cpp    ----> newname_python_application.cpp

Then you have to look inside the following files: test_application.h test_application.cpp test_python_application.cpp and perform the following substitutions:

 KratosTestApplication    ----> KratosNewNameApplication
 include test_application.h    ----> #include newname_application.h

and in the CMakeLists.txt

 test_application.cpp    ----> newname_application.cpp
 test_python_application.cpp    ----> newname_python_application.cpp    ---->

Editing other files to include the test application


To begin with me must include the folder we have just created so that it can be compiled: in the first line, next to the other messages we add:


and scrolling a bit below we add the new directory:


cmake_build/ (configure.bat in Windows)

Finally you have to edit your .sh file (the one that was so that your application is compiled too.

to do so, simply add the line:


among the other applications and you are ready. The new application should be compiled.

NOTE: It is important that the last thing on the line must be the \ . If you add spaces or other characters cmake will not be able to read the file correctly.

Importing the new application from the scripts ( .py files)

To do so, if the Kratos path was set correctly, you only need to import KratosMultyphisics and then the test app:

 #including kratos path
 from KratosMultiphysics import *
 from KratosMultiphysics.TestApplication import *
 #and any other apps that you need to help solving your problem
Personal tools