SLib
SLib - A universal, efficient, light-weight framework for building cross-platform applications on Android/iOS/macOS/Tizen/Win32/Linux platforms, developed by SLIBIO. Based on C++, provides desktop/mobile widgets, OpenGL rendering and networking solutions.
Install / Use
/learn @SLIBIO/SLibREADME
SLib
SLib is a universal cross-platform library, specially designed for the various UI components, OpenGL rendering and networking solutions.
SLib enables software developers to build multi-platform(Android/iOS/MacOS/Tizen/Win32) applications and games under the most effective workflows and the coding conventions of C++, while providing easy-to-use toolkits to develop HTTP/Socket servers on the Linux/MacOS/Win32 platforms.
Modules
-
core
Auto Reference Counting, String, List, Map, File, Thread, Synchronizing, Time, Variant, Json, Xml, ...
-
crypto
AES, RSA, GZIP, SHA1/2, GCM, MD5, Blowfish, DES, TripleDES, ...
-
db
SQLite, MySQL, Redis
-
device
Sensor, Vibrator
-
graphics
Bitmap, Image, Canvas, Font, ...
-
math
BigInt, Uint128, Matrix, Vector, Transform, ...
-
media
MediaPlayer, AudioRecorder, AudioPlayer, Camera, ...
-
network
UrlRequest, Socket, Asynchronous I/O, HttpServer, ...
-
render
RenderEngine, RenderProgram, VertexBuffer, IndexBuffer, Texture, ...
-
ui
Window, View, ViewGroup, LinearView, ScrollView, Animation, Button, EditView, TabView, WebView, ...
-
web
WebController, WebService
-
geo
LatLon, GeoLocation, GeoLine, GeoRectangle, Globe, Earth
Getting Started
Prerequisites
- Xcode 9.4 or higher for compiling macOS/iOS packages
- Android Studio 3.2 or higher for compiling Android packages
- Visual Studio 2017 or higher for compiling Win32 packages
- Tizen Studio 1.1.1 or higher for compiling Tizen packages
- CMake (>=3.0), GCC/C++ (>=4.8.1) for compiling Linux packages. Optional: KDevelop(>=4.7)
Clone the repository from Github.
git clone https://github.com/SLIBIO/SLib.git
Build the static libraries
You can see the following projects in build directory.
| Project| Description | | ----|----| | Android | Android Studio project for Android | | iOS | Xcode project for iOS | | macOS | Xcode project for macOS | | Win32 | Visual Studio solution for Win32 | | Tizen | Tizen Studio project for Tizen | | Linux | CMake/KDevelop project for Linux |
After compiling the projects, you can find the static libraries in the lib directory.
Setup Environment
It's time to setup the environment variables. It is a bit different depending on the platforms.
On macOS and Linux, you'll need to run the setup-path script on Terminal or Finder.
./setup-path
On Windows, you'll need to run the setup-path.bat batch file on Command Prompt or File Explorer.
setup-path.bat
setup-path will register the current source directory as SLIB-PATH environment variable depending on the Operating Systems and IDEs(XCode and KDevelop).
After setting up the environment variables, please close all the running IDEs(Xcode, Android Studio, Tizen Studio,...) and terminal (or konsole) windows, and then reopen them. (on macOS, press Command+Q to completely close the IDEs).
Creating new projects based on SLib
After setting up environment using setup-path(setup-path.bat), please reopen Terminal (Command Prompt) window.
And then please create an empty directory, and then create a C++ project using following commands.
| Platform | Application Type | Command |
| ----|----|----|
| Android <br/> iOS | Mobile App <br/>(With sapp) | new-slib-app-mobile YOUR_PROJECT_NAME YOUR_APPLICATION_ID |
| macOS <br/> Win32 | Desktop App <br/>(With sapp) | new-slib-app-desktop YOUR_PROJECT_NAME |
| Android | Mobile App <br/>(Without sapp) | new-slib-app-android YOUR_PROJECT_NAME YOUR_APPLICATION_ID |
| iOS | Mobile App <br/>(Without sapp) | new-slib-app-ios YOUR_PROJECT_NAME |
| macOS | Desktop App <br/>(Without sapp) | new-slib-app-macos YOUR_PROJECT_NAME |
| macOS | Console App <br/>(Without sapp) | new-slib-console-macos YOUR_PROJECT_NAME |
| Win32 | Desktop App <br/>(Without sapp) | new-slib-app-win32 YOUR_PROJECT_NAME |
| Win32 | Console App <br/>(Without sapp) | new-slib-console-win32 YOUR_PROJECT_NAME |
| Linux | Desktop App <br/>(Without sapp) | new-slib-app-linux YOUR_PROJECT_NAME |
| Linux | Console App <br/>(Without sapp) | new-slib-console-linux YOUR_PROJECT_NAME |
Note that you have to compile SLib before creating new SLib application projects.
Here is an example for creating a mobile app project.
mkdir ~/SLibMobileExample
cd ~/SLibMobileExample
new-slib-app-mobile Test org.example.testapp
To preview the user interface xml files
cd src/sapp/ui
sapp LaunchScreen
sapp MainPage
Here is an example for creating a desktop app project.
mkdir ~/SLibDesktopExample
cd ~/SLibDesktopExample
new-slib-app-desktop Test
Here is an example for creating an Android project.
mkdir ~/SLibAndroidExample
cd ~/SLibAndroidExample
new-slib-app-android Test org.example.testapp
Here is an example for creating a macOS Desktop project.
mkdir ~/SLibMacOSExample
cd ~/SLibMacOSExample
new-slib-app-macos Test
After creating projects, you can share same source code across the projects by adding same sources using IDE.
Integrating SLib with existing C++ projects
It is very easy to integrate SLib into your existing C++ project. You just need to setup include and lib directories into your existing C++ project.
| Platform | IDE | Include Directory | Link Directory | | ----|----|----|----| | Android | Android Studio (CMake) | ${SLIB_PATH}/include | ${SLIB_PATH}/lib/Android/${CMAKE_BUILD_TYPE}-${ANDROID_ABI} | | iOS | Xcode | $(SLIB_PATH)/include | $(SLIB_PATH)/lib/iOS/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) | | Tizen | Tizen Studio | ${SLIB_PATH}/include | ${SLIB_PATH}/lib/Tizen/${ConfigName}-${SDK_ARCH} | | macOS | Xcode | $(SLIB_PATH)/include | $(SLIB_PATH)/lib/macOS/$(CONFIGURATION) | | Win32 | Visual Studio | $(SLIB_PATH)/include | $(SLIB_PATH)/lib/Win32/$(Configuration)-$(Platform) | | Linux | CMake, KDevelop | ${SLIB_PATH}/include | ${SLIB_PATH}/lib/Linux/${CMAKE_BUILD_TYPE}-${CMAKE_HOST_SYSTEM_PROCESSOR} |
You can also integrate SLib into any types of C++ projects using similar include and lib directory rules.
Important: Your C++ project must be compiled with C++11 support.
After setup directories, link slib library via IDE or set -lslib option to the linker.
To make your project more portable, you can copy the include directory and the precompiled static libraries into your project and use the relative path instead of the environment variable.
Android Studio (using CMake)
Firstly, open and build the project in the build/Android directory in the SLib source. After completion of build, you can see the precompiled static libraries and slib.aar in the lib/Android directory.
Secondly, open your Android project created by yourself which will use SLib.
Important: Use gradle version 2.3.1 or higher.
Edit the build.gradle in your app module as following.
...
android {
...
defaultConfig {
...
externalNativeBuild {
...
cmake {
cppFlags "-std=c++11"
arguments "-DSLIB_PATH=${System.env.SLIB_PATH}"
}
...
}
ndk {
abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
}
...
}
}
...
repositories {
...
flatDir{
...
dirs "${System.env.SLIB_PATH}/lib/Android"
}
}
dependencies {
...
compile ':slib@aar'
}
Edit CMakeLists.txt in your app module as following.
...
include_directories (${SLIB_PATH}/include)
link_directories (${SLIB_PATH}/lib/Android/${CMAKE_BUILD_TYPE}-${ANDROID_ABI})
...
target_link_libraries (
your-native-module-name
...
slib
log GLESv2 OpenSLES
...
)
...
Edit the main cpp file (for example, native-lib.cpp), and insert the following code snippet.
#include <slib/core/platform_android.h>
JNIEXPORT jint JNI_OnLoad(JavaVM* jvm, void* reserved)
{
slib::Android::initialize(jvm);
return JNI_VERSION_1_4;
}
If you already defined JNI_OnLoad in somewhere, please insert slib::Android::initialize(jvm); in the existing definition, instead of inserting above code snippet.
Xcode (iOS, macOS)
Firstly, open and build the project in the build/iOS (or build/macOS for macOS) directory in the SLib source. After completion of build, you can see the precompiled static libraries in the lib/iOS (or lib/macOS for macOS) directory.
Secondly, open your Xcode project created by yourself which will use SLib.
-
Click on the project icon in the inspector (on the left side)
-
Click on the
Build Settingstab on the right side -
Find
Search Pathssection-
Add following path to
Header Search Paths$(SLIB_PATH)/include -
Add following path to
Library Search Pathson iOS
$(SLIB_PATH)/lib/iOS/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)on macOS
$(SLIB_PATH)/lib/macOS/$(CONFIGURATION)
-
-
Find
LinkingsectionAdd following linker flag to
Other Linker Flags-lslib
Tizen Studio
Firstly, open and build the project in the build/Tizen directory in the SLib source. After completion of build, you can see the precompiled static libraries in the lib/Tizen directory.
Secondly, open your Tizen project created by yourself which will use SLib.
-
Right click on the project in the
Project Explorer -
Click on
Propertieson the popup menu.Then,
Propertiespopup window will be shown. -
Find
C/C++ Generalin the left tree and then open itSelect the subitem:
Paths and Symbols. Then,Paths and Symbolsproperty page will be shown on the right side.-
Select
Includestab on the property page-
Select
GNU C++inLanguageslist on the left side of the property page. -
Click on the
Addbutton on the right side of the property page. -
In the
Add directory pathdialog, input the follow
-
-
