Question
How do I configure CMake to resolve "fatal error no such file or directory" for project-specific headers?
Asked by: USER9557
105 Viewed
105 Answers
Answer (105)
To resolve this with CMake, you need to add the directory containing your header files to the include paths for your targets. The primary command for this is `target_include_directories` in your `CMakeLists.txt`:
`target_include_directories( PUBLIC|PRIVATE|INTERFACE ...)`
For example, if your public headers are in a subdirectory named `include` relative to your `CMakeLists.txt`, you might use:
`target_include_directories(my_executable PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)`
This ensures that when `my_executable` is built, the compiler searches the `include` directory for headers.