THRIFT-3424 Add CMake android build option
Client: Build
Patch: Nobuaki Sukegawa
This closes #696
diff --git a/lib/c_glib/test/CMakeLists.txt b/lib/c_glib/test/CMakeLists.txt
index 1b32c46..bd5d1ee 100644
--- a/lib/c_glib/test/CMakeLists.txt
+++ b/lib/c_glib/test/CMakeLists.txt
@@ -138,13 +138,13 @@
gen-c_glib/t_test_service_for_exception_with_a_map.h
gen-c_glib/t_test_srv.c
gen-c_glib/t_test_srv.h
- COMMAND thrift-compiler --gen c_glib ${PROJECT_SOURCE_DIR}/test/DebugProtoTest.thrift
+ COMMAND ${THRIFT_COMPILER} --gen c_glib ${PROJECT_SOURCE_DIR}/test/DebugProtoTest.thrift
)
add_custom_command(OUTPUT
gen-c_glib/t_test_optional_required_test_types.c
gen-c_glib/t_test_optional_required_test_types.h
- COMMAND thrift-compiler --gen c_glib ${PROJECT_SOURCE_DIR}/test/OptionalRequiredTest.thrift
+ COMMAND ${THRIFT_COMPILER} --gen c_glib ${PROJECT_SOURCE_DIR}/test/OptionalRequiredTest.thrift
)
add_custom_command(OUTPUT
@@ -154,7 +154,7 @@
gen-c_glib/t_test_second_service.h
gen-c_glib/t_test_thrift_test.h
gen-c_glib/t_test_thrift_test_types.h
- COMMAND thrift-compiler --gen c_glib ${PROJECT_SOURCE_DIR}/test/ThriftTest.thrift
+ COMMAND ${THRIFT_COMPILER} --gen c_glib ${PROJECT_SOURCE_DIR}/test/ThriftTest.thrift
)
add_custom_command(OUTPUT
@@ -164,7 +164,7 @@
gen-cpp/ThriftTest.h
gen-cpp/ThriftTest_constants.h
gen-cpp/ThriftTest_types.h
- COMMAND thrift-compiler --gen cpp ${PROJECT_SOURCE_DIR}/test/ThriftTest.thrift
+ COMMAND ${THRIFT_COMPILER} --gen cpp ${PROJECT_SOURCE_DIR}/test/ThriftTest.thrift
)
# TODO: Add memory checks using ctest_memcheck or similar
diff --git a/lib/cpp/CMakeLists.txt b/lib/cpp/CMakeLists.txt
index a0b9743..9404112 100755
--- a/lib/cpp/CMakeLists.txt
+++ b/lib/cpp/CMakeLists.txt
@@ -46,7 +46,6 @@
src/thrift/protocol/TJSONProtocol.cpp
src/thrift/protocol/TMultiplexedProtocol.cpp
src/thrift/protocol/TProtocol.cpp
- src/thrift/protocol/THeaderProtocol.cpp
src/thrift/transport/TTransportException.cpp
src/thrift/transport/TFDTransport.cpp
src/thrift/transport/TSimpleFileTransport.cpp
@@ -58,7 +57,6 @@
src/thrift/transport/TServerSocket.cpp
src/thrift/transport/TTransportUtils.cpp
src/thrift/transport/TBufferTransports.cpp
- src/thrift/transport/THeaderTransport.cpp
src/thrift/server/TConnectedClient.cpp
src/thrift/server/TServerFramework.cpp
src/thrift/server/TSimpleServer.cpp
@@ -119,7 +117,11 @@
)
list(APPEND SYSLIBS "${Boost_LIBRARIES}")
elseif(UNIX AND NOT WITH_STDTHREADS)
- list(APPEND SYSLIBS pthread)
+ if(ANDROID)
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
+ else()
+ list(APPEND SYSLIBS pthread)
+ endif()
set( thriftcpp_threads_SOURCES
src/thrift/concurrency/PosixThreadFactory.cpp
src/thrift/concurrency/Mutex.cpp
@@ -127,8 +129,11 @@
)
else()
if(UNIX)
- # need pthread for multi-thread support
- list(APPEND SYSLIBS pthread)
+ if(ANDROID)
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
+ else()
+ list(APPEND SYSLIBS pthread)
+ endif()
endif()
set( thriftcpp_threads_SOURCES
src/thrift/concurrency/StdThreadFactory.cpp
@@ -150,6 +155,8 @@
src/thrift/transport/TZlibTransport.cpp
src/thrift/protocol/THeaderProtocol.cpp
src/thrift/transport/THeaderTransport.cpp
+ src/thrift/protocol/THeaderProtocol.cpp
+ src/thrift/transport/THeaderTransport.cpp
)
# Thrift Qt4 server
diff --git a/lib/cpp/test/CMakeLists.txt b/lib/cpp/test/CMakeLists.txt
index 033b4d2..02932cb 100644
--- a/lib/cpp/test/CMakeLists.txt
+++ b/lib/cpp/test/CMakeLists.txt
@@ -347,33 +347,33 @@
add_custom_command(OUTPUT gen-cpp/DebugProtoTest_types.cpp gen-cpp/DebugProtoTest_types.h gen-cpp/EmptyService.cpp gen-cpp/EmptyService.h
- COMMAND thrift-compiler --gen cpp ${PROJECT_SOURCE_DIR}/test/DebugProtoTest.thrift
+ COMMAND ${THRIFT_COMPILER} --gen cpp ${PROJECT_SOURCE_DIR}/test/DebugProtoTest.thrift
)
add_custom_command(OUTPUT gen-cpp/EnumTest_types.cpp gen-cpp/EnumTest_types.h
- COMMAND thrift-compiler --gen cpp ${PROJECT_SOURCE_DIR}/test/EnumTest.thrift
+ COMMAND ${THRIFT_COMPILER} --gen cpp ${PROJECT_SOURCE_DIR}/test/EnumTest.thrift
)
add_custom_command(OUTPUT gen-cpp/TypedefTest_types.cpp gen-cpp/TypedefTest_types.h
- COMMAND thrift-compiler --gen cpp ${PROJECT_SOURCE_DIR}/test/TypedefTest.thrift
+ COMMAND ${THRIFT_COMPILER} --gen cpp ${PROJECT_SOURCE_DIR}/test/TypedefTest.thrift
)
add_custom_command(OUTPUT gen-cpp/OptionalRequiredTest_types.cpp gen-cpp/OptionalRequiredTest_types.h
- COMMAND thrift-compiler --gen cpp ${PROJECT_SOURCE_DIR}/test/OptionalRequiredTest.thrift
+ COMMAND ${THRIFT_COMPILER} --gen cpp ${PROJECT_SOURCE_DIR}/test/OptionalRequiredTest.thrift
)
add_custom_command(OUTPUT gen-cpp/Recursive_types.cpp gen-cpp/Recursive_types.h
- COMMAND thrift-compiler --gen cpp ${PROJECT_SOURCE_DIR}/test/Recursive.thrift
+ COMMAND ${THRIFT_COMPILER} --gen cpp ${PROJECT_SOURCE_DIR}/test/Recursive.thrift
)
add_custom_command(OUTPUT gen-cpp/Service.cpp gen-cpp/StressTest_types.cpp
- COMMAND thrift-compiler --gen cpp ${PROJECT_SOURCE_DIR}/test/StressTest.thrift
+ COMMAND ${THRIFT_COMPILER} --gen cpp ${PROJECT_SOURCE_DIR}/test/StressTest.thrift
)
add_custom_command(OUTPUT gen-cpp/SecondService.cpp gen-cpp/ThriftTest_constants.cpp gen-cpp/ThriftTest.cpp gen-cpp/ThriftTest_types.cpp gen-cpp/ThriftTest_types.h
- COMMAND thrift-compiler --gen cpp ${PROJECT_SOURCE_DIR}/test/ThriftTest.thrift
+ COMMAND ${THRIFT_COMPILER} --gen cpp ${PROJECT_SOURCE_DIR}/test/ThriftTest.thrift
)
add_custom_command(OUTPUT gen-cpp/ChildService.cpp gen-cpp/ChildService.h gen-cpp/ParentService.cpp gen-cpp/ParentService.h gen-cpp/proc_types.cpp gen-cpp/proc_types.h
- COMMAND thrift-compiler --gen cpp:templates,cob_style ${CMAKE_CURRENT_SOURCE_DIR}/processor/proc.thrift
+ COMMAND ${THRIFT_COMPILER} --gen cpp:templates,cob_style ${CMAKE_CURRENT_SOURCE_DIR}/processor/proc.thrift
)
diff --git a/lib/java/CMakeLists.txt b/lib/java/CMakeLists.txt
index ba11f34..2014f5c 100644
--- a/lib/java/CMakeLists.txt
+++ b/lib/java/CMakeLists.txt
@@ -17,32 +17,50 @@
# under the License.
#
-if(IS_ABSOLUTE "${LIB_INSTALL_DIR}")
- set(JAVA_INSTALL_DIR "${LIB_INSTALL_DIR}/java")
-else()
- set(JAVA_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/${LIB_INSTALL_DIR}/java")
-endif()
+file(GLOB java_sources src/**/*.java)
-if(IS_ABSOLUTE "${DOC_INSTALL_DIR}")
- set(JAVA_DOC_INSTALL_DIR "${DOC_INSTALL_DIR}/java")
-else()
- set(JAVA_DOC_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/${DOC_INSTALL_DIR}/java")
-endif()
+if(ANDROID)
+ set(android_sources
+ android/build.gradle
+ android/settings.gradle
+ android/src/main/AndroidManifest.xml
+ )
+ set(THRIFT_AAR outputs/aar/thrift-debug.aar outputs/aar/thrift-release.aar)
+ add_custom_command(
+ OUTPUT ${THRIFT_AAR}
+ COMMAND ${GRADLE_EXECUTABLE} -p${CMAKE_CURRENT_SOURCE_DIR}/android -PbuildDir=${CMAKE_CURRENT_BINARY_DIR} assemble
+ DEPENDS ${java_sources} ${android_sources})
+ add_custom_target(thrift_aar ALL DEPENDS ${THRIFT_AAR})
-add_custom_target(ant_build ALL
- COMMAND ${Ant_EXECUTABLE} ${ANT_FLAGS} -Dbuild.dir=${CMAKE_CURRENT_BINARY_DIR} -Dworking.dir=${work_dir} -f build.xml
- WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
- COMMENT "Building Java library using Ant"
-)
+else(ANDROID)
-# Hook the ant install task into CMake install
-install(CODE "execute_process(
- COMMAND ${Ant_EXECUTABLE} ${ANT_FLAGS} install
- -Dbuild.dir=${CMAKE_CURRENT_BINARY_DIR} -Dworking.dir=${work_dir}
- -Dinstall.path=${JAVA_INSTALL_DIR} -Dinstall.javadoc.path=${JAVA_DOC_INSTALL_DIR} -f build.xml
- WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
-)")
+ if(IS_ABSOLUTE "${LIB_INSTALL_DIR}")
+ set(JAVA_INSTALL_DIR "${LIB_INSTALL_DIR}/java")
+ else()
+ set(JAVA_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/${LIB_INSTALL_DIR}/java")
+ endif()
-if(BUILD_TESTING)
- #add_subdirectory(test)
-endif()
+ if(IS_ABSOLUTE "${DOC_INSTALL_DIR}")
+ set(JAVA_DOC_INSTALL_DIR "${DOC_INSTALL_DIR}/java")
+ else()
+ set(JAVA_DOC_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/${DOC_INSTALL_DIR}/java")
+ endif()
+
+ add_custom_target(ant_build ALL
+ COMMAND ${Ant_EXECUTABLE} ${ANT_FLAGS} -Dbuild.dir=${CMAKE_CURRENT_BINARY_DIR} -Dworking.dir=${work_dir} -f build.xml
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+ COMMENT "Building Java library using Ant"
+ )
+
+ # Hook the ant install task into CMake install
+ install(CODE "execute_process(
+ COMMAND ${Ant_EXECUTABLE} ${ANT_FLAGS} install
+ -Dbuild.dir=${CMAKE_CURRENT_BINARY_DIR} -Dworking.dir=${work_dir}
+ -Dinstall.path=${JAVA_INSTALL_DIR} -Dinstall.javadoc.path=${JAVA_DOC_INSTALL_DIR} -f build.xml
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+ )")
+
+ if(BUILD_TESTING)
+ #add_subdirectory(test)
+ endif()
+endif(ANDROID)
diff --git a/lib/java/android/build.gradle b/lib/java/android/build.gradle
new file mode 100644
index 0000000..4aa2864
--- /dev/null
+++ b/lib/java/android/build.gradle
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+apply plugin: 'com.android.library'
+
+android {
+ compileSdkVersion 23
+ buildToolsVersion "23.0.1"
+ useLibrary 'org.apache.http.legacy'
+ sourceSets.main.java {
+ srcDir '../src'
+ exclude 'org/apache/thrift/transport/TSaslClientTransport.java'
+ exclude 'org/apache/thrift/transport/TSaslServerTransport.java'
+ exclude 'org/apache/thrift/transport/TSaslTransport.java'
+ }
+}
+
+repositories {
+ mavenCentral()
+}
+dependencies {
+ compile 'org.slf4j:slf4j-api:1.7.13'
+ compile 'javax.servlet:servlet-api:2.5'
+ compile 'org.apache.httpcomponents:httpcore:4.4.4'
+}
+
+buildscript {
+ repositories {
+ mavenCentral()
+ }
+ dependencies {
+ classpath 'com.android.tools.build:gradle:1.5.0'
+ }
+}
diff --git a/lib/java/android/settings.gradle b/lib/java/android/settings.gradle
new file mode 100644
index 0000000..75e97be
--- /dev/null
+++ b/lib/java/android/settings.gradle
@@ -0,0 +1 @@
+rootProject.name='thrift'
diff --git a/lib/java/android/src/main/AndroidManifest.xml b/lib/java/android/src/main/AndroidManifest.xml
new file mode 100644
index 0000000..43abdb7
--- /dev/null
+++ b/lib/java/android/src/main/AndroidManifest.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest package="org.apache.thrift">
+ <application />
+</manifest>