Project

General

Profile

Start to build Scol using CMAKE » History » Version 20

brainsandwich, 06/29/2015 04:44 PM

1 1 arkeon
h1. Start to build Scol using CMAKE
2 1 arkeon
3 1 arkeon
4 20 brainsandwich
h2. Tools
5 1 arkeon
6 20 brainsandwich
h3. Common to all platforms
7 1 arkeon
8 20 brainsandwich
* "CMake":http://www.cmake.org/download/
9 20 brainsandwich
* Visual Studio (not free)
10 20 brainsandwich
* "Tortoise SVN":http://tortoisesvn.net/ (or any SVN client)
11 20 brainsandwich
* "Tortoise git":https://code.google.com/p/tortoisegit/ (or any Git client too)
12 1 arkeon
13 20 brainsandwich
h3. Windows target
14 1 arkeon
15 20 brainsandwich
The minimum compiler supported is the one in Visual Studio 2010.
16 20 brainsandwich
You can try with a newer version at your own risks !
17 1 arkeon
18 20 brainsandwich
h3. Android target
19 1 arkeon
20 20 brainsandwich
_With standard tools_
21 1 arkeon
22 20 brainsandwich
i.e. free tools found on the web or provided by Google
23 1 arkeon
24 20 brainsandwich
* "Java Development Kit (JDK)":http://www.oracle.com/technetwork/java/javase/downloads
25 20 brainsandwich
* "Android SDK":https://developer.android.com/sdk/installing
26 20 brainsandwich
* "Native Development Kit (NDK)":https://developer.android.com/tools/sdk/ndk
27 20 brainsandwich
* "Apache ANT":http://ant.apache.org/
28 1 arkeon
29 20 brainsandwich
_With Tegra Android Development Pack_
30 10 brainsandwich
31 20 brainsandwich
A package provided by Nvidia to build applications for Android. The download process requires authentication to the Nvidia Developper Network (it's free and not too spammy though)
32 20 brainsandwich
33 20 brainsandwich
* "TADP":https://developer.nvidia.com/gameworksdownload
34 20 brainsandwich
* On setup, let it download everything or at least the tools described in the previous section.
35 20 brainsandwich
36 20 brainsandwich
_SDK preparation_
37 20 brainsandwich
38 20 brainsandwich
You should launch the SDK to download other tools like emulators for each API you want to target.
39 20 brainsandwich
(Our target API is 17 so you can get any emulator above).
40 20 brainsandwich
41 20 brainsandwich
h3. Linux target
42 20 brainsandwich
43 20 brainsandwich
Not supported yet.
44 20 brainsandwich
45 20 brainsandwich
h3. Mac OS target
46 20 brainsandwich
47 20 brainsandwich
Not supported yet.
48 20 brainsandwich
49 20 brainsandwich
50 7 brainsandwich
h2. Get the Scol sources
51 1 arkeon
52 20 brainsandwich
Scol uses Subversion for source control and you can use your SVN client to get the source code.
53 6 arkeon
54 1 arkeon
So first retrieve the sources from "https://svn.scolring.org/trunk/", accept the certificate and go take some coffee.
55 1 arkeon
The source directories contains most of the dependencies, and since some of them are modified they are provided in the sources.
56 7 brainsandwich
57 20 brainsandwich
Some sources like curl use Git as source control and are downloaded when building, so make sure it's installed before building the project
58 7 brainsandwich
59 20 brainsandwich
60 20 brainsandwich
61 1 arkeon
h2. Dependencies search paths
62 8 brainsandwich
63 1 arkeon
h3. Windows
64 1 arkeon
65 1 arkeon
Once you get the sources, you can execute "setWindowsSearchPaths.bat" in the dependencies directory.
66 1 arkeon
!!WARNING!! when you execute the bat file using the mouse the current directory is wrong.
67 1 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.
68 1 arkeon
 
69 1 arkeon
This will add needed environment variables and paths.
70 1 arkeon
71 1 arkeon
h3. Android
72 1 arkeon
73 20 brainsandwich
If you downloaded the TADP, the following variables are likely to be defined already (or they should look alike).
74 20 brainsandwich
If not, add these to the environment variables
75 1 arkeon
* ANDROID_HOME : path/to/sdk
76 1 arkeon
* ANDROID_SDK_HOME : path/to/sdk
77 1 arkeon
* ANDROID_SDK : path/to/sdk
78 1 arkeon
* ANDROID_NDK : path/to/ndk
79 1 arkeon
* ANT_HOME : path/to/ant
80 7 brainsandwich
* JAVA_HOME : path/to/jdk -- should be something like "C:\Progra~1\Java\<jdkfolder>"
81 1 arkeon
* CMAKE : path/to/cmake
82 7 brainsandwich
83 20 brainsandwich
Then you should add these variables into the PATH:
84 1 arkeon
85 1 arkeon
@%ANDROID_NDK%;%ANT_HOME%\bin;%ANDROID_SDK%\tools;%ANDROID_SDK%\platform-tools;%CMAKE%;%JAVA_HOME%\bin;@
86 1 arkeon
87 20 brainsandwich
88 20 brainsandwich
89 20 brainsandwich
90 1 arkeon
h2. Build needed dependencies
91 1 arkeon
92 20 brainsandwich
h3. From Windows, for Windows
93 1 arkeon
94 20 brainsandwich
1. Launch cmake-gui from a Visual Studio command line (it configures environment so you can build things correctly)
95 20 brainsandwich
2. Specify the source folder to trunk/dependencies and the build to trunk/dependencies/build/windows/x86
96 20 brainsandwich
3. Hit configure, specifying no toolchain, using your Visual Studio version as generator.
97 20 brainsandwich
4. Wait for things to set up
98 20 brainsandwich
5. Configure again
99 20 brainsandwich
6. Generate
100 20 brainsandwich
7. Build the project in Visual Studio (Build->Batch Build, check debug and release for "INSTALL" configuration)
101 20 brainsandwich
8. Wait for completion
102 20 brainsandwich
9. Read the start of the output of "CMake configure" and do as it says (it says you have to check/uncheck some "SCOL_" configuration variables)
103 20 brainsandwich
10. Repeat steps 4 to 8 until everything's built
104 7 brainsandwich
105 20 brainsandwich
h3. From Windows, for Android
106 7 brainsandwich
107 20 brainsandwich
Do the same as for Windows target, but
108 20 brainsandwich
* Set source folder to trunk/dependencies and build folder to trunk/scol/build/android/<target abi>
109 20 brainsandwich
* Specify the generator : "NMake"
110 20 brainsandwich
* The toolchain for crosscompile : trunk/dependencies/CMake/toolchain/android.toolchain.cmake
111 20 brainsandwich
* Build dependencies with "nmake install" command from a command line.
112 13 brainsandwich
113 13 brainsandwich
114 19 brainsandwich
115 20 brainsandwich
116 19 brainsandwich
h2. Build the Scol project
117 13 brainsandwich
118 20 brainsandwich
As for the dependencies:
119 13 brainsandwich
120 20 brainsandwich
h3. Windows target
121 3 arkeon
122 20 brainsandwich
* Set source folder to trunk/scol and build folder to trunk/scol/build/windows/x86
123 20 brainsandwich
* Configure, generate and build from Visual Studio
124 20 brainsandwich
125 20 brainsandwich
h3. Android target
126 20 brainsandwich
127 20 brainsandwich
* Set source folder to trunk/scol and build folder to trunk/scol/build/android/<target abi>
128 20 brainsandwich
* If you're using Nsight with Visual Studio (TADP), some build paramaters should be modified for each build if you want to install and test the project on a device :
129 20 brainsandwich
  - Open ScolLauncher subproject -> properties
130 20 brainsandwich
  - Configuration Properties -> General -> Configuration Type -> Make Application (ndk-build -> .apk|.so|.a)
131 20 brainsandwich
  - Configuration Properties -> Deployment -> Fast Deploy -> No
132 20 brainsandwich
  - Configuration Properties -> Ant Build -> Skip Ant Step -> No
133 20 brainsandwich
* Without TADP, after it's build, go to trunk/scol/build/android/<target abi>/App/bin, and run "ant debug install" if you wish to install the project on an emulator or your device  
134 1 arkeon
135 1 arkeon
h1. Start your new plugin
136 1 arkeon
137 1 arkeon
h2. Source paths
138 1 arkeon
139 1 arkeon
Start by creating a directory with your new plugin name in the trunk/scol/plugins folder.
140 1 arkeon
For example trunk/scol/plugins/myPlugin
141 4 arkeon
142 4 arkeon
Usually we prefer to separate the sources and the includes.
143 1 arkeon
So creates a "src" and "include" directory in your plugin folder.
144 1 arkeon
145 1 arkeon
Creates the empty files you will need for your project, usually :
146 1 arkeon
- include/myplugin.h for your classes declaration
147 1 arkeon
- src/myplugin.cpp for your classes definition
148 1 arkeon
- src/scolplugin.cpp for the Scol binding functions
149 1 arkeon
150 1 arkeon
h2. Dependencies
151 1 arkeon
152 1 arkeon
If your project need an external SDK or dependencies, add then in the trunk/dependencies directory.
153 1 arkeon
Then create a findMydepname.cmake file in trunk\scol\CMake\Packages.
154 1 arkeon
You can copy and change an existing Find.cmake file to make yours.
155 1 arkeon
Start from a simple one like FindMyo.cmake for example.
156 1 arkeon
157 1 arkeon
h2. Cmake files
158 1 arkeon
159 1 arkeon
It's time to creates the CMAKE script for your plugin.
160 1 arkeon
161 1 arkeon
Create a "CMakeLists.txt" file in the plugin directory.
162 1 arkeon
trunk/scol/plugins/myPlugin/CMakeLists.txt
163 1 arkeon
164 1 arkeon
And edit the file with a text editor.
165 1 arkeon
166 1 arkeon
<pre>
167 1 arkeon
#-------------------------------------------------------------------
168 1 arkeon
# This file is part of the CMake build system for Scol
169 1 arkeon
#
170 1 arkeon
# The contents of this file are placed in the public domain. Feel
171 1 arkeon
# free to make use of it in any way you like.
172 1 arkeon
#-------------------------------------------------------------------
173 1 arkeon
174 1 arkeon
############################################################
175 1 arkeon
# CmakeList file for Myplugin
176 1 arkeon
############################################################
177 1 arkeon
178 1 arkeon
#Your project name
179 1 arkeon
PROJECT(myPLugin)
180 1 arkeon
181 1 arkeon
# define header and source files for the library
182 1 arkeon
set (MYPLUGIN_HEADER_FILES
183 1 arkeon
  include/myplugin.h
184 1 arkeon
)
185 1 arkeon
186 1 arkeon
set (MYPLUGIN_SOURCE_FILES
187 1 arkeon
  src/myplugin.cpp
188 1 arkeon
  src/scolplugin.cpp
189 1 arkeon
)
190 1 arkeon
191 1 arkeon
# Add includes directories from dependencies
192 1 arkeon
#  include_directories(include ${MYDEP_INCLUDE_DIRS})
193 1 arkeon
194 1 arkeon
# Add definition for P4 optimizations, warnings removal.
195 1 arkeon
add_definitions(-DOPTI_P4 -D_CRT_SECURE_NO_WARNINGS -D)
196 1 arkeon
197 1 arkeon
# Add dependencies libraries
198 1 arkeon
#  set(LIBRARIES
199 1 arkeon
#    ${MYDEP_LIBRARIES}
200 1 arkeon
#    ${ZLIB_LIBRARIES}
201 1 arkeon
#    ${PNG_LIBRARIES}
202 1 arkeon
#  )
203 1 arkeon
204 1 arkeon
# setup Scol plugin target
205 1 arkeon
add_library(myPLugin
206 1 arkeon
  ${Scol_LIB_TYPE}
207 1 arkeon
  ${MYPLUGIN_HEADER_FILES}
208 1 arkeon
  ${MYPLUGIN_SOURCE_FILES}
209 1 arkeon
)
210 1 arkeon
add_dependencies(myPLugin kernel)
211 1 arkeon
212 1 arkeon
# set the dll version.
213 1 arkeon
set_target_properties(myPLugin PROPERTIES VERSION ${Scol_VERSION} SOVERSION ${Scol_VERSION_MAJOR})
214 1 arkeon
target_link_libraries(myPLugin ${LIBRARIES})
215 1 arkeon
216 1 arkeon
# install Scol
217 1 arkeon
scol_config_plugin(myPLugin)
218 1 arkeon
install(FILES ${MYPLUGIN_HEADER_FILES} DESTINATION include/SCOL/plugins/myPLugin)
219 1 arkeon
</pre>
220 1 arkeon
221 1 arkeon
Now we need to declare this new plugin in the common Scol cmake files.
222 1 arkeon
Edit the trunk/scol/CMakeLists.txt file and add your plugin definition like the following.
223 1 arkeon
224 1 arkeon
If you don't have dependencies.
225 1 arkeon
<pre>
226 1 arkeon
option(Scol_BUILD_MYPLUGIN "Build myPluginplugin, my library" TRUE)
227 1 arkeon
</pre>
228 1 arkeon
229 1 arkeon
If you have depencies
230 1 arkeon
<pre>
231 1 arkeon
cmake_dependent_option(Scol_BUILD_MYPLUGIN "Build myPlugin, my library." TRUE "MYDEP_FOUND;ZLIB_FOUND;PNG_FOUND" FALSE)
232 1 arkeon
</pre>
233 1 arkeon
234 1 arkeon
Now edit the trunk/scol/plugin/CMakeLists.txt file and add the following.
235 1 arkeon
<pre>
236 1 arkeon
# Configure myPlugin plugin build
237 1 arkeon
if (Scol_BUILD_MYPLUGIN)
238 1 arkeon
  add_subdirectory(myPlugin)
239 1 arkeon
endif ()
240 1 arkeon
</pre>
241 1 arkeon
242 1 arkeon
Only if you have dependencies, edit the trunk/scol/CMake/ScolDependencies.cmake file and add the dependencies resolution as the following
243 1 arkeon
244 1 arkeon
<pre>
245 1 arkeon
# Find MyDep
246 1 arkeon
find_package(MYDEP)
247 1 arkeon
macro_log_feature(MYDEP_FOUND "Mydep" "MydepLibrary" "http://Mydep.org/" FALSE "" "")
248 1 arkeon
</pre>
249 1 arkeon
250 1 arkeon
h2. Almost done
251 1 arkeon
252 1 arkeon
Open the CMAKE-gui again.
253 1 arkeon
Hit the "Configure button" and check if you found your plugin in the scol group.
254 1 arkeon
Then hit the generate button, and open the scol.sln project again.
255 1 arkeon
256 1 arkeon
You should have the project added in Visual Studio.