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