Project

General

Profile

Start to build Scol using CMAKE » History » Version 17

brainsandwich, 05/20/2015 03:55 PM

1 1 arkeon
h1. Start to build Scol using CMAKE
2 1 arkeon
3 10 brainsandwich
h2. Prepare all the necessary tools
4 10 brainsandwich
5 10 brainsandwich
Before going any further, you should take care of having everything ready for the builds.
6 10 brainsandwich
7 10 brainsandwich
h3. Windows
8 10 brainsandwich
9 10 brainsandwich
On Windows, the Scol project is built with CMake and Visual Studio 2010.
10 10 brainsandwich
11 10 brainsandwich
* You can get CMake freely at http://www.cmake.org/download/
12 10 brainsandwich
* However Visual Studio 2010 is not free. If you don't have it you can still get Visual Studio 2010 express at https://www.visualstudio.com/downloads/download-visual-studio-vs (there is VS 2010 express down the page) or the complete edition by -getting the torrent- having a good friend who still has the software at home. Because as far as I know you can't even buy it anymore. Hopefully the express edition should suffice. Eventually the build will migrate to a newer VS edition (like VS 2013 community edition, which is free as soon as you are not doing commercial products).
13 10 brainsandwich
14 10 brainsandwich
It should be about it.
15 10 brainsandwich
16 10 brainsandwich
h3. Android
17 10 brainsandwich
18 10 brainsandwich
On Android you need to download more stuff. The configurator is also CMake but you can build the final project with almost anything.
19 10 brainsandwich
At I-Maginer we're using Visual Studio 2013 community edition with some Nvidia plugins, and NMake (which is provided by any version of Visual Studio).
20 10 brainsandwich
21 10 brainsandwich
First thing is then to download CMake and a version of Visual Studio that suits you.
22 10 brainsandwich
23 10 brainsandwich
When it's done, you have got 2 options : either you want to rely on Visual Studio or only on NMake manual commands.
24 10 brainsandwich
25 10 brainsandwich
* If you opted for the first choice, it's quite simple, just go to https://developer.nvidia.com/gameworksdownload and download the Tegra Android Development Pack (TADP). It contains all you need to develop for android targets, available on Windows, Linux and Mac OS platforms. It will add the Visual Studio "Nsight Tegra" plugin, the android SDK and NDK and all the environment variables you'll need.
26 10 brainsandwich
* If you chosed the second choice, well, it's the way of the hero.
27 10 brainsandwich
¤ Download the JDK (Java Development Kit) at http://www.oracle.com/technetwork/java/javase/downloads
28 11 brainsandwich
¤ Fetch the Android SDK (Software Development Kit) at https://developer.android.com/sdk/installing and go for "Stand-Alone SDK tools" -- when it's done, extract the content and put it in some memorable folder where you keep your dev SDK
29 10 brainsandwich
¤ Same for the Android NDK (Native Development Kit) at https://developer.android.com/tools/sdk/ndk
30 1 arkeon
¤ Finally get the ANT (Another Neat Tool) build system at http://ant.apache.org/
31 11 brainsandwich
Now everything is downloaded, there's one last thing to do :
32 11 brainsandwich
¤ Launch the Android SDK (you can find it in your Android SDK folder) and let it download all the things it wants. 
33 9 brainsandwich
34 1 arkeon
h2. Get the Scol sources
35 1 arkeon
36 1 arkeon
Scol use Subversion for source control and you can use "Tortoise SVN":http://tortoisesvn.net/ to get the source code.
37 1 arkeon
38 1 arkeon
So first retrieve the sources from "https://svn.scolring.org/trunk/", accept the certificate and go take some coffee.
39 1 arkeon
The source directories contains most of the dependencies, and since some of them are modified they are provided in the sources.
40 1 arkeon
41 1 arkeon
h2. Dependencies search paths
42 1 arkeon
43 7 brainsandwich
h3. Windows
44 7 brainsandwich
45 1 arkeon
Once you get the sources, you can execute "setWindowsSearchPaths.bat" in the dependencies directory.
46 7 brainsandwich
!!WARNING!! when you execute the bat file using the mouse the current directory is wrong.
47 6 arkeon
You need to start a DOS command line "cmd.exe" as administrator and go to the dependencies directory to start the bat file manually.
48 6 arkeon
 
49 1 arkeon
This will add needed environment variables and paths.
50 7 brainsandwich
51 7 brainsandwich
h3. Android
52 7 brainsandwich
53 12 brainsandwich
(Don't take care about this if you downloaded the TADP thing)
54 7 brainsandwich
For Android build on Windows, there's no such bat file for the moment (sorry). You will have to put the environment variables
55 8 brainsandwich
yourself. Right click on Computer -> Properties (in file explorer for example) -> System Parameters -> Environment Variables
56 7 brainsandwich
Then add these entries (into "system variables") :
57 7 brainsandwich
* ANDROID_HOME : path/to/sdk
58 7 brainsandwich
* ANDROID_SDK_HOME : path/to/sdk
59 7 brainsandwich
* ANDROID_SDK : path/to/sdk
60 7 brainsandwich
* ANDROID_NDK : path/to/ndk
61 7 brainsandwich
* ANT_HOME : path/to/ant
62 7 brainsandwich
* JAVA_HOME : path/to/jdk -- should be something like "C:\Progra~1\Java\<jdkfolder>"
63 7 brainsandwich
* CMAKE : path/to/cmake
64 7 brainsandwich
65 7 brainsandwich
Then add these variables into the PATH one (you can copy pasta the following) :
66 7 brainsandwich
67 7 brainsandwich
@%ANDROID_NDK%;%ANT_HOME%\bin;%ANDROID_SDK%\tools;%ANDROID_SDK%\platform-tools;%CMAKE%;%JAVA_HOME%\bin;@
68 1 arkeon
69 1 arkeon
h2. Build needed dependencies
70 1 arkeon
71 13 brainsandwich
Most of the configure/build process is automated, but there is little manual actions to do.
72 13 brainsandwich
73 13 brainsandwich
First either launch cmake-gui from a Visual Studio command line (very important, Visual Studio command line adds environment variables important for a correct configuration) or prepare to run cmake from a command line if you are on Linux (or just a command-line masochist -- as I am but not enough for this huge project).
74 13 brainsandwich
75 17 brainsandwich
In cmake-gui, set the sources directory to trunk/dependencies and the build to trunk/dependencies/build/<target OS>/<target platform> and hit the "configure" button. After a moment, there should be lots of red variables on the gui. Don't change anything, hit configure again and finally "generate". Now go to the build folder and open the SCOLDEPS.sln if your on windows or take your terminal window, go to the build folder and run @nmake install@. If you're not doing the build on an IBM supercluster, you should go take another coffee.
76 13 brainsandwich
77 17 brainsandwich
When it's done, come check back on cmake-gui. Now look into "SCOLDEPS" variables and turn on libPng, curl, OpenAL and Ogre. Same as before, build the newly generated project and -seriously make us a call if you're doing this with a supercomputer and tell us how Scol's doing on that beast.-
78 13 brainsandwich
79 14 brainsandwich
Finally, check once again the cmake-gui and tell it to build SkyX, HydraX and CAUDIO. Now it's okay, the dependencies are ready.
80 3 arkeon
81 16 brainsandwich
h2. Build the Scol project
82 1 arkeon
83 15 brainsandwich
>But wait, there's more !
84 1 arkeon
85 15 brainsandwich
Now you can do the thing with Scol itself. Set the sources directory of cmake-gui to trunk/scol and the output to trunk/build/<target OS>/<target platform> and hit configure + generate. Build the project using nmake in the build folder. You can go bake some pie until it's done (just prepare the recipy in your head if you've got the supercomputer).
86 1 arkeon
87 1 arkeon
The compiled binaries are exported under trunk/scol_sdk/bin/Release or Debug.
88 1 arkeon
89 1 arkeon
h1. Start your new plugin
90 1 arkeon
91 1 arkeon
h2. Source paths
92 2 arkeon
93 1 arkeon
Start by creating a directory with your new plugin name in the trunk/scol/plugins folder.
94 1 arkeon
For example trunk/scol/plugins/myPlugin
95 1 arkeon
96 1 arkeon
Usually we prefer to separate the sources and the includes.
97 1 arkeon
So creates a "src" and "include" directory in your plugin folder.
98 1 arkeon
99 1 arkeon
Creates the empty files you will need for your project, usually :
100 4 arkeon
- include/myplugin.h for your classes declaration
101 4 arkeon
- src/myplugin.cpp for your classes definition
102 1 arkeon
- src/scolplugin.cpp for the Scol binding functions
103 1 arkeon
104 1 arkeon
h2. Dependencies
105 1 arkeon
106 1 arkeon
If your project need an external SDK or dependencies, add then in the trunk/dependencies directory.
107 1 arkeon
Then create a findMydepname.cmake file in trunk\scol\CMake\Packages.
108 1 arkeon
You can copy and change an existing Find.cmake file to make yours.
109 1 arkeon
Start from a simple one like FindMyo.cmake for example.
110 1 arkeon
111 1 arkeon
h2. Cmake files
112 1 arkeon
113 1 arkeon
It's time to creates the CMAKE script for your plugin.
114 1 arkeon
115 1 arkeon
Create a "CMakeLists.txt" file in the plugin directory.
116 1 arkeon
trunk/scol/plugins/myPlugin/CMakeLists.txt
117 1 arkeon
118 1 arkeon
And edit the file with a text editor.
119 1 arkeon
120 1 arkeon
<pre>
121 1 arkeon
#-------------------------------------------------------------------
122 1 arkeon
# This file is part of the CMake build system for Scol
123 1 arkeon
#
124 1 arkeon
# The contents of this file are placed in the public domain. Feel
125 1 arkeon
# free to make use of it in any way you like.
126 1 arkeon
#-------------------------------------------------------------------
127 1 arkeon
128 1 arkeon
############################################################
129 1 arkeon
# CmakeList file for Myplugin
130 1 arkeon
############################################################
131 1 arkeon
132 1 arkeon
#Your project name
133 1 arkeon
PROJECT(myPLugin)
134 1 arkeon
135 1 arkeon
# define header and source files for the library
136 1 arkeon
set (MYPLUGIN_HEADER_FILES
137 1 arkeon
  include/myplugin.h
138 1 arkeon
)
139 1 arkeon
140 1 arkeon
set (MYPLUGIN_SOURCE_FILES
141 1 arkeon
  src/myplugin.cpp
142 1 arkeon
  src/scolplugin.cpp
143 1 arkeon
)
144 1 arkeon
145 1 arkeon
# Add includes directories from dependencies
146 1 arkeon
#  include_directories(include ${MYDEP_INCLUDE_DIRS})
147 1 arkeon
148 1 arkeon
# Add definition for P4 optimizations, warnings removal.
149 1 arkeon
add_definitions(-DOPTI_P4 -D_CRT_SECURE_NO_WARNINGS -D)
150 1 arkeon
151 1 arkeon
# Add dependencies libraries
152 1 arkeon
#  set(LIBRARIES
153 1 arkeon
#    ${MYDEP_LIBRARIES}
154 1 arkeon
#    ${ZLIB_LIBRARIES}
155 1 arkeon
#    ${PNG_LIBRARIES}
156 1 arkeon
#  )
157 1 arkeon
158 1 arkeon
# setup Scol plugin target
159 1 arkeon
add_library(myPLugin
160 1 arkeon
  ${Scol_LIB_TYPE}
161 1 arkeon
  ${MYPLUGIN_HEADER_FILES}
162 1 arkeon
  ${MYPLUGIN_SOURCE_FILES}
163 1 arkeon
)
164 1 arkeon
add_dependencies(myPLugin kernel)
165 1 arkeon
166 1 arkeon
# set the dll version.
167 1 arkeon
set_target_properties(myPLugin PROPERTIES VERSION ${Scol_VERSION} SOVERSION ${Scol_VERSION_MAJOR})
168 1 arkeon
target_link_libraries(myPLugin ${LIBRARIES})
169 1 arkeon
170 1 arkeon
# install Scol
171 1 arkeon
scol_config_plugin(myPLugin)
172 1 arkeon
install(FILES ${MYPLUGIN_HEADER_FILES} DESTINATION include/SCOL/plugins/myPLugin)
173 1 arkeon
</pre>
174 1 arkeon
175 1 arkeon
Now we need to declare this new plugin in the common Scol cmake files.
176 1 arkeon
Edit the trunk/scol/CMakeLists.txt file and add your plugin definition like the following.
177 1 arkeon
178 1 arkeon
If you don't have dependencies.
179 1 arkeon
<pre>
180 1 arkeon
option(Scol_BUILD_MYPLUGIN "Build myPluginplugin, my library" TRUE)
181 1 arkeon
</pre>
182 1 arkeon
183 1 arkeon
If you have depencies
184 1 arkeon
<pre>
185 1 arkeon
cmake_dependent_option(Scol_BUILD_MYPLUGIN "Build myPlugin, my library." TRUE "MYDEP_FOUND;ZLIB_FOUND;PNG_FOUND" FALSE)
186 1 arkeon
</pre>
187 1 arkeon
188 1 arkeon
Now edit the trunk/scol/plugin/CMakeLists.txt file and add the following.
189 1 arkeon
<pre>
190 1 arkeon
# Configure myPlugin plugin build
191 1 arkeon
if (Scol_BUILD_MYPLUGIN)
192 1 arkeon
  add_subdirectory(myPlugin)
193 1 arkeon
endif ()
194 1 arkeon
</pre>
195 1 arkeon
196 1 arkeon
Only if you have dependencies, edit the trunk/scol/CMake/ScolDependencies.cmake file and add the dependencies resolution as the following
197 1 arkeon
198 1 arkeon
<pre>
199 1 arkeon
# Find MyDep
200 1 arkeon
find_package(MYDEP)
201 1 arkeon
macro_log_feature(MYDEP_FOUND "Mydep" "MydepLibrary" "http://Mydep.org/" FALSE "" "")
202 1 arkeon
</pre>
203 1 arkeon
204 1 arkeon
h2. Almost done
205 1 arkeon
206 1 arkeon
Open the CMAKE-gui again.
207 1 arkeon
Hit the "Configure button" and check if you found your plugin in the scol group.
208 1 arkeon
Then hit the generate button, and open the scol.sln project again.
209 1 arkeon
210 1 arkeon
You should have the project added in Visual Studio.