You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by st...@apache.org on 2014/08/26 22:46:42 UTC

[09/15] git commit: use different compiler flags for debug/release build

use different compiler flags for debug/release build


Project: http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/commit/91aa1ea9
Tree: http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/tree/91aa1ea9
Diff: http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/diff/91aa1ea9

Branch: refs/heads/master
Commit: 91aa1ea98977a937193a82594a9128e06ac78dcf
Parents: 8978638
Author: Maxim Ermilov <ma...@canonical.com>
Authored: Sun Jun 22 04:36:27 2014 +0400
Committer: Maxim Ermilov <ma...@canonical.com>
Committed: Tue Aug 19 14:20:10 2014 +0400

----------------------------------------------------------------------
 CMakeLists.txt          |  9 ++++++++-
 bin/build/build         |  2 +-
 bin/build/lib/ubuntu.js | 34 +++++++++++++++++++++++-----------
 3 files changed, 32 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/blob/91aa1ea9/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2e9f546..5ffcb09 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -20,7 +20,14 @@ configure_file (
   "${PROJECT_BINARY_DIR}/CordovaView.qml"
 )
 
-SET(CMAKE_CXX_FLAGS "-std=c++11 -fno-omit-frame-pointer -O2 -g -Wall -Wextra -DCORDOVA_UBUNTU_VERSION=\\\"${VERSION}\\\" -DCORDOVA_UBUNTU_MAJOR_VERSION=${MAJOR_VERSION} -DCORDOVA_UBUNTU_MINOR_VERSION=${MINOR_VERSION} -I ${PROJECT_SOURCE_DIR}/src")
+SET(CMAKE_CXX_FLAGS "-std=c++11 -fno-omit-frame-pointer -Wall -Wextra -DCORDOVA_UBUNTU_VERSION=\\\"${VERSION}\\\" -DCORDOVA_UBUNTU_MAJOR_VERSION=${MAJOR_VERSION} -DCORDOVA_UBUNTU_MINOR_VERSION=${MINOR_VERSION} -I ${PROJECT_SOURCE_DIR}/src")
+
+if(CMAKE_BUILD_TYPE STREQUAL "Release")
+  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flto -Os")
+endif()
+if(CMAKE_BUILD_TYPE STREQUAL "Debug")
+  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O1 -g")
+endif()
 
 add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/qml
   COMMAND mkdir -p ${PROJECT_BINARY_DIR}/qml

http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/blob/91aa1ea9/bin/build/build
----------------------------------------------------------------------
diff --git a/bin/build/build b/bin/build/build
index e4caeba..e40d98e 100755
--- a/bin/build/build
+++ b/bin/build/build
@@ -28,5 +28,5 @@ var www = path.join(root, 'www');
 var argv = require('optimist').string(['framework']).argv;
 
 platform.check_reqs(root).then(function () {
-    return platform.build(root, platform.ALL, false, undefined, argv.framework);
+    return platform.build(root, platform.ALL, false, undefined, argv.framework, false);
 }).done();

http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/blob/91aa1ea9/bin/build/lib/ubuntu.js
----------------------------------------------------------------------
diff --git a/bin/build/lib/ubuntu.js b/bin/build/lib/ubuntu.js
index 1a0c9c6..dac2114 100644
--- a/bin/build/lib/ubuntu.js
+++ b/bin/build/lib/ubuntu.js
@@ -150,7 +150,7 @@ function checkClickPackage(prefixDir) {
     popd();
 }
 
-function buildClickPackage(campoDir, ubuntuDir, nobuild, architecture, framework) {
+function buildClickPackage(campoDir, ubuntuDir, nobuild, architecture, framework, debug) {
     assert.ok(architecture && architecture.match(/^[a-z0-9_]+$/));
 
     var archDir = path.join(ubuntuDir, framework, architecture);
@@ -173,8 +173,12 @@ function buildClickPackage(campoDir, ubuntuDir, nobuild, architecture, framework
 
     pushd(path.join(archDir, 'build'));
 
+    var buildType = '"Debug"';
+    if (!debug)
+        buildType = '"Release"';
+
     var cmakeCmd = 'click chroot -a' + architecture + ' -f ' + framework + ' run cmake ' + campoDir
-              + ' -DCMAKE_INSTALL_PREFIX="' + prefixDir + '"';
+              + ' -DCMAKE_INSTALL_PREFIX="' + prefixDir + '"' + ' -DCMAKE_BUILD_TYPE=' + buildType;
     if (framework == 'ubuntu-sdk-13.10')
         cmakeCmd += ' -DCMAKE_TOOLCHAIN_FILE=/etc/dpkg-cross/cmake/CMakeCross.txt';
     return execAsync(cmakeCmd).then(function () {
@@ -206,7 +210,7 @@ function buildClickPackage(campoDir, ubuntuDir, nobuild, architecture, framework
     });
 }
 
-function buildNative(campoDir, ubuntuDir, nobuild) {
+function buildNative(campoDir, ubuntuDir, nobuild, debug) {
     var nativeDir = path.join(ubuntuDir, 'native');
     var prefixDir = path.join(nativeDir, 'prefix');
 
@@ -222,8 +226,13 @@ function buildNative(campoDir, ubuntuDir, nobuild) {
 
     pushd(path.join(nativeDir, 'build'));
 
+    var buildType = '"Debug"';
+    if (!debug)
+        buildType = '"Release"';
+
     var debDir;
-    return execAsync('cmake ' + campoDir + ' -DCMAKE_INSTALL_PREFIX="' + prefixDir + '"').then(function () {
+    return execAsync('cmake ' + campoDir + ' -DCMAKE_INSTALL_PREFIX="' + prefixDir + '"'
+                      + ' -DCMAKE_BUILD_TYPE=' + buildType).then(function () {
         return execAsync('make -j ' + cpuCount() + '; make install');
     }).then(function () {
         cp(path.join(ubuntuDir, 'config.xml'), prefixDir);
@@ -263,7 +272,7 @@ module.exports.ALL = 2;
 module.exports.PHONE = 0;
 module.exports.DESKTOP = 1;
 
-module.exports.build = function(rootDir, target, nobuild, architecture, framework) {
+module.exports.build = function(rootDir, target, nobuild, architecture, framework, debug) {
     var ubuntuDir = path.join(rootDir, 'platforms', 'ubuntu');
     var campoDir = path.join(ubuntuDir, 'build');
 
@@ -278,7 +287,7 @@ module.exports.build = function(rootDir, target, nobuild, architecture, framewor
     if (target === module.exports.PHONE)
         return buildClickPackage(campoDir, ubuntuDir, nobuild, architecture, framework);
     if (target === module.exports.DESKTOP)
-        return buildNative(campoDir, ubuntuDir, nobuild);
+        return buildNative(campoDir, ubuntuDir, nobuild, debug);
     if (target === module.exports.ALL) {
         return buildClickPackage(campoDir, ubuntuDir, nobuild, architecture, framework).then(function () {
             return buildNative(campoDir, ubuntuDir, nobuild);
@@ -292,10 +301,13 @@ function runNative(rootDir, debug) {
 
     pushd(path.join(nativeDir, 'prefix'));
 
-    if (debug)
-        console.error('Debug enabled. Try pointing a WebKit browser to http://127.0.0.1:9222');
+    var cmd = 'QTWEBKIT_INSPECTOR_SERVER=9222 ./cordova-ubuntu www/';
+    if (debug) {
+        cmd = "DEBUG=1 " + cmd;
+        console.error('Debug enabled. Try pointing a WebKit browser to http://127.0.0.1:9222'.yellow);
+    }
 
-    return execAsync('QTWEBKIT_INSPECTOR_SERVER=9222 ./cordova-ubuntu www/').then(function () {
+    return execAsync(cmd).then(function () {
         popd();
     });
 }
@@ -391,7 +403,7 @@ function runOnDevice(rootDir, debug, target, architecture, framework) {
 
 module.exports.run = function(rootDir, desktop, debug, target, nobuild, emulator, framework) {
     if (desktop && !emulator) {
-        return module.exports.build(rootDir, module.exports.DESKTOP, nobuild).then(function () {
+        return module.exports.build(rootDir, module.exports.DESKTOP, nobuild, null, null, debug).then(function () {
             return runNative(rootDir, debug);
         });
     }
@@ -426,7 +438,7 @@ module.exports.run = function(rootDir, desktop, debug, target, nobuild, emulator
     }
     var arch = getDeviceArch(target);
 
-    return module.exports.build(rootDir, module.exports.PHONE, nobuild, arch, framework).then(function () {
+    return module.exports.build(rootDir, module.exports.PHONE, nobuild, arch, framework, debug).then(function () {
         return runOnDevice(rootDir, debug, target, arch, framework);
     });
 }