Improve library resolution
This commit is contained in:
parent
641f37e8eb
commit
1a95bee5f3
|
@ -185,8 +185,8 @@ public class LWJGLUtil {
|
||||||
* @param classloader The classloader to ask for library paths
|
* @param classloader The classloader to ask for library paths
|
||||||
* @return Paths to located libraries, if any
|
* @return Paths to located libraries, if any
|
||||||
*/
|
*/
|
||||||
public static String[] getLibraryPaths(String libname, String platform_lib_name, ClassLoader classloader) {
|
public static List<String> getLibraryPaths(String libname, String platform_lib_name, ClassLoader classloader) {
|
||||||
return getLibraryPaths(libname, new String[]{platform_lib_name}, classloader);
|
return getLibraryPaths(libname, List.of(platform_lib_name), classloader);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -197,19 +197,22 @@ public class LWJGLUtil {
|
||||||
* @param classloader The classloader to ask for library paths
|
* @param classloader The classloader to ask for library paths
|
||||||
* @return Paths to located libraries, if any
|
* @return Paths to located libraries, if any
|
||||||
*/
|
*/
|
||||||
public static String[] getLibraryPaths(String libname, String[] platform_lib_names, ClassLoader classloader) {
|
public static List<String> getLibraryPaths(String libname, List<String> platform_lib_names, ClassLoader classloader) {
|
||||||
String overridePath = getPrivilegedProperty("org.lwjgl.librarypath");
|
String overridePath = getPrivilegedProperty("org.lwjgl.librarypath.override." + libname);
|
||||||
if (overridePath != null) {
|
if (overridePath != null) {
|
||||||
String[] paths = new String[platform_lib_names.length];
|
// override specifies an exact path
|
||||||
for (int i = 0; i < paths.length; i++) {
|
return List.of(overridePath);
|
||||||
paths[i] = overridePath + File.separator + platform_lib_names[i];
|
|
||||||
}
|
|
||||||
return paths;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// need to pass path of possible locations of library to native side
|
// need to pass path of possible locations of library to native side
|
||||||
List<String> possible_paths = new ArrayList<String>();
|
List<String> possible_paths = new ArrayList<String>();
|
||||||
|
|
||||||
|
// generic custom path
|
||||||
|
String customPath = getPrivilegedProperty("org.lwjgl.librarypath");
|
||||||
|
for (String platform_lib_name : platform_lib_names) {
|
||||||
|
possible_paths.add(customPath + File.separator + platform_lib_name);
|
||||||
|
}
|
||||||
|
|
||||||
String classloader_path = getPathFromClassLoader(libname, classloader);
|
String classloader_path = getPathFromClassLoader(libname, classloader);
|
||||||
if (classloader_path != null) {
|
if (classloader_path != null) {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
|
@ -242,8 +245,7 @@ public class LWJGLUtil {
|
||||||
possible_paths.add(platform_lib_name);
|
possible_paths.add(platform_lib_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
//create needed string array
|
return possible_paths;
|
||||||
return possible_paths.toArray(new String[possible_paths.size()]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void execPrivileged(String... cmd_array) throws Exception {
|
static void execPrivileged(String... cmd_array) throws Exception {
|
||||||
|
|
|
@ -35,7 +35,7 @@ import org.lwjgl.LWJGLException;
|
||||||
import org.lwjgl.LWJGLUtil;
|
import org.lwjgl.LWJGLUtil;
|
||||||
import org.lwjgl.Sys;
|
import org.lwjgl.Sys;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
|
@ -114,30 +114,30 @@ public final class AL {
|
||||||
if (created)
|
if (created)
|
||||||
throw new IllegalStateException("Only one OpenAL context may be instantiated at any one time.");
|
throw new IllegalStateException("Only one OpenAL context may be instantiated at any one time.");
|
||||||
String libname;
|
String libname;
|
||||||
String[] library_names;
|
List<String> library_names;
|
||||||
switch (LWJGLUtil.getPlatform()) {
|
switch (LWJGLUtil.getPlatform()) {
|
||||||
case LWJGLUtil.PLATFORM_WINDOWS:
|
case LWJGLUtil.PLATFORM_WINDOWS:
|
||||||
if ( Sys.is64Bit() ) {
|
if ( Sys.is64Bit() ) {
|
||||||
libname = "OpenAL64";
|
libname = "OpenAL64";
|
||||||
library_names = new String[]{"OpenAL64.dll"};
|
library_names = List.of("OpenAL64.dll");
|
||||||
} else {
|
} else {
|
||||||
libname = "OpenAL32";
|
libname = "OpenAL32";
|
||||||
library_names = new String[]{"OpenAL32.dll"};
|
library_names = List.of("OpenAL32.dll");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case LWJGLUtil.PLATFORM_LINUX:
|
case LWJGLUtil.PLATFORM_LINUX:
|
||||||
libname = "openal";
|
libname = "openal";
|
||||||
library_names = new String[]{"libopenal64.so", "libopenal.so", "libopenal.so.0"};
|
library_names = List.of("libopenal64.so", "libopenal.so", "libopenal.so.0");
|
||||||
break;
|
break;
|
||||||
case LWJGLUtil.PLATFORM_MACOSX:
|
case LWJGLUtil.PLATFORM_MACOSX:
|
||||||
libname = "openal";
|
libname = "openal";
|
||||||
library_names = new String[]{"openal.dylib"};
|
library_names = List.of("openal.dylib");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new LWJGLException("Unknown platform: " + LWJGLUtil.getPlatform());
|
throw new LWJGLException("Unknown platform: " + LWJGLUtil.getPlatform());
|
||||||
}
|
}
|
||||||
String[] oalPaths = LWJGLUtil.getLibraryPaths(libname, library_names, AL.class.getClassLoader());
|
List<String> oalPaths = LWJGLUtil.getLibraryPaths(libname, library_names, AL.class.getClassLoader());
|
||||||
LWJGLUtil.logger().log(() -> "Found " + oalPaths.length + " OpenAL paths: " + Arrays.toString(oalPaths));
|
LWJGLUtil.logger().log(() -> "Found " + oalPaths.size() + " OpenAL paths: " + oalPaths);
|
||||||
for ( String oalPath : oalPaths ) {
|
for ( String oalPath : oalPaths ) {
|
||||||
try {
|
try {
|
||||||
nCreate(oalPath);
|
nCreate(oalPath);
|
||||||
|
|
|
@ -37,6 +37,7 @@ import org.lwjgl.MemoryUtil;
|
||||||
import org.lwjgl.Sys;
|
import org.lwjgl.Sys;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* LWJGL users must use this class to initialize OpenCL
|
* LWJGL users must use this class to initialize OpenCL
|
||||||
|
@ -82,26 +83,26 @@ public final class CL {
|
||||||
//throw new IllegalStateException("OpenCL has already been created.");
|
//throw new IllegalStateException("OpenCL has already been created.");
|
||||||
|
|
||||||
final String libname;
|
final String libname;
|
||||||
final String[] library_names;
|
final List<String> library_names;
|
||||||
switch ( LWJGLUtil.getPlatform() ) {
|
switch ( LWJGLUtil.getPlatform() ) {
|
||||||
case LWJGLUtil.PLATFORM_WINDOWS:
|
case LWJGLUtil.PLATFORM_WINDOWS:
|
||||||
libname = "OpenCL";
|
libname = "OpenCL";
|
||||||
library_names = new String[] { "OpenCL.dll" };
|
library_names = List.of("OpenCL.dll");
|
||||||
break;
|
break;
|
||||||
case LWJGLUtil.PLATFORM_LINUX:
|
case LWJGLUtil.PLATFORM_LINUX:
|
||||||
libname = "OpenCL";
|
libname = "OpenCL";
|
||||||
library_names = new String[] { "libOpenCL64.so", "libOpenCL.so" }; // TODO: Fix this
|
library_names = List.of("libOpenCL64.so", "libOpenCL.so"); // TODO: Fix this
|
||||||
break;
|
break;
|
||||||
case LWJGLUtil.PLATFORM_MACOSX:
|
case LWJGLUtil.PLATFORM_MACOSX:
|
||||||
libname = "OpenCL";
|
libname = "OpenCL";
|
||||||
library_names = new String[] { "OpenCL.dylib" }; // TODO: Fix this
|
library_names = List.of("OpenCL.dylib"); // TODO: Fix this
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new LWJGLException("Unknown platform: " + LWJGLUtil.getPlatform());
|
throw new LWJGLException("Unknown platform: " + LWJGLUtil.getPlatform());
|
||||||
}
|
}
|
||||||
|
|
||||||
final String[] oclPaths = LWJGLUtil.getLibraryPaths(libname, library_names, CL.class.getClassLoader());
|
final List<String> oclPaths = LWJGLUtil.getLibraryPaths(libname, library_names, CL.class.getClassLoader());
|
||||||
LWJGLUtil.log("Found " + oclPaths.length + " OpenCL paths");
|
LWJGLUtil.log("Found " + oclPaths.size() + " OpenCL paths");
|
||||||
for ( String oclPath : oclPaths ) {
|
for ( String oclPath : oclPaths ) {
|
||||||
try {
|
try {
|
||||||
nCreate(oclPath);
|
nCreate(oclPath);
|
||||||
|
@ -157,4 +158,4 @@ public final class CL {
|
||||||
|
|
||||||
private static native void resetNativeStubs(Class clazz);
|
private static native void resetNativeStubs(Class clazz);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue