使用VSCode Cmake启动位于同一Cmake文件中的两个项目

kjthegm6  于 7个月前  发布在  Vscode
关注(0)|答案(1)|浏览(94)

我的CMakeLists.txt文件中有两个不同的项目。我在.vscode'文件夹中的launch.json`文件中使用了这样的配置:

{
  "name": "Launch main project",
  "type": "cppdbg",
  "request": "launch",
  // Resolved by CMake Tools:
  "program": "${command:cmake.launchTargetPath}",
  "args": [],
  "stopAtEntry": false,
  "cwd": "${workspaceFolder}",
  "environment": [
    {
      // add the directory where our target was built to the PATHs
      // it gets resolved by CMake Tools:
      "name": "PATH",
      "value": "${env:PATH}:${command:cmake.getLaunchTargetDirectory}"
    }
  ],
  "MIMode": "gdb",
  "setupCommands": [
    {
      "description": "Enable pretty-printing for gdb",
      "text": "-enable-pretty-printing",
      "ignoreFailures": true
    }
  ]
},

字符串
问题是,vscode-cmake-tools只识别测试项目,而不是我的主项目。
有没有办法告诉vscode和extension运行main_project来运行另一个项目?
这是我的cmake文件:

cmake_minimum_required(VERSION 3.2.0...3.5)
   project(main_project  VERSION 0.1.0)
   set(CPACK_PROJECT_NAME ${PROJECT_NAME})
   set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
   include(CPack)

   add_subdirectory( tests )  # this is the test project 
   add_executable(main_project main.cpp)
   target_include_directories(main_project  PRIVATE ${YOUR_DIRECTORY})

iyr7buue

iyr7buue1#

我找到的“解决方案”就是分别启动每一个,然后在每个之前运行一个构建任务。

// launch.json
 { "configurations": [
    {
     ...
     "program": "${workspaceFolder}\\build\\tests\\test_runner.exe",
     ...
     "preLaunchTask": "CMake: build"
     }
    ]
 }

字符串
在tasks.json中:

{  
  "tasks": [
    {
      "type": "cmake",
      "label": "CMake: build",
      "command": "build",
      "targets": ["main_project", "test_runner"],
      "group": "build",
      "problemMatcher": [],
      "detail": "CMake  build task"
    }
  ]
}

相关问题