3

So, I want to build my project with additional include path using CMake and clang as a frontend for VS2019.

What I already try:

  • 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 (Empty)

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

And which errors I get:

>------ 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.

How should I do to add include path?

stakemura
  • 41
  • 1
  • 3

1 Answers1

0

I modified CMakeList.txt as following. It seems to be solved.

# 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")
stakemura
  • 41
  • 1
  • 3