Skip to content

Commit

Permalink
Merge pull request #48 from castortech/master
Browse files Browse the repository at this point in the history
Improved msbuild support + fix bug
  • Loading branch information
gnodet authored Apr 2, 2019
2 parents 73e0b4f + c0cfb25 commit d028542
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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) ) {
Expand Down Expand Up @@ -340,8 +373,8 @@ private FilterWrapper[] filters(boolean filter) throws IOException {
}
sources += " src/"+f;

xml_sources+=" <File RelativePath=\".\\src\\"+ (f.replace('/', '\\')) +"\"/>\n";
vs10_sources+=" <ClCompile Include=\".\\src\\"+ (f.replace('/', '\\')) +"\"/>\n";
xml_sources+=" <File RelativePath=\".\\src\\"+ (f.replace('/', '\\')) +"\" />\n";
vs10_sources+=" <ClCompile Include=\".\\src\\"+ (f.replace('/', '\\')) +"\" />\n"; //VS adds trailing space and eases compares
}

if( cpp_files.isEmpty() ) {
Expand All @@ -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 ? "<Import Project=\"" +
(windowsProjectName != null ? windowsProjectName : "vs2010") + ".custom.props\" />" : "");
values.put("TOOLS_VERSION", windowsToolsVersion);
values.put("TARGET_PLATFORM_VERSION", windowsTargetPlatformVersion != null ?
"<WindowsTargetPlatformVersion>" + windowsTargetPlatformVersion + "</WindowsTargetPlatformVersion>" : "");
values.put("PLATFORM_TOOLSET", windowsPlatformToolset != null ?
"<PlatformToolset>" + windowsPlatformToolset + "</PlatformToolset>" : "");

FileUtils.FilterWrapper wrapper = new FileUtils.FilterWrapper() {
public Reader getReader(Reader reader) {
StringSearchInterpolator propertiesInterpolator = new StringSearchInterpolator(startExp, endExp);
propertiesInterpolator.addValueSource(new MapBasedValueSource(values));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
[1]: https://developer.microsoft.com/en-us/windows/downloads
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!--
# This is just a stub. If you wish to customize your vs2010.vcxproj
# just copy this file to src/main/native-package/vs2010.custom.props
# then replace add your msbuild statements here.
<ItemDefinitionGroup>
<ClCompile>
<AdditionalIncludeDirectories>$(ProjectDir)\my-headers;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<AdditionalDependencies>$(ProjectDir)\libmylibrary.a;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
-->
</Project>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- msbuild vs2008.vcxproj -->
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project DefaultTargets="Build" ToolsVersion="@TOOLS_VERSION@" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="debug|Win32">
<Configuration>debug</Configuration>
Expand All @@ -22,24 +22,29 @@
<PropertyGroup Label="Globals">
<ProjectName>@PROJECT_NAME@</ProjectName>
<RootNamespace>@PROJECT_NAME@</RootNamespace>
@TARGET_PLATFORM_VERSION@
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
@PLATFORM_TOOLSET@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
@PLATFORM_TOOLSET@
<WholeProgramOptimization>true</WholeProgramOptimization>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
@PLATFORM_TOOLSET@
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
@PLATFORM_TOOLSET@
<WholeProgramOptimization>true</WholeProgramOptimization>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
Expand Down Expand Up @@ -73,6 +78,7 @@
<IntDir Condition="'$(Configuration)|$(Platform)'=='debug|x64'">$(ProjectDir)/target/$(Platform)-$(Configuration)/obj\</IntDir>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='debug|x64'">true</LinkIncremental>
</PropertyGroup>
@CUSTOM_PROPS@
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='release|Win32'">
<ClCompile>
<AdditionalIncludeDirectories>$(JAVA_HOME)\include;$(JAVA_HOME)\include\win32;$(ProjectDir)\src\windows;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ final public String[] getSpecificSearchDirs() {
getPlatform() + "/" + System.getProperty("os.arch"),
getPlatform(),
getOperatingSystem(),
null
"."
};
}

Expand Down
9 changes: 4 additions & 5 deletions hawtjni-website/src/documentation/developer-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit d028542

Please sign in to comment.