blob: 28158c0077618d1d016d9e92af56ca27fed1c837 [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)
James E. King III98f379e2019-01-22 09:22:04 -050021
Nobuaki Sukegawaca939362015-11-14 00:23:40 +090022 set(THRIFT_AAR outputs/aar/thrift-debug.aar outputs/aar/thrift-release.aar)
23 add_custom_command(
24 OUTPUT ${THRIFT_AAR}
Alex Volanis7004a612018-01-24 10:30:13 -050025 COMMAND ${GRADLE_EXECUTABLE}
26 -p "${CMAKE_CURRENT_SOURCE_DIR}/android"
27 "-PbuildDir=${CMAKE_CURRENT_BINARY_DIR}/android/build" assemble
28 )
Nobuaki Sukegawaca939362015-11-14 00:23:40 +090029 add_custom_target(thrift_aar ALL DEPENDS ${THRIFT_AAR})
Pascal Bachd5f87e12014-12-12 15:59:17 +010030
James E. King III98f379e2019-01-22 09:22:04 -050031else()
Mario Emmenlauer66d110b2019-04-15 13:36:02 +020032 if(NOT JAVA_INSTALL_DIR)
33 if(IS_ABSOLUTE "${LIB_INSTALL_DIR}")
34 set(JAVA_INSTALL_DIR "${LIB_INSTALL_DIR}/java")
35 else()
36 set(JAVA_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/${LIB_INSTALL_DIR}/java")
37 endif()
Nobuaki Sukegawaca939362015-11-14 00:23:40 +090038 endif()
Pascal Bachd5f87e12014-12-12 15:59:17 +010039
Nobuaki Sukegawaca939362015-11-14 00:23:40 +090040 if(IS_ABSOLUTE "${DOC_INSTALL_DIR}")
41 set(JAVA_DOC_INSTALL_DIR "${DOC_INSTALL_DIR}/java")
42 else()
43 set(JAVA_DOC_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/${DOC_INSTALL_DIR}/java")
44 endif()
45
James E. King III98f379e2019-01-22 09:22:04 -050046 set(PRELEASE "true")
47 if (CMAKE_BUILD_TYPE MATCHES DEBUG)
48 set(PRELEASE "false")
49 endif ()
50
Nobuaki Sukegawaaa7d0d52016-02-27 03:04:34 +090051 add_custom_target(ThriftJava ALL
Alex Volanis7004a612018-01-24 10:30:13 -050052 COMMENT "Building Java library using Gradle Wrapper"
53 COMMAND ${GRADLEW_EXECUTABLE} ${GRADLE_OPTS} assemble
54 --console=plain --no-daemon
James E. King III98f379e2019-01-22 09:22:04 -050055 -Prelease=${PRELEASE}
Alex Volanis7004a612018-01-24 10:30:13 -050056 -Pthrift.version=${thrift_VERSION}
57 "-Pbuild.dir=${CMAKE_CURRENT_BINARY_DIR}/build"
58 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
Nobuaki Sukegawaca939362015-11-14 00:23:40 +090059 )
60
Alex Volanis7004a612018-01-24 10:30:13 -050061 # Enable publishing from CMake if the publishing information is provided
62 add_custom_target(MavenPublish
63 COMMENT "Publishing Java Library to Apache Maven staging"
64 COMMAND ${GRADLEW_EXECUTABLE} ${GRADLE_OPTS} clean uploadArchives
65 --console=plain --no-daemon
James E. King III98f379e2019-01-22 09:22:04 -050066 -Prelease=${PRELEASE}
Alex Volanis7004a612018-01-24 10:30:13 -050067 -Pthrift.version=${thrift_VERSION}
68 "-Pbuild.dir=${CMAKE_CURRENT_BINARY_DIR}/build"
Nobuaki Sukegawaca939362015-11-14 00:23:40 +090069 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
Alex Volanis7004a612018-01-24 10:30:13 -050070 )
71
72 # Hook the CMake install process to the results from make ALL.
73 # This works best when 'make all && sudo make install/fast' is used.
74 # Using slash to end the source location to avoid copying the directory path.
75 install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/build/libs/
76 DESTINATION ${JAVA_INSTALL_DIR}
77 FILES_MATCHING PATTERN "libthrift-${thrift_VERSION}.jar")
78 install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/build/deps/
79 DESTINATION ${JAVA_INSTALL_DIR}
80 FILES_MATCHING PATTERN "*.jar")
81 install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/build/docs/javadoc/
82 DESTINATION ${JAVA_DOC_INSTALL_DIR})
Nobuaki Sukegawaca939362015-11-14 00:23:40 +090083
84 if(BUILD_TESTING)
Nobuaki Sukegawaaa7d0d52016-02-27 03:04:34 +090085 add_test(NAME JavaTest
Alex Volanis7004a612018-01-24 10:30:13 -050086 COMMAND ${GRADLEW_EXECUTABLE} ${GRADLE_OPTS} test
87 --console=plain --no-daemon
James E. King III98f379e2019-01-22 09:22:04 -050088 -Prelease=${PRELEASE}
Alex Volanis7004a612018-01-24 10:30:13 -050089 -Pthrift.version=${thrift_VERSION}
90 "-Pbuild.dir=${CMAKE_CURRENT_BINARY_DIR}/build"
91 "-Pthrift.compiler=${THRIFT_COMPILER}"
92 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
Nobuaki Sukegawaca939362015-11-14 00:23:40 +090093 endif()
James E. King III98f379e2019-01-22 09:22:04 -050094
95endif()