0

I have one build script per each environment (debug, release, relwithdebuginfo etc).

Each script calls CMake with the relevant build environment set:

cmake -DCMAKE_BUILD_TYPE=Debug -DARG_FORCE_CLANG=True

a flag inside the CMakeLists.txt file controls the sanitize flag. However, I would like to control this from a new sanitize build script, something like:

cmake -DCMAKE_BUILD_TYPE=Debug -DARG_FORCE_CLANG=True -SANITIZE=true

Is there any way to achieve this?

user997112
  • 29,025
  • 43
  • 182
  • 361
  • Does this answer work for you? https://stackoverflow.com/a/55911219/461597 – Unapiedra Mar 31 '20 at 17:18
  • @Unapiedra That's awesome. Only problem is how do I control whether I want my sanitize to be debug, release or relwithdebuginfo? – user997112 Mar 31 '20 at 17:24
  • "ASAN" doesn't seem to be documented here: https://cmake.org/cmake/help/v3.17/variable/CMAKE_BUILD_TYPE.html – user997112 Mar 31 '20 at 17:34
  • Question: Why do you want to run a sanitizer on Debug? That's not recommended. What do you gain by running all these configurations? – Unapiedra Mar 31 '20 at 17:35
  • Sorry, I don't want to dismiss your use case. Could you explain your use case for me, please? – Unapiedra Mar 31 '20 at 17:36
  • @Unapiedra sure. Sometimes when debugging I require a debug build because I need to step through the code in GDB with no optimizations. However, other times I need a release build because a bug only triggers due to certain timing constraints. Btw did you see the link I posted? "ASAN" isn't in the CMake documentation? – user997112 Mar 31 '20 at 17:38
  • One solution that I see, is using CMake toolchain files. (`cmake -DCMAKE_TOOLCHAIN_FILE=../../one_config.cmake`). That way you can configure your flags as you like for all the configurations. More info: https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html + the doc to CMAKE_TOOLCHAIN_FILE – Unapiedra Mar 31 '20 at 17:40
  • Ah so extract all my current Cmake Clang settings and put them in that one toolchain file? – user997112 Mar 31 '20 at 17:46
  • It seems you can pass any value to -DCMAKE_BUILD_TYPE so I passed "SanitizeDebug" and then I just check for "SanitizeDebug" inside the CMakeList.txt ??? – user997112 Mar 31 '20 at 17:58
  • In the end I created a cmake cache variable: https://stackoverflow.com/a/12899005/997112 – user997112 Mar 31 '20 at 23:32

0 Answers0