Skip to content

Commit

Permalink
Merge pull request #1195 from moai/feature/cmake-hosts
Browse files Browse the repository at this point in the history
Feature/cmake hosts
  • Loading branch information
patrickmeehan authored Oct 25, 2017
2 parents 8d36134 + b34fb78 commit 000329f
Show file tree
Hide file tree
Showing 157 changed files with 6,177 additions and 31 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,8 @@ docs/api-reference
env.sh
sample-browser/
util/build-sample-browser/temprom/
android-studio/app/.externalNativeBuild/
android-studio/libmoai/.externalNativeBuild/
cmake/cmake/hosts/host-win-sdl/.vs/
cmake/lib/
cmake/env-local.bat
49 changes: 31 additions & 18 deletions android-studio/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ apply plugin: 'com.android.application'

android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
buildToolsVersion '25.0.0'

defaultConfig {
applicationId "com.moaisdk.refapp"
minSdkVersion 17
targetSdkVersion 22
versionCode 8
versionName "1.0"

}
buildTypes {
release {
Expand All @@ -23,34 +24,46 @@ android {
packagingOptions {
exclude 'META-INF/LICENSE.txt'
}

}

//task ( 'cleanLuaScripts', type: Delete ) {
// delete 'src/main/assets/lua'
//}
if (hasProperty('luaRoot')) {
task ( 'cleanLuaScripts', type: Delete ) {
delete 'src/main/assets/lua'
}

task ( 'copyLuaScripts', type: Copy ) {
from new File(luaRoot).canonicalPath
into 'src/main/assets/lua'
}

task ( 'cleanLibraries', type: Delete ) {
delete 'src/main/jniLibs'
clean.dependsOn cleanLuaScripts
preBuild.dependsOn copyLuaScripts
}

//task ( 'copyLuaScripts', type: Copy ) {
// from '../../samples/anim-basic'
// into 'src/main/assets/lua'
//}
//set on command line or in gradle.properties
boolean usePrebuiltLibs = hasProperty('usePrebuiltMoaiFrom')

task ( 'copyLibraries', type: Copy ) {
from '../../android-ndk/libs'
into 'src/main/jniLibs'
}
if (usePrebuiltLibs) {
task('copyLibraries', type: Copy) {
from new File(usePrebuiltMoaiFrom).canonicalPath
into 'src/main/jniLibs'
}

//clean.dependsOn cleanLuaScripts
clean.dependsOn cleanLibraries
task ( 'cleanLibraries', type: Delete ) {
delete 'src/main/jniLibs'
}

//preBuild.dependsOn copyLuaScripts
preBuild.dependsOn copyLibraries
clean.dependsOn cleanLibraries
preBuild.dependsOn copyLibraries
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:22.1.1'
compile project(':core')
if (!usePrebuiltLibs) {
compile project(":libmoai")
}
}

15 changes: 9 additions & 6 deletions android-studio/app/src/main/assets/lua/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,27 @@
-- http://getmoai.com
----------------------------------------------------------------

MOAISim.openWindow ( "test", 320, 480 )
-- MOAISim.openWindow ( "test", 320, 480 )
local width = MOAIEnvironment.horizontalResolution
local height = MOAIEnvironment.verticalResolution


viewport = MOAIViewport.new ()
viewport:setSize ( 320, 480 )
viewport:setScale ( 320, 480 )
viewport:setSize ( width, height )
viewport:setScale ( width, height )

layer = MOAILayer.new ()
layer = MOAIPartitionViewLayer.new ()
layer:setViewport ( viewport )
layer:pushRenderPass ()

prop = MOAIProp.new ()
prop:setDeck ( 'moai.png' )
prop:setLayer ( layer )
prop:setPartition ( layer )
prop:moveRot ( 0, 0, 360, 5 )

prop = MOAIProp.new ()
prop:setDeck ( 'test.png' )
prop:setColor ( 1, 1, 1, 0 )
prop:setScl ( 2, 2, 1 )
prop:setLayer ( layer )
prop:setPartition ( layer )
prop:moveRot ( 0, 0, -360, 5 )
2 changes: 1 addition & 1 deletion android-studio/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.0'
classpath 'com.android.tools.build:gradle:2.3.3'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
14 changes: 13 additions & 1 deletion android-studio/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,16 @@
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
# org.gradle.parallel=true

# set the below to your moai sdk root (if it is different)
moaiSdkRoot=../

# uncomment below to have the lua source located at the specified folder copied into your android host on build

#luaRoot= ../samples/hello-moai

# uncomment below and set to the location of the prebuilt android libmoai to use prebuilt libraries for this host instead of
# of building from source.

#usePrebuiltMoaiFrom=../cmake/lib/android
1 change: 1 addition & 0 deletions android-studio/libmoai/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
41 changes: 41 additions & 0 deletions android-studio/libmoai/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 22
buildToolsVersion "25.0.0"

defaultConfig {
minSdkVersion 17
targetSdkVersion 22
versionCode 1
versionName "1.0"
externalNativeBuild {
cmake {
arguments "-DBUILD_ANDROID=TRUE", "-DMOAI_ANDROID=TRUE", "-DANDROID_STL=c++_static", "-DMOAI_SDK_HOME=" + new File(moaiSdkRoot).canonicalPath
}
}
ndk {
// Specifies the ABI configurations of your native
// libraries Gradle should build and package with your APK.
abiFilters 'x86'//, 'x86_64', 'armeabi-v7a'

}


}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
externalNativeBuild {
cmake {
path new File(moaiSdkRoot).canonicalPath + '/cmake/cmake/hosts/host-android/CMakeLists.txt'
}
}
}

dependencies {

}
25 changes: 25 additions & 0 deletions android-studio/libmoai/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in C:\dev\android-sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
10 changes: 10 additions & 0 deletions android-studio/libmoai/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"

package="com.example.libmoai">

<application android:allowBackup="true" android:label="@string/app_name"
android:supportsRtl="true">

</application>

</manifest>
3 changes: 3 additions & 0 deletions android-studio/libmoai/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<resources>
<string name="app_name">libmoai</string>
</resources>
6 changes: 4 additions & 2 deletions android-studio/settings.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
include ':app'

include ':core'
project(':core').projectDir = new File('../src/moai-android/java')
project(':core').projectDir = new File(moaiSdkRoot+'/src/moai-android/java')
if (!hasProperty('usePrebuiltMoaiFrom')) {
include(":libmoai")
}
57 changes: 57 additions & 0 deletions cmake/build-android.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
@echo off
setlocal enableextensions
call "%~dp0%\env-win.bat"

echo "Setting CMAKE bin path..."
set "PATH=%PATH%;%CMAKE_PATH%"

echo "Setting MingW Gcc path"
set "PATH=%MINGW_PATH%;%PATH%"

rem ----- Requirements Check -----
set "PITO_HOME=%~dp0..\"

if "%ANDROID_NDK%"=="" echo "You need to set ANDROID_NDK to your ndk path try using env-win.bat and env-local.bat in scripts" && exit /b 1
if "%MOAI_SDK_HOME%"=="" echo "You need to set MOAI_SDK_HOME to your moai sdk folder" && exit /b 1

where mingw32-make || echo "mingw32-make is required. Install TCC Mingw from http://tdm-gcc.tdragon.net/ and add to the path" && goto ERROR

where cmake || echo "Cmake 3.2+ is required, download from cmake.org" && goto ERROR

rem ----- Build libmoai -----
pushd "%~dp0%"

set "CMAKEROOT=%cd%"

mkdir build
cd build
mkdir build-android
cd build-android

set "BUILDROOT=%cd%"
rem for %%a in (x86 armeabi-v7a arm64-v8a)
for %%a in (x86) do (
cmake ^
-H%CMAKEROOT%\cmake\hosts\host-android ^
-B%BUILDROOT% ^
-G"MinGW Makefiles" ^
-DANDROID_ABI=%%a ^
-DANDROID_NDK=%ANDROID_NDK% ^
-DCMAKE_LIBRARY_OUTPUT_DIRECTORY="%CMAKEROOT%\lib\android\%%a" ^
-DCMAKE_BUILD_TYPE=Release ^
-DCMAKE_TOOLCHAIN_FILE=%ANDROID_NDK%\build\cmake\android.toolchain.cmake ^
-DANDROID_PLATFORM=android-17 ^
-DBUILD_ANDROID=TRUE ^
-DMOAI_ANDROID=TRUE ^
-DANDROID_STL=c++_static ^
-DMOAI_SDK_HOME=%MOAI_SDK_HOME% ^
-DHOST_ROOT=%MOAI_SDK_HOME%/src || goto ERROR

cmake --build . --target moai -- -j3 || goto ERROR
)

goto END
:ERROR
exit /b 1

:END
46 changes: 46 additions & 0 deletions cmake/build-android.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@



uname -a | grep -i Darwin && ENVSCRIPT=./env-osx.sh || ENVSCRIPT=./env-linux.sh
source $ENVSCRIPT

# requirements
: "${MOAI_SDK_HOME:?Please set MOAI_SDK_HOME variable to point to your Moai SDK }"
: "${ANDROID_NDK:?You need to set ANDROID_NDK to point to your ndk path. Try using env-local.sh }"

javac -version || { echo "Can't find a JDK" ; exit 1; }
cmake --version || { echo "Can't find cmake"; exit 1; }

#----- Build libmoai using sdk methods -----
pushd `dirname $0`

CMAKEROOT=$(pwd)

mkdir -p build/build-android
cd build/build-android

BUILDROOT=$(pwd)

# for a in x86 armeabi-v7a arm64-v8a; do
for a in x86; do
echo "building for :$a:"
cmake \
-H$CMAKEROOT/cmake/hosts/host-android \
-B$BUILDROOT \
-G"Unix Makefiles" \
-DANDROID_ABI=$a \
-DANDROID_NDK=$ANDROID_NDK \
-DCMAKE_LIBRARY_OUTPUT_DIRECTORY="$CMAKEROOT/lib/android/$a" \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake \
-DANDROID_PLATFORM=android-17 \
-DBUILD_ANDROID=TRUE \
-DMOAI_ANDROID=TRUE \
-DANDROID_STL=c++_static \
-DMOAI_SDK_HOME=$MOAI_SDK_HOME \
-DHOST_ROOT=$MOAI_SDK_HOME/src || { echo "error running cmake"; exit 1; }

make moai -j3 || { echo "error building libmoai"; exit 1; }
done

popd
Loading

0 comments on commit 000329f

Please sign in to comment.