blob: 46064e6008a6a5d498631367ef41833ff392612b [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 +090020if(ANDROID)
Nobuaki Sukegawaca939362015-11-14 00:23:40 +090021 set(THRIFT_AAR outputs/aar/thrift-debug.aar outputs/aar/thrift-release.aar)
22 add_custom_command(
23 OUTPUT ${THRIFT_AAR}
Alex Volanis7004a612018-01-24 10:30:13 -050024 COMMAND ${GRADLE_EXECUTABLE}
25 -p "${CMAKE_CURRENT_SOURCE_DIR}/android"
26 "-PbuildDir=${CMAKE_CURRENT_BINARY_DIR}/android/build" assemble
27 )
Nobuaki Sukegawaca939362015-11-14 00:23:40 +090028 add_custom_target(thrift_aar ALL DEPENDS ${THRIFT_AAR})
Pascal Bachd5f87e12014-12-12 15:59:17 +010029
Nobuaki Sukegawaca939362015-11-14 00:23:40 +090030else(ANDROID)
Pascal Bachd5f87e12014-12-12 15:59:17 +010031
Nobuaki Sukegawaca939362015-11-14 00:23:40 +090032 if(IS_ABSOLUTE "${LIB_INSTALL_DIR}")
33 set(JAVA_INSTALL_DIR "${LIB_INSTALL_DIR}/java")
34 else()
35 set(JAVA_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/${LIB_INSTALL_DIR}/java")
36 endif()
Pascal Bachd5f87e12014-12-12 15:59:17 +010037
Nobuaki Sukegawaca939362015-11-14 00:23:40 +090038 if(IS_ABSOLUTE "${DOC_INSTALL_DIR}")
39 set(JAVA_DOC_INSTALL_DIR "${DOC_INSTALL_DIR}/java")
40 else()
41 set(JAVA_DOC_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/${DOC_INSTALL_DIR}/java")
42 endif()
43
Nobuaki Sukegawaaa7d0d52016-02-27 03:04:34 +090044 add_custom_target(ThriftJava ALL
Alex Volanis7004a612018-01-24 10:30:13 -050045 COMMENT "Building Java library using Gradle Wrapper"
46 COMMAND ${GRADLEW_EXECUTABLE} ${GRADLE_OPTS} assemble
47 --console=plain --no-daemon
48 -Prelease=true
49 -Pthrift.version=${thrift_VERSION}
50 "-Pbuild.dir=${CMAKE_CURRENT_BINARY_DIR}/build"
51 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
Nobuaki Sukegawaca939362015-11-14 00:23:40 +090052 )
53
Alex Volanis7004a612018-01-24 10:30:13 -050054 # Enable publishing from CMake if the publishing information is provided
55 add_custom_target(MavenPublish
56 COMMENT "Publishing Java Library to Apache Maven staging"
57 COMMAND ${GRADLEW_EXECUTABLE} ${GRADLE_OPTS} clean uploadArchives
58 --console=plain --no-daemon
59 -Prelease=true
60 -Pthrift.version=${thrift_VERSION}
61 "-Pbuild.dir=${CMAKE_CURRENT_BINARY_DIR}/build"
Nobuaki Sukegawaca939362015-11-14 00:23:40 +090062 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
Alex Volanis7004a612018-01-24 10:30:13 -050063 )
64
65 # Hook the CMake install process to the results from make ALL.
66 # This works best when 'make all && sudo make install/fast' is used.
67 # Using slash to end the source location to avoid copying the directory path.
68 install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/build/libs/
69 DESTINATION ${JAVA_INSTALL_DIR}
70 FILES_MATCHING PATTERN "libthrift-${thrift_VERSION}.jar")
71 install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/build/deps/
72 DESTINATION ${JAVA_INSTALL_DIR}
73 FILES_MATCHING PATTERN "*.jar")
74 install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/build/docs/javadoc/
75 DESTINATION ${JAVA_DOC_INSTALL_DIR})
Nobuaki Sukegawaca939362015-11-14 00:23:40 +090076
77 if(BUILD_TESTING)
Nobuaki Sukegawaaa7d0d52016-02-27 03:04:34 +090078 add_test(NAME JavaTest
Alex Volanis7004a612018-01-24 10:30:13 -050079 COMMAND ${GRADLEW_EXECUTABLE} ${GRADLE_OPTS} test
80 --console=plain --no-daemon
81 -Prelease=true
82 -Pthrift.version=${thrift_VERSION}
83 "-Pbuild.dir=${CMAKE_CURRENT_BINARY_DIR}/build"
84 "-Pthrift.compiler=${THRIFT_COMPILER}"
85 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
Nobuaki Sukegawaca939362015-11-14 00:23:40 +090086 endif()
87endif(ANDROID)