# VSCode's variable substitution doesn't seen to work in CMakeLists.txt (Absolute paths works)

**URL:** <https://discourse.cmake.org/t/vscodes-variable-substitution-doesnt-seen-to-work-in-cmakelists-txt-absolute-paths-works/5701>\
**Category:** Code\
**Tags:** os:windows\
**Created:** [May 21, 2022, 6:34pm UTC](https://discourse.cmake.org/t/vscodes-variable-substitution-doesnt-seen-to-work-in-cmakelists-txt-absolute-paths-works/5701 "2022-05-21T18:34:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Coziyu](https://discourse.cmake.org/user_avatar/discourse.cmake.org/coziyu/32/2438_2.png) [@Coziyu](https://discourse.cmake.org/u/Coziyu)\
**Post date:** [May 21, 2022, 6:34pm UTC](https://discourse.cmake.org/t/vscodes-variable-substitution-doesnt-seen-to-work-in-cmakelists-txt-absolute-paths-works/5701/1 "2022-05-21T18:34:39Z")

</div>

Hey!  
I am a beginner learning how to use CMake in my VSCode C++ projects and I ran into some issues trying to figure out how to get CMake to include headers. Mainly, ${workspaceFolder} doesn’t seem to be substituting the correct path to my CMakeLists.txt file.

However if instead I used my full path `D:\\Code\\Projects\\TestProject\\include` instead of `${workspaceFolder}\\include`, my code compiles and everything is fine.

Is there anything I did wrongly?

Here is my project file structure:

```nohighlight
TestProject
|.vscode
|build
||autogenerated stuff here
|include
||headers
|||myPrint.h
|||printME.h
|src
||functionality_test.cpp
||myPrint.cpp
||printME.cpp
|CMakeLists.txt

```

CMakeLists.txt:

```auto
cmake_minimum_required(VERSION 3.0.0)
project(functionality_test VERSION 0.1.0)

include(CTest)
enable_testing()

add_executable(functionality_test 
src/functionality_test.cpp
src/myPrint.cpp
src/printME.cpp
)

#target_include_directories(functionality_test PUBLIC D:\\Code\\Projects\\TestProject\\include)
#The above allows me to compile without errors. The line below spits errors
target_include_directories(functionality_test PUBLIC "${workspaceFolder}\\include")

set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)

```

functionality\_test.cpp:

```auto
#include <iostream>
#include <fstream>
#include "headers/myPrint.h" <--- Error squiggles here: (cannot open source file "headers/myPrint.h" C/C++(1696)) & (headers/myPrint.h: No such file or directory)
#include "headers/printME.h" <--- Error squiggles here: (cannot open source file "headers/printME.h")
int main()
{
    ...
    ...
    ...

    printME();

    return 0;
}

```

myPrint.cpp:

```auto
#include <string>
#include <iostream>
void myPrint(const std::string &s){
    std::cout << s << std::endl;
}

```

printME.cpp:

```auto
#include "headers/myPrint.h" <---(cannot open source file "headers/myPrint.h" C/C++(1696)) & (headers/myPrint.h: No such file or directory)

void printME(){
    myPrint("ME");
}

```

myPrint.h:

```auto
#pragma once
#include <string>
void myPrint(const std::string &s);

```

printME.h:

```auto
#pragma once
void printME();

```

---

<div class="post-metadata">

**Author:** ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)\
**Post date:** [May 21, 2022, 6:42pm UTC](https://discourse.cmake.org/t/vscodes-variable-substitution-doesnt-seen-to-work-in-cmakelists-txt-absolute-paths-works/5701/2 "2022-05-21T18:42:48Z")

</div>

> [@Coziyu](#):
>
> `target_include_directories(functionality_test PUBLIC "${workspaceFolder}\\include")`

CMake doesn’t understand VSCode variables, so you’ll have to have VSCode pass it to CMake in some way. However, you should instead use `${CMAKE_CURRENT_SOURCE_DIR}` as that is (I believe) the CMake variable that does what you’re looking for here.

---

<div class="post-metadata">

**Author:** ![Coziyu](https://discourse.cmake.org/user_avatar/discourse.cmake.org/coziyu/32/2438_2.png) [@Coziyu](https://discourse.cmake.org/u/Coziyu)\
**Post date:** [May 21, 2022, 6:54pm UTC](https://discourse.cmake.org/t/vscodes-variable-substitution-doesnt-seen-to-work-in-cmakelists-txt-absolute-paths-works/5701/3 "2022-05-21T18:54:07Z")

</div>

Ah I see, I wrongly assumed that CMake understood VSCode variables. Thanks so much for the swift reply!
