blob: a67845aba5da04c890a37855b94ddc4d677466bf [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()
Pascal Bachd5f87e12014-12-12 15:59:17 +010032
Nobuaki Sukegawaca939362015-11-14 00:23:40 +090033 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()
Pascal Bachd5f87e12014-12-12 15:59:17 +010038
Nobuaki Sukegawaca939362015-11-14 00:23:40 +090039 if(IS_ABSOLUTE "${DOC_INSTALL_DIR}")
40 set(JAVA_DOC_INSTALL_DIR "${DOC_INSTALL_DIR}/java")
41 else()
42 set(JAVA_DOC_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/${DOC_INSTALL_DIR}/java")
43 endif()
44
James E. King III98f379e2019-01-22 09:22:04 -050045 set(PRELEASE "true")
46 if (CMAKE_BUILD_TYPE MATCHES DEBUG)
47 set(PRELEASE "false")
48 endif ()
49
Nobuaki Sukegawaaa7d0d52016-02-27 03:04:34 +090050 add_custom_target(ThriftJava ALL
Alex Volanis7004a612018-01-24 10:30:13 -050051 COMMENT "Building Java library using Gradle Wrapper"
52 COMMAND ${GRADLEW_EXECUTABLE} ${GRADLE_OPTS} assemble
53 --console=plain --no-daemon
James E. King III98f379e2019-01-22 09:22:04 -050054 -Prelease=${PRELEASE}
Alex Volanis7004a612018-01-24 10:30:13 -050055 -Pthrift.version=${thrift_VERSION}
56 "-Pbuild.dir=${CMAKE_CURRENT_BINARY_DIR}/build"
57 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
Nobuaki Sukegawaca939362015-11-14 00:23:40 +090058 )
59
Alex Volanis7004a612018-01-24 10:30:13 -050060 # Enable publishing from CMake if the publishing information is provided
61 add_custom_target(MavenPublish
62 COMMENT "Publishing Java Library to Apache Maven staging"
63 COMMAND ${GRADLEW_EXECUTABLE} ${GRADLE_OPTS} clean uploadArchives
64 --console=plain --no-daemon
James E. King III98f379e2019-01-22 09:22:04 -050065 -Prelease=${PRELEASE}
Alex Volanis7004a612018-01-24 10:30:13 -050066 -Pthrift.version=${thrift_VERSION}
67 "-Pbuild.dir=${CMAKE_CURRENT_BINARY_DIR}/build"
Nobuaki Sukegawaca939362015-11-14 00:23:40 +090068 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
Alex Volanis7004a612018-01-24 10:30:13 -050069 )
70
71 # Hook the CMake install process to the results from make ALL.
72 # This works best when 'make all && sudo make install/fast' is used.
73 # Using slash to end the source location to avoid copying the directory path.
74 install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/build/libs/
75 DESTINATION ${JAVA_INSTALL_DIR}
76 FILES_MATCHING PATTERN "libthrift-${thrift_VERSION}.jar")
77 install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/build/deps/
78 DESTINATION ${JAVA_INSTALL_DIR}
79 FILES_MATCHING PATTERN "*.jar")
80 install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/build/docs/javadoc/
81 DESTINATION ${JAVA_DOC_INSTALL_DIR})
Nobuaki Sukegawaca939362015-11-14 00:23:40 +090082
83 if(BUILD_TESTING)
Nobuaki Sukegawaaa7d0d52016-02-27 03:04:34 +090084 add_test(NAME JavaTest
Alex Volanis7004a612018-01-24 10:30:13 -050085 COMMAND ${GRADLEW_EXECUTABLE} ${GRADLE_OPTS} test
86 --console=plain --no-daemon
James E. King III98f379e2019-01-22 09:22:04 -050087 -Prelease=${PRELEASE}
Alex Volanis7004a612018-01-24 10:30:13 -050088 -Pthrift.version=${thrift_VERSION}
89 "-Pbuild.dir=${CMAKE_CURRENT_BINARY_DIR}/build"
90 "-Pthrift.compiler=${THRIFT_COMPILER}"
91 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
Nobuaki Sukegawaca939362015-11-14 00:23:40 +090092 endif()
James E. King III98f379e2019-01-22 09:22:04 -050093
94endif()