Skip to content

Commit aa7d0d5

Browse files
committed
THRIFT-3677 Improve CMake Java build
This closes apache#897
1 parent 6bbc9e3 commit aa7d0d5

File tree

4 files changed

+42
-22
lines changed

4 files changed

+42
-22
lines changed

appveyor.yml

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,27 +53,32 @@ install:
5353
- move *.h include\
5454
- cd ..
5555
- cinst winflexbison
56-
- cinst nsis
57-
# TODO: Enable Java build
5856
# - cinst ant -ignoreDependencies
57+
- cd \
58+
- appveyor DownloadFile http://www.us.apache.org/dist//ant/binaries/apache-ant-1.9.6-bin.zip
59+
- 7z x apache-ant-1.9.6-bin.zip
60+
- cd %APPVEYOR_BUILD_FOLDER%
5961
# TODO: Enable Haskell build
6062
# - cinst HaskellPlatform -version 2014.2.0.0
6163

6264

6365
build_script:
64-
# - set PATH=C:\ProgramData\chocolatey\bin;C:\tools\apache-ant-1.9.4\bin;%PATH%
65-
# - set JAVA_HOME=C:\Program Files\Java\jdk1.7.0
66-
# - set PATH=%JAVA_HOME%\bin;%PATH%
66+
- set PATH=C:\ProgramData\chocolatey\bin;C:\apache-ant-1.9.6\bin;%PATH%
67+
- set JAVA_HOME=C:\Program Files\Java\jdk1.7.0
68+
- set PATH=%JAVA_HOME%\bin;%PATH%
6769
# - set PATH=%PATH%;C:\Program Files (x86)\Haskell Platform\2014.2.0.0\bin
6870
# - set PATH=%PATH%;C:\Program Files (x86)\Haskell Platform\2014.2.0.0\lib\extralibs\bin
6971
- set PATH=C:\Python27-x64;%PATH%
7072
- mkdir cmake-build
7173
- cd cmake-build
72-
- cmake -G "Visual Studio 14 2015 Win64" -DWITH_JAVA=OFF -DWITH_SHARED_LIB=OFF -DLIBEVENT_ROOT=%APPVEYOR_BUILD_FOLDER%\libevent-2.0.22-stable -DZLIB_INCLUDE_DIR=%APPVEYOR_BUILD_FOLDER%\zlib-1.2.8 -DZLIB_LIBRARY=%APPVEYOR_BUILD_FOLDER%\zlib-1.2.8\release\zlibstatic.lib -DBOOST_ROOT="%BOOST_ROOT% -DBOOST_LIBRARYDIR="%BOOST_LIBRARYDIR% ..
74+
- cmake -G "Visual Studio 14 2015 Win64" -DWITH_JAVA=ON -DWITH_SHARED_LIB=OFF -DLIBEVENT_ROOT=%APPVEYOR_BUILD_FOLDER%\libevent-2.0.22-stable -DZLIB_INCLUDE_DIR=%APPVEYOR_BUILD_FOLDER%\zlib-1.2.8 -DZLIB_LIBRARY=%APPVEYOR_BUILD_FOLDER%\zlib-1.2.8\release\zlibstatic.lib -DBOOST_ROOT="%BOOST_ROOT% -DBOOST_LIBRARYDIR="%BOOST_LIBRARYDIR% ..
75+
- findstr /b /e BUILD_COMPILER:BOOL=ON CMakeCache.txt
76+
- findstr /b /e BUILD_JAVA:BOOL=ON CMakeCache.txt
77+
- findstr /b /e BUILD_TESTING:BOOL=ON CMakeCache.txt
7378
# - cmake --build .
7479
- cmake --build . --config Release
7580
# TODO: Fix cpack
7681
# - cpack
77-
- ctest -C Release -VV -E "(concurrency_test|processor_test|python_test$|^Python)"
82+
- ctest -C Release -VV -E "(concurrency_test|processor_test|python_test$|^Python|^Java)"
7883

7984
#TODO make it perfect ;-r

build/cmake/CPackConfig.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
5858
"https://issues.apache.org/jira/browse/THRIFT" "Apache Thrift - Issues")
5959
set(CPACK_NSIS_CONTACT ${CPACK_PACKAGE_CONTACT})
6060
set(CPACK_NSIS_MODIFY_PATH "ON")
61-
set(CPACK_PACKAGE_INSTALL_DIRECTORY ${CPACK_PACKAGE_NAME})
61+
set(CPACK_PACKAGE_INSTALL_DIRECTORY "${CPACK_PACKAGE_NAME}")
6262
else()
6363
set(CPACK_GENERATOR "DEB" )
6464
set(CPACK_DEBIAN_PACKAGE_MAINTAINER ${CPACK_PACKAGE_CONTACT})

lib/java/CMakeLists.txt

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ if(ANDROID)
2828
set(THRIFT_AAR outputs/aar/thrift-debug.aar outputs/aar/thrift-release.aar)
2929
add_custom_command(
3030
OUTPUT ${THRIFT_AAR}
31-
COMMAND ${GRADLE_EXECUTABLE} -p${CMAKE_CURRENT_SOURCE_DIR}/android -PbuildDir=${CMAKE_CURRENT_BINARY_DIR} assemble
31+
COMMAND ${GRADLE_EXECUTABLE} -p"${CMAKE_CURRENT_SOURCE_DIR}/android" -PbuildDir="${CMAKE_CURRENT_BINARY_DIR}" assemble
3232
DEPENDS ${java_sources} ${android_sources})
3333
add_custom_target(thrift_aar ALL DEPENDS ${THRIFT_AAR})
3434

@@ -46,21 +46,35 @@ else(ANDROID)
4646
set(JAVA_DOC_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/${DOC_INSTALL_DIR}/java")
4747
endif()
4848

49-
add_custom_target(ant_build ALL
50-
COMMAND ${Ant_EXECUTABLE} ${ANT_FLAGS} -Dbuild.dir=${CMAKE_CURRENT_BINARY_DIR} -Dworking.dir=${work_dir} -f build.xml
49+
file(GLOB_RECURSE ThriftJava_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/*.java)
50+
set(ThriftJava_ARTIFACTS
51+
libthrift-${thrift_VERSION}.jar
52+
libthrift-${thrift_VERSION}.pom
53+
)
54+
add_custom_command(
55+
OUTPUT ${ThriftJava_ARTIFACTS}
56+
COMMAND ${Ant_EXECUTABLE} ${ANT_FLAGS} -Dbuild.dir="${CMAKE_CURRENT_BINARY_DIR}" -f build.xml
57+
MAIN_DEPENDENCY ${CMAKE_CURRENT_SOURCE_DIR}/build.xml
58+
DEPENDS ${ThriftJava_SOURCES}
5159
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
60+
)
61+
62+
add_custom_target(ThriftJava ALL
5263
COMMENT "Building Java library using Ant"
64+
DEPENDS ${ThriftJava_ARTIFACTS}
5365
)
5466

5567
# Hook the ant install task into CMake install
5668
install(CODE "execute_process(
5769
COMMAND ${Ant_EXECUTABLE} ${ANT_FLAGS} install
58-
-Dbuild.dir=${CMAKE_CURRENT_BINARY_DIR} -Dworking.dir=${work_dir}
59-
-Dinstall.path=${JAVA_INSTALL_DIR} -Dinstall.javadoc.path=${JAVA_DOC_INSTALL_DIR} -f build.xml
70+
-Dbuild.dir=\"${CMAKE_CURRENT_BINARY_DIR}\"
71+
-Dinstall.path=\"${JAVA_INSTALL_DIR}\" -Dinstall.javadoc.path=\"${JAVA_DOC_INSTALL_DIR}\" -f build.xml
6072
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
6173
)")
6274

6375
if(BUILD_TESTING)
64-
#add_subdirectory(test)
76+
add_test(NAME JavaTest
77+
COMMAND ${Ant_EXECUTABLE} ${ANT_FLAGS} -Dbuild.dir="${CMAKE_CURRENT_BINARY_DIR}" -Dthrift.compiler="${THRIFT_COMPILER}" -f build.xml test
78+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
6579
endif()
6680
endif(ANDROID)

lib/java/build.xml

100755100644
Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636

3737
<property name="final.name" value="${thrift.artifactid}-${version}"/>
3838

39+
<property name="thrift.compiler" location="../../compiler/cpp/thrift"/>
3940
<property name="src" location="${basedir}/src"/>
4041
<property name="build.dir" location="${basedir}/build"/>
4142
<property name="build.lib.dir" location="${build.dir}/lib"/>
@@ -260,31 +261,31 @@
260261

261262
<target name="generate">
262263
<!-- Generate the thrift gen-java source -->
263-
<exec executable="../../compiler/cpp/thrift" failonerror="true">
264+
<exec executable="${thrift.compiler}" failonerror="true">
264265
<arg line="--gen java ${test.thrift.home}/ThriftTest.thrift"/>
265266
</exec>
266-
<exec executable="../../compiler/cpp/thrift" failonerror="true">
267+
<exec executable="${thrift.compiler}" failonerror="true">
267268
<arg line="--gen java ${test.thrift.home}/DebugProtoTest.thrift"/>
268269
</exec>
269-
<exec executable="../../compiler/cpp/thrift" failonerror="true">
270+
<exec executable="${thrift.compiler}" failonerror="true">
270271
<arg line="--gen java ${test.thrift.home}/OptionalRequiredTest.thrift"/>
271272
</exec>
272-
<exec executable="../../compiler/cpp/thrift" failonerror="true">
273+
<exec executable="${thrift.compiler}" failonerror="true">
273274
<arg line="--gen java:beans,nocamel ${test.thrift.home}/JavaBeansTest.thrift"/>
274275
</exec>
275-
<exec executable="../../compiler/cpp/thrift" failonerror="true">
276+
<exec executable="${thrift.compiler}" failonerror="true">
276277
<arg line="--gen java ${test.thrift.home}/ManyOptionals.thrift"/>
277278
</exec>
278279
<exec executable="mkdir" failonerror="true">
279280
<arg line="-p ${genfullcamel}"/>
280281
</exec>
281-
<exec executable="../../compiler/cpp/thrift" failonerror="true">
282+
<exec executable="${thrift.compiler}" failonerror="true">
282283
<arg line="--gen java:fullcamel -out ${genfullcamel} ${test.thrift.home}/FullCamelTest.thrift"/>
283284
</exec>
284285
<exec executable="mkdir" failonerror="true">
285286
<arg line="-p ${genreuse}"/>
286287
</exec>
287-
<exec executable="../../compiler/cpp/thrift" failonerror="true">
288+
<exec executable="${thrift.compiler}" failonerror="true">
288289
<arg line="--gen java:reuse-objects -out ${genreuse} ${test.thrift.home}/ReuseObjects.thrift"/>
289290
</exec>
290291
</target>
@@ -370,7 +371,7 @@
370371

371372
<!-- Dependencies needed for testing -->
372373
<artifact:dependencies filesetId="test-dependency-jars" useScope="runtime">
373-
<dependency groupId="org.slf4j" artifactId="slf4j-log4j12" version="1.5.8"/>
374+
<dependency groupId="org.slf4j" artifactId="slf4j-log4j12" version="${slf4j.version}"/>
374375
<dependency groupId="junit" artifactId="junit" version="4.4"/>
375376
</artifact:dependencies>
376377

0 commit comments

Comments
 (0)