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.ReapiVersionInfo import gradlecpp.VelocityUtils apply plugin: 'cpp' apply plugin: 'windows-resources' apply plugin: IccCompilerPlugin List 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', '/src/mods', '/src/natives', '/include', '/include/metamod', '/include/cssdk/common', '/include/cssdk/dlls', '/include/cssdk/engine', '/include/cssdk/game_shared', '/include/cssdk/pm_shared', '/include/cssdk/public') if (cfg instanceof MsvcToolchainConfig) { cfg.compilerOptions.pchConfig = new MsvcToolchainConfig.PrecompiledHeadersConfig( enabled: true, pchHeader: 'precompiled.h', pchSourceSet: 'reapi_pch' ) cfg.compilerOptions.args '/Ob2', '/Oi', '/GF', '/GR-', '/GS-' cfg.singleDefines('_CRT_SECURE_NO_WARNINGS') } else if (cfg instanceof GccToolchainConfig) { cfg.compilerOptions.pchConfig = new GccToolchainConfig.PrecompilerHeaderOptions( enabled: true, pchSourceSet: 'reapi_pch' ) cfg.compilerOptions.languageStandard = 'c++0x' cfg.defines([ '_stricmp': 'strcasecmp', '_strnicmp': 'strncasecmp', '_vsnprintf': 'vsnprintf', '_snprintf': 'snprintf' ]) 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' } 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 { reapi(NativeLibrarySpec) { targetPlatform 'x86' baseName GradleCppUtils.windows ? 'reapi_amxx' : 'reapi_amxx_i386' sources { reapi_pch(CppSourceSet) { source { srcDirs "src" include "precompiled.cpp" } exportedHeaders { srcDirs "include", "version" } } reapi_src(CppSourceSet) { source { srcDirs "src", "include/cssdk/public" include "**/*.cpp" exclude "precompiled.cpp" exclude "engine_api.cpp", "tier0/dbg.cpp" } exportedHeaders { srcDirs "include", "version" } } rc { source { srcDir "msvc" include "reapi.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\\reapi.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 { ReapiVersionInfo verInfo = (ReapiVersionInfo) rootProject.reapiVersionInfo def tplversionFile = project.file('version/appversion.vm') def versionFile = project.file('version/appversion.h') inputs.file tplversionFile inputs.file project.file('gradle.properties') outputs.file versionFile doLast { def versionContent = VelocityUtils.renderTemplate(tplversionFile, verInfo) versionFile.delete() versionFile.write(versionContent, 'utf-8') } }