Skip to content

Commit

Permalink
Added customization for the Windows build.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
castortech committed Apr 25, 2018
1 parent 98b1531 commit 6c1f140
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 6 deletions.
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
@@ -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

0 comments on commit 6c1f140

Please sign in to comment.