Start to build Scol using CMAKE » History » Version 23
  hector, 01/11/2016 02:28 PM 
  
| 1 | 1 | arkeon | h1. Start to build Scol using CMAKE | 
|---|---|---|---|
| 2 | |||
| 3 | |||
| 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 | * Visual Studio (not free) | ||
| 10 | * "Tortoise SVN":http://tortoisesvn.net/ (or any SVN client) | ||
| 11 | * "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 | 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 | * "Android SDK":https://developer.android.com/sdk/installing | ||
| 26 | * "Native Development Kit (NDK)":https://developer.android.com/tools/sdk/ndk | ||
| 27 | * "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 | |||
| 33 | * "TADP":https://developer.nvidia.com/gameworksdownload | ||
| 34 | * On setup, let it download everything or at least the tools described in the previous section. | ||
| 35 | |||
| 36 | _SDK preparation_ | ||
| 37 | |||
| 38 | You should launch the SDK to download other tools like emulators for each API you want to target. | ||
| 39 | (Our target API is 17 so you can get any emulator above). | ||
| 40 | |||
| 41 | h3. Linux target | ||
| 42 | |||
| 43 | Not supported yet. | ||
| 44 | |||
| 45 | h3. Mac OS target | ||
| 46 | |||
| 47 | Not supported yet. | ||
| 48 | |||
| 49 | |||
| 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 | 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 | |||
| 61 | 1 | arkeon | h2. Dependencies search paths | 
| 62 | 8 | brainsandwich | |
| 63 | 1 | arkeon | h3. Windows | 
| 64 | |||
| 65 | Once you get the sources, you can execute "setWindowsSearchPaths.bat" in the dependencies directory. | ||
| 66 | !!WARNING!! when you execute the bat file using the mouse the current directory is wrong. | ||
| 67 | 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 | |||
| 69 | This will add needed environment variables and paths. | ||
| 70 | |||
| 71 | h3. Android | ||
| 72 | |||
| 73 | 20 | brainsandwich | If you downloaded the TADP, the following variables are likely to be defined already (or they should look alike). | 
| 74 | If not, add these to the environment variables | ||
| 75 | 1 | arkeon | * ANDROID_HOME : path/to/sdk | 
| 76 | * ANDROID_SDK_HOME : path/to/sdk | ||
| 77 | * ANDROID_SDK : path/to/sdk | ||
| 78 | * ANDROID_NDK : path/to/ndk | ||
| 79 | * 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 | @%ANDROID_NDK%;%ANT_HOME%\bin;%ANDROID_SDK%\tools;%ANDROID_SDK%\platform-tools;%CMAKE%;%JAVA_HOME%\bin;@ | ||
| 86 | |||
| 87 | 20 | brainsandwich | |
| 88 | |||
| 89 | |||
| 90 | 1 | arkeon | h2. Build needed dependencies | 
| 91 | |||
| 92 | 20 | brainsandwich | h3. From Windows, for Windows | 
| 93 | 1 | arkeon | |
| 94 | 22 | hector | # Launch cmake-gui from a Visual Studio command line (it configures environment so you can build things correctly) | 
| 95 | # Specify the source folder to trunk/dependencies and the build to trunk/dependencies/build/windows/x86 | ||
| 96 | 21 | hector | |
| 97 | You will see a list of categories, under which are variables to tweak build parameters. | ||
| 98 | The category SCOLDEPS contains CMake variables that enable/disable the build of individual SCOL dependencies. | ||
| 99 | Some of these dependencies depend on one or several others. Since CMake needs to detect these "sub-dependencies" when configuring, | ||
| 100 | we need to make several build passes, in order to build said "sub-dependencies" before the dependencies that depend on them. | ||
| 101 | |||
| 102 | 23 | hector | # Leave all variables at their default values. | 
| 103 | 22 | hector | # Hit Configure, specifying no toolchain, using your Visual Studio version as generator. | 
| 104 | # When configuring is done, you will see new variables appear in red. Simply hit Configure again. | ||
| 105 | # Hit Generate to generate a Visual Studio project. | ||
| 106 | # Build the project in Visual Studio (Build->Batch Build, check debug and release for "INSTALL" configuration). | ||
| 107 | 23 | hector | # When the build is done, in CMake, check LIBPNG, OPENAL, CURL under SCOLDEPS (leave the other vaiables as they are). | 
| 108 | 22 | hector | # Repeat steps 3 to 5. | 
| 109 | 23 | hector | # Check OGRE, CAUDIO, LIBHARU under SCOLDEPS, and repeat steps 3 to 5. | 
| 110 | 22 | hector | # Check HYDRAX and SKYX under SCOLDEPS, and repeat steps 3 to 5. | 
| 111 | 21 | hector | |
| 112 | Now every required dependency should be built. The ones that we left unchecked aren't needed. | ||
| 113 | 7 | brainsandwich | |
| 114 | 20 | brainsandwich | h3. From Windows, for Android | 
| 115 | 7 | brainsandwich | |
| 116 | 20 | brainsandwich | Do the same as for Windows target, but | 
| 117 | * Set source folder to trunk/dependencies and build folder to trunk/scol/build/android/<target abi> | ||
| 118 | * Specify the generator : "NMake" | ||
| 119 | * The toolchain for crosscompile : trunk/dependencies/CMake/toolchain/android.toolchain.cmake | ||
| 120 | * Build dependencies with "nmake install" command from a command line. | ||
| 121 | 13 | brainsandwich | |
| 122 | |||
| 123 | 19 | brainsandwich | |
| 124 | 20 | brainsandwich | |
| 125 | 19 | brainsandwich | h2. Build the Scol project | 
| 126 | 13 | brainsandwich | |
| 127 | 20 | brainsandwich | As for the dependencies: | 
| 128 | 13 | brainsandwich | |
| 129 | 20 | brainsandwich | h3. Windows target | 
| 130 | 3 | arkeon | |
| 131 | 20 | brainsandwich | * Set source folder to trunk/scol and build folder to trunk/scol/build/windows/x86 | 
| 132 | * Configure, generate and build from Visual Studio | ||
| 133 | |||
| 134 | h3. Android target | ||
| 135 | |||
| 136 | * Set source folder to trunk/scol and build folder to trunk/scol/build/android/<target abi> | ||
| 137 | * 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 : | ||
| 138 | - Open ScolLauncher subproject -> properties | ||
| 139 | - Configuration Properties -> General -> Configuration Type -> Make Application (ndk-build -> .apk|.so|.a) | ||
| 140 | - Configuration Properties -> Deployment -> Fast Deploy -> No | ||
| 141 | - Configuration Properties -> Ant Build -> Skip Ant Step -> No | ||
| 142 | * 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 | ||
| 143 | 1 | arkeon | |
| 144 | h1. Start your new plugin | ||
| 145 | |||
| 146 | h2. Source paths | ||
| 147 | |||
| 148 | Start by creating a directory with your new plugin name in the trunk/scol/plugins folder. | ||
| 149 | For example trunk/scol/plugins/myPlugin | ||
| 150 | 4 | arkeon | |
| 151 | Usually we prefer to separate the sources and the includes. | ||
| 152 | 1 | arkeon | So creates a "src" and "include" directory in your plugin folder. | 
| 153 | |||
| 154 | Creates the empty files you will need for your project, usually : | ||
| 155 | - include/myplugin.h for your classes declaration | ||
| 156 | - src/myplugin.cpp for your classes definition | ||
| 157 | - src/scolplugin.cpp for the Scol binding functions | ||
| 158 | |||
| 159 | h2. Dependencies | ||
| 160 | |||
| 161 | If your project need an external SDK or dependencies, add then in the trunk/dependencies directory. | ||
| 162 | Then create a findMydepname.cmake file in trunk\scol\CMake\Packages. | ||
| 163 | You can copy and change an existing Find.cmake file to make yours. | ||
| 164 | Start from a simple one like FindMyo.cmake for example. | ||
| 165 | |||
| 166 | h2. Cmake files | ||
| 167 | |||
| 168 | It's time to creates the CMAKE script for your plugin. | ||
| 169 | |||
| 170 | Create a "CMakeLists.txt" file in the plugin directory. | ||
| 171 | trunk/scol/plugins/myPlugin/CMakeLists.txt | ||
| 172 | |||
| 173 | And edit the file with a text editor. | ||
| 174 | |||
| 175 | <pre> | ||
| 176 | #------------------------------------------------------------------- | ||
| 177 | # This file is part of the CMake build system for Scol | ||
| 178 | # | ||
| 179 | # The contents of this file are placed in the public domain. Feel | ||
| 180 | # free to make use of it in any way you like. | ||
| 181 | #------------------------------------------------------------------- | ||
| 182 | |||
| 183 | ############################################################ | ||
| 184 | # CmakeList file for Myplugin | ||
| 185 | ############################################################ | ||
| 186 | |||
| 187 | #Your project name | ||
| 188 | PROJECT(myPLugin) | ||
| 189 | |||
| 190 | # define header and source files for the library | ||
| 191 | set (MYPLUGIN_HEADER_FILES | ||
| 192 | include/myplugin.h | ||
| 193 | ) | ||
| 194 | |||
| 195 | set (MYPLUGIN_SOURCE_FILES | ||
| 196 | src/myplugin.cpp | ||
| 197 | src/scolplugin.cpp | ||
| 198 | ) | ||
| 199 | |||
| 200 | # Add includes directories from dependencies | ||
| 201 | #  include_directories(include ${MYDEP_INCLUDE_DIRS}) | ||
| 202 | |||
| 203 | # Add definition for P4 optimizations, warnings removal. | ||
| 204 | add_definitions(-DOPTI_P4 -D_CRT_SECURE_NO_WARNINGS -D) | ||
| 205 | |||
| 206 | # Add dependencies libraries | ||
| 207 | # set(LIBRARIES | ||
| 208 | #    ${MYDEP_LIBRARIES} | ||
| 209 | #    ${ZLIB_LIBRARIES} | ||
| 210 | #    ${PNG_LIBRARIES} | ||
| 211 | # ) | ||
| 212 | |||
| 213 | # setup Scol plugin target | ||
| 214 | add_library(myPLugin | ||
| 215 |   ${Scol_LIB_TYPE} | ||
| 216 |   ${MYPLUGIN_HEADER_FILES} | ||
| 217 |   ${MYPLUGIN_SOURCE_FILES} | ||
| 218 | ) | ||
| 219 | add_dependencies(myPLugin kernel) | ||
| 220 | |||
| 221 | # set the dll version. | ||
| 222 | set_target_properties(myPLugin PROPERTIES VERSION ${Scol_VERSION} SOVERSION ${Scol_VERSION_MAJOR}) | ||
| 223 | target_link_libraries(myPLugin ${LIBRARIES}) | ||
| 224 | |||
| 225 | # install Scol | ||
| 226 | scol_config_plugin(myPLugin) | ||
| 227 | install(FILES ${MYPLUGIN_HEADER_FILES} DESTINATION include/SCOL/plugins/myPLugin) | ||
| 228 | </pre> | ||
| 229 | |||
| 230 | Now we need to declare this new plugin in the common Scol cmake files. | ||
| 231 | Edit the trunk/scol/CMakeLists.txt file and add your plugin definition like the following. | ||
| 232 | |||
| 233 | If you don't have dependencies. | ||
| 234 | <pre> | ||
| 235 | option(Scol_BUILD_MYPLUGIN "Build myPluginplugin, my library" TRUE) | ||
| 236 | </pre> | ||
| 237 | |||
| 238 | If you have depencies | ||
| 239 | <pre> | ||
| 240 | cmake_dependent_option(Scol_BUILD_MYPLUGIN "Build myPlugin, my library." TRUE "MYDEP_FOUND;ZLIB_FOUND;PNG_FOUND" FALSE) | ||
| 241 | </pre> | ||
| 242 | |||
| 243 | Now edit the trunk/scol/plugin/CMakeLists.txt file and add the following. | ||
| 244 | <pre> | ||
| 245 | # Configure myPlugin plugin build | ||
| 246 | if (Scol_BUILD_MYPLUGIN) | ||
| 247 | add_subdirectory(myPlugin) | ||
| 248 | endif () | ||
| 249 | </pre> | ||
| 250 | |||
| 251 | Only if you have dependencies, edit the trunk/scol/CMake/ScolDependencies.cmake file and add the dependencies resolution as the following | ||
| 252 | |||
| 253 | <pre> | ||
| 254 | # Find MyDep | ||
| 255 | find_package(MYDEP) | ||
| 256 | macro_log_feature(MYDEP_FOUND "Mydep" "MydepLibrary" "http://Mydep.org/" FALSE "" "") | ||
| 257 | </pre> | ||
| 258 | |||
| 259 | h2. Almost done | ||
| 260 | |||
| 261 | Open the CMAKE-gui again. | ||
| 262 | Hit the "Configure button" and check if you found your plugin in the scol group. | ||
| 263 | Then hit the generate button, and open the scol.sln project again. | ||
| 264 | |||
| 265 | You should have the project added in Visual Studio. |