-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
195 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
dependencies { | ||
implementation(project(":example:lib:core")) | ||
implementation(project(":example:lib:core-ext")) | ||
|
||
implementation("com.badlogicgames.gdx:gdx:${LibExt.gdxVersion}") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
dependencies { | ||
implementation(project(":example:lib:core")) | ||
} |
7 changes: 7 additions & 0 deletions
7
example/lib-ext/ext-base/src/main/java/com.lib.ext/CustomLib.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.lib.ext; | ||
|
||
public class CustomLib { | ||
/*[-C++;-NATIVE] | ||
#include "CustomLib.h" | ||
*/ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
plugins { | ||
id("java") | ||
} | ||
|
||
dependencies { | ||
implementation(project(":example:lib:core")) | ||
} | ||
|
||
tasks.named("clean") { | ||
doFirst { | ||
val srcPath = "$projectDir/src/main/" | ||
project.delete(files(srcPath)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
plugins { | ||
id("java") | ||
} | ||
|
||
val mainClassName = "Main" | ||
|
||
dependencies { | ||
implementation(project(":example:lib:core")) | ||
implementation(project(":jParser:core")) | ||
implementation(project(":jParser:idl")) | ||
implementation(project(":jParser:teavm")) | ||
implementation(project(":jParser:cpp")) | ||
implementation(project(":jParser:builder")) | ||
} | ||
|
||
tasks.register<JavaExec>("build_project") { | ||
group = "gen" | ||
description = "Generate native project" | ||
mainClass.set(mainClassName) | ||
classpath = sourceSets["main"].runtimeClasspath | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
interface CustomLib { | ||
static void print(); | ||
}; |
1 change: 1 addition & 0 deletions
1
example/lib-ext/ext-generator/src/main/cpp/cpp-source/custom/CustomLib.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#include "CustomLib.h" |
14 changes: 14 additions & 0 deletions
14
example/lib-ext/ext-generator/src/main/cpp/cpp-source/custom/CustomLib.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#pragma once | ||
|
||
#include <iostream> | ||
|
||
class CustomLib { | ||
|
||
private: | ||
|
||
public: | ||
|
||
static void print() { | ||
std::cout << " PRINT " << std::endl; | ||
} | ||
}; |
72 changes: 72 additions & 0 deletions
72
example/lib-ext/ext-generator/src/main/java/BuildCustomCode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import com.github.xpenatan.jparser.builder.BuildConfig; | ||
import com.github.xpenatan.jparser.builder.BuildMultiTarget; | ||
import com.github.xpenatan.jparser.builder.BuildTarget; | ||
import com.github.xpenatan.jparser.builder.JBuilder; | ||
import com.github.xpenatan.jparser.builder.targets.WindowsTarget; | ||
import com.github.xpenatan.jparser.core.JParser; | ||
import com.github.xpenatan.jparser.core.util.FileHelper; | ||
import com.github.xpenatan.jparser.cpp.CppCodeParser; | ||
import com.github.xpenatan.jparser.cpp.CppGenerator; | ||
import com.github.xpenatan.jparser.cpp.NativeCPPGenerator; | ||
import com.github.xpenatan.jparser.idl.IDLReader; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import java.util.ArrayList; | ||
|
||
public class BuildCustomCode { | ||
|
||
public static void build() throws Exception { | ||
String libName = "extlib"; | ||
String basePackage = "com.lib.ext"; | ||
|
||
String libPath = new File("../../lib").getCanonicalPath().replace("\\", "/"); | ||
String idlPath = new File("src/main/cpp/ExtLib.idl").getCanonicalPath(); | ||
IDLReader idlReader = IDLReader.readIDL(idlPath); | ||
String baseJavaDir = new File(".").getAbsolutePath() + "./ext-base/src/main/java"; | ||
|
||
String cppSourceDir = new File("./src/main/cpp/cpp-source//source/").getCanonicalPath(); | ||
String libsDir = new File("./build/c++/libs/").getCanonicalPath(); | ||
String libBuildPath = new File("./build/c++/").getCanonicalPath(); | ||
String cppDestinationPath = libBuildPath + "/src"; | ||
String libDestinationPath = cppDestinationPath + "/extlib"; | ||
|
||
FileHelper.copyDir(cppSourceDir, libDestinationPath); | ||
|
||
Path copyOut = new File(libDestinationPath).toPath(); | ||
FileHelper.copyDir(new File("src/main/cpp/cpp-source/custom").toPath(), copyOut); | ||
|
||
JParser.CREATE_IDL_HELPER = false; | ||
|
||
CppGenerator cppGenerator = new NativeCPPGenerator(libDestinationPath, false); | ||
CppCodeParser cppParser = new CppCodeParser(cppGenerator, idlReader, basePackage, cppSourceDir); | ||
cppParser.generateClass = true; | ||
JParser.generate(cppParser, baseJavaDir, "../ext-core/src/main/java"); | ||
|
||
BuildConfig buildConfig = new BuildConfig(cppDestinationPath, libBuildPath, libsDir, libName); | ||
|
||
ArrayList<BuildMultiTarget> targets = new ArrayList<>(); | ||
if(BuildTarget.isWindows() || BuildTarget.isUnix()) { | ||
targets.add(getWindowBuildTarget(libPath)); | ||
} | ||
|
||
JBuilder.build(buildConfig, targets); | ||
} | ||
|
||
private static BuildMultiTarget getWindowBuildTarget(String libPath) throws IOException { | ||
BuildMultiTarget multiTarget = new BuildMultiTarget(); | ||
|
||
String libCppPath = libPath + "/generator/build/c++"; | ||
|
||
WindowsTarget windowsTarget = new WindowsTarget(); | ||
windowsTarget.headerDirs.add("-I" + libCppPath + "/src/imgui"); | ||
windowsTarget.isStatic = true; | ||
windowsTarget.addJNI = true; | ||
windowsTarget.headerDirs.add("-Isrc/extlib/"); | ||
windowsTarget.cppInclude.add("**/extlib/*.cpp"); | ||
multiTarget.add(windowsTarget); | ||
|
||
return multiTarget; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
public class Main { | ||
public static void main(String[] args) throws Exception { | ||
BuildCustomCode.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
plugins { | ||
id("java") | ||
} | ||
|
||
|
||
dependencies { | ||
implementation(project(":example:lib:core")) | ||
implementation("org.teavm:teavm-jso:${LibExt.teaVMVersion}") | ||
implementation("org.teavm:teavm-classlib:${LibExt.teaVMVersion}") | ||
} | ||
|
||
tasks.named("clean") { | ||
doFirst { | ||
val srcPath = "$projectDir/src/main/java/gen" | ||
project.delete(files(srcPath)) | ||
} | ||
} |
Empty file.
1 change: 1 addition & 0 deletions
1
example/lib-ext/ext-teavm/src/main/resources/META-INF/teavm.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
mapPackageHierarchy|gen.com=com |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
plugins { | ||
id("java-library") | ||
} | ||
|
||
dependencies { | ||
api(project(":example:lib:core")) | ||
api(project(":example:lib-ext:ext-core")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters