Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Find first the exact SDK request and add the forcing of 32 bit build to VS 2005 #276

Merged
merged 1 commit into from
May 15, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 95 additions & 9 deletions src/main/java/com/github/maven_nar/Msvc.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,12 @@ static boolean isMSVC(final AbstractNarMojo mojo) {
}

static boolean isMSVC(final String name) {

return "msvc".equalsIgnoreCase(name);
}

public void configureCCTask(final CCTask task) throws MojoExecutionException {

if (OS.WINDOWS.equals(mojo.getOS()) && isMSVC(mojo)) {
addIncludePath(task, this.home, "VC/include");
addIncludePath(task, this.home, "VC/atlmfc/include");
Expand Down Expand Up @@ -338,12 +340,54 @@ else if (!osArchitecture.equals(mojoArchitecture) && !matchMojo) {
addPath(this.windowsHome, "System32/wbem");
}

private void initPath8() throws MojoExecutionException {
// clearing the path, add back the windows system folders
addPath(this.windowsHome, "System32");
addPath(this.windowsHome, "");
addPath(this.windowsHome, "System32/wbem");
}
private void initPath8() throws MojoExecutionException {
final String mojoArchitecture = this.mojo.getArchitecture();
final String osArchitecture = NarUtil.getArchitecture(null);
// 32 bit build on 64 bit OS can be built with 32 bit tool, or 64 bit tool
// in amd64_x86 - currently defaulting to prefer 64 bit tools - match os
final boolean matchMojo = false;
// TODO: toolset architecture
// match os - os x86 mojo(x86 / x86_amd64); os x64 mojo(amd64_x86 / amd64);
// 32bit - force 32 on 64bit mojo(x86 / x86_amd64)
// match mojo - os x86 is as above; os x64 mojo (x86 / amd64)

// Cross tools first if necessary, platform tools second, more generic tools
// later

if (force_requested_arch)
{
if ("amd64".equals(mojoArchitecture) && !matchMojo) {
addPath(this.home, "VC/bin/amd64");
toolPathLinker = new File(this.home, "VC/bin/amd64").getAbsolutePath();
} else {
addPath(this.home, "VC/bin");
toolPathLinker = new File(this.home, "VC/bin").getAbsolutePath();
}

}
else if (!osArchitecture.equals(mojoArchitecture) && !matchMojo) {
if (!addPath(this.home, "VC/bin/" + osArchitecture + "_" + mojoArchitecture)) {
throw new MojoExecutionException("Unable to find compiler for architecture " + mojoArchitecture + ".\n"
+ new File(this.home, "VC/bin/" + osArchitecture + "_" + mojoArchitecture));
}
toolPathLinker = new File(this.home, "VC/bin/" + osArchitecture + "_" + mojoArchitecture).getAbsolutePath();
}
if (null == toolPathLinker) {
if ("amd64".equals(mojoArchitecture))
toolPathLinker = new File(this.home, "VC/bin/amd64").getAbsolutePath();
else
toolPathLinker = new File(this.home, "VC/bin").getAbsolutePath();
}
if ("amd64".equals(osArchitecture) && !matchMojo) {
addPath(this.home, "VC/bin/amd64");
} else {
addPath(this.home, "VC/bin");
}
// clearing the path, add back the windows system folders
addPath(this.windowsHome, "System32");
addPath(this.windowsHome, "");
addPath(this.windowsHome, "System32/wbem");
}

private void initVisualStudio() throws MojoFailureException, MojoExecutionException {
mojo.getLog().debug(" -- Searching for usable VisualStudio ");
Expand Down Expand Up @@ -464,6 +508,8 @@ private void initWindowsSdk() throws MojoExecutionException {

mojo.getLog().debug(" -- Searching for usable WindowSDK ");
// newer first: 10 -> 8.1 -> 8.0 -> 7.1 and look for libs specified


for (final File directory : Arrays.asList(
new File("C:/Program Files (x86)/Windows Kits"),
new File("C:/Program Files (x86)/Microsoft SDKs/Windows"),
Expand All @@ -481,8 +527,8 @@ private void initWindowsSdk() throws MojoExecutionException {
if (kitVersion.charAt(0) == 'v') {
kitVersion = kitVersion.substring(1);
}
if (this.windowsSdkVersion!=null && compareVersion(kitVersion,this.windowsSdkVersion)>0)
continue; // skip versions higher than the previous version
if (this.windowsSdkVersion!=null && !(compareVersion(kitVersion,this.windowsSdkVersion)==0))
continue; // skip versions not identical to exact version
mojo.getLog()
.debug(String.format(" WindowSDK %1s found %2s", kitVersion, kitDirectory.getAbsolutePath()));
if (kitVersion.matches("\\d+\\.\\d+?[A-Z]?")) {
Expand All @@ -499,6 +545,45 @@ private void initWindowsSdk() throws MojoExecutionException {
}
}
}
if (!foundSDK)
{ // Search for SDK with lower versions
for (final File directory : Arrays.asList(
new File("C:/Program Files (x86)/Windows Kits"),
new File("C:/Program Files (x86)/Microsoft SDKs/Windows"),
new File("C:/Program Files/Windows Kits"),
new File("C:/Program Files/Microsoft SDKs/Windows") )) {
if (directory.exists()) {
final File[] kitDirectories = directory.listFiles();
Arrays.sort(kitDirectories, versionComparator);
if (kitDirectories != null) {
for (final File kitDirectory : kitDirectories) {

if (new File(kitDirectory, "Include").exists()) {
// legacy SDK
String kitVersion = kitDirectory.getName();
if (kitVersion.charAt(0) == 'v') {
kitVersion = kitVersion.substring(1);
}
if (this.windowsSdkVersion!=null && compareVersion(kitVersion,this.windowsSdkVersion)>0)
continue; // skip versions higher than the previous version
mojo.getLog()
.debug(String.format(" WindowSDK %1s found %2s", kitVersion, kitDirectory.getAbsolutePath()));
if (kitVersion.matches("\\d+\\.\\d+?[A-Z]?")) {
// windows <= 8.1
legacySDK(kitDirectory);
} else if (kitVersion.matches("\\d+?")) {
// windows 10 SDK supports
addNewSDKLibraries(kitDirectory);
}
}
}
if (libsRequired.size() == 0) // need it here to break out of the outer loop
break;
}
}
}
}

if (!foundSDK)
throw new MojoExecutionException("msvc.windowsSdkVersion not specified and versions cannot be found");
mojo.getLog().debug(String.format(" Using WindowSDK %1s found %2s", this.windowsSdkVersion, this.windowsSdkHome));
Expand Down Expand Up @@ -583,10 +668,11 @@ private void initWindowsSdk8() throws MojoExecutionException {
}

public void setMojo(final AbstractNarMojo mojo) throws MojoFailureException, MojoExecutionException {
if (mojo != this.mojo) {
if (mojo != this.mojo) {
this.mojo = mojo;
init();
}

}

@Override
Expand Down