diff --git a/wpilibjExamples/build.gradle b/wpilibjExamples/build.gradle index ac59aa1213..ee8ae94de1 100644 --- a/wpilibjExamples/build.gradle +++ b/wpilibjExamples/build.gradle @@ -1,3 +1,5 @@ +import edu.wpi.first.toolchain.NativePlatforms + apply plugin: 'java' apply plugin: 'jacoco' @@ -83,6 +85,115 @@ ext { commandFile = new File("$projectDir/src/main/java/edu/wpi/first/wpilibj/commands/commands.json") } +apply plugin: 'cpp' +apply plugin: 'edu.wpi.first.NativeUtils' + +apply from: '../shared/config.gradle' + + +model { + components { + wpilibjExamplesDev(NativeExecutableSpec) { + targetBuildTypes 'debug' + sources { + cpp { + source { + srcDirs 'src/dev/native/cpp' + include '**/*.cpp' + } + exportedHeaders { + srcDirs 'src/dev/native/include' + } + } + } + binaries.all { binary -> + lib project: ':wpilibOldCommands', library: 'wpilibOldCommands', linkage: 'shared' + lib project: ':wpilibNewCommands', library: 'wpilibNewCommands', linkage: 'shared' + lib project: ':wpilibc', library: 'wpilibc', linkage: 'shared' + lib project: ':wpimath', library: 'wpimath', linkage: 'shared' + lib project: ':ntcore', library: 'ntcore', linkage: 'shared' + lib project: ':cscore', library: 'cscore', linkage: 'shared' + lib project: ':ntcore', library: 'ntcoreJNIShared', linkage: 'shared' + lib project: ':cscore', library: 'cscoreJNIShared', linkage: 'shared' + project(':hal').addHalDependency(binary, 'shared') + project(':hal').addHalJniDependency(binary) + lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared' + lib project: ':cameraserver', library: 'cameraserver', linkage: 'shared' + if (binary.targetPlatform.name == nativeUtils.wpi.platforms.roborio) { + nativeUtils.useRequiredLibrary(binary, 'netcomm_shared', 'chipobject_shared', 'visa_shared', 'ni_runtime_shared') + } else { + def systemArch = getCurrentArch() + if (binary.targetPlatform.name == systemArch) { + lib project: ":simulation:halsim_gui", library: 'halsim_gui', linkage: 'shared' + } + } + nativeUtils.useRequiredLibrary(binary, 'opencv_shared') + } + } + } + tasks { + def c = $.components + def found = false + c.each { + if (it in NativeExecutableSpec && it.name == "wpilibjExamplesDev") { + it.binaries.each { + if (!found) { + def arch = it.targetPlatform.name + if (arch == NativePlatforms.desktop) { + found = true + def filePath = it.tasks.install.installDirectory.get().toString() + File.separatorChar + 'lib' + + def doFirstTask = { task -> + def extensions = '' + it.tasks.install.installDirectory.get().getAsFile().eachFileRecurse { + def name = it.name + if (!(name.endsWith('.dll') || name.endsWith('.so') || name.endsWith('.dylib'))) { + return + } + def file = it + if (name.startsWith("halsim_gui") || name.startsWith("libhalsim_gui".toString())) { + extensions += file.absolutePath + File.pathSeparator + } + } + if (extensions != '') { + task.environment 'HALSIM_EXTENSIONS', extensions + } + } + + project.tasks.create("runCpp", Exec) { task -> + dependsOn it.tasks.install + commandLine it.tasks.install.runScriptFile.get().asFile.toString() + test.dependsOn it.tasks.install + test.systemProperty 'java.library.path', filePath + test.environment 'LD_LIBRARY_PATH', filePath + test.workingDir filePath + } + + new groovy.json.JsonSlurper().parseText(exampleFile.text).each { entry -> + project.tasks.create("run${entry.foldername}", JavaExec) { run -> + main = "edu.wpi.first.wpilibj.examples." + entry.foldername + ".Main" + classpath = sourceSets.main.runtimeClasspath + run.dependsOn it.tasks.install + run.systemProperty 'java.library.path', filePath + run.environment 'LD_LIBRARY_PATH', filePath + run.workingDir filePath + doFirst { doFirstTask(run) } + + if (org.gradle.internal.os.OperatingSystem.current().isMacOsX()) { + run.jvmArgs = ['-XstartOnFirstThread'] + } + } + } + + found = true + } + } + } + } + } + } +} + ext { isCppCommands = false } diff --git a/wpilibjExamples/src/dev/native/cpp/main.cpp b/wpilibjExamples/src/dev/native/cpp/main.cpp new file mode 100644 index 0000000000..8798bb9b1f --- /dev/null +++ b/wpilibjExamples/src/dev/native/cpp/main.cpp @@ -0,0 +1,8 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2020 FIRST. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in the root directory of */ +/* the project. */ +/*----------------------------------------------------------------------------*/ + +int main() {}