2016-07-26 03:22:47 +03:00
import org.doomedsociety.gradlecpp.GradleCppUtils
import org.doomedsociety.gradlecpp.toolchain.icc.IccCompilerPlugin
import org.doomedsociety.gradlecpp.toolchain.icc.Icc
import org.doomedsociety.gradlecpp.cfg.ToolchainConfig
import org.doomedsociety.gradlecpp.msvc.MsvcToolchainConfig
import org.doomedsociety.gradlecpp.gcc.GccToolchainConfig
import org.doomedsociety.gradlecpp.cfg.ToolchainConfigUtils
import org.gradle.language.cpp.CppSourceSet
import org.gradle.language.rc.tasks.WindowsResourceCompile
import org.gradle.nativeplatform.NativeBinarySpec
import versioning.MetamodVersionInfo
import gradlecpp.VelocityUtils
apply plugin: 'cpp'
apply plugin: 'windows-resources'
apply plugin: IccCompilerPlugin
List < Task > getRcCompileTasks ( NativeBinarySpec binary ) {
def linkTask = GradleCppUtils . getLinkTask ( binary )
def res = linkTask . taskDependencies . getDependencies ( linkTask ) . findAll { Task t - > t instanceof WindowsResourceCompile }
return res as List
}
void postEvaluate ( NativeBinarySpec b ) {
if ( GradleCppUtils . windows ) {
getRcCompileTasks ( b ) . each { Task t - >
t . dependsOn project . generateAppVersion
}
} else {
// attach generateAppVersion task to all 'compile source' tasks
GradleCppUtils . getCompileTasks ( b ) . each { Task t - >
t . dependsOn project . generateAppVersion
}
}
}
void setupToolchain ( NativeBinarySpec b )
{
ToolchainConfig cfg = rootProject . createToolchainConfig ( b )
cfg . projectInclude ( project , '' , '/src' , '/include/common' , '/include/dlls' , '/include/engine' , '/include/game_shared' , '/include/pm_shared' , '/include/public' )
2016-07-26 19:31:47 +03:00
cfg . singleDefines 'METAMOD_CORE' ;
2016-07-26 03:22:47 +03:00
if ( cfg instanceof MsvcToolchainConfig ) {
cfg . compilerOptions . pchConfig = new MsvcToolchainConfig . PrecompiledHeadersConfig (
enabled: true ,
pchHeader: 'precompiled.h' ,
2016-07-26 05:08:43 +03:00
pchSourceSet: 'rmod_pch'
2016-07-26 03:22:47 +03:00
)
2017-01-17 23:51:43 +03:00
cfg . extraLibs 'psapi.lib'
2016-07-26 03:22:47 +03:00
cfg . singleDefines ( '_CRT_SECURE_NO_WARNINGS' )
} else if ( cfg instanceof GccToolchainConfig ) {
cfg . compilerOptions . pchConfig = new GccToolchainConfig . PrecompilerHeaderOptions (
enabled: true ,
2016-07-26 05:08:43 +03:00
pchSourceSet: 'rmod_pch'
2016-07-26 03:22:47 +03:00
)
cfg . compilerOptions . languageStandard = 'c++0x'
cfg . defines ( [
'_stricmp' : 'strcasecmp' ,
'_strnicmp' : 'strncasecmp' ,
2016-07-26 05:08:43 +03:00
'_strdup' : 'strdup' ,
'_unlink' : 'unlink' ,
2016-07-26 19:31:47 +03:00
'_write' : 'write' ,
'_close' : 'close' ,
'_getcwd' : 'getcwd' ,
2016-07-26 03:22:47 +03:00
'_vsnprintf' : 'vsnprintf' ,
2016-07-26 19:31:47 +03:00
'_vsnwprintf' : 'vswprintf' ,
'_snprintf' : 'snprintf'
2016-07-26 03:22:47 +03:00
] )
2017-06-28 20:27:46 +03:00
cfg . compilerOptions . args '-Qoption,cpp,--treat_func_as_string_literal_cpp' , '-msse2' , '-fomit-frame-pointer' , '-inline-forceinline' , '-fvisibility=default' , '-fvisibility-inlines-hidden' , '-fno-rtti' , '-g0' , '-s' , '-fno-exceptions'
2016-07-26 03:22:47 +03:00
}
ToolchainConfigUtils . apply ( project , cfg , b )
GradleCppUtils . onTasksCreated ( project , 'postEvaluate' , {
postEvaluate ( b )
} )
}
model {
buildTypes {
debug
release
}
platforms {
x86 {
architecture "x86"
}
}
toolChains {
visualCpp ( VisualCpp ) {
}
icc ( Icc ) {
}
}
components {
metamod ( NativeLibrarySpec ) {
targetPlatform 'x86'
2017-01-17 23:51:43 +03:00
baseName GradleCppUtils . windows ? 'metamod' : 'metamod_i386'
2016-07-26 03:22:47 +03:00
sources {
2016-07-26 05:08:43 +03:00
rmod_pch ( CppSourceSet ) {
2016-07-26 03:22:47 +03:00
source {
srcDirs "src"
include "precompiled.cpp"
}
exportedHeaders {
srcDirs "include"
}
}
2016-07-26 05:08:43 +03:00
rmod_src ( CppSourceSet ) {
2016-07-26 03:22:47 +03:00
source {
srcDir "src"
srcDir "version"
include "**/*.cpp"
2016-07-26 05:08:43 +03:00
2016-07-26 03:22:47 +03:00
exclude "precompiled.cpp"
}
exportedHeaders {
srcDirs "include"
}
}
rc {
source {
2016-07-26 05:08:43 +03:00
srcDirs "msvc"
2016-07-26 03:22:47 +03:00
include "metamod.rc"
}
exportedHeaders {
srcDirs "msvc"
}
}
}
binaries . all {
NativeBinarySpec b - > project . setupToolchain ( b )
}
}
}
}
afterEvaluate {
project . binaries . all {
NativeBinarySpec binary - >
Tool linker = binary . linker
if ( GradleCppUtils . windows ) {
linker . args "/DEF:${projectDir}\\msvc\\metamod.def"
}
}
}
task buildRelease {
dependsOn binaries . withType ( SharedLibraryBinarySpec ) . matching { SharedLibraryBinarySpec blib - >
blib . buildable & & blib . buildType . name = = 'release'
}
}
tasks . clean . doLast {
project . file ( 'version/appversion.h' ) . delete ( )
}
task generateAppVersion {
MetamodVersionInfo verInfo = ( MetamodVersionInfo ) rootProject . metamodVersionInfo
def tplFile = project . file ( 'version/appversion.vm' )
def renderedFile = project . file ( 'version/appversion.h' )
inputs . file tplFile
inputs . file project . file ( 'gradle.properties' )
outputs . file renderedFile
inputs . property ( 'version' , verInfo . asMavenVersion ( ) )
inputs . property ( 'lastCommitDate' , verInfo . lastCommitDate . toString ( ) )
2017-06-28 20:27:46 +03:00
println "##teamcity[buildNumber '" + verInfo . asVersion ( ) + "']" ;
2016-07-26 03:22:47 +03:00
doLast {
2016-07-26 05:08:43 +03:00
def content = VelocityUtils . renderTemplate ( tplFile , verInfo )
2016-07-26 03:22:47 +03:00
renderedFile . delete ( )
renderedFile . write ( content , 'utf-8' )
println 'The current Metamod version is ' + verInfo . asVersion ( ) . toString ( ) + ', maven version is ' + verInfo . asMavenVersion ( ) . toString ( ) + ', commit id: ' + verInfo . commitID . toString ( ) + ', commit author: ' + verInfo . authorCommit . toString ( ) + ', url: (' + verInfo . urlCommits . toString ( ) + ')' ;
}
}