Project

General

Profile

Start to build Scol using CMAKE » History » Version 42

lpousse, 10/14/2019 10:49 AM

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 39 lpousse
* "CMake":http://www.cmake.org/download/ (While installing, allow CMake to add the CMake directory to the PATH)
9 39 lpousse
* Visual Studio Community 2015 Update 3
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 41 lpousse
* "Yasm":https://yasm.tortall.net/Download.html (download the exe version, rename it to "yasm.exe" and add its location to the PATH)
13 41 lpousse
* "Nasm":https://www.nasm.us/ (once installed, add its location to the PATH)
14 1 arkeon
15 1 arkeon
h3. Windows target
16 1 arkeon
17 41 lpousse
* "DirectX9 SDK":https://www.microsoft.com/en-us/download/details.aspx?id=6812
18 1 arkeon
If the installation fails: https://support.microsoft.com/fr-fr/help/2728613/s1023-error-when-you-install-the-directx-sdk-june-2010
19 39 lpousse
* a Perl installation (such as "Strawberry Perl":http://strawberryperl.com/)
20 39 lpousse
Be careful not to let Perl add paths to c headers and executables to your path as it can mess with your build environnement
21 42 lpousse
* "MSYS2":https://www.msys2.org/ (once installed, launch msys2.exe and install make with the command "pacman -S make")
22 39 lpousse
23 39 lpousse
The minimum compiler supported is the one in Visual Studio 2015.
24 20 brainsandwich
You can try with a newer version at your own risks !
25 1 arkeon
26 42 lpousse
h3. Android target from Windows
27 1 arkeon
28 42 lpousse
* "Android Studio":https://developer.android.com/studio
29 42 lpousse
Launch Android Studio and go to File > Settings > Appearance & Behaviour > System Settings > Android SDK. In the SDK Tools tab, check the LLDB, CMake and NDK (not "NDK(Side by side)") boxes to install these components
30 42 lpousse
* a Perl installation (such as "Strawberry Perl":http://strawberryperl.com/)
31 42 lpousse
Be careful not to let Perl add paths to c headers and executables to your path as it can mess with your build environnement
32 42 lpousse
* "MSYS2":https://www.msys2.org/ (once installed, launch msys2.exe and install make with the command "pacman -S make")
33 20 brainsandwich
34 42 lpousse
Our target API is 19.
35 20 brainsandwich
36 20 brainsandwich
h3. Linux target
37 20 brainsandwich
38 30 arkeon
TODO.
39 20 brainsandwich
40 20 brainsandwich
h3. Mac OS target
41 20 brainsandwich
42 31 arkeon
TODO.
43 20 brainsandwich
44 7 brainsandwich
h2. Get the Scol sources
45 1 arkeon
46 20 brainsandwich
Scol uses Subversion for source control and you can use your SVN client to get the source code.
47 6 arkeon
48 1 arkeon
So first retrieve the sources from "https://svn.scolring.org/trunk/", accept the certificate and go take some coffee.
49 1 arkeon
The source directories contains most of the dependencies, and since some of them are modified they are provided in the sources.
50 7 brainsandwich
51 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
52 7 brainsandwich
53 20 brainsandwich
54 20 brainsandwich
55 1 arkeon
h2. Dependencies search paths
56 8 brainsandwich
57 1 arkeon
h3. Windows
58 1 arkeon
59 1 arkeon
Once you get the sources, you can execute "setWindowsSearchPaths.bat" in the dependencies directory.
60 1 arkeon
!!WARNING!! when you execute the bat file using the mouse the current directory is wrong.
61 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.
62 1 arkeon
 
63 1 arkeon
This will add needed environment variables and paths.
64 1 arkeon
65 40 lpousse
Additionally, you need to add the folders where you installed Nasm and Yasm to your Path environment variable
66 40 lpousse
67 1 arkeon
h3. Android
68 1 arkeon
69 20 brainsandwich
If you downloaded the TADP, the following variables are likely to be defined already (or they should look alike).
70 20 brainsandwich
If not, add these to the environment variables
71 1 arkeon
* ANDROID_HOME : path/to/sdk
72 1 arkeon
* ANDROID_SDK_HOME : path/to/sdk
73 1 arkeon
* ANDROID_SDK : path/to/sdk
74 1 arkeon
* ANDROID_NDK : path/to/ndk
75 1 arkeon
* ANT_HOME : path/to/ant
76 7 brainsandwich
* JAVA_HOME : path/to/jdk -- should be something like "C:\Progra~1\Java\<jdkfolder>"
77 1 arkeon
* CMAKE : path/to/cmake
78 7 brainsandwich
79 20 brainsandwich
Then you should add these variables into the PATH:
80 1 arkeon
81 20 brainsandwich
@%ANDROID_NDK%;%ANT_HOME%\bin;%ANDROID_SDK%\tools;%ANDROID_SDK%\platform-tools;%CMAKE%;%JAVA_HOME%\bin;@
82 1 arkeon
83 36 arkeon
84 36 arkeon
85 1 arkeon
86 36 arkeon
h2. Build needed dependencies
87 36 arkeon
88 32 arkeon
h3. From Windows, for Windows
89 1 arkeon
90 40 lpousse
The following instructions are written to compile for 32 bits Windows. To compile for 64 bits Windows, use the 64 bits toolchain for each CMake configuration, and replace every instance of "x86" by "x64" in the instructions below.
91 39 lpousse
92 1 arkeon
Launch cmake-gui from a Visual Studio command line (it configures the environment so you can build things correctly)
93 22 hector
# Specify the source folder to trunk/dependencies and the build to trunk/dependencies/build/windows/x86
94 40 lpousse
# Hit Configure. In the message box, select your Visual Studio version as generator, and select "Specify toolchain file for cross-compiling". On the next screen, select trunk/dependencies/CMake/toolchain/win32.toolchain.cmake as the toolchain (for 64 bits, select the 64 bits variant of your VS version, and select trunk/dependencies/CMake/toolchain/win64.toolchain.cmake as the toolchain). This first configure will take a long time since it will download and compile some of the basic dependencies (probably about an hour depending on the power.
95 1 arkeon
96 1 arkeon
You will see a list of categories, under which are variables to tweak build parameters.
97 1 arkeon
The category SCOLDEPS contains CMake variables that enable/disable the build of individual SCOL dependencies.
98 1 arkeon
Some of these dependencies depend on one or several others. Since CMake needs to detect these "sub-dependencies" when configuring,
99 21 hector
we need to make several build passes, in order to build said "sub-dependencies" before the dependencies that depend on them.
100 21 hector
101 21 hector
# Leave all variables at their default values.
102 21 hector
# Keep hitting Configure until no variables are highlighted in red.
103 1 arkeon
# Hit Generate to generate a Visual Studio project.
104 1 arkeon
# Build the project in Visual Studio (Build->Batch Build, check debug and release for "INSTALL" configuration).
105 39 lpousse
# When the build is done, in CMake, check HYDRAX and SKYX under SCOLDEPS (leave the other variables as they are).
106 21 hector
# Hit Configure again. When configuring is done, you will see new variables appear in red. Leave them at their default values.
107 1 arkeon
# Repeat steps 2 to 4.
108 1 arkeon
# HYDRAX / SKYX build might fail due to header conflicts. To solve them, in Visual Studio :
109 1 arkeon
## In the solution explorer, open the properties of the *RenderSystem_Direct3D11* project.
110 1 arkeon
## In the properties window, Select *All configurations*.
111 25 hector
## Under *Configuration Properties* > *C/C++* > *General*, modify the *Other include directories* entry.
112 39 lpousse
## In the directories list, move the directory at the bottom all the way to the top.
113 38 aurelio
## Save the changes.
114 39 lpousse
## Repeat the same steps for the *RenderSystem_Direct3D9* project.
115 39 lpousse
## Re-run the build.
116 39 lpousse
# Optionnal: Check SCOLDEPS_BUILD_TUIO and SCOLDEPS_BUILD_TUIO, hit configure and repeat steps 2 to 4.
117 39 lpousse
118 26 hector
Now every required dependency should be built. The ones that we left unchecked aren't needed.
119 26 hector
120 26 hector
h3. From Windows, for Android
121 26 hector
122 39 lpousse
Supported ABIs : armeabi-v7a, arm64-v8a, x86, x86_64
123 39 lpousse
Android API version : 19 (21 for 64 bits ABIs)
124 39 lpousse
125 7 brainsandwich
Do the same as for Windows target, but
126 39 lpousse
* If you did not already make a Windows build, run trunk/dependencies/boost/bootstrap.bat from a Visual Studio command line
127 1 arkeon
* Set source folder to trunk/dependencies and build folder to trunk/scol/build/android/<target ABI> (More generally, replace every instance of "windows/x86" in the build and install paths by "android/<target ABI>")
128 1 arkeon
* Specify the generator : "NMake"
129 1 arkeon
* The toolchain for crosscompile : trunk/dependencies/CMake/toolchain/android.<target ABI>.toolchain.cmake
130 20 brainsandwich
* When building the Scol dependencies uncheck CAUDIO_ENABLE_REROUTE_STL_ALLOCATIONS
131 39 lpousse
* Build dependencies with "nmake install" command from a Visual Studio command line.
132 39 lpousse
133 39 lpousse
134 39 lpousse
135 13 brainsandwich
136 13 brainsandwich
h2. Build the Scol project
137 19 brainsandwich
138 20 brainsandwich
As for the dependencies:
139 1 arkeon
140 40 lpousse
h3. Windows target
141 20 brainsandwich
142 20 brainsandwich
* Set source folder to trunk/scol and build folder to trunk/scol/build/windows/x86
143 20 brainsandwich
* Hit configure and provide the toolchain, the same as for the dependencies
144 20 brainsandwich
* Generate and build from Visual Studio
145 20 brainsandwich
146 20 brainsandwich
h3. Android target
147 20 brainsandwich
148 42 lpousse
* Open the project in trunk/scol/android with Android Studio
149 42 lpousse
* Sync Gradle files (Files > Sync Project with Gradle Files)
150 42 lpousse
* Launch the build with Build > Make Project
151 1 arkeon
152 1 arkeon
h1. Start your new plugin
153 1 arkeon
154 1 arkeon
h2. Source paths
155 1 arkeon
156 1 arkeon
Start by creating a directory with your new plugin name in the trunk/scol/plugins folder.
157 1 arkeon
For example trunk/scol/plugins/myPlugin
158 4 arkeon
159 4 arkeon
Usually we prefer to separate the sources and the includes.
160 1 arkeon
So creates a "src" and "include" directory in your plugin folder.
161 1 arkeon
162 1 arkeon
Creates the empty files you will need for your project, usually :
163 1 arkeon
- include/myplugin.h for your classes declaration
164 1 arkeon
- src/myplugin.cpp for your classes definition
165 1 arkeon
- src/scolplugin.cpp for the Scol binding functions
166 1 arkeon
167 1 arkeon
h2. Dependencies
168 1 arkeon
169 1 arkeon
If your project need an external SDK or dependencies, add then in the trunk/dependencies directory.
170 1 arkeon
Then create a findMydepname.cmake file in trunk\scol\CMake\Packages.
171 1 arkeon
You can copy and change an existing Find.cmake file to make yours.
172 1 arkeon
Start from a simple one like FindMyo.cmake for example.
173 1 arkeon
174 1 arkeon
h2. Cmake files
175 1 arkeon
176 1 arkeon
It's time to creates the CMAKE script for your plugin.
177 1 arkeon
178 1 arkeon
Create a "CMakeLists.txt" file in the plugin directory.
179 1 arkeon
trunk/scol/plugins/myPlugin/CMakeLists.txt
180 1 arkeon
181 1 arkeon
And edit the file with a text editor.
182 1 arkeon
183 1 arkeon
<pre>
184 1 arkeon
#-------------------------------------------------------------------
185 1 arkeon
# This file is part of the CMake build system for Scol
186 1 arkeon
#
187 1 arkeon
# The contents of this file are placed in the public domain. Feel
188 1 arkeon
# free to make use of it in any way you like.
189 1 arkeon
#-------------------------------------------------------------------
190 1 arkeon
191 1 arkeon
############################################################
192 1 arkeon
# CmakeList file for Myplugin
193 1 arkeon
############################################################
194 1 arkeon
195 1 arkeon
#Your project name
196 1 arkeon
PROJECT(myPLugin)
197 1 arkeon
198 1 arkeon
# define header and source files for the library
199 1 arkeon
set (MYPLUGIN_HEADER_FILES
200 1 arkeon
  include/myplugin.h
201 1 arkeon
)
202 1 arkeon
203 1 arkeon
set (MYPLUGIN_SOURCE_FILES
204 1 arkeon
  src/myplugin.cpp
205 1 arkeon
  src/scolplugin.cpp
206 1 arkeon
)
207 1 arkeon
208 1 arkeon
# Add includes directories from dependencies
209 1 arkeon
#  include_directories(include ${MYDEP_INCLUDE_DIRS})
210 1 arkeon
211 1 arkeon
# Add definition for P4 optimizations, warnings removal.
212 1 arkeon
add_definitions(-DOPTI_P4 -D_CRT_SECURE_NO_WARNINGS -D)
213 1 arkeon
214 1 arkeon
# Add dependencies libraries
215 1 arkeon
#  set(LIBRARIES
216 1 arkeon
#    ${MYDEP_LIBRARIES}
217 1 arkeon
#    ${ZLIB_LIBRARIES}
218 1 arkeon
#    ${PNG_LIBRARIES}
219 1 arkeon
#  )
220 1 arkeon
221 1 arkeon
# setup Scol plugin target
222 1 arkeon
add_library(myPLugin
223 1 arkeon
  ${Scol_LIB_TYPE}
224 1 arkeon
  ${MYPLUGIN_HEADER_FILES}
225 1 arkeon
  ${MYPLUGIN_SOURCE_FILES}
226 1 arkeon
)
227 1 arkeon
add_dependencies(myPLugin kernel)
228 1 arkeon
229 1 arkeon
# set the dll version.
230 1 arkeon
set_target_properties(myPLugin PROPERTIES VERSION ${Scol_VERSION} SOVERSION ${Scol_VERSION_MAJOR})
231 1 arkeon
target_link_libraries(myPLugin ${LIBRARIES})
232 1 arkeon
233 1 arkeon
# install Scol
234 1 arkeon
scol_config_plugin(myPLugin)
235 1 arkeon
install(FILES ${MYPLUGIN_HEADER_FILES} DESTINATION include/SCOL/plugins/myPLugin)
236 1 arkeon
</pre>
237 1 arkeon
238 1 arkeon
Now we need to declare this new plugin in the common Scol cmake files.
239 1 arkeon
Edit the trunk/scol/CMakeLists.txt file and add your plugin definition like the following.
240 1 arkeon
241 1 arkeon
If you don't have dependencies.
242 1 arkeon
<pre>
243 1 arkeon
option(Scol_BUILD_MYPLUGIN "Build myPluginplugin, my library" TRUE)
244 1 arkeon
</pre>
245 1 arkeon
246 1 arkeon
If you have depencies
247 1 arkeon
<pre>
248 1 arkeon
cmake_dependent_option(Scol_BUILD_MYPLUGIN "Build myPlugin, my library." TRUE "MYDEP_FOUND;ZLIB_FOUND;PNG_FOUND" FALSE)
249 1 arkeon
</pre>
250 1 arkeon
251 1 arkeon
Now edit the trunk/scol/plugin/CMakeLists.txt file and add the following.
252 1 arkeon
<pre>
253 1 arkeon
# Configure myPlugin plugin build
254 1 arkeon
if (Scol_BUILD_MYPLUGIN)
255 1 arkeon
  add_subdirectory(myPlugin)
256 1 arkeon
endif ()
257 1 arkeon
</pre>
258 1 arkeon
259 1 arkeon
Only if you have dependencies, edit the trunk/scol/CMake/ScolDependencies.cmake file and add the dependencies resolution as the following
260 1 arkeon
261 1 arkeon
<pre>
262 1 arkeon
# Find MyDep
263 1 arkeon
find_package(MYDEP)
264 1 arkeon
macro_log_feature(MYDEP_FOUND "Mydep" "MydepLibrary" "http://Mydep.org/" FALSE "" "")
265 1 arkeon
</pre>
266 1 arkeon
267 1 arkeon
h2. Almost done
268 1 arkeon
269 1 arkeon
Open the CMAKE-gui again.
270 1 arkeon
Hit the "Configure button" and check if you found your plugin in the scol group.
271 1 arkeon
Then hit the generate button, and open the scol.sln project again.
272 1 arkeon
273 1 arkeon
You should have the project added in Visual Studio.