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
|
||||
* @return Paths to located libraries, if any
|
||||
*/
|
||||
public static String[] getLibraryPaths(String libname, String platform_lib_name, ClassLoader classloader) {
|
||||
return getLibraryPaths(libname, new String[]{platform_lib_name}, classloader);
|
||||
public static List<String> getLibraryPaths(String libname, String platform_lib_name, ClassLoader 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
|
||||
* @return Paths to located libraries, if any
|
||||
*/
|
||||
public static String[] getLibraryPaths(String libname, String[] platform_lib_names, ClassLoader classloader) {
|
||||
String overridePath = getPrivilegedProperty("org.lwjgl.librarypath");
|
||||
public static List<String> getLibraryPaths(String libname, List<String> platform_lib_names, ClassLoader classloader) {
|
||||
String overridePath = getPrivilegedProperty("org.lwjgl.librarypath.override." + libname);
|
||||
if (overridePath != null) {
|
||||
String[] paths = new String[platform_lib_names.length];
|
||||
for (int i = 0; i < paths.length; i++) {
|
||||
paths[i] = overridePath + File.separator + platform_lib_names[i];
|
||||
}
|
||||
return paths;
|
||||
// override specifies an exact path
|
||||
return List.of(overridePath);
|
||||
}
|
||||
|
||||
// need to pass path of possible locations of library to native side
|
||||
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);
|
||||
if (classloader_path != null) {
|
||||
if (DEBUG) {
|
||||
|
@ -242,8 +245,7 @@ public class LWJGLUtil {
|
|||
possible_paths.add(platform_lib_name);
|
||||
}
|
||||
|
||||
//create needed string array
|
||||
return possible_paths.toArray(new String[possible_paths.size()]);
|
||||
return possible_paths;
|
||||
}
|
||||
|
||||
static void execPrivileged(String... cmd_array) throws Exception {
|
||||
|
|
|
@ -35,7 +35,7 @@ import org.lwjgl.LWJGLException;
|
|||
import org.lwjgl.LWJGLUtil;
|
||||
import org.lwjgl.Sys;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
|
@ -114,30 +114,30 @@ public final class AL {
|
|||
if (created)
|
||||
throw new IllegalStateException("Only one OpenAL context may be instantiated at any one time.");
|
||||
String libname;
|
||||
String[] library_names;
|
||||
List<String> library_names;
|
||||
switch (LWJGLUtil.getPlatform()) {
|
||||
case LWJGLUtil.PLATFORM_WINDOWS:
|
||||
if ( Sys.is64Bit() ) {
|
||||
libname = "OpenAL64";
|
||||
library_names = new String[]{"OpenAL64.dll"};
|
||||
library_names = List.of("OpenAL64.dll");
|
||||
} else {
|
||||
libname = "OpenAL32";
|
||||
library_names = new String[]{"OpenAL32.dll"};
|
||||
library_names = List.of("OpenAL32.dll");
|
||||
}
|
||||
break;
|
||||
case LWJGLUtil.PLATFORM_LINUX:
|
||||
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;
|
||||
case LWJGLUtil.PLATFORM_MACOSX:
|
||||
libname = "openal";
|
||||
library_names = new String[]{"openal.dylib"};
|
||||
library_names = List.of("openal.dylib");
|
||||
break;
|
||||
default:
|
||||
throw new LWJGLException("Unknown platform: " + LWJGLUtil.getPlatform());
|
||||
}
|
||||
String[] oalPaths = LWJGLUtil.getLibraryPaths(libname, library_names, AL.class.getClassLoader());
|
||||
LWJGLUtil.logger().log(() -> "Found " + oalPaths.length + " OpenAL paths: " + Arrays.toString(oalPaths));
|
||||
List<String> oalPaths = LWJGLUtil.getLibraryPaths(libname, library_names, AL.class.getClassLoader());
|
||||
LWJGLUtil.logger().log(() -> "Found " + oalPaths.size() + " OpenAL paths: " + oalPaths);
|
||||
for ( String oalPath : oalPaths ) {
|
||||
try {
|
||||
nCreate(oalPath);
|
||||
|
|
|
@ -37,6 +37,7 @@ import org.lwjgl.MemoryUtil;
|
|||
import org.lwjgl.Sys;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 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.");
|
||||
|
||||
final String libname;
|
||||
final String[] library_names;
|
||||
final List<String> library_names;
|
||||
switch ( LWJGLUtil.getPlatform() ) {
|
||||
case LWJGLUtil.PLATFORM_WINDOWS:
|
||||
libname = "OpenCL";
|
||||
library_names = new String[] { "OpenCL.dll" };
|
||||
library_names = List.of("OpenCL.dll");
|
||||
break;
|
||||
case LWJGLUtil.PLATFORM_LINUX:
|
||||
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;
|
||||
case LWJGLUtil.PLATFORM_MACOSX:
|
||||
libname = "OpenCL";
|
||||
library_names = new String[] { "OpenCL.dylib" }; // TODO: Fix this
|
||||
library_names = List.of("OpenCL.dylib"); // TODO: Fix this
|
||||
break;
|
||||
default:
|
||||
throw new LWJGLException("Unknown platform: " + LWJGLUtil.getPlatform());
|
||||
}
|
||||
|
||||
final String[] oclPaths = LWJGLUtil.getLibraryPaths(libname, library_names, CL.class.getClassLoader());
|
||||
LWJGLUtil.log("Found " + oclPaths.length + " OpenCL paths");
|
||||
final List<String> oclPaths = LWJGLUtil.getLibraryPaths(libname, library_names, CL.class.getClassLoader());
|
||||
LWJGLUtil.log("Found " + oclPaths.size() + " OpenCL paths");
|
||||
for ( String oclPath : oclPaths ) {
|
||||
try {
|
||||
nCreate(oclPath);
|
||||
|
|
Loading…
Reference in New Issue