Skip to content

Commit cbabf9f

Browse files
committed
Add contrib/thrift-maven-plugin to CMake build process.
1 parent 3bfd72c commit cbabf9f

File tree

4 files changed

+126
-0
lines changed

4 files changed

+126
-0
lines changed

CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,12 @@ if(BUILD_PYTHON)
128128
endif()
129129
endif()
130130

131+
if(BUILD_CONTRIB)
132+
if(BUILD_MAVEN_PLUGIN)
133+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/contrib/thrift-maven-plugin)
134+
endif()
135+
endif()
136+
131137
# Create the uninstall target
132138
add_custom_target(uninstall "${CMAKE_COMMAND}" -P "${PROJECT_SOURCE_DIR}/build/cmake/uninstall.cmake")
133139

build/cmake/DefineOptions.cmake

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ endif()
3131
CMAKE_DEPENDENT_OPTION(BUILD_TESTING "Build with unit tests" ON "HAVE_COMPILER" OFF)
3232
CMAKE_DEPENDENT_OPTION(BUILD_TUTORIALS "Build Thrift tutorials" ON "HAVE_COMPILER" OFF)
3333
option(BUILD_LIBRARIES "Build Thrift libraries" ON)
34+
option(BUILD_CONTRIB "Build Thrift contrib" ON)
3435

3536
# Libraries to build
3637

@@ -125,6 +126,13 @@ find_package(Python3
125126
CMAKE_DEPENDENT_OPTION(BUILD_PYTHON "Build Python library" ON
126127
"BUILD_LIBRARIES;WITH_PYTHON;Python3_Interpreter_FOUND;Python3_Development_FOUND" OFF)
127128

129+
## Maven Plugin
130+
option(WITH_MAVEN_PLUGIN "Build Maven plugin" ON)
131+
find_package(Java QUIET)
132+
find_package(Maven QUIET)
133+
CMAKE_DEPENDENT_OPTION(BUILD_MAVEN_PLUGIN "Build Maven plugin" ON
134+
"BUILD_CONTRIB;WITH_JAVA;JAVA_FOUND;MAVEN_FOUND" OFF)
135+
128136
# Common library options
129137
# https://cmake.org/cmake/help/latest/variable/BUILD_SHARED_LIBS.html
130138
# Default on Windows is static, shared mode library support needs work...
@@ -167,6 +175,8 @@ message(STATUS " Build compiler: ${BUILD_COMPILER}"
167175
message(STATUS " Build libraries: ${BUILD_LIBRARIES}")
168176
message(STATUS " Build tests: ${BUILD_TESTING}")
169177
MESSAGE_DEP(HAVE_COMPILER "Disabled because BUILD_COMPILER=OFF and no valid THRIFT_COMPILER is given")
178+
message(STATUS " Build contrib: ${BUILD_CONTRIB}")
179+
MESSAGE_DEP(BUILD_CONTRIB "Disabled because BUILD_CONTRIB=OFF")
170180
message(STATUS " Build type: ${CMAKE_BUILD_TYPE}")
171181
message(STATUS)
172182
message(STATUS "Language libraries:")
@@ -218,6 +228,12 @@ if(MSVC)
218228
message(STATUS " Using static runtime library: ${WITH_MT}")
219229
endif(MSVC)
220230
message(STATUS)
231+
message(STATUS "Contributed:")
232+
message(STATUS)
233+
message(STATUS " Build Maven plugin: ${BUILD_MAVEN_PLUGIN}")
234+
MESSAGE_DEP(WITH_MAVEN_PLUGIN "Disabled by WITH_MAVEN_PLUGIN=OFF")
235+
MESSAGE_DEP(JAVA_FOUND "Java Runtime missing")
236+
MESSAGE_DEP(MAVEN_FOUND "Maven missing")
221237
message(STATUS)
222238
message(STATUS "----------------------------------------------------------")
223239
endmacro(PRINT_CONFIG_SUMMARY)

build/cmake/FindMaven.cmake

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#
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+
20+
21+
# MAVEN_FOUND - system has Maven
22+
# MAVEN_EXECUTABLE - the Maven executable
23+
#
24+
# It will search the environment variable MAVEN_HOME if it is set
25+
26+
include(FindPackageHandleStandardArgs)
27+
28+
find_program(MAVEN_EXECUTABLE NAMES mvn PATHS $ENV{MAVEN_HOME}/bin NO_CMAKE_FIND_ROOT_PATH)
29+
find_package_handle_standard_args(Maven DEFAULT_MSG MAVEN_EXECUTABLE)
30+
mark_as_advanced(MAVEN_EXECUTABLE)
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#
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+
20+
if(NOT THRIFTMAVENPLUGIN_INSTALL_DIR)
21+
if(IS_ABSOLUTE "${CONTRIB_INSTALL_DIR}")
22+
set(THRIFTMAVENPLUGIN_INSTALL_DIR "${CONTRIB_INSTALL_DIR}/thrift-maven-plugin")
23+
else()
24+
set(THRIFTMAVENPLUGIN_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/${CONTRIB_INSTALL_DIR}/thrift-maven-plugin")
25+
endif()
26+
endif()
27+
28+
set(PRELEASE "true")
29+
if (CMAKE_BUILD_TYPE MATCHES DEBUG)
30+
set(PRELEASE "false")
31+
endif ()
32+
33+
set(MAVEN_OUTPUT_JAR "${CMAKE_CURRENT_SOURCE_DIR}/target/thrift-maven-plugin-${thrift_VERSION}.jar")
34+
35+
file(GLOB_RECURSE THRIFTMAVENPLUGIN_SOURCES LIST_DIRECTORIES false
36+
"${CMAKE_CURRENT_SOURCE_DIR}/src/*"
37+
"${CMAKE_CURRENT_SOURCE_DIR}/pom.xml")
38+
39+
add_custom_command(OUTPUT "${MAVEN_OUTPUT_JAR}"
40+
COMMENT "Building Maven plugin using Maven"
41+
COMMAND ${MAVEN_EXECUTABLE} clean package
42+
-B -DskipTests
43+
-Drelease=${PRELEASE}
44+
-Dthrift.version=${thrift_VERSION}
45+
DEPENDS ${THRIFTMAVENPLUGIN_SOURCES}
46+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
47+
)
48+
49+
add_custom_target(ThriftMavenPlugin ALL DEPENDS "${MAVEN_OUTPUT_JAR}")
50+
51+
# Enable publishing from CMake if the publishing information is provided
52+
add_custom_target(ThriftMavenPluginMavenPublish
53+
COMMENT "Publishing Maven plugin to Apache Maven staging"
54+
DEPENDS ThriftMavenPlugin
55+
COMMAND ${MAVEN_EXECUTABLE} deploy
56+
-B -DskipTests
57+
-Drelease=${PRELEASE}
58+
-Dthrift.version=${thrift_VERSION}
59+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
60+
)
61+
62+
# Hook the CMake install process to the results from make ALL.
63+
# This works best when 'make all && sudo make install/fast' is used.
64+
install(FILES "${MAVEN_OUTPUT_JAR}" DESTINATION ${THRIFTMAVENPLUGIN_INSTALL_DIR})
65+
66+
if(BUILD_TESTING)
67+
add_test(NAME ThriftMavenPluginTest
68+
COMMAND ${MAVEN_EXECUTABLE} test
69+
-B
70+
-Drelease=${PRELEASE}
71+
-Dthrift.version=${thrift_VERSION}
72+
-Dthrift.compiler=${THRIFT_COMPILER}
73+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
74+
endif()

0 commit comments

Comments
 (0)