迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):Tocea/gradle-cpp-plugin开源软件地址(OpenSource Url):https://github.com/Tocea/gradle-cpp-plugin开源编程语言(OpenSource Language):Groovy 49.7%开源软件介绍(OpenSource Introduction):gradle-cpp-pluginGradle C/C++ plugin with C++ build tools interactions. This plugins launches C++ build tools and adds Gradle capabilities like :
UsageTo use the gradle-cpp-plugin, include the following in your build script: Exemple 1. Using the gradle-cpp-plugin build.gradle buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "gradle.plugin.fr.echoes.gradle.plugins:cpp-project-plugin:1.2.9"
}
}
apply plugin: "fr.echoes.gradle.cpp" Source setsThe Cpp plugin is used to be used with this kind of structure folders
TasksThe cpp plugin adds a number of tasks to your project, as shown below. Table 1. Cpp plugin - tasks
Figure 1. Cpp plugin -tasks Dependency managementThe cpp plugin adds a number of dependencies configurations to your project, as shown below. It assigns those configurations to tasks such as compileCpp. Table 2. Cpp plugin - dependency configurations
Exemple 2. External dependencies dependencies {
compile "fr.extern:sqlapi:4.1.4:lin_x86_64@clib"
// or
compile group: "fr.extern", name: "sqlapi", version: "4.1.4", classifier: "lin_x86_64", ext: "clib"
} Exemple 3. Internal dependencies dependencies {
compile project(path: ":projectPath", configuration: "cArchives"
} The notion of 'Projects'Gradle is a project and dependencies manager. So, a gradle project must be seen as an atomic project which contains only :
The C building tool under Gradle have to be able to :
Projects examples can be found in the plugin source code in the note : at this time, I'm not a cmake expert. I do not succes to create all this make rules with CMake : I only manage to compile sources and test sources with the command Cmake project are used to have a Exemple of possible refactorings for the project cmake-hello-worldIn this project, a library 'hello' is used by the main file Use the library as a sources.First choice, you considere that the 'hello' library, as the 'helloword.cpp' file is a part of the project et must be placed inside as sources : Exemple : A single gradle project cmake-hello-world
|___build.gradle
|___gradle.properties
|___CmakeLists.txt
|___src/
|___main/
|___headers/
| |___Speaker.h
|___cpp/
|___Speaker.cpp
|___helloWord.cpp
Use the library as an external dependencySecond choice, you considere that the 'hello' library has nothing to do with the project. This library can be used by many projects, in many computers. So create a gradle project 'hello-library', place the souces inside, and upload it in an artifact reposotory manager as Nexus for example. Then in the project cmake-hello-world, use it as a dependency. Exemple : use hello dependency in the build.gradle file dependencies {
compile ("com.example:hello-library:1.0@clib"
} Use this library as a sub-module projectThird choice, The 'hello' library has nothing to in this project. but this library is close of the project. The project and the library are a part of the same product. In this case, It can be a good idea te create a gradle project for this product which contain sub-modules (the 'hello' library and the 'cmake-hello-world' project). Exemple : gradle multi-modules project exemple-project
|___settings.gradle
|___gradle.properties
|___build.gradle
|___hello-library
| |___src/…
| |___CMakeLists.txt
| |___build.gradle
|___cmake-hello-world
|___src/…
|___CMakeLists.txt
|___build.gradle And adding in the cmake-hello-world/build.gradle the dependency to the 'hello-library' dependencies {
compile project(path: ":hello-library", configuration: "cArchives")
} In Conclusion :The gradle cpp plugin create a real notion of Projects and libraries. User of this plugins have to have in minds these notions when they create their projects configurations with usual C tools (Make, CMake…). You can find the 3 possibles solutions in the 'exemplek folders in the source code. Extension propertiesThe Java plugin adds a number of conventions properties to the project, shown below. You can use these properties in your build script as though they were properties of the project object. Table 3. Cpp plugin - Project projerties
Exemple 2. Cpp extension exemple cpp {
// some contents
} Table 4. Cpp plugin - CppPluginExtension projerties
Exemple 4. Cpp extension exemple cpp {
applicationType = "capplication"
classifier = "lin_gcc_x32_64"
buildTasksEnabled = true
exec.with {
// some contents
}
} Table 5. Cpp plugin - CppExecConfiguration projerties
Exemple 5. CppExecConfiguration exemple cpp {
exec.with {
execPath = 'echo'
env = [JAVA_HOME: "/usr/lib/jvm/java-8-oracle"]
compileCppExecPath = "make"
compileCppBaseArgs = "compile"
compileCppExecWorkingDir = "build"
}
} CleanThe clean task is an instance of Delete. It simply removes the directory denoted by its ${project.buildDir} property. modulesTo simplify the configurations of the C build tools, some modules are provideds. At this time only cmake modules are provided. Provided lists : Exemple of configuration with CmakeExemple 6. Exemple of build.gradle to use cmake task launchCMake(type: Exec, group: "init") {
workingDir = buildDir
executable = "cmake"
args ".."
}
compileCpp.dependsOn launchCMake
cpp {
applicationType = "clibrary"
exec.with {
execPath = 'echo'
compileCppExecPath = "make"
compileCppBaseArgs = "compile"
compileCppExecWorkingDir = "build"
}
} Then launch the build.
An exemple of console output.
![]() |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论