0

My cmake-based legacy C++ code base contains some specific preprocessor debug macro - let his name be DEBUG_ATTRIBUTE - responsible for certain types of debug output. Despite his name, the macro shouldn't be turned on for a standard debug build. For some reason, also all the CMakeLists.txt etc. have to be let alone.

What would be the best way to set the define from cmake's command line, depending on the build-type 'Debug' (cmake creates a Visual Studio 2010 solution)? Can I use generator expressions for this (I suspect, they don't work because of their defining traits)?

Michael
  • 107
  • 10
  • For me it sounds like you should add [toolchains](https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html) for all supported compilers. The possibilities discussed [here](http://stackoverflow.com/questions/28732209/change-default-value-of-cmake-cxx-flags-debug-and-friends-in-cmake) can all be triggered from the command line. – Florian Dec 06 '16 at 14:07

1 Answers1

0

There is a solution besides going the long way by writing another script file and injecting this via something like CMAKE_TOOLCHAIN_FILE or CMAKE_PROJECT_<PROJECT-NAME>_INCLUDE.

I've tested the following with CMake's Visual Studio 2015 generator:

cmake -DCMAKE_CXX_FLAGS_DEBUG_INIT:STRING="-DDEBUG_ATTRIBUTE=SomeValue" ..

References

Community
  • 1
  • 1
Florian
  • 39,996
  • 9
  • 133
  • 149
  • I believe the "-D" inside quotes needs to have a space after it: `cmake -DCMAKE_CXX_FLAGS_DEBUG_INIT:STRING="-D DEBUG_ATTRIBUTE=SomeValue" ...` – Stephen G Tuggy Oct 08 '19 at 23:29