我是Gradle的新手并尝试创建跨平台构建脚本。 我希望使用自定义源目录。不是src / {ProjectName} / cpp或header / {ProjectName} / cpp。 我的源文件位于名为“src”和“include”的文件夹中,与build.gradle文件位于同一级别。
请参阅我的项目目录结构图片
如何仅链接到这些源文件夹? gradle cpp库示例不包括此内容。 我已成功构建脚本但不生成exe。我猜是因为它无法找到cpp文件。
更好的是,我怎样才能看到gradle使用的路径? 选项 - " -info"并且“-debug”似乎没有输出使用的源路径。
以下是我的完整脚本......
apply plugin: 'cpp'
model {
buildTypes {
debug
release
}
platforms {
//osx_64 {
//architecture "x86_64"
//operatingSystem "osx"
//}
windows_x86 {
architecture "x86"
operatingSystem "windows"
}
windows_64 {
architecture "x86_64"
operatingSystem "windows"
}
}
repositories {
libs(PrebuiltLibraries) {
libcinder {
headers.srcDir "/../cinder/include/"
binaries.withType(StaticLibraryBinary) {
if (targetPlatform.operatingSystem.windows) {
if (targetPlatform == platforms.windows_x86) {
if(buildType == buildTypes.debug) {
staticLibraryFile = file("/../cinder/lib/msw/x86/Debug/v140/cinder.lib")
} else if(buildType == buildTypes.release) {
staticLibraryFile = file("/../cinder/lib/msw/x86/Release/v140/cinder.lib")
}
} else if(targetPlatform == platforms.windows_64) {
if(buildType == buildTypes.debug) {
staticLibraryFile = file("/../cinder/lib/msw/x64/Debug/v140/cinder.lib")
} else if(buildType == buildTypes.release) {
staticLibraryFile = file("/../cinder/lib/msw/x64/Release/v140/cinder.lib")
}
}
} //else if(targetPlatform.operatingSystem.o osx) {
//if (targetPlatform == platforms.osx_64) {
//if(buildType == buildTypes.debug) {
//staticLibraryFile = file("/../cinder/lib/macosx/Debug/libcinder.a")
//} else if(buildType == buildTypes.release) {
//staticLibraryFile = file("/../cinder/lib/macosx/Release/libcinder.a")
//}
//}
//}
}
}
}
}
components {
main(NativeExecutableSpec) {
sources {
cpp {
source {
srcDir "src"
include "include"
cpp.lib library: "libcinder", linkage: "static"
}
}
}
}
}
/*
components {
main(NativeExecutableSpec) {
sources {
cpp.lib library: "libcinder", linkage: "static"
}
}
}
*/
}
答案 0 :(得分:1)
您可以使用sourceSets配置资源,例如。
apply plugin: 'java'
sourceSets {
main {
java {
srcDirs = [
"$projectDir/src/main/java",
"$projectDir/$generatedDir",
"$projectDir/config/sql"
]
include '**/*.java'
}
resources {
srcDirs = [
"$projectDir/src/main/resources"
]
}
}
test {
java { srcDir 'src/test/java'}
resources { srcDir 'src/test/resources' }
}
componentTest {
java { srcDir 'src/ctest/java' }
resources { srcDir 'src/ctest/resources' }
}
}
答案 1 :(得分:0)
Gradle C ++项目的完成方式与Java项目中的完成方式不同。
cpp-application
/ cpp-library
这些插件是introduced in 2018,是以后构建C ++项目的首选方法(请参见full documentation)。
摘自“ Customizing file and directory locations”上的文档:
plugins {
id 'cpp-application'
}
application {
source.from file('src')
privateHeaders.from file('src')
publicHeaders.from file('include')
}
plugins {
id 'cpp-library'
}
library {
source.from file('src')
privateHeaders.from file('src')
publicHeaders.from file('include')
}
请注意,通过声明这些内容,Gradle将仅在这些目录中搜索(而不在src/main/cpp
的默认位置中)。
cpp
插件(已弃用)使用该软件模型的cpp
插件是一种过时的,过时的构建C ++项目的方法(请参见documentation)。
apply plugin: "cpp"
sources {
cpp {
source {
srcDir "src"
// Note that this reference to "include" refers to the files that should be matched in this directory and has nothing to do with the include directory
include "**/*.cpp"
}
exportedHeaders {
srcDir "include"
}
}
}