CMake Tutorial Step 2 Exercise 1 build failed

Hello, just started working with CMake and was going through the tutorial fine until step 2 exercise 1, Creating a library. I completed all the TODOs but when I go to build the solution, I get an error:

[project path]Step2\tutorial.cpp(8,10): error C1083: Cannot open include file: 'MathFunctions.h': No such file or directory [[project path]\Step2\Step2_build\Tutorial.vcxproj].

I am using powershell to run the commands and even tried it with the exact same commands and file, yet I’m still getting an error.

Here is what I have added for top level “CMakeLists.txt”:

// ...omitted code...
# TODO 2: Use add_subdirectory() to add MathFunctions to this project
add_subdirectory(MathFunctions)

# add the executable
add_executable(Tutorial tutorial.cpp)

# TODO 3: Use target_link_libraries to link the library to our executable
target_link_libraries(Tutorial PUBLIC MathFunctions)

# TODO 4: Add MathFunctions to Tutorial's target_include_directories()
# Hint: ${PROJECT_SOURCE_DIR} is a path to the project source. AKA This folder!

# add the binary tree to the search path for include files to find TutorialConfig.h
target_include_directories(Tutorial PUBLIC 
	"${PROJECT_BINARY_DIR}"
	"${PROJECT_BINARY_DIR}/MathFunctions"
)

Here is what I have in “MathFunctions/CMakeLists.txt”:

add_library(MathFunctions
	MathFunctions.cpp
	mysqrt.cpp
)

My tutorial.cpp also has the “MathFunctions.h” include.

I also noticed when opening up the solution in Visual Studio that MathFunctions is setup as another project in the solution. Is that supposed to be correct? What am I missing that causes the error?

If you change the directory structure, you have to change this too:

target_include_directories(Tutorial PUBLIC 
	"${CMAKE_CURRENT_SOURCE_DIR}"
	"${CMAKE_CURRENT_SOURCE_DIR}/MathFunctions"
)

P.S.: this is not part of Step 2?

Thank you for your suggestion! I tried using your suggestion but it still had the same error, but after looking at the steps again, and some sleep, I noticed where I went wrong and just had to change the value of the second path from "${PROJECT_BINARY_DIR}/MathFunctions" to "${PROJECT_SOURCE_DIR}/MathFunctions".

They did have it as a hint and as the solution but I guess I was too tired and tunnel visioned to see it lol.

Here is the change:

// Old code
# add the binary tree to the search path for include files to find TutorialConfig.h
target_include_directories(Tutorial PUBLIC 
	"${PROJECT_BINARY_DIR}"
	"${PROJECT_BINARY_DIR}/MathFunctions"
)
// New code
# add the binary tree to the search path for include files to find TutorialConfig.h
target_include_directories(Tutorial PUBLIC 
	"${PROJECT_BINARY_DIR}"
	"${PROJECT_SOURCE_DIR}/MathFunctions"
)