From 6f891af96768e77f5e800fd0f723712b87e30735 Mon Sep 17 00:00:00 2001 From: Alain Picard Date: Tue, 24 Apr 2018 16:23:45 -0400 Subject: [PATCH 1/4] Updated documentation to clearly indicate the vcbuild is deprecated and that msbuild is supported. --- .../src/main/resources/project-template/readme.md | 13 +++++++++---- .../src/documentation/developer-guide.md | 9 ++++----- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/hawtjni-maven-plugin/src/main/resources/project-template/readme.md b/hawtjni-maven-plugin/src/main/resources/project-template/readme.md index fe1469f7..6e4877fa 100644 --- a/hawtjni-maven-plugin/src/main/resources/project-template/readme.md +++ b/hawtjni-maven-plugin/src/main/resources/project-template/readme.md @@ -42,11 +42,16 @@ all the headers, libraries, and build tools needed to compile the JNI library. Set the `JAVA_HOME` environment variable to the location where your JDK is installed. -Use the "Start>All Programs>Microsoft Windows SDK vX.X>CMD" command window -and change to the directory that this file is located in and then run: +Use the installed command window and change to the directory that this file is located in and then run: - vcbuild vs2008.vcproj +For recent SDK Versions: + + msbuild vs2010.vcxproj (or ) + +For legacy SDK Versions: + + vcbuild vs2008.vcproj The dll files will be located under the target directory. -[1]: http://www.microsoft.com/downloads/details.aspx?FamilyID=c17ba869-9671-4330-a63e-1fd44e0e2505 \ No newline at end of file +[1]: https://developer.microsoft.com/en-us/windows/downloads \ No newline at end of file diff --git a/hawtjni-website/src/documentation/developer-guide.md b/hawtjni-website/src/documentation/developer-guide.md index 63bfecb3..ef06141e 100644 --- a/hawtjni-website/src/documentation/developer-guide.md +++ b/hawtjni-website/src/documentation/developer-guide.md @@ -800,13 +800,12 @@ Download and install the free [Microsoft Windows SDK][ms_sdk]. The SDK includes all the headers, libraries, and build tools needed to compile the JNI library. Set the `JAVA_HOME` environment variable to the location where your JDK is -installed. +installed. -Make sure the `vcbuild` tool is on in your system PATH. The simplest way -to use SDK command prompt by following the following menu choices: -`Start > All Programs > Microsoft Windows SDK ... > CMD` +Make sure the `msbuild` (`vcbuild` for legacy SDK versions) tool is on in your system PATH. The simplest way +is to use SDK command prompt. -[ms_sdk]: http://www.microsoft.com/downloads/details.aspx?FamilyID=c17ba869-9671-4330-a63e-1fd44e0e2505 +[ms_sdk]: https://developer.microsoft.com/en-us/windows/downloads ### Ubuntu Linux From a103c50b1b1b357d6a5d932cac7ebc599bb0d16b Mon Sep 17 00:00:00 2001 From: Alain Picard Date: Tue, 24 Apr 2018 16:24:19 -0400 Subject: [PATCH 2/4] Added support to detect newer versions of Visual Studio as candidates for msbuild --- .../main/java/org/fusesource/hawtjni/maven/BuildMojo.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/hawtjni-maven-plugin/src/main/java/org/fusesource/hawtjni/maven/BuildMojo.java b/hawtjni-maven-plugin/src/main/java/org/fusesource/hawtjni/maven/BuildMojo.java index e0ca5b7e..24845a72 100644 --- a/hawtjni-maven-plugin/src/main/java/org/fusesource/hawtjni/maven/BuildMojo.java +++ b/hawtjni-maven-plugin/src/main/java/org/fusesource/hawtjni/maven/BuildMojo.java @@ -258,7 +258,9 @@ private void vsBasedBuild(File buildDir) throws CommandLineException, MojoExecut if( vcinstalldir!=null ) { if( vcinstalldir.contains("Microsoft Visual Studio 10") || vcinstalldir.contains("Microsoft Visual Studio 11") || - vcinstalldir.contains("Microsoft Visual Studio 12") + vcinstalldir.contains("Microsoft Visual Studio 12") || + vcinstalldir.contains("Microsoft Visual Studio 14") || + vcinstalldir.contains("Microsoft Visual Studio\\2017") ) { useMSBuild = true; } @@ -286,8 +288,6 @@ private void vsBasedBuild(File buildDir) throws CommandLineException, MojoExecut } } - - File libFile=FileUtils.resolveFile(buildDir, "target/"+platform+"-"+configuration+"/lib/"+library.getLibraryFileName()); if( !libFile.exists() ) { throw new MojoExecutionException("vcbuild did not generate: "+libFile); @@ -318,7 +318,7 @@ private void configureBasedBuild(File buildDir) throws IOException, MojoExecutio File distDirectory = new File(buildDir, "target"); File distLibDirectory = new File(distDirectory, "lib"); - distLibDirectory.mkdirs(); + distLibDirectory.mkdirs(); if( autogen.exists() && !skipAutogen ) { if( (!configure.exists() && !CLI.IS_WINDOWS) || forceAutogen ) { From 98b1531628f236aa9a68fd49b67ac09f1b547868 Mon Sep 17 00:00:00 2001 From: Alain Picard Date: Tue, 24 Apr 2018 16:24:51 -0400 Subject: [PATCH 3/4] Added missing case of "no directory" as per method documentation. --- .../src/main/java/org/fusesource/hawtjni/runtime/Library.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hawtjni-runtime/src/main/java/org/fusesource/hawtjni/runtime/Library.java b/hawtjni-runtime/src/main/java/org/fusesource/hawtjni/runtime/Library.java index da25e825..5e089c30 100755 --- a/hawtjni-runtime/src/main/java/org/fusesource/hawtjni/runtime/Library.java +++ b/hawtjni-runtime/src/main/java/org/fusesource/hawtjni/runtime/Library.java @@ -288,7 +288,8 @@ final public String[] getSpecificSearchDirs() { return new String[] { getPlatform() + "/" + System.getProperty("os.arch"), getPlatform(), - getOperatingSystem() + getOperatingSystem(), + "." }; } From 6c1f140970a59727a102b8ee2daef909eb991b78 Mon Sep 17 00:00:00 2001 From: Alain Picard Date: Wed, 25 Apr 2018 06:58:36 -0400 Subject: [PATCH 4/4] Added customization for the Windows build. It includes: -ability to generate/include an import custom.props file -ability to change the tools version -ability to include WindowsTargetPlatformVersion -ability to include PlatformToolset --- .../hawtjni/maven/GenerateMojo.java | 51 +++++++++++++++++-- .../project-template/vs2010.custom.props | 16 ++++++ .../resources/project-template/vs2010.vcxproj | 8 ++- 3 files changed, 69 insertions(+), 6 deletions(-) create mode 100644 hawtjni-maven-plugin/src/main/resources/project-template/vs2010.custom.props diff --git a/hawtjni-maven-plugin/src/main/java/org/fusesource/hawtjni/maven/GenerateMojo.java b/hawtjni-maven-plugin/src/main/java/org/fusesource/hawtjni/maven/GenerateMojo.java index d26ef59d..85a909db 100644 --- a/hawtjni-maven-plugin/src/main/java/org/fusesource/hawtjni/maven/GenerateMojo.java +++ b/hawtjni-maven-plugin/src/main/java/org/fusesource/hawtjni/maven/GenerateMojo.java @@ -148,7 +148,7 @@ public class GenerateMojo extends AbstractMojo { /** * The build tool to use on Windows systems. Set - * to 'msbuild', 'vcbuild', or 'detect' + * to 'msbuild', 'vcbuild', or 'detect' or 'none' */ @Parameter(defaultValue = "detect") private String windowsBuildTool; @@ -160,6 +160,33 @@ public class GenerateMojo extends AbstractMojo { */ @Parameter private String windowsProjectName; + + /** + * Set this value to true to include the import of a custom properties file in your vcxproj (not applicable + * to vs2008). This greatly simplifies the configurability of your project. + */ + @Parameter(defaultValue = "false") + private boolean windowsCustomProps; + + /** + * The tools version used in the header of your vcxproj (not applicable to vs2008). + */ + @Parameter(defaultValue = "4.0") + private String windowsToolsVersion; + + /** + * The target platform version used in your vcxproj (not applicable to vs2008). + * Not supplied by default. + */ + @Parameter + private String windowsTargetPlatformVersion; + + /** + * The platform toolset version used in your vcxproj (not applicable to vs2008). + * Not supplied by default. + */ + @Parameter + private String windowsPlatformToolset; private File targetSrcDir; @@ -235,8 +262,14 @@ private void generateBuildSystem() throws MojoExecutionException { if( "detect".equals(tool) ) { copyTemplateResource("vs2008.vcproj", (windowsProjectName != null ? windowsProjectName : "vs2008") + ".vcproj", true); copyTemplateResource("vs2010.vcxproj", (windowsProjectName != null ? windowsProjectName : "vs2010") + ".vcxproj", true); + if (windowsCustomProps) { + copyTemplateResource("vs2010.custom.props", (windowsProjectName != null ? windowsProjectName : "vs2010") + ".custom.props", true); + } } else if( "msbuild".equals(tool) ) { copyTemplateResource("vs2010.vcxproj", (windowsProjectName != null ? windowsProjectName : "vs2010") + ".vcxproj", true); + if (windowsCustomProps) { + copyTemplateResource("vs2010.custom.props", (windowsProjectName != null ? windowsProjectName : "vs2010") + ".custom.props", true); + } } else if( "vcbuild".equals(tool) ) { copyTemplateResource("vs2008.vcproj", (windowsProjectName != null ? windowsProjectName : "vs2008") + ".vcproj", true); } else if( "none".equals(tool) ) { @@ -340,8 +373,8 @@ private FilterWrapper[] filters(boolean filter) throws IOException { } sources += " src/"+f; - xml_sources+=" \n"; - vs10_sources+=" \n"; + xml_sources+=" \n"; + vs10_sources+=" \n"; //VS adds trailing space and eases compares } if( cpp_files.isEmpty() ) { @@ -353,8 +386,16 @@ private FilterWrapper[] filters(boolean filter) throws IOException { values.put("PROJECT_SOURCES", sources); values.put("PROJECT_XML_SOURCES", xml_sources); values.put("PROJECT_VS10_SOURCES", vs10_sources); - - FileUtils.FilterWrapper wrapper = new FileUtils.FilterWrapper() { + + values.put("CUSTOM_PROPS", windowsCustomProps ? "" : ""); + values.put("TOOLS_VERSION", windowsToolsVersion); + values.put("TARGET_PLATFORM_VERSION", windowsTargetPlatformVersion != null ? + "" + windowsTargetPlatformVersion + "" : ""); + values.put("PLATFORM_TOOLSET", windowsPlatformToolset != null ? + "" + windowsPlatformToolset + "" : ""); + + FileUtils.FilterWrapper wrapper = new FileUtils.FilterWrapper() { public Reader getReader(Reader reader) { StringSearchInterpolator propertiesInterpolator = new StringSearchInterpolator(startExp, endExp); propertiesInterpolator.addValueSource(new MapBasedValueSource(values)); diff --git a/hawtjni-maven-plugin/src/main/resources/project-template/vs2010.custom.props b/hawtjni-maven-plugin/src/main/resources/project-template/vs2010.custom.props new file mode 100644 index 00000000..93c79d47 --- /dev/null +++ b/hawtjni-maven-plugin/src/main/resources/project-template/vs2010.custom.props @@ -0,0 +1,16 @@ + + + + \ No newline at end of file diff --git a/hawtjni-maven-plugin/src/main/resources/project-template/vs2010.vcxproj b/hawtjni-maven-plugin/src/main/resources/project-template/vs2010.vcxproj index 44c1f87e..97161fa7 100755 --- a/hawtjni-maven-plugin/src/main/resources/project-template/vs2010.vcxproj +++ b/hawtjni-maven-plugin/src/main/resources/project-template/vs2010.vcxproj @@ -1,6 +1,6 @@ - + debug @@ -22,24 +22,29 @@ @PROJECT_NAME@ @PROJECT_NAME@ + @TARGET_PLATFORM_VERSION@ DynamicLibrary Unicode + @PLATFORM_TOOLSET@ DynamicLibrary Unicode + @PLATFORM_TOOLSET@ true DynamicLibrary + @PLATFORM_TOOLSET@ Unicode DynamicLibrary Unicode + @PLATFORM_TOOLSET@ true @@ -73,6 +78,7 @@ $(ProjectDir)/target/$(Platform)-$(Configuration)/obj\ true + @CUSTOM_PROPS@ $(JAVA_HOME)\include;$(JAVA_HOME)\include\win32;$(ProjectDir)\src\windows;%(AdditionalIncludeDirectories)