Browse Source

Better build support for profiles

Kajetan Johannes Hammerle 2 months ago
parent
commit
93bb1907eb
2 changed files with 97 additions and 44 deletions
  1. 2 1
      .gitignore
  2. 95 43
      tasks

+ 2 - 1
.gitignore

@@ -1,4 +1,5 @@
 .vscode
-build
+build_debug
+build_release
 install
 profile

+ 95 - 43
tasks

@@ -4,17 +4,17 @@ clear
 cd $(dirname $0)
 
 printHelpExit() {
-    echo "$0 clean       | remove build results"
-    echo "$0 build       | build everything"
-    echo "$0 install     | move build results into the install folder"
-    echo "$0 test        | run the tests"
-    echo "$0 valgrind    | run the tests with valgrind"
-    echo "$0 coverage    | generate code coverage"
-    echo "$0 performance | run the performance tests"
-    echo "$0 final       | find classes / structs which are not final"
-    echo "$0 macro       | find macros without CORE" 
-    echo "$0 include     | find system includes" 
-    echo "$0 time        | check build time"
+    echo "$0 clean           | remove build results"
+    echo "$0 build <type>    | build everything"
+    echo "$0 install         | move build results into the install folder"
+    echo "$0 test <type>     | run the tests"
+    echo "$0 valgrind <type> | run the tests with valgrind"
+    echo "$0 coverage        | generate code coverage"
+    echo "$0 performance     | run the performance tests"
+    echo "$0 final           | find classes / structs which are not final"
+    echo "$0 macro           | find macros without CORE" 
+    echo "$0 include         | find system includes" 
+    echo "$0 time            | check build time"
     exit 0
 }
 
@@ -23,40 +23,83 @@ if [ -z "$task" ]; then
     printHelpExit
 fi
 
-# tasks
-build=false
-test=false
-valgrind=false
+# task vars
+build_debug=false
+build_release=false
+
+test_debug=false
+test_release=false
+
+valgrind=""
 performance=false
 time=false
 install=false
 coverage=false
-profile=$(cat profile)
 
 # parsing
 if [ "$task" = "clean" ]; then
-    rm -rf build install
-    exit 0
+    rm -rf build_debug build_release install
 elif [ "$task" = "build" ]; then
-    build=true
+    type=$2
+    if [ "$type" = "debug" ]; then
+        build_debug=true
+    elif [ "$type" = "release" ]; then
+        build_release=true
+    elif [ "$type" = "all" ]; then
+        build_debug=true
+        build_test_release=true
+        build_release=true
+    else
+        echo "Valid build types are: debug, release, all"
+        printHelpExit
+    fi
 elif [ "$task" = "install" ]; then
-    build=true
+    build_release=true
     install=true
 elif [ "$task" = "coverage" ]; then
-    build=true
+    build_debug=true
+    test_debug=true
     coverage=true
-    test=true
 elif [ "$task" = "test" ]; then
-    build=true
-    test=true
+    type=$2
+    if [ "$type" = "debug" ]; then
+        build_debug=true
+        test_debug=true
+    elif [ "$type" = "release" ]; then
+        build_test_release=true
+        test_release=true
+    elif [ "$type" = "all" ]; then
+        build_debug=true
+        test_debug=true
+        build_test_release=true
+        test_release=true
+    else
+        echo "Valid test types are: debug, release, all"
+        printHelpExit
+    fi
 elif [ "$task" = "valgrind" ]; then
-    build=true
-    valgrind=true
+    type=$2
+    if [ "$type" = "debug" ]; then
+        build_debug=true
+        test_debug=true
+    elif [ "$type" = "release" ]; then
+        build_test_release=true
+        test_release=true
+    elif [ "$type" = "all" ]; then
+        build_debug=true
+        test_debug=true
+        build_test_release=true
+        test_release=true
+    else
+        echo "Valid valgrind types are: debug, release, all"
+        printHelpExit
+    fi
+    valgrind="valgrind"
 elif [ "$task" = "performance" ]; then
-    build=true
+    build_release=true
     performance=true
 elif [ "$task" = "time" ]; then
-    build=true
+    build_release=true
     time=true
 elif [ "$task" = "final" ]; then
     grep -r " class" src include | grep -v -E 'final|enum|.git' || true
@@ -78,32 +121,41 @@ else
 fi
 
 # task execution
-if $build; then
-    if [ ! -e build ]; then 
-        cmake -B build -S . -G Ninja -DCMAKE_INSTALL_PREFIX=./install \
-            -DCMAKE_BUILD_TYPE=$profile
+buildProfile() {
+    folder=$1
+    shift 1
+    if [ ! -e "$folder" ]; then 
+        cmake -B "$folder" -S . -G Ninja -DCMAKE_INSTALL_PREFIX=./install $@
     fi
-    ninja -C build
+    ninja -C "$folder"
+}
+
+if $build_debug; then
+    buildProfile build_debug -DCMAKE_BUILD_TYPE=Debug
+fi
+if $build_release; then
+    buildProfile build_release -DCMAKE_BUILD_TYPE=Release
 fi
 if $install; then
-    ninja -C build install
+    ninja -C build_release install
 fi
-if $test; then
-    cd build
-    ./test light || true
+if $test_debug; then
+    cd build_debug
+    $valgrind ./test light $valgrind || true
     cd ..
 fi
-if $valgrind; then
-    cd build
-    valgrind ./test light valgrind || true
+if $test_release; then
+    cd build_release
+    $valgrind ./test light $valgrind || true
     cd ..
 fi
 if $performance; then
-    cd build
+    cd build_release
     ./performance
+    cd ..
 fi
 if $time; then
-    lines=$(cat build/.ninja_log | grep "^[0-9]")
+    lines=$(cat build_release/.ninja_log | grep "^[0-9]")
 
     startMillis=0
     endMillis=0
@@ -125,5 +177,5 @@ if $time; then
     printf "$output" | sort -n
 fi
 if $coverage; then
-    gcovr -r . build -e test -e performance
+    gcovr -r . build_debug -e test -e performance
 fi