Skip to content

Commit

Permalink
support iOS and Android
Browse files Browse the repository at this point in the history
support char16_t, u16string, char32_t, and u32string
  • Loading branch information
alexchicn committed Nov 4, 2018
1 parent b7b082a commit 55e6200
Show file tree
Hide file tree
Showing 18 changed files with 493 additions and 364 deletions.
1 change: 1 addition & 0 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ install:
- git submodule update --init

before_build:
- cd tools/batch/ && update_parser_by_scheme.bat && cd ../../
- mkdir build
- cd build
- if "%TARGET_VSENV%" equ "VS14_WIN32" cmake -G "Visual Studio 14 2015" -D CMAKE_CONFIGURATION_TYPES=%CONFIGURATION% -D CMAKE_CXX_COMPILER_ID=MSVC_14 ../
Expand Down
128 changes: 91 additions & 37 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
variables:
GIT_SUBMODULE_STRATEGY: "recursive"
ANDROID_NDK: "~/develop/android-ndk-r18b"

before_script:
- git lfs fetch
Expand All @@ -10,60 +11,54 @@ after_script:

stages:
- check
- test
- build

checked_by_cppcheck:
stage: check
script:
- echo check
- 'cd tools/batch/ && ./update_parser_by_scheme.sh && cd ../../'
- 'cppcheck . --enable=warning,style,performance,portability --xml-version=2 --error-exitcode=1 -i external/ -i build/ -i tools/'
tags:
- linux
- python
- cppcheck

test_win32:
stage: test
compile_windows:
stage: build
script:
- 'cd tools/batch/ && python .\..\..\tools\jsonschematoc11 glTF_2.0_schema.ini && cd ../../'
- 'call "%VS140COMNTOOLS%VsDevCmd.bat"'
- 'if exist build rmdir /s /q build'
- 'if exist output rmdir /s /q output'
- 'mkdir build'
- 'cd build'
- 'cmake -G "Visual Studio 14 2015" ../'
- 'mkdir build && cd build'
- 'mkdir win32 && cd win32'
- 'cmake -G "Visual Studio 14 2015" -DLIBGLTF_WITH_UNICODE=TRUE ../../'
- 'msbuild libgltf.sln /t:Rebuild /p:Configuration="Debug" /p:Platform="Win32"'
- '..\output\bin\win32\Debug\runtest.exe ..\resource\example-2.0\glTF-BarramundiFish.gltf'
- '..\output\bin\win32\Debug\runtest.exe ..\resource\example-2.0\glTF-Draco-BarramundiFish.gltf'
- '..\output\bin\win32\Debug\runtest.exe ..\resource\example-2.0\glTF-pbrSpecularGlossinessBarramundiFish.gltf'
- '..\..\output\bin\win32\Debug\runtest.exe ..\..\resource\example-2.0\glTF-BarramundiFish.gltf'
- '..\..\output\bin\win32\Debug\runtest.exe ..\..\resource\example-2.0\glTF-Draco-BarramundiFish.gltf'
- '..\..\output\bin\win32\Debug\runtest.exe ..\..\resource\example-2.0\glTF-pbrSpecularGlossinessBarramundiFish.gltf'
- 'cd ../'
tags:
- win32
- cmake
- vs2015

test_win64:
stage: test
script:
- 'call "%VS140COMNTOOLS%VsDevCmd.bat"'
- 'if exist build rmdir /s /q build'
- 'if exist output rmdir /s /q output'
- 'mkdir build'
- 'cd build'
- 'cmake -G "Visual Studio 14 2015 Win64" ../'
- 'mkdir win64 && cd win64'
- 'cmake -G "Visual Studio 14 2015 Win64" -DLIBGLTF_WITH_UNICODE=TRUE ../../'
- 'msbuild libgltf.sln /t:Rebuild /p:Configuration="Debug" /p:Platform="x64"'
- '..\output\bin\win64\Debug\runtest.exe ..\resource\example-2.0\glTF-BarramundiFish.gltf'
- '..\output\bin\win64\Debug\runtest.exe ..\resource\example-2.0\glTF-Draco-BarramundiFish.gltf'
- '..\output\bin\win64\Debug\runtest.exe ..\resource\example-2.0\glTF-pbrSpecularGlossinessBarramundiFish.gltf'
- '..\..\output\bin\win64\Debug\runtest.exe ..\..\resource\example-2.0\glTF-BarramundiFish.gltf'
- '..\..\output\bin\win64\Debug\runtest.exe ..\..\resource\example-2.0\glTF-Draco-BarramundiFish.gltf'
- '..\..\output\bin\win64\Debug\runtest.exe ..\..\resource\example-2.0\glTF-pbrSpecularGlossinessBarramundiFish.gltf'
- 'cd ../'
- 'cd ../'
tags:
- win32
- win64
- python
- cmake
- vs2015

test_linux:
stage: test
compile_linux:
stage: build
script:
- 'mkdir build'
- 'cd build'
- 'cmake -DCMAKE_BUILD_TYPE=Debug -DLIBGLTF_BUILD_GCOV=TRUE -G "Unix Makefiles" ../'
- 'cd tools/batch/ && ./update_parser_by_scheme.sh && cd ../../'
- 'mkdir build && cd build'
- 'cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug -DLIBGLTF_BUILD_GCOV=TRUE ../'
- 'make'
- 'valgrind --leak-check=full --show-leak-kinds=all ./../output/bin/linux/runtest --coveralls'
- 'valgrind --leak-check=full --show-leak-kinds=all ./../output/bin/linux/runtest --coveralls ../resource/nothing.gltf'
Expand All @@ -80,17 +75,17 @@ test_linux:
- 'cd ../'
tags:
- linux
- python
- cmake
- make
- valgrind
- gcc
- gcovr

test_macos:
stage: test
compile_macos:
stage: build
script:
- 'mkdir build'
- 'cd build'
- 'cd tools/batch/ && ./update_parser_by_scheme.sh && cd ../../'
- 'mkdir build && cd build'
- 'cmake -G "Unix Makefiles" ../'
- 'make'
- './../output/bin/macos/runtest ../resource/example-2.0/glTF-BarramundiFish.gltf'
Expand All @@ -99,6 +94,65 @@ test_macos:
- 'cd ../'
tags:
- macos
- python
- cmake
- make
- gcc

compile_android:
stage: build
script:
- 'cd tools/batch/ && ./update_parser_by_scheme.sh && cd ../../'
- 'mkdir build && cd build'
- 'mkdir armeabi-v7a && cd armeabi-v7a'
- 'cmake -G "Ninja" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_MAKE_PROGRAM=/usr/bin/ninja -DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake -DANDROID_ABI=armeabi-v7a -DANDROID_NDK=$ANDROID_NDK -DANDROID_NATIVE_API_LEVEL=19 -DANDROID_TOOLCHAIN=clang ../../'
- 'ninja'
- 'cd ../'
- 'mkdir armeabi-v7a-with-neon && cd armeabi-v7a-with-neon'
- 'cmake -G "Ninja" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_MAKE_PROGRAM=/usr/bin/ninja -DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake -DANDROID_ABI=armeabi-v7a -DANDROID_ARM_NEON=ON -DANDROID_NDK=$ANDROID_NDK -DANDROID_NATIVE_API_LEVEL=19 -DANDROID_TOOLCHAIN=clang ../../'
- 'ninja'
- 'cd ../'
- 'mkdir arm64-v8a && cd arm64-v8a'
- 'cmake -G "Ninja" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_MAKE_PROGRAM=/usr/bin/ninja -DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake -DANDROID_ABI=arm64-v8a -DANDROID_NDK=$ANDROID_NDK -DANDROID_NATIVE_API_LEVEL=19 -DANDROID_TOOLCHAIN=clang ../../'
- 'ninja'
- 'cd ../'
- 'mkdir x86 && cd x86'
- 'cmake -G "Ninja" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_MAKE_PROGRAM=/usr/bin/ninja -DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake -DANDROID_ABI=x86 -DANDROID_NDK=$ANDROID_NDK -DANDROID_NATIVE_API_LEVEL=19 -DANDROID_TOOLCHAIN=clang ../../'
- 'ninja'
- 'cd ../'
- 'mkdir x86_64 && cd x86_64'
- 'cmake -G "Ninja" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_MAKE_PROGRAM=/usr/bin/ninja -DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake -DANDROID_ABI=x86_64 -DANDROID_NDK=$ANDROID_NDK -DANDROID_NATIVE_API_LEVEL=19 -DANDROID_TOOLCHAIN=clang ../../'
- 'ninja'
- 'cd ../'
- 'cd ../'
tags:
- linux
- android
- python
- cmake
- ninja

compile_ios:
stage: build
script:
- 'cd tools/batch/ && ./update_parser_by_scheme.sh && cd ../../'
- 'mkdir build && cd build'
- 'mkdir os && cd os'
- 'cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=../../external/ios-cmake/toolchain/iOS.cmake -DIOS_PLATFORM=OS -DLIBGLTF_PLATFORM_IOS=TRUE -DLIBGLTF_WITH_UNICODE=TRUE -DLIBGLTF_USING_CHAR16=TRUE ../../'
- 'make libgltf'
- 'cd ../'
- 'mkdir simulator && cd simulator'
- 'cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=../../external/ios-cmake/toolchain/iOS.cmake -DIOS_PLATFORM=SIMULATOR -DLIBGLTF_PLATFORM_IOS=TRUE -DLIBGLTF_WITH_UNICODE=TRUE -DLIBGLTF_USING_CHAR16=TRUE ../../'
- 'make libgltf'
- 'cd ../'
- 'mkdir watchos && cd watchos'
- 'cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=../../external/ios-cmake/toolchain/iOS.cmake -DIOS_PLATFORM=WATCHOS -DLIBGLTF_PLATFORM_IOS=TRUE -DLIBGLTF_WITH_UNICODE=TRUE -DLIBGLTF_USING_CHAR16=TRUE ../../'
- 'make libgltf'
- 'cd ../'
- 'cd ../'
tags:
- macos
- ios
- python
- cmake
- make
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
[submodule "external/glTF"]
path = external/glTF
url = https://github.com/KhronosGroup/glTF.git
[submodule "external/ios-cmake"]
path = external/ios-cmake
url = https://github.com/Yangqing/ios-cmake.git
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ install:

script:
- set -e
- cd tools/batch/ && ./update_parser_by_scheme.sh && cd ../../
- mkdir ./build && cd ./build
- if [ $RUN_COVERALLS == true ]; then cmake -D LIBGLTF_COVERAGE_GCOV=TRUE ./../; else cmake ./../; fi
- make
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## 0.1.4 (2018/11/5)

* Support Android and iOS platforms

## 0.0.1 (2017/12/5)

### Changes
Expand Down
27 changes: 24 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ set(CMAKE_DEBUG_POSTFIX "d")
set(LIBGLTF_PLATFORM_WINDOWS FALSE)
set(LIBGLTF_PLATFORM_LINUX FALSE)
set(LIBGLTF_PLATFORM_MACOS FALSE)
set(LIBGLTF_PLATFORM_ANDROID FALSE)
option(LIBGLTF_PLATFORM_IOS OFF)

option(LIBGLTF_COVERAGE_GCOV "Coverage gcov (debug, Linux builds only)" OFF)
option(LIBGLTF_WITH_UNICODE "Build with UNICODE" OFF)
Expand Down Expand Up @@ -46,7 +48,17 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -lgcov")
add_definitions(-DBUILD_COVERALLS)
endif()
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
elseif(CMAKE_SYSTEM_NAME STREQUAL "Android")
set(LIBGLTF_PLATFORM_ANDROID TRUE)
add_definitions(-DLIBGLTF_PLATFORM_LINUX)
set(DYNAMIC_LIBRARY_EXTENSION ".so")
set(STATIC_LIBRARY_EXTENSION ".a")
set(PLATFORM_NAME "android")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wshadow -Wconversion -Wno-long-long -pedantic")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wextra -Wshadow -Wconversion -Wsign-conversion -Wno-long-long -pedantic")
set(CMAKE_STATIC_LIBRARY_PREFIX "")
set(CMAKE_SHARED_LIBRARY_PREFIX "")
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND (NOT ${LIBGLTF_PLATFORM_IOS}))
set(LIBGLTF_PLATFORM_MACOS TRUE)
add_definitions(-DLIBGLTF_PLATFORM_MACOS)
set(DYNAMIC_LIBRARY_EXTENSION ".dylib")
Expand All @@ -56,9 +68,19 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set(CMAKE_CXX_FLAGS "-std=c++11 -Wall -Wextra -Wshadow -Wconversion -Wsign-conversion -Wno-long-long -pedantic ${CMAKE_CXX_FLAGS}")
set(CMAKE_STATIC_LIBRARY_PREFIX "")
set(CMAKE_SHARED_LIBRARY_PREFIX "")
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND ${LIBGLTF_PLATFORM_IOS})
set(LIBGLTF_PLATFORM_IOS TRUE)
add_definitions(-DLIBGLTF_PLATFORM_IOS)
set(DYNAMIC_LIBRARY_EXTENSION ".dylib")
set(STATIC_LIBRARY_EXTENSION ".a")
set(PLATFORM_NAME "ios")
set(CMAKE_C_FLAGS "-Wall -Wextra -Wshadow -Wconversion -Wno-long-long -pedantic ${CMAKE_C_FLAGS}")
set(CMAKE_CXX_FLAGS "-std=c++11 -Wall -Wextra -Wshadow -Wconversion -Wsign-conversion -Wno-long-long -pedantic ${CMAKE_CXX_FLAGS}")
set(CMAKE_STATIC_LIBRARY_PREFIX "")
set(CMAKE_SHARED_LIBRARY_PREFIX "")
endif()

if((NOT ${LIBGLTF_PLATFORM_WINDOWS}) AND (NOT ${LIBGLTF_PLATFORM_LINUX}) AND (NOT ${LIBGLTF_PLATFORM_MACOS}))
if((NOT ${LIBGLTF_PLATFORM_WINDOWS}) AND (NOT ${LIBGLTF_PLATFORM_LINUX}) AND (NOT ${LIBGLTF_PLATFORM_ANDROID}) AND (NOT ${LIBGLTF_PLATFORM_MACOS}) AND (NOT ${LIBGLTF_PLATFORM_IOS}))
message(FATAL_ERROR "Sorry, don't support your system ${CMAKE_SYSTEM_NAME}!")
endif()

Expand Down Expand Up @@ -106,4 +128,3 @@ add_subdirectory(source)
add_subdirectory(tools)

set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT libgltf)

15 changes: 14 additions & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
# About

This project can automatically generate C++11 code by glTF JSON schema. Then you can compile the generated C++11 code to parser the glTF to a struct `SGlTF` or convert the struct `SGlTF` to JSON string.
This project can automatically generate C++11 code by glTF JSON schema. Then you can compile the generated C++11 code to parser the glTF string to a struct `SGlTF` or convert the struct `SGlTF` to JSON string.

It was used in [glTFForUE4](https://github.com/code4game/glTFForUE4).

## Platforms

### Desktop

* Windows
* Linux
* MacOS

### Mobile

* Android (armeabi-v7a, armeabi-v7a-with-neon, arm64-v8a, x86 and x86_64)
* iOS (iOS, simulator and watchOS)

## Donation

[![Become a patreon](https://img.shields.io/badge/donation-become%20a%20patreon-ff69b4.svg?style=flat)](https://www.patreon.com/bePatron?u=7553208)
Expand Down
17 changes: 15 additions & 2 deletions docs/usage.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
# Usage

Generate the `makefile` or `vs project` by [CMake].
Generate the `makefile` or `ninja` or `vs project` by [CMake].

For now, just build to a static library - `libgltf.(lib/a/dylib)`.

## Advance

### Generate new code by the official glTF schema

> You can update the c++11 source code by `jsonschematoc11`.
Generate the c++11 code:

1. Run `tools/batch/update_parser_by_scheme.bat` or `tools/batch/update_parser_by_scheme.sh`
1. Run `tools/batch/update_parser_by_scheme.bat` (Windows) or `tools/batch/update_parser_by_scheme.sh` (Unix/Linux/MacOS)
2. Build your version by [CMake], [Ninja] or [VisualStudio].

### String encode

* default using utf8, char and std::string
* set LIBGLTF_WITH_UNICODE as TRUE in cmake command, if you want using unicode
* default using wchar_t and std::wstring
* set LIBGLTF_USING_CHAR16 as TRUE in cmake command, if you wnat using utf16, char16_t and std::u16string
* set LIBGLTF_USING_CHAR32 as TRUE in cmake command, if you want using utf32, char32_t and std::u32string

[CMake]: https://cmake.org
[Ninja]: https://ninja-build.org
[VisualStudio]: https://visualstudio.microsoft.com
1 change: 1 addition & 0 deletions external/ios-cmake
Submodule ios-cmake added at 8abaed
Loading

0 comments on commit 55e6200

Please sign in to comment.