2015-06-30 12:46:07 +03:00
import gradlecpp.RegamedllPlayTestPlugin
import gradlecpp.RegamedllPlayTestTask
import gradlecpp.VelocityUtils
import org.doomedsociety.gradlecpp.GradleCppUtils
import org.doomedsociety.gradlecpp.LazyNativeDepSet
import org.doomedsociety.gradlecpp.cfg.ToolchainConfig
import org.doomedsociety.gradlecpp.cfg.ToolchainConfigUtils
import org.doomedsociety.gradlecpp.gcc.GccToolchainConfig
import org.doomedsociety.gradlecpp.msvc.EnhancedInstructionsSet
import org.doomedsociety.gradlecpp.msvc.FloatingPointModel
import org.doomedsociety.gradlecpp.msvc.MsvcToolchainConfig
import org.doomedsociety.gradlecpp.toolchain.icc.Icc
import org.doomedsociety.gradlecpp.toolchain.icc.IccCompilerPlugin
import org.gradle.language.cpp.CppSourceSet
import org.gradle.nativeplatform.NativeBinarySpec
import org.gradle.nativeplatform.NativeExecutableSpec
import org.gradle.nativeplatform.NativeLibrarySpec
import org.gradle.nativeplatform.SharedLibraryBinarySpec
import regamedll.testdemo.RegamedllDemoRunner
import versioning.RegamedllVersionInfo
import org.apache.commons.io.FilenameUtils
2015-07-05 14:05:26 +03:00
import org.apache.commons.compress.archivers.ArchiveInputStream
2015-06-30 12:46:07 +03:00
apply plugin: 'cpp'
apply plugin: IccCompilerPlugin
apply plugin: RegamedllPlayTestPlugin
apply plugin: gradlecpp . CppUnitTestPlugin
repositories {
maven {
url 'http://nexus.rehlds.org/nexus/content/repositories/regamedll-releases/'
}
}
configurations {
2015-12-05 22:40:30 +03:00
regamedll_tests
2015-06-30 12:46:07 +03:00
}
dependencies {
2016-02-23 22:54:07 +03:00
regamedll_tests 'regamedll.testdemos:cstrike-basic:1.0'
2015-06-30 12:46:07 +03:00
}
project . ext . dep_cppunitlite = project ( ':dep/cppunitlite' )
void createIntergrationTestTask ( NativeBinarySpec b ) {
2015-12-05 22:40:30 +03:00
boolean regamedllFixes = b . flavor . name . contains ( 'regamedllFixes' )
2016-02-23 22:54:07 +03:00
boolean mpLib = b . name . toLowerCase ( ) . contains ( 'mp' )
2015-12-05 22:40:30 +03:00
if ( ! ( b instanceof SharedLibraryBinarySpec ) ) return
if ( ! GradleCppUtils . windows ) return
if ( regamedllFixes ) return
2016-02-23 22:54:07 +03:00
if ( ! mpLib ) return
2015-12-05 22:40:30 +03:00
String unitTestTask = b . hasProperty ( 'cppUnitTestTask' ) ? b . cppUnitTestTask : null
def demoItgTestTask = project . tasks . create ( b . namingScheme . getTaskName ( 'demoItgTest' ) , RegamedllPlayTestTask )
demoItgTestTask . with {
regamedllImageRoot = new File ( project . projectDir , '_regamedllTestImg' )
regamedllTestLogs = new File ( this . project . buildDir , "_regamedllTestLogs/${b.name}" )
testDemos = project . configurations . regamedll_tests
testFor = b
2016-02-23 22:54:07 +03:00
//inputs/outputs for up-to-date check
inputs . files testDemos . files
outputs . dir regamedllTestLogs
2015-12-05 22:40:30 +03:00
2016-02-23 22:54:07 +03:00
//dependencies on test executable
if ( unitTestTask ) {
dependsOn unitTestTask
}
2015-12-05 22:40:30 +03:00
2016-02-23 22:54:07 +03:00
postExtractAction {
def binaryOutFile = GradleCppUtils . getBinaryOutputFile ( b )
def binaryOutDir = new File ( project . projectDir , '/_regamedllTestImg/cstrike/dlls' )
GradleCppUtils . copyFile ( binaryOutFile , new File ( binaryOutDir , binaryOutFile . name ) , true )
2015-12-05 22:40:30 +03:00
}
}
b . buildTask . dependsOn demoItgTestTask
2015-06-30 12:46:07 +03:00
}
void postEvaluate ( NativeBinarySpec b ) {
2015-12-05 22:40:30 +03:00
// attach generateAppVersion task to all 'compile source' tasks
GradleCppUtils . getCompileTasks ( b ) . each { Task t - >
t . dependsOn project . generateAppVersion
}
2015-06-30 12:46:07 +03:00
2015-12-05 22:40:30 +03:00
createIntergrationTestTask ( b )
2015-06-30 12:46:07 +03:00
}
2015-12-05 22:40:30 +03:00
void setupToolchain ( NativeBinarySpec b )
{
boolean unitTestExecutable = b . component . name . endsWith ( '_tests' )
boolean mpLib = b . name . toLowerCase ( ) . contains ( 'mp' )
boolean regamedllFixes = b . flavor . name . contains ( 'regamedllFixes' )
ToolchainConfig cfg = rootProject . createToolchainConfig ( b )
2016-02-23 02:13:52 +03:00
cfg . projectInclude ( project , '' , '/engine' , '/common' , '/dlls' , '/game_shared' , '/pm_shared' , '/regamedll' , '/hookers' , '/public' , '/public/regamedll' )
2015-12-05 22:40:30 +03:00
if ( unitTestExecutable )
{
cfg . projectInclude ( dep_cppunitlite , '/include' )
b . lib LazyNativeDepSet . create ( dep_cppunitlite , 'cppunitlite' , b . buildType . name , true )
}
cfg . singleDefines 'USE_BREAKPAD_HANDLER' , 'DEDICATED' , 'REGAMEDLL_SELF' , 'CLIENT_WEAPONS'
if ( cfg instanceof MsvcToolchainConfig )
{
cfg . compilerOptions . pchConfig = new MsvcToolchainConfig . PrecompiledHeadersConfig (
enabled: true ,
pchHeader: 'precompiled.h' ,
pchSourceSet: 'regamedll_pch'
) ;
cfg . singleDefines ( '_CRT_SECURE_NO_WARNINGS' )
if ( ! regamedllFixes )
{
cfg . compilerOptions . floatingPointModel = FloatingPointModel . PRECISE
cfg . compilerOptions . enhancedInstructionsSet = EnhancedInstructionsSet . DISABLED
}
if ( mpLib )
{
cfg . linkerOptions . randomizedBaseAddress = false
cfg . linkerOptions . baseAddress = '0x4970000'
}
}
2016-02-04 03:18:26 +03:00
else if ( cfg instanceof GccToolchainConfig )
{
2015-12-05 22:40:30 +03:00
cfg . compilerOptions . pchConfig = new GccToolchainConfig . PrecompilerHeaderOptions (
enabled: true ,
pchSourceSet: 'regamedll_pch'
) ;
cfg . compilerOptions . languageStandard = 'c++0x'
cfg . defines ( [
'_stricmp' : 'strcasecmp' ,
'_strnicmp' : 'strncasecmp' ,
'_strdup' : 'strdup' ,
'_unlink' : 'unlink' ,
'_vsnprintf' : 'vsnprintf' ,
'_write' : 'write' ,
'_close' : 'close' ,
2016-01-19 14:54:31 +03:00
'_vsnwprintf' : 'vswprintf'
2015-12-05 22:40:30 +03:00
] )
2015-12-06 22:02:16 +03:00
cfg . linkerOptions . args '-no-opt-class-analysis'
cfg . compilerOptions . args '-Qoption,cpp,--treat_func_as_string_literal_cpp' , '-g'
2016-02-23 02:13:52 +03:00
cfg . extraLibs 'dl' , 'm' , 'stdc++'
2015-12-05 22:40:30 +03:00
}
2016-02-23 22:54:07 +03:00
if ( mpLib & & GradleCppUtils . windows & & ! unitTestExecutable ) {
2015-12-05 22:40:30 +03:00
cfg . linkerOptions . definitionFile = "${projectDir}\\msvc\\mp.def" ;
}
2016-02-23 22:54:07 +03:00
if ( unitTestExecutable ) {
2015-12-05 22:40:30 +03:00
cfg . singleDefines 'REGAMEDLL_UNIT_TESTS'
2016-02-23 22:54:07 +03:00
} else if ( ! mpLib ) {
cfg . singleDefines 'HOOK_GAMEDLL'
2015-12-05 22:40:30 +03:00
}
2016-02-23 22:54:07 +03:00
if ( regamedllFixes ) {
2016-01-19 20:43:27 +03:00
cfg . singleDefines 'REGAMEDLL_FIXES' , 'REGAMEDLL_CHECKS' , 'REGAMEDLL_ADD' , 'NDEBUG'
2016-02-23 22:54:07 +03:00
} else {
cfg . singleDefines 'PLAY_GAMEDLL'
2015-12-05 22:40:30 +03:00
}
ToolchainConfigUtils . apply ( project , cfg , b )
GradleCppUtils . onTasksCreated ( project , 'postEvaluate' , {
postEvaluate ( b )
} )
2015-06-30 12:46:07 +03:00
}
class RegamedllSrc {
2015-12-05 22:40:30 +03:00
static void regamedll_src ( def h ) {
h . regamedll_src ( CppSourceSet ) {
source {
srcDirs "engine" , "dlls" , "game_shared" , "pm_shared" , "regamedll" , "public" , "version"
include "**/*.cpp"
exclude "precompiled.cpp"
2016-02-04 03:18:26 +03:00
exclude "tier0/dbg.cpp" , "utlsymbol.cpp" , "utlbuffer.cpp"
2015-12-05 22:40:30 +03:00
2016-02-23 02:13:52 +03:00
if ( GradleCppUtils . windows )
{
2015-12-05 22:40:30 +03:00
exclude "tier0/platform_linux.cpp"
2016-02-23 02:13:52 +03:00
}
else
{
2015-12-05 22:40:30 +03:00
exclude "tier0/platform_win32.cpp"
2016-01-29 16:46:52 +03:00
exclude "classes_dummy.cpp"
2015-12-05 22:40:30 +03:00
}
}
}
}
2015-06-30 12:46:07 +03:00
2015-12-05 22:40:30 +03:00
static void regamedll_pch ( def h ) {
h . regamedll_pch ( CppSourceSet ) {
source {
srcDirs "regamedll"
include "precompiled.cpp"
}
2015-06-30 12:46:07 +03:00
}
2015-12-05 22:40:30 +03:00
}
static void regamedll_hooker_src ( def h ) {
h . regamedll_hooker_src ( CppSourceSet ) {
source {
srcDirs "hookers"
2016-02-23 02:13:52 +03:00
include "main.cpp" , "6153_hooker.cpp" , "hooker.cpp" , "memory.cpp" , "hooker_impl.cpp" , "RegameDLLRuntimeConfig.cpp"
2015-12-05 22:40:30 +03:00
}
}
}
2016-02-23 02:13:52 +03:00
static void regamedll_mp_src ( def h ) {
h . regamedll_mp_src ( CppSourceSet ) {
2015-12-05 22:40:30 +03:00
source {
srcDirs "hookers"
include "main_mp.cpp"
}
}
}
static void regamedll_tests_src ( def h ) {
h . regamedll_tests_src ( CppSourceSet ) {
source {
srcDir "unittests"
include "**/*.cpp"
}
}
}
2015-06-30 12:46:07 +03:00
}
model {
2015-12-05 22:40:30 +03:00
buildTypes {
debug
release
}
platforms {
x86 {
architecture "x86"
}
}
toolChains {
visualCpp ( VisualCpp ) {
}
icc ( Icc ) {
}
}
flavors {
regamedllNofixes
regamedllFixes
}
components {
regamedll_hooker_gamedll ( NativeLibrarySpec ) {
targetPlatform 'x86'
baseName 'filesystem_stdio'
sources {
RegamedllSrc . regamedll_pch ( it )
RegamedllSrc . regamedll_src ( it )
RegamedllSrc . regamedll_hooker_src ( it )
}
binaries . all { NativeBinarySpec b - > project . setupToolchain ( b ) }
}
regamedll_mp_gamedll ( NativeLibrarySpec ) {
targetPlatform 'x86'
baseName GradleCppUtils . windows ? 'mp' : 'cs'
sources {
RegamedllSrc . regamedll_pch ( it )
RegamedllSrc . regamedll_src ( it )
2016-02-23 02:13:52 +03:00
RegamedllSrc . regamedll_mp_src ( it )
2015-12-05 22:40:30 +03:00
}
binaries . all { NativeBinarySpec b - > project . setupToolchain ( b ) }
}
regamedll_hooker_gamedll_tests ( NativeExecutableSpec ) {
targetPlatform 'x86'
sources {
RegamedllSrc . regamedll_pch ( it )
RegamedllSrc . regamedll_src ( it )
RegamedllSrc . regamedll_tests_src ( it )
}
binaries . all { NativeBinarySpec b - > project . setupToolchain ( b ) }
}
regamedll_mp_gamedll_tests ( NativeExecutableSpec ) {
targetPlatform 'x86'
sources {
RegamedllSrc . regamedll_pch ( it )
RegamedllSrc . regamedll_src ( it )
RegamedllSrc . regamedll_tests_src ( it )
}
binaries . all { NativeBinarySpec b - > project . setupToolchain ( b ) }
}
}
2015-06-30 12:46:07 +03:00
}
task buildRelease {
2015-12-05 22:40:30 +03:00
dependsOn binaries . withType ( SharedLibraryBinarySpec ) . matching { SharedLibraryBinarySpec blib - >
blib . buildable & & blib . buildType . name = = 'release' & & ! blib . name . contains ( 'Regamedll_hooker_gamedll' )
}
2015-06-30 12:46:07 +03:00
}
task prepareDevEnvTests {
2015-12-05 22:40:30 +03:00
def regamedllTests = new File ( project . projectDir , '_dev/testDemos' )
inputs . files configurations . regamedll_tests . files
outputs . dir regamedllTests
doLast {
regamedllTests . mkdirs ( )
configurations . regamedll_tests . files . each { File f - >
def t = zipTree ( f )
copy {
into new File ( regamedllTests , FilenameUtils . getBaseName ( f . absolutePath ) )
from t
}
}
}
2015-06-30 12:46:07 +03:00
}
task prepareDevEnvGamedll < < {
[ '_dev/regamedll' , '_dev/regamedll_mp' ] . each { gamedllDir - >
def regamedllImage = new File ( project . projectDir , gamedllDir )
regamedllImage . mkdirs ( )
def demoRunner = new RegamedllDemoRunner ( project . configurations . regamedll_playtest_image . getFiles ( ) , regamedllImage , null )
2015-07-05 14:05:26 +03:00
demoRunner . prepareEngine ( )
//demoRunner.prepareDemo()
2015-06-30 12:46:07 +03:00
}
}
task prepareDevEnv {
2015-12-05 22:40:30 +03:00
dependsOn prepareDevEnvGamedll , prepareDevEnvTests
2015-06-30 12:46:07 +03:00
}
tasks . clean . doLast {
2015-12-05 22:40:30 +03:00
project . file ( 'version/appversion.h' ) . delete ( )
2015-06-30 12:46:07 +03:00
}
task generateAppVersion {
RegamedllVersionInfo verInfo = ( RegamedllVersionInfo ) rootProject . regamedllVersionInfo
def tplFile = project . file ( 'version/appversion.vm' )
def renderedFile = project . file ( 'version/appversion.h' )
2015-12-05 22:40:30 +03:00
2015-06-30 12:46:07 +03:00
inputs . file tplFile
inputs . file project . file ( 'gradle.properties' )
outputs . file renderedFile
inputs . property ( 'version' , verInfo . asMavenVersion ( ) )
inputs . property ( 'lastCommitDate' , verInfo . lastCommitDate . toString ( ) )
2015-12-05 22:40:30 +03:00
2015-06-30 12:46:07 +03:00
doLast {
def templateCtx = [
verInfo: verInfo
]
2015-12-05 22:40:30 +03:00
2015-06-30 12:46:07 +03:00
def content = VelocityUtils . renderTemplate ( tplFile , templateCtx )
renderedFile . delete ( )
renderedFile . write ( content , 'utf-8' )
2016-02-01 13:46:31 +03:00
2016-03-01 01:23:28 +03:00
println 'The current ReGameDLL version is ' + verInfo . asVersion ( ) . toString ( ) + ', maven version is ' + verInfo . asMavenVersion ( ) . toString ( ) + ', commit id: ' + verInfo . commitID . toString ( ) + ', commit author: ' + verInfo . authorCommit . toString ( ) ;
2015-06-30 12:46:07 +03:00
}
}