Visual Studio 2019 - define a pragma or macro in launch.vs.json

156 Views Asked by At

I need to define a precompiler element(pragma? macro? not sure how you call them) as DEBUG in a cmake project loaded with VS

{
  "version": "0.2.1",
  "defaults": {},
  "configurations": [        
    {
      "type": "default",
      "project": "CMakeLists.txt",
      "projectTarget": "main.exe (bin\\main.exe)",
      "name": "main.exe (bin\\main.exe)",
      "pragmas": [
        "DEBUG":"true"
      ]
    }
  ]
}

so it can be used in the code as

#ifdef DEBUG
#if DEBUG

is it possible ?

thanks for your help

1

There are 1 best solutions below

0
Buzz On

launch.vs.json contains all the settings to help Visual Studio understand how to launch your already compiled executable.

What you're looking for is a place that gives the compiler (not the launcher) the instructions how to create the executable (depending upon the preprocessor directives).

Different ways of doing this, depending on your project type.

  • If it's a native VS project (.sln solution, just for clearance): right click on your Project, click on Properties, then move to C/C++ / Preprocessor and fill in Preprocessor definitions field.

  • If you're writing a CMake project, you can use the command add_compile_definitions in your CMakeLists.txt list file.