Skip to content

Commit

Permalink
+) Gradle
Browse files Browse the repository at this point in the history
 - Support for gradle / Android JNI
  • Loading branch information
luncliff committed Aug 27, 2018
1 parent d89b29a commit 0f23e79
Show file tree
Hide file tree
Showing 12 changed files with 266 additions and 49 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.externalNativeBuild/
.gradle/

[Bb]uild/

Expand Down
68 changes: 34 additions & 34 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ install:
brew upgrade llvm > /dev/null 2>&1;
brew info llvm;
fi
# Linux: Install llvm stable
# https://apt.llvm.org/
- if [ "${TRAVIS_OS_NAME}" == "linux" ]; then
deb http://apt.llvm.org/trusty/ llvm-toolchain-trusty-6.0 main;
deb-src http://apt.llvm.org/trusty/ llvm-toolchain-trusty-6.0 main;
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -;
sudo apt-get install libllvm6.0 llvm-6.0 llvm-6.0-dev llvm-6.0-runtime;
sudo apt-get install clang-6.0 lldb-6.0 lld-6.0;
fi
# # Linux: Install llvm stable
# # https://apt.llvm.org/
# - if [ "${TRAVIS_OS_NAME}" == "linux" ]; then
# deb http://apt.llvm.org/trusty/ llvm-toolchain-trusty-6.0 main;
# deb-src http://apt.llvm.org/trusty/ llvm-toolchain-trusty-6.0 main;
# wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -;
# sudo apt-get install libllvm6.0 llvm-6.0 llvm-6.0-dev llvm-6.0-runtime;
# sudo apt-get install clang-6.0 lldb-6.0 lld-6.0;
# fi
- tree --version
- ninja --version

Expand All @@ -67,8 +67,8 @@ script:
-DCMAKE_INSTALL_PREFIX=../$PLATFORM/$CONFIG
- ninja install
# Display build results and start tests
- tree .
- ./cppmagic_test
- tree -f ./CMakeFiles/

after_success:
- cd ${TRAVIS_BUILD_DIR}
Expand Down Expand Up @@ -103,16 +103,16 @@ matrix:
- CONFIG=Debug
- BUILD_SHARED=true

# Linux : x86_64 Release Static
- env:
- PLATFORM=linux
- CONFIG=Release
- BUILD_SHARED=false
# Linux : x86_64 Release Dynamic
- env:
- PLATFORM=linux
- CONFIG=Release
- BUILD_SHARED=true
# # Linux : x86_64 Release Static
# - env:
# - PLATFORM=linux
# - CONFIG=Release
# - BUILD_SHARED=false
# # Linux : x86_64 Release Dynamic
# - env:
# - PLATFORM=linux
# - CONFIG=Release
# - BUILD_SHARED=true

# OS X : x86_64 Debug Static
- os: osx
Expand All @@ -129,20 +129,20 @@ matrix:
- CONFIG=Debug
- BUILD_SHARED=true

# OS X : x86_64 Release Static
- os: osx
osx_image: xcode9.3
env:
- PLATFORM=osx
- CONFIG=Release
- BUILD_SHARED=false
# OS X : x86_64 Release Dynamic
- os: osx
osx_image: xcode9.3
env:
- PLATFORM=osx
- CONFIG=Release
- BUILD_SHARED=true
# # OS X : x86_64 Release Static
# - os: osx
# osx_image: xcode9.3
# env:
# - PLATFORM=osx
# - CONFIG=Release
# - BUILD_SHARED=false
# # OS X : x86_64 Release Dynamic
# - os: osx
# osx_image: xcode9.3
# env:
# - PLATFORM=osx
# - CONFIG=Release
# - BUILD_SHARED=true

notifications:
email:
Expand Down
124 changes: 112 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ endif()

project(cppmagic LANGUAGES CXX
VERSION 1.0.1
DESCRIPTION "Auto-magically working C++ coroutine"
)
message(STATUS "========== ${PROJECT_NAME} : ${PROJECT_VERSION} ==========")

Expand All @@ -43,6 +42,24 @@ message(STATUS "Build Type \t: ${CMAKE_BUILD_TYPE}")

# System / Compiler

if(ANDROID)
set(PLATFORM ${ANDROID_ABI})
elseif(IOS OR IOS_DEPLOYMENT_TARGET)
set(PLATFORM iOS)
elseif(${CMAKE_SYSTEM} MATCHES Windows)
set(PLATFORM Windows)
elseif(${CMAKE_SYSTEM} MATCHES Darwin)
set(OSX true)
set(PLATFORM OSX)
elseif(${CMAKE_SYSTEM} MATCHES Linux)
set(LINUX true)
set(PLATFORM Linux)
endif()

if(ANDROID OR WIN32)
SET(BUILD_SHARED_LIBS true)
endif()

message(STATUS "System \t: ${CMAKE_SYSTEM}")
message(STATUS "Compiler")
message(STATUS " - ID \t: ${CMAKE_CXX_COMPILER_ID}")
Expand All @@ -59,6 +76,84 @@ set_target_properties(${PROJECT_NAME} PROPERTIES
# # We will use `-std=c++1z` instead
)

# Platform-specific configurations

if(ANDROID)
message(STATUS "Android")
message(STATUS " Platform\t: ${ANDROID_PLATFORM}") # Android-21 ++
message(STATUS " Arch \t: ${ANDROID_ARCH_NAME}") # arm
message(STATUS " ABI \t: ${ANDROID_ABI}") # armeabi-v7a or else
message(STATUS " NDK Path\t: ${ANDROID_NDK}") # Path/to/NDK
message(STATUS " STL \t: ${ANDROID_STL}") # expect c++_shared

target_compile_options(${PROJECT_NAME}
PRIVATE
-fstack-protector-strong
)

# <asm/types.h> 를 찾는다. 현재는 armv7, armv8, x86에 대해서만.
if(${ANDROID_ABI} STREQUAL "arm64-v8a")
target_include_directories(${PROJECT_NAME}
PRIVATE
${ANDROID_NDK}/sysroot/usr/include/aarch64-linux-android
)
elseif(${ANDROID_ABI} MATCHES "arm")
target_include_directories(${PROJECT_NAME}
PRIVATE
${ANDROID_NDK}/sysroot/usr/include/arm-linux-androideabi
)
elseif(${ANDROID_ABI} MATCHES "x86") # x86, x86_64
target_include_directories(${PROJECT_NAME}
PRIVATE
${ANDROID_NDK}/sysroot/usr/include/x86_64-linux-android
)
endif()

# STL: GNU Shared
if(${ANDROID_STL} STREQUAL "gnustl_shared")
target_include_directories(${PROJECT_NAME}
PRIVATE
${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/include/
)
# link_directories(
# ${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/4.9/libs/${ANDROID_ABI}/
# )
# STL: C++ Shared
elseif(${ANDROID_STL} STREQUAL "c++_shared")
target_include_directories(${PROJECT_NAME}
PRIVATE
${ANDROID_NDK}/sources/cxx-stl/llvm-libc++/include/
)
# link_directories(
# ${ANDROID_NDK}/sources/cxx-stl/llvm-libc++/libs/${ANDROID_ABI}/
# )
endif()

target_include_directories(${PROJECT_NAME}
PRIVATE
# JNI
${ANDROID_NDK}/sysroot/usr/include/
${ANDROID_NDK}/sources/android/support/include/
# ABI
${ANDROID_NDK}/platforms/${ANDROID_PLATFORM}/arch-${ANDROID_ARCH_NAME}/usr/include/
# JNI declarations
${PROJECT_DIR}/android/jni/
)

# link_directories(
# # ABI
# ${ANDROID_NDK}/platforms/${ANDROID_PLATFORM}/arch-${ANDROID_ARCH_NAME}/usr/lib/
# # Nested libraries
# ${PROJECT_DIR}/android/jniLibs/${ANDROID_ABI}
# )

target_sources(${PROJECT_NAME}
PRIVATE
${PROJECT_DIR}/android/jni/adapter.h
${PROJECT_DIR}/android/jni/adapter.cpp
)
endif() # Android

target_include_directories(${PROJECT_NAME}
PUBLIC
${PROJECT_DIR}
Expand Down Expand Up @@ -126,23 +221,24 @@ if(APPLE)
target_compile_options(${PROJECT_NAME}
PUBLIC
-stdlib=libc++
-fmodules-ts
# -fmodules-ts
)
elseif(UNIX) # Only for Unix/Linux
target_include_directories(${PROJECT_NAME}
PRIVATE
${PROJECT_DIR}/prebuilt/include/c++/v1/
)
target_compile_options(${PROJECT_NAME}
PRIVATE
# For manual libc++ configuration
-nostdinc++ -nodefaultlibs
)
target_link_libraries(${PROJECT_NAME}
PUBLIC
${PROJECT_DIR}/prebuilt/lib/libc++.so
${PROJECT_DIR}/prebuilt/lib/libc++experimental.a
)
# target_compile_options(${PROJECT_NAME}
# PRIVATE
# # For manual libc++ configuration
# -nostdinc++ -nodefaultlibs
# )

# target_link_libraries(${PROJECT_NAME}
# PUBLIC
# ${PROJECT_DIR}/prebuilt/lib/libc++.so
# ${PROJECT_DIR}/prebuilt/lib/libc++experimental.a
# )
endif()
target_link_libraries(${PROJECT_NAME}
PUBLIC
Expand Down Expand Up @@ -177,6 +273,10 @@ endif()

# [cppmagic_test]: Test suite for Non-Windows

# if(NOT BUILD_TESTS)
# return()
# endif()

set(TEST_NAME ${PROJECT_NAME}_test)

add_executable(${TEST_NAME}
Expand Down
4 changes: 1 addition & 3 deletions ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,15 @@ Auto**magic**ally working C++ Coroutine: [Documentation](https://github.com/lunc

## Build
For detailed build steps, reference [`.travis.yml`](/.travis.yml) and [`appveyor.yml`](/appveyor.yml).
- [Travis CI Docs](https://docs.travis-ci.com/user/languages/cpp/)
- [AppVeyor Docs](https://www.appveyor.com/docs/)

#### Visual Studio 2017(vc141)
- compiler option: [`/await`](https://blogs.msdn.microsoft.com/vcblog/2015/04/29/more-about-resumable-functions-in-c/)
- compiler option: `/std:c++latest`

#### Clang 6 for Windows
Install following packages with [Chocolaty](https://chocolatey.org/). Uses CMake for project generation.
- Chocolaty [LLVM package](https://chocolatey.org/packages/llvm)
- Chocolaty [Ninja package](https://chocolatey.org/packages/ninja)
- Uses CMake for project generation

#### Clang for Linux
Since libc++ apt package doesn't contain experimental headers, the build steps [downloads libc++ and build with them](https://libcxx.llvm.org/docs/BuildingLibcxx.html).
Expand Down
3 changes: 3 additions & 0 deletions android/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="github.luncliff" />
Empty file added android/assets/.gitignore
Empty file.
Empty file added android/java/.gitignore
Empty file.
Empty file added android/jni/.gitignore
Empty file.
2 changes: 2 additions & 0 deletions android/jni/adapter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#include "adapter.h"

6 changes: 6 additions & 0 deletions android/jni/adapter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#pragma once

#include <jni.h>

// ...

Empty file added android/test/.gitignore
Empty file.
Loading

0 comments on commit 0f23e79

Please sign in to comment.