如何在VS 2019的Ninja和Clang上添加包含路径?

时间:2019-06-06 09:06:01

标签: c++ visual-studio cmake clang ninja

因此,我想使用CMake和clang作为VS2019的前端,使用其他包含路径构建我的项目。

我已经尝试过的方法:

  • CMakeLists.txt
# CMakeList.txt : CMake project for test-llvm, include source and define
# project specific logic here.
#
cmake_minimum_required (VERSION 3.8)

# Add source to this project's executable.
add_executable (test-llvm "test-llvm.cpp" "test-llvm.h")

# TODO: Add tests and install targets if needed.
set(INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include")
  • CMakeSettings.json
{
  "configurations": [
    {
      "name": "x64-Clang-Debug",
      "generator": "Ninja",
      "configurationType": "Debug",
      "buildRoot": "${projectDir}\\out\\build\\${name}",
      "installRoot": "${projectDir}\\out\\install\\${name}",
      "cmakeCommandArgs": "",
      "buildCommandArgs": "-v",
      "ctestCommandArgs": "",
      "inheritEnvironments": [ "clang_cl_x64" ],
      "variables": []
    },
    {
      "name": "x86-Clang-Release",
      "generator": "Ninja",
      "configurationType": "RelWithDebInfo",
      "buildRoot": "${projectDir}\\out\\build\\${name}",
      "installRoot": "${projectDir}\\out\\install\\${name}",
      "cmakeCommandArgs": "",
      "buildCommandArgs": "-v",
      "ctestCommandArgs": "",
      "inheritEnvironments": [ "clang_cl_x86" ],
      "variables": []
    }
  ]
}
  • test-llvm.cpp
#include <needtoinclude.h>

int main()
{
    std::cout << "Hello world" << std::endl;
}
  • test-llvm.h(空)

  • include / needtoinclude.h
#pragma once
#include <iostream>

我得到哪些错误

>------ Build All started: Project: test-llvm, Configuration: x64-Clang-Debug ------
  [1/2] C:\PROGRA~2\MIB055~1\2019\PROFES~1\COMMON7\IDE\COMMON~1\MICROS~1\Llvm\bin\clang-cl.exe  /nologo -TP   -m64 -fdiagnostics-absolute-paths  /DWIN32 /D_WINDOWS /W3 /GR /EHsc /MDd /Zi /Ob0 /Od /RTC1 /showIncludes /FoCMakeFiles\test-llvm.dir\test-llvm.cpp.obj /FdCMakeFiles\test-llvm.dir\ -c ..\..\..\test-llvm.cpp
  FAILED: CMakeFiles/test-llvm.dir/test-llvm.cpp.obj 
  C:\PROGRA~2\MIB055~1\2019\PROFES~1\COMMON7\IDE\COMMON~1\MICROS~1\Llvm\bin\clang-cl.exe  /nologo -TP   -m64 -fdiagnostics-absolute-paths  /DWIN32 /D_WINDOWS /W3 /GR /EHsc /MDd /Zi /Ob0 /Od /RTC1 /showIncludes /FoCMakeFiles\test-llvm.dir\test-llvm.cpp.obj /FdCMakeFiles\test-llvm.dir\ -c ..\..\..\test-llvm.cpp
C:\Users\stakemura\Dropbox\Documents\test-llvm\test-llvm.cpp(1,13): fatal error : 'needtoinclude.h' file not found
  <U+FEFF>#include <needtoinclude.h>
                   ^~~~~~~~~~~~~~~~~
  1 error generated.
  ninja: build stopped: subcommand failed.

Build All failed.

我应该如何添加包含路径?

1 个答案:

答案 0 :(得分:0)

我如下修改了CMakeList.txt。看来已经解决了。

# CMakeList.txt : CMake project for test-llvm, include source and define
# project specific logic here.
#
cmake_minimum_required (VERSION 3.8)

# Add source to this project's executable.
add_executable (test-llvm "test-llvm.cpp" "test-llvm.h")

# TODO: Add tests and install targets if needed.
include_directories("include")