blob: b9bfc8175ddb33ad0bd8501c79d481a618089e8e [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
Mario Emmenlauer037916b2020-05-11 16:19:44 +020051 file(GLOB_RECURSE THRIFTJAVA_SOURCES LIST_DIRECTORIES false
52 "${CMAKE_CURRENT_SOURCE_DIR}/src/*")
53 add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/build/libs/libthrift.jar"
Alex Volanis7004a612018-01-24 10:30:13 -050054 COMMENT "Building Java library using Gradle Wrapper"
55 COMMAND ${GRADLEW_EXECUTABLE} ${GRADLE_OPTS} assemble
56 --console=plain --no-daemon
James E. King III98f379e2019-01-22 09:22:04 -050057 -Prelease=${PRELEASE}
Alex Volanis7004a612018-01-24 10:30:13 -050058 -Pthrift.version=${thrift_VERSION}
59 "-Pbuild.dir=${CMAKE_CURRENT_BINARY_DIR}/build"
Mario Emmenlauer037916b2020-05-11 16:19:44 +020060 DEPENDS ${THRIFTJAVA_SOURCES}
Alex Volanis7004a612018-01-24 10:30:13 -050061 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
Nobuaki Sukegawaca939362015-11-14 00:23:40 +090062 )
Mario Emmenlauer037916b2020-05-11 16:19:44 +020063 add_custom_target(ThriftJava ALL
64 DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/build/libs/libthrift.jar")
Nobuaki Sukegawaca939362015-11-14 00:23:40 +090065
Alex Volanis7004a612018-01-24 10:30:13 -050066 # Enable publishing from CMake if the publishing information is provided
67 add_custom_target(MavenPublish
68 COMMENT "Publishing Java Library to Apache Maven staging"
Mario Emmenlauer037916b2020-05-11 16:19:44 +020069 DEPENDS ThriftJava
Alex Volanis7004a612018-01-24 10:30:13 -050070 COMMAND ${GRADLEW_EXECUTABLE} ${GRADLE_OPTS} clean uploadArchives
71 --console=plain --no-daemon
James E. King III98f379e2019-01-22 09:22:04 -050072 -Prelease=${PRELEASE}
Alex Volanis7004a612018-01-24 10:30:13 -050073 -Pthrift.version=${thrift_VERSION}
74 "-Pbuild.dir=${CMAKE_CURRENT_BINARY_DIR}/build"
Nobuaki Sukegawaca939362015-11-14 00:23:40 +090075 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
Alex Volanis7004a612018-01-24 10:30:13 -050076 )
77
78 # Hook the CMake install process to the results from make ALL.
79 # This works best when 'make all && sudo make install/fast' is used.
80 # Using slash to end the source location to avoid copying the directory path.
81 install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/build/libs/
82 DESTINATION ${JAVA_INSTALL_DIR}
83 FILES_MATCHING PATTERN "libthrift-${thrift_VERSION}.jar")
84 install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/build/deps/
85 DESTINATION ${JAVA_INSTALL_DIR}
86 FILES_MATCHING PATTERN "*.jar")
87 install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/build/docs/javadoc/
88 DESTINATION ${JAVA_DOC_INSTALL_DIR})
Nobuaki Sukegawaca939362015-11-14 00:23:40 +090089
90 if(BUILD_TESTING)
Nobuaki Sukegawaaa7d0d52016-02-27 03:04:34 +090091 add_test(NAME JavaTest
Mario Emmenlauer037916b2020-05-11 16:19:44 +020092 COMMAND ${GRADLEW_EXECUTABLE} ${GRADLE_OPTS} test
93 --console=plain --no-daemon
94 -Prelease=${PRELEASE}
95 -Pthrift.version=${thrift_VERSION}
96 "-Pbuild.dir=${CMAKE_CURRENT_BINARY_DIR}/build"
97 "-Pthrift.compiler=${THRIFT_COMPILER}"
98 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
Nobuaki Sukegawaca939362015-11-14 00:23:40 +090099 endif()
James E. King III98f379e2019-01-22 09:22:04 -0500100
101endif()