blob: 57b97f1054e7439ecd0b48a1433c870a2fc546fe [file] [log] [blame]
Pascal Bachd5f87e12014-12-12 15:59:17 +01001#
2# Licensed to the Apache Software Foundation (ASF) under one
3# or more contributor license agreements. See the NOTICE file
4# distributed with this work for additional information
5# regarding copyright ownership. The ASF licenses this file
6# to you under the Apache License, Version 2.0 (the
7# "License"); you may not use this file except in compliance
8# with the License. You may obtain a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing,
13# software distributed under the License is distributed on an
14# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15# KIND, either express or implied. See the License for the
16# specific language governing permissions and limitations
17# under the License.
18#
19
Nobuaki Sukegawaca939362015-11-14 00:23:40 +090020file(GLOB java_sources src/**/*.java)
Pascal Bachd5f87e12014-12-12 15:59:17 +010021
Nobuaki Sukegawaca939362015-11-14 00:23:40 +090022if(ANDROID)
23 set(android_sources
24 android/build.gradle
25 android/settings.gradle
26 android/src/main/AndroidManifest.xml
27 )
28 set(THRIFT_AAR outputs/aar/thrift-debug.aar outputs/aar/thrift-release.aar)
29 add_custom_command(
30 OUTPUT ${THRIFT_AAR}
Nobuaki Sukegawaaa7d0d52016-02-27 03:04:34 +090031 COMMAND ${GRADLE_EXECUTABLE} -p"${CMAKE_CURRENT_SOURCE_DIR}/android" -PbuildDir="${CMAKE_CURRENT_BINARY_DIR}" assemble
Nobuaki Sukegawaca939362015-11-14 00:23:40 +090032 DEPENDS ${java_sources} ${android_sources})
33 add_custom_target(thrift_aar ALL DEPENDS ${THRIFT_AAR})
Pascal Bachd5f87e12014-12-12 15:59:17 +010034
Nobuaki Sukegawaca939362015-11-14 00:23:40 +090035else(ANDROID)
Pascal Bachd5f87e12014-12-12 15:59:17 +010036
Nobuaki Sukegawaca939362015-11-14 00:23:40 +090037 if(IS_ABSOLUTE "${LIB_INSTALL_DIR}")
38 set(JAVA_INSTALL_DIR "${LIB_INSTALL_DIR}/java")
39 else()
40 set(JAVA_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/${LIB_INSTALL_DIR}/java")
41 endif()
Pascal Bachd5f87e12014-12-12 15:59:17 +010042
Nobuaki Sukegawaca939362015-11-14 00:23:40 +090043 if(IS_ABSOLUTE "${DOC_INSTALL_DIR}")
44 set(JAVA_DOC_INSTALL_DIR "${DOC_INSTALL_DIR}/java")
45 else()
46 set(JAVA_DOC_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/${DOC_INSTALL_DIR}/java")
47 endif()
48
Nobuaki Sukegawaaa7d0d52016-02-27 03:04:34 +090049 file(GLOB_RECURSE ThriftJava_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/*.java)
50 set(ThriftJava_ARTIFACTS
51 libthrift-${thrift_VERSION}.jar
52 libthrift-${thrift_VERSION}.pom
53 )
54 add_custom_command(
55 OUTPUT ${ThriftJava_ARTIFACTS}
56 COMMAND ${Ant_EXECUTABLE} ${ANT_FLAGS} -Dbuild.dir="${CMAKE_CURRENT_BINARY_DIR}" -f build.xml
57 MAIN_DEPENDENCY ${CMAKE_CURRENT_SOURCE_DIR}/build.xml
58 DEPENDS ${ThriftJava_SOURCES}
Nobuaki Sukegawaca939362015-11-14 00:23:40 +090059 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
Nobuaki Sukegawaaa7d0d52016-02-27 03:04:34 +090060 )
61
62 add_custom_target(ThriftJava ALL
Nobuaki Sukegawaca939362015-11-14 00:23:40 +090063 COMMENT "Building Java library using Ant"
Nobuaki Sukegawaaa7d0d52016-02-27 03:04:34 +090064 DEPENDS ${ThriftJava_ARTIFACTS}
Nobuaki Sukegawaca939362015-11-14 00:23:40 +090065 )
66
67 # Hook the ant install task into CMake install
68 install(CODE "execute_process(
69 COMMAND ${Ant_EXECUTABLE} ${ANT_FLAGS} install
Nobuaki Sukegawaaa7d0d52016-02-27 03:04:34 +090070 -Dbuild.dir=\"${CMAKE_CURRENT_BINARY_DIR}\"
71 -Dinstall.path=\"${JAVA_INSTALL_DIR}\" -Dinstall.javadoc.path=\"${JAVA_DOC_INSTALL_DIR}\" -f build.xml
Nobuaki Sukegawaca939362015-11-14 00:23:40 +090072 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
73 )")
74
75 if(BUILD_TESTING)
Nobuaki Sukegawaaa7d0d52016-02-27 03:04:34 +090076 add_test(NAME JavaTest
77 COMMAND ${Ant_EXECUTABLE} ${ANT_FLAGS} -Dbuild.dir="${CMAKE_CURRENT_BINARY_DIR}" -Dthrift.compiler="${THRIFT_COMPILER}" -f build.xml test
78 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
Nobuaki Sukegawaca939362015-11-14 00:23:40 +090079 endif()
80endif(ANDROID)