-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathusing_cmake_unix_common.jemdoc
102 lines (81 loc) · 3.91 KB
/
using_cmake_unix_common.jemdoc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# jemdoc: menu{MENU}{documentation.html}
= Making your own projects using Cmake
Here is going to be explained how to setup projects that utilize ACADO. At the moment, this page covers usage of the toolkit from C\+\+, on Linux and OS X operating systems and on Windows while using Cygwin. There are basically two ways to setup a project - a simple one and one more complex but more powerful procedure.
== A simple way of building ACADO based executables
You can put your own C\+\+ files in the +<ACADO\_ROOT\>\/examples\/my\_examples folder+. The only restriction is that one executable can correspond to only one source (+.cpp+) file. After you put your source file in +my\_examples+ folder, go to +<ACADO_ROOT\>\/build+ and type:
~~~
{}{}
cmake ..
make
~~~
Once the build process is over, return to +<ACADO\_ROOT>\/examples\/my\_examples+. You will find there your executable, i.e. if the name of your source file is +my\_nice\_code.cpp+, you will find there an executable named +my\_nice\_code+.
== Building ACADO based executables outside ACADO source tree
=== Setting up the environment
The first thing you need to do is to make Linux\/OS X environment aware of ACADO toolkit. One way of doing this is to add a simple bash script to your environment file.
- *Linux users and Cygwin users* need to edit .bashrc file in the home folder.
- *OS X users* need to edit .bash\_profile (or .profile) file in the home folder. In case you do not have such a file on your computer defined, [http://redfinsolutions.com/blog/creating-bashprofile-your-mac here] is a short explanation how to create it.
When you open the corresponding file, append the following line to the file:
~~~
{}{}
source <ACADO_ROOT>/build/acado_env.sh
~~~
where <ACADO\_ROOT> corresponds to the ACADO toolkit root folder, as explained on the installation instructions.
Afterwards, *Linux and Cygwin users* should refresh the environment by typing in the terminal
~~~
{}{}
. ~/.bashrc
~~~
*OS X users* should refresh the environment by typing
~~~
{}{}
. ~/.bash_profile
~~~
or .profile, where applicable.
=== Making a simple project
Now we can start setting up a simple project. We will refer to MY_PROJECT folder as to a folder where you want to put source files and build an executable.
- Copy +<ACADO\_ROOT\>\/cmake\/FindACADO.cmake+ to the MY_PROJECT folder.
- Create a file +CMakeLists.txt+ in the MY_PROJECT folder.
- Open +CMakeLists.txt+ in your favorite text editor and copy the following text into it.
~~~
{}{}
#
# Project settings
#
# Minimum required version of cmake
CMAKE_MINIMUM_REQUIRED( VERSION 2.8 )
# Project name and programming languages used
PROJECT( MY_COOL_PROJECT CXX )
# CMake module(s) path
SET( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR} )
#
# Prerequisites
#
FIND_PACKAGE( ACADO REQUIRED )
#
# Include directories
#
INCLUDE_DIRECTORIES( . ${ACADO_INCLUDE_DIRS} )
#
# Build an executable
#
ADD_EXECUTABLE( <EXEC_NAME> <EXEC_SOURCES> )
# Linux and OS X
TARGET_LINK_LIBRARIES( <EXEC_NAME> ${ACADO_SHARED_LIBRARIES} )
# Windows
#TARGET_LINK_LIBRARIES( <EXEC_NAME> ${ACADO_STATIC_LIBRARIES} )
SET_TARGET_PROPERTIES( <EXEC_NAME>
PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} )
~~~~~~
- Edit <EXEC\_NAME> and <EXEC\_SOURCES> tags. <EXEC_NAME> tag is the executable name and <EXEC\_SOURCES>is the list of source (.cpp) files. For more help with CMake refer to [http://www.cmake.org CMake website].
- If you are using Windows, make sure that you link your app against static libraries.
- Go again to the terminal, and navigate to the MY\_PROJECT folder. Then type:
~~~
{}{}
mkdir build
cd build
cmake ..
make
cd ..
~~~
When the build process is over, an executable with the name <EXEC\_NAME> should appear in the MY\_PROJECT folder.
You can build more than one application using the same set of commands lying below the comment "Build an executable". Please keep in mind that name of the executable, <EXEC\_NAME>, has to be unique.