From a42867ed02ac9011b0cf4b49a01cd797d2441fcc Mon Sep 17 00:00:00 2001 From: Juraj Michalek Date: Sat, 23 Nov 2013 17:00:25 +0100 Subject: [PATCH] add example how to configure Gradle C++ Debug --- README.md | 27 ++++++++++++++----- gradle/03-hello-muni-with-debug/build.gradle | 14 ++++++++++ .../src/main/cpp/hellomuni.cpp | 9 +++++++ 3 files changed, 43 insertions(+), 7 deletions(-) create mode 100644 gradle/03-hello-muni-with-debug/build.gradle create mode 100644 gradle/03-hello-muni-with-debug/src/main/cpp/hellomuni.cpp diff --git a/README.md b/README.md index 7965fce..a0eab06 100644 --- a/README.md +++ b/README.md @@ -71,6 +71,8 @@ How to run: Gradle ------ +### 01-hello-muni ### + Example of building C/C++ project by Gradle. Gradle is using build.gradle file in main project directory. Check out project layout. Source code is stored in src/main/cpp, @@ -82,16 +84,15 @@ Note for Visual Studio 2013: Use Gradle at least night build 1.10-20131122230018 How to run: - cd gradle/hellomuni + cd gradle/01-hello-muni gradle mainExecutable cd build/binaries/mainExecutable - ./hellomuni + ./01-hello-muni -Gradle with wrapper -------------------- +### 02-hello-muni-with-gradle-wrapper ### -In gradle/hellomuni example you have to download and install Gradle manually. +It's not necessary to download Gradle manually like in previous example. Gradle projects are sometimes provided with wrapper which downloads all necessary files with Gradle. It's sufficient to start wrapper and then you can work with local instance of Gradle. This is useful when you want to fix version of Gradle or simplify bootstrap process. @@ -101,10 +102,22 @@ support. How to run: - cd gradle/hello-with-wrapper + cd gradle/02-hello-muni-with-gradle-wrapper ./gradlew mainExecutable (or .\gradle.bat mainExecutable for PowerShell) cd build/binaries/mainExecutable - ./hello-with-wrapper + ./02-hello-muni-with-gradle-wrapper + +### 03-hello-muni-with-debug ### + +Current implementation of C++ support in Gradle is in early stage, but it's very promising. +This example shows how to update build script to add debug flags for compilers like GCC or VS. + +How to run: + + cd gradle/03-hello-muni-with-debug + gradle mainExecutable + cd build/binaries/mainExecutable + ./03-hello-muni-with-debug Minunit testing --------------- diff --git a/gradle/03-hello-muni-with-debug/build.gradle b/gradle/03-hello-muni-with-debug/build.gradle new file mode 100644 index 0000000..e43f043 --- /dev/null +++ b/gradle/03-hello-muni-with-debug/build.gradle @@ -0,0 +1,14 @@ +apply plugin: 'cpp-exe' + + +// Based on http://www.gradle.org/docs/current/userguide/nativeBinaries.html +binaries.all { + if (toolChain in Gcc && buildType == buildTypes.debug) { + cppCompiler.args "-g" + } + if (toolChain in VisualCpp && buildType == buildTypes.debug) { + cppCompiler.args '/Zi' + cppCompiler.define 'DEBUG' + linker.args '/DEBUG' + } +} diff --git a/gradle/03-hello-muni-with-debug/src/main/cpp/hellomuni.cpp b/gradle/03-hello-muni-with-debug/src/main/cpp/hellomuni.cpp new file mode 100644 index 0000000..76274b1 --- /dev/null +++ b/gradle/03-hello-muni-with-debug/src/main/cpp/hellomuni.cpp @@ -0,0 +1,9 @@ +#include + +using namespace std; + +int main() { + cout << "Hello FI MUNI!" << endl; + return 0; +} +