Project

General

Profile

Start to build Scol using CMAKE » History » Version 37

arkeon, 03/02/2017 03:13 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 29 arkeon
* Visual Studio Community 2013
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 28 arkeon
The minimum compiler supported is the one in Visual Studio 2013.
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 30 arkeon
TODO.
44 20 brainsandwich
45 20 brainsandwich
h3. Mac OS target
46 20 brainsandwich
47 31 arkeon
TODO.
48 20 brainsandwich
49 7 brainsandwich
h2. Get the Scol sources
50 1 arkeon
51 20 brainsandwich
Scol uses Subversion for source control and you can use your SVN client to get the source code.
52 6 arkeon
53 1 arkeon
So first retrieve the sources from "https://svn.scolring.org/trunk/", accept the certificate and go take some coffee.
54 1 arkeon
The source directories contains most of the dependencies, and since some of them are modified they are provided in the sources.
55 7 brainsandwich
56 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
57 7 brainsandwich
58 20 brainsandwich
59 20 brainsandwich
60 1 arkeon
h2. Dependencies search paths
61 8 brainsandwich
62 1 arkeon
h3. Windows
63 1 arkeon
64 1 arkeon
Once you get the sources, you can execute "setWindowsSearchPaths.bat" in the dependencies directory.
65 1 arkeon
!!WARNING!! when you execute the bat file using the mouse the current directory is wrong.
66 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.
67 1 arkeon
 
68 1 arkeon
This will add needed environment variables and paths.
69 1 arkeon
70 1 arkeon
h3. Android
71 1 arkeon
72 20 brainsandwich
If you downloaded the TADP, the following variables are likely to be defined already (or they should look alike).
73 20 brainsandwich
If not, add these to the environment variables
74 1 arkeon
* ANDROID_HOME : path/to/sdk
75 1 arkeon
* ANDROID_SDK_HOME : path/to/sdk
76 1 arkeon
* ANDROID_SDK : path/to/sdk
77 1 arkeon
* ANDROID_NDK : path/to/ndk
78 1 arkeon
* ANT_HOME : path/to/ant
79 7 brainsandwich
* JAVA_HOME : path/to/jdk -- should be something like "C:\Progra~1\Java\<jdkfolder>"
80 1 arkeon
* CMAKE : path/to/cmake
81 7 brainsandwich
82 20 brainsandwich
Then you should add these variables into the PATH:
83 1 arkeon
84 1 arkeon
@%ANDROID_NDK%;%ANT_HOME%\bin;%ANDROID_SDK%\tools;%ANDROID_SDK%\platform-tools;%CMAKE%;%JAVA_HOME%\bin;@
85 1 arkeon
86 20 brainsandwich
87 20 brainsandwich
88 20 brainsandwich
89 1 arkeon
h2. Build needed dependencies
90 1 arkeon
91 20 brainsandwich
h3. From Windows, for Windows
92 1 arkeon
93 33 arkeon
Almost everything is built with CMAKE, but some dependencies still need manual process.
94 36 arkeon
# Go in trunk/dependencies/OpenSSL and launch build-openssl.bat in command line tool
95 36 arkeon
# Command for Windows: build-openssl vc12 x86 release openssl
96 36 arkeon
# Then copy the .lib files from the openssl/build/win32 folder to the dependencies/OpenSSL/lib folder
97 32 arkeon
98 36 arkeon
Next grab the OpenCV sources from https://github.com/opencv/opencv
99 36 arkeon
# Run cmake-gui and select the OpenCV sources directory
100 36 arkeon
# Uncheck Tests, Docs and Java options
101 36 arkeon
# Check "WITH_OPENMP" option
102 36 arkeon
# In CMAKE_INSTALL_PREFIX set the scol sources directory "trunk/"dependencies/OpenCV/SDK/windows/x86"
103 36 arkeon
# Build the INSTALL project in Release and Debug
104 32 arkeon
105 36 arkeon
For FFMPEG, check the trunk/dependencies/ffmpeg/sources/README.txt file
106 37 arkeon
# sh ffmpeg_build.sh win32 release FFmpeg ../sdk/x86
107 32 arkeon
108 36 arkeon
Now you can launch cmake-gui from a Visual Studio command line (it configures environment so you can build things correctly)
109 22 hector
# Specify the source folder to trunk/dependencies and the build to trunk/dependencies/build/windows/x86
110 24 hector
# Hit Configure. In the message box, select your Visual Studio version as generator, and check "Use default native compilers".
111 21 hector
112 21 hector
You will see a list of categories, under which are variables to tweak build parameters.
113 21 hector
The category SCOLDEPS contains CMake variables that enable/disable the build of individual SCOL dependencies.
114 21 hector
Some of these dependencies depend on one or several others. Since CMake needs to detect these "sub-dependencies" when configuring,
115 21 hector
we need to make several build passes, in order to build said "sub-dependencies" before the dependencies that depend on them.
116 21 hector
117 22 hector
# Leave all variables at their default values.
118 25 hector
# Keep hitting Configure until no variables are highlighted in red.
119 1 arkeon
# Hit Generate to generate a Visual Studio project.
120 22 hector
# Build the project in Visual Studio (Build->Batch Build, check debug and release for "INSTALL" configuration).
121 24 hector
# When the build is done, in CMake, check LIBPNG, OPENAL, CURL under SCOLDEPS (leave the other variables as they are).
122 1 arkeon
# Hit Configure again. When configuring is done, you will see new variables appear in red. Leave them at their default values.
123 25 hector
# Repeat steps 2 to 4.
124 25 hector
# Check OGRE, CAUDIO, LIBHARU under SCOLDEPS, hit Configure, and repeat steps 2 to 4.
125 25 hector
# Check HYDRAX and SKYX under SCOLDEPS, hit Configure, and repeat steps 2 to 4.
126 26 hector
# HYDRAX / SKYX build might fail due to header conflicts. To solve them, in Visual Studio :
127 26 hector
## In the solution explorer, open the properties of the *RenderSystem_Direct3D11* project.
128 26 hector
## In the properties window, Select *All configurations*.
129 26 hector
## Under *Configuration Properties* > *C/C++* > *General*, modify the *Other include directories* entry.
130 26 hector
## In the directories list, move the directory at the bottom all the way to the top.
131 26 hector
## Save the changes.
132 26 hector
## Repeat the same steps for the *RenderSystem_Direct3D9* project.
133 26 hector
## Re-run the build.
134 21 hector
135 21 hector
Now every required dependency should be built. The ones that we left unchecked aren't needed.
136 7 brainsandwich
137 20 brainsandwich
h3. From Windows, for Android
138 7 brainsandwich
139 20 brainsandwich
Do the same as for Windows target, but
140 20 brainsandwich
* Set source folder to trunk/dependencies and build folder to trunk/scol/build/android/<target abi>
141 20 brainsandwich
* Specify the generator : "NMake"
142 20 brainsandwich
* The toolchain for crosscompile : trunk/dependencies/CMake/toolchain/android.toolchain.cmake
143 20 brainsandwich
* Build dependencies with "nmake install" command from a command line.
144 13 brainsandwich
145 13 brainsandwich
146 19 brainsandwich
147 20 brainsandwich
148 19 brainsandwich
h2. Build the Scol project
149 13 brainsandwich
150 20 brainsandwich
As for the dependencies:
151 13 brainsandwich
152 20 brainsandwich
h3. Windows target
153 3 arkeon
154 20 brainsandwich
* Set source folder to trunk/scol and build folder to trunk/scol/build/windows/x86
155 20 brainsandwich
* Configure, generate and build from Visual Studio
156 20 brainsandwich
157 20 brainsandwich
h3. Android target
158 20 brainsandwich
159 20 brainsandwich
* Set source folder to trunk/scol and build folder to trunk/scol/build/android/<target abi>
160 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 :
161 20 brainsandwich
  - Open ScolLauncher subproject -> properties
162 20 brainsandwich
  - Configuration Properties -> General -> Configuration Type -> Make Application (ndk-build -> .apk|.so|.a)
163 20 brainsandwich
  - Configuration Properties -> Deployment -> Fast Deploy -> No
164 20 brainsandwich
  - Configuration Properties -> Ant Build -> Skip Ant Step -> No
165 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  
166 1 arkeon
167 1 arkeon
h1. Start your new plugin
168 1 arkeon
169 1 arkeon
h2. Source paths
170 1 arkeon
171 1 arkeon
Start by creating a directory with your new plugin name in the trunk/scol/plugins folder.
172 1 arkeon
For example trunk/scol/plugins/myPlugin
173 4 arkeon
174 4 arkeon
Usually we prefer to separate the sources and the includes.
175 1 arkeon
So creates a "src" and "include" directory in your plugin folder.
176 1 arkeon
177 1 arkeon
Creates the empty files you will need for your project, usually :
178 1 arkeon
- include/myplugin.h for your classes declaration
179 1 arkeon
- src/myplugin.cpp for your classes definition
180 1 arkeon
- src/scolplugin.cpp for the Scol binding functions
181 1 arkeon
182 1 arkeon
h2. Dependencies
183 1 arkeon
184 1 arkeon
If your project need an external SDK or dependencies, add then in the trunk/dependencies directory.
185 1 arkeon
Then create a findMydepname.cmake file in trunk\scol\CMake\Packages.
186 1 arkeon
You can copy and change an existing Find.cmake file to make yours.
187 1 arkeon
Start from a simple one like FindMyo.cmake for example.
188 1 arkeon
189 1 arkeon
h2. Cmake files
190 1 arkeon
191 1 arkeon
It's time to creates the CMAKE script for your plugin.
192 1 arkeon
193 1 arkeon
Create a "CMakeLists.txt" file in the plugin directory.
194 1 arkeon
trunk/scol/plugins/myPlugin/CMakeLists.txt
195 1 arkeon
196 1 arkeon
And edit the file with a text editor.
197 1 arkeon
198 1 arkeon
<pre>
199 1 arkeon
#-------------------------------------------------------------------
200 1 arkeon
# This file is part of the CMake build system for Scol
201 1 arkeon
#
202 1 arkeon
# The contents of this file are placed in the public domain. Feel
203 1 arkeon
# free to make use of it in any way you like.
204 1 arkeon
#-------------------------------------------------------------------
205 1 arkeon
206 1 arkeon
############################################################
207 1 arkeon
# CmakeList file for Myplugin
208 1 arkeon
############################################################
209 1 arkeon
210 1 arkeon
#Your project name
211 1 arkeon
PROJECT(myPLugin)
212 1 arkeon
213 1 arkeon
# define header and source files for the library
214 1 arkeon
set (MYPLUGIN_HEADER_FILES
215 1 arkeon
  include/myplugin.h
216 1 arkeon
)
217 1 arkeon
218 1 arkeon
set (MYPLUGIN_SOURCE_FILES
219 1 arkeon
  src/myplugin.cpp
220 1 arkeon
  src/scolplugin.cpp
221 1 arkeon
)
222 1 arkeon
223 1 arkeon
# Add includes directories from dependencies
224 1 arkeon
#  include_directories(include ${MYDEP_INCLUDE_DIRS})
225 1 arkeon
226 1 arkeon
# Add definition for P4 optimizations, warnings removal.
227 1 arkeon
add_definitions(-DOPTI_P4 -D_CRT_SECURE_NO_WARNINGS -D)
228 1 arkeon
229 1 arkeon
# Add dependencies libraries
230 1 arkeon
#  set(LIBRARIES
231 1 arkeon
#    ${MYDEP_LIBRARIES}
232 1 arkeon
#    ${ZLIB_LIBRARIES}
233 1 arkeon
#    ${PNG_LIBRARIES}
234 1 arkeon
#  )
235 1 arkeon
236 1 arkeon
# setup Scol plugin target
237 1 arkeon
add_library(myPLugin
238 1 arkeon
  ${Scol_LIB_TYPE}
239 1 arkeon
  ${MYPLUGIN_HEADER_FILES}
240 1 arkeon
  ${MYPLUGIN_SOURCE_FILES}
241 1 arkeon
)
242 1 arkeon
add_dependencies(myPLugin kernel)
243 1 arkeon
244 1 arkeon
# set the dll version.
245 1 arkeon
set_target_properties(myPLugin PROPERTIES VERSION ${Scol_VERSION} SOVERSION ${Scol_VERSION_MAJOR})
246 1 arkeon
target_link_libraries(myPLugin ${LIBRARIES})
247 1 arkeon
248 1 arkeon
# install Scol
249 1 arkeon
scol_config_plugin(myPLugin)
250 1 arkeon
install(FILES ${MYPLUGIN_HEADER_FILES} DESTINATION include/SCOL/plugins/myPLugin)
251 1 arkeon
</pre>
252 1 arkeon
253 1 arkeon
Now we need to declare this new plugin in the common Scol cmake files.
254 1 arkeon
Edit the trunk/scol/CMakeLists.txt file and add your plugin definition like the following.
255 1 arkeon
256 1 arkeon
If you don't have dependencies.
257 1 arkeon
<pre>
258 1 arkeon
option(Scol_BUILD_MYPLUGIN "Build myPluginplugin, my library" TRUE)
259 1 arkeon
</pre>
260 1 arkeon
261 1 arkeon
If you have depencies
262 1 arkeon
<pre>
263 1 arkeon
cmake_dependent_option(Scol_BUILD_MYPLUGIN "Build myPlugin, my library." TRUE "MYDEP_FOUND;ZLIB_FOUND;PNG_FOUND" FALSE)
264 1 arkeon
</pre>
265 1 arkeon
266 1 arkeon
Now edit the trunk/scol/plugin/CMakeLists.txt file and add the following.
267 1 arkeon
<pre>
268 1 arkeon
# Configure myPlugin plugin build
269 1 arkeon
if (Scol_BUILD_MYPLUGIN)
270 1 arkeon
  add_subdirectory(myPlugin)
271 1 arkeon
endif ()
272 1 arkeon
</pre>
273 1 arkeon
274 1 arkeon
Only if you have dependencies, edit the trunk/scol/CMake/ScolDependencies.cmake file and add the dependencies resolution as the following
275 1 arkeon
276 1 arkeon
<pre>
277 1 arkeon
# Find MyDep
278 1 arkeon
find_package(MYDEP)
279 1 arkeon
macro_log_feature(MYDEP_FOUND "Mydep" "MydepLibrary" "http://Mydep.org/" FALSE "" "")
280 1 arkeon
</pre>
281 1 arkeon
282 1 arkeon
h2. Almost done
283 1 arkeon
284 1 arkeon
Open the CMAKE-gui again.
285 1 arkeon
Hit the "Configure button" and check if you found your plugin in the scol group.
286 1 arkeon
Then hit the generate button, and open the scol.sln project again.
287 1 arkeon
288 1 arkeon
You should have the project added in Visual Studio.