Skip to content

Commit

Permalink
Merge pull request zeromq#1239 from sappo/master
Browse files Browse the repository at this point in the history
Windows fixes for JNI, cmake and travisci
  • Loading branch information
bluca authored Mar 7, 2020
2 parents f44fb77 + ba294b1 commit d3f38c8
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 47 deletions.
7 changes: 7 additions & 0 deletions zproject_cmake.gsl
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,13 @@ foreach(TEST_CLASS ${TEST_CLASSES})
NAME ${TEST_CLASS}
COMMAND $(project.prefix)_selftest --continue --verbose --test ${TEST_CLASS}
)
IF (WIN32 AND CMAKE_PREFIX_PATH)
file(TO_NATIVE_PATH "${CMAKE_PREFIX_PATH}" CMAKE_PREFIX_PATH_WIN)
set_tests_properties(
${TEST_CLASS}
PROPERTIES ENVIRONMENT "PATH=%PATH%\\;${CMAKE_PREFIX_PATH_WIN}\\\\bin"
)
ENDIF (WIN32 AND CMAKE_PREFIX_PATH)
set_tests_properties(
${TEST_CLASS}
PROPERTIES TIMEOUT ${CLASSTEST_TIMEOUT}
Expand Down
97 changes: 50 additions & 47 deletions zproject_java.gsl
Original file line number Diff line number Diff line change
Expand Up @@ -216,35 +216,26 @@ task generateJniHeaders(type: Exec, dependsOn: 'classes') {

tasks.withType(Test) {
def defaultJavaLibraryPath = System.getProperty("java.library.path")
def extraJavaLibraryPath = hasNotEmptyProperty('buildPrefix') ? "$project.buildPrefix/lib" : ''
if (osdetector.os == 'windows') {
systemProperty "java.library.path", "${projectDir}/build/Release${File.pathSeparator}" +
"${defaultJavaLibraryPath}${File.pathSeparator}" +
"${extraJavaLibraryPath}"
def extraJavaLibraryPath = hasNotEmptyProperty('buildPrefix') ? "$project.buildPrefix\\\\bin;$project.buildPrefix\\\\lib" : ''
extraJavaLibraryPath = extraJavaLibraryPath.replace("/", "\\\\")
systemProperty "java.library.path", "${projectDir}\\\\build\\\\Release${File.pathSeparator}" +
"${extraJavaLibraryPath}${File.pathSeparator}" +
"${defaultJavaLibraryPath}"
} else {
systemProperty "java.library.path", "${projectDir}${File.pathSeparator}" +
"${defaultJavaLibraryPath}${File.pathSeparator}" +
def extraJavaLibraryPath = hasNotEmptyProperty('buildPrefix') ? "$project.buildPrefix/lib" : ''
systemProperty "java.library.path", "${projectDir}/build${File.pathSeparator}" +
"/usr/local/lib${File.pathSeparator}" +
"/tmp/lib${File.pathSeparator}" +
"${extraJavaLibraryPath}"
"${extraJavaLibraryPath}${File.pathSeparator}" +
"${defaultJavaLibraryPath}"
}
}

task initCMake(type: Exec, dependsOn: 'generateJniHeaders') {
if (osdetector.os == 'windows') {
def includePath = "${rootDir}/../../include"
. for project.use
includePath += "${File.pathSeparator}${rootDir}/../../../$(use.project)/include"
. endfor
workingDir 'build'
commandLine 'cmake',
'-G', vsGenerator,
'-D', "CMAKE_INCLUDE_PATH=\\"${includePath}\\"",
'..'
} else {
def findRootPathOpt = hasNotEmptyProperty('buildPrefix') ? "-DCMAKE_FIND_ROOT_PATH=$project.buildPrefix" : ''
commandLine 'cmake', "$findRootPathOpt", '.'
}
workingDir 'build'
def prefixPath = hasNotEmptyProperty('buildPrefix') ? "-DCMAKE_PREFIX_PATH=$project.buildPrefix" : ''
commandLine 'cmake', "$prefixPath", '..'
}

task buildNative(type: Exec, dependsOn: 'initCMake') {
Expand All @@ -255,7 +246,8 @@ task buildNative(type: Exec, dependsOn: 'initCMake') {
'--target', '$(project.prefix)jni',
'--', '-verbosity:Minimal', '-maxcpucount'
} else {
commandLine 'make'
commandLine 'cmake',
'--build', 'build'
}
}

Expand Down Expand Up @@ -442,8 +434,18 @@ dependencies {
task copyLibs(type: Copy) {
def libraryPaths = System.getProperty('java.library.path').split(File.pathSeparator).toList()
libraryPaths.add('/usr/local/lib')
libraryPaths.add("${rootDir}/$(project.prefix:c)-jni")
libraryPaths.add("${rootDir}/$(project.prefix:c)-jni/build/Release")
if (osdetector.os == 'windows') {
libraryPaths.add("${rootDir}/$(project.prefix:c)-jni/build/Release")
} else {
libraryPaths.add("${rootDir}/$(project.prefix:c)-jni/build")
}
if (project.hasProperty('buildPrefix')) {
if (osdetector.os == 'windows') {
// DLLs are installed to the bin directory by cmake
libraryPaths.add("${project.buildPrefix}/bin")
}
libraryPaths.add("${project.buildPrefix}/lib")
}

libraryPaths.each { path ->
from path
Expand Down Expand Up @@ -597,22 +599,23 @@ Prerequisites:
* Java JDK 8 or later is installed

Environment Variables:
* Add MSBuild.exe to the PATH, e.g. C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\MSBuild\\Current\\Bin
* Set JAVA_HOME to the installation location, e.g. C:\\Program Files\\Java\\jdk1.8.0_66.
* Add MSBuild.exe to the PATH (e.g. `C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\MSBuild\\Current\\Bin`)
* Set JAVA_HOME to the installation location (e.g. `C:\\Program Files\\Java\\jdk1.8.0_66`).

1. Check out all dependent projects from github, at the same level as this project. E.g.: libzmq, czmq.
2. Follow the dependent projects instructions to build their '.dll' and '.lib' file.
3. Copy a dependent '.dll' and '.lib' files to a folder
4. Add this library folder to the path, e.g.:
1. Check out all dependent projects from github, at the same level as this project (e.g. libzmq, czmq).
2. Follow the dependent projects instructions to build their `.dll` and `.lib` file.

PATH %PATH%;C:\\projects\\libs
If you used cmake to install the dependencies you can skip the following steps.

Now run:
3. Create a folder where to place the dlls and libs (e.g. `C:\\tmp\\deps`).
4. Copy all dependent `.dll` files to the `bin` subfolder (e.g. `C:\\tmp\\deps\\bin`)
5. Copy all dependent `.lib` files to the `lib` subfolder (e.g. `C:\\tmp\\deps\\lib`)
6. Copy all dependent `.h` files to the `include` subfolder (e.g. `C:\\tmp\deps\\include`)

gradlew build jar "-PvsGenerator=Visual Studio 16 2019"
gradlew test "-PvsGenerator=Visual Studio 16 2019"
Now run:

Change the vsGenerator parameter to the version of MS Visual Studio you have installed.
gradlew build jar -PbuildPrefix=C:\\tmp\\deps
gradlew test -PbuildPrefix=C:\\tmp\\deps

## Installing the JNI Layer

Expand Down Expand Up @@ -971,18 +974,18 @@ if [ "$TRAVIS_OS_NAME" == "linux" ] && [ "$BINDING_OPTS" == "android" ]; then
export NDK_VERSION=android-ndk-r20
export ANDROID_NDK_ROOT="/tmp/${NDK_VERSION}"

case \$(uname | tr '[:upper:]' '[:lower:]') in
linux*)
HOST_PLATFORM=linux-x86_64
;;
darwin*)
HOST_PLATFORM=darwin-x86_64
;;
*)
echo "Unsupported platform"
exit 1
;;
esac
case \$(uname | tr '[:upper:]' '[:lower:]') in
linux*)
HOST_PLATFORM=linux-x86_64
;;
darwin*)
HOST_PLATFORM=darwin-x86_64
;;
*)
echo "Unsupported platform"
exit 1
;;
esac

if [ ! -d "${ANDROID_NDK_ROOT}" ]; then
export FILENAME=$NDK_VERSION-$HOST_PLATFORM.zip
Expand Down
41 changes: 41 additions & 0 deletions zproject_travis.gsl
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,47 @@ case "$CI_TRACE" in
set -x ;;
esac

case $TRAVIS_OS_NAME in
windows)
export
choco install openjdk
export JAVA_HOME="C:\\Program Files\\OpenJDK\\jdk-13.0.2"
export BUILD_PREFIX=$TEMP/ci_build

cd ..

.for project.use where !optional & defined (use.repository)
. if defined (use.release)
git clone --quiet --depth 1 -b $(use.release:) $(use.repository) $(use.project)
. else
git clone --quiet --depth 1 $(use.repository) $(use.project)
. endif
cd $(use.project)
mkdir build
cd build
cmake .. -DCMAKE_INSTALL_PREFIX=$BUILD_PREFIX -DCMAKE_PREFIX_PATH=$BUILD_PREFIX
cmake --build . --config Release --target install
cd ../..

.endfor
cd $(project.name)
mkdir build
cd build
cmake .. -DCMAKE_INSTALL_PREFIX=$BUILD_PREFIX -DCMAKE_PREFIX_PATH=$BUILD_PREFIX
cmake --build . --config Release --target install
ctest --build-config Release
cd ../..

cd $(project.name)
cd bindings/jni
ls $BUILD_PREFIX/bin
ls $BUILD_PREFIX/lib
./gradlew build jar -PbuildPrefix=$BUILD_PREFIX -x test --info
./gradlew publishToMavenLocal -PbuildPrefix=$BUILD_PREFIX --info

exit 0
esac

case "$BUILD_TYPE" in
default|default-Werror|default-with-docs|valgrind|clang-format-check)
LANG=C
Expand Down

0 comments on commit d3f38c8

Please sign in to comment.