Skip to content

Instantly share code, notes, and snippets.

@mouse0w0
Created June 1, 2020 16:55
Show Gist options
  • Save mouse0w0/cf67feec954ba6c6a49aff146573eac0 to your computer and use it in GitHub Desktop.
Save mouse0w0/cf67feec954ba6c6a49aff146573eac0 to your computer and use it in GitHub Desktop.
add compilerArgs to gradle cpp-library
/*
* This file was generated by the Gradle 'init' task.
*
* This generated file contains a sample C++ project to get you started.
* For more details take a look at the Building C++ applications and libraries chapter in the Gradle
* User Manual available at https://docs.gradle.org/6.0.1/userguide/building_cpp_projects.html
*/
import org.apache.tools.ant.taskdefs.condition.Os
plugins {
// Apply the cpp-library plugin to add support for building C++ libraries
id 'cpp-library'
}
group = 'com.github.gconde'
version = '1.0'
// Set the target operating system and architecture for this library
library {
targetMachines.add(machines.windows.x86_64)
targetMachines.add(machines.linux.x86_64)
source.from file("${rootProject.projectDir}/cpp/src")
publicHeaders.from file("${rootProject.projectDir}/cpp/include")
}
tasks.withType(CppCompile).configureEach {
// Define a preprocessor macro for every binary
if (Os.isFamily(Os.FAMILY_WINDOWS))
{
macros.put('SIMULATOR_EXPORTS', '')
macros.put('_WINDLL', '')
macros.put('_UNICODE', '')
macros.put('UNICODE', '')
}
// Define toolchain-specific compiler options
compilerArgs.addAll toolChain.map { toolChain ->
if (toolChain in [ Gcc, Clang ]) {
return ['-O3', '-c', '-Wall', '-pthread']
} else if (toolChain in VisualCpp) {
return ['/Zi', '/EHsc', '/GS', '/GL', '/W3', '/Gy', '/Zc:wchar_t', '/Gm-', '/O2', '/sdl', '/Zc:inline', '/fp:precise', '/errorReport:prompt', '/WX-', '/Zc:forScope', '/Gd', '/Oi', '/MD', '/FC', '/nologo', '/diagnostics:classic']
}
return []
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment