Reputation: 541
I'm browsing a project which has a src directory similar to:
src/
|-- A.cpp
|-- dir/
|-- |-- B.h
|-- |-- B.cpp
In A.cpp they include B.h as such:
// In A.cpp:
#include "B.h"
In the visual studio 2010 solution generated with CMake this compiles just fine, and there exists no conflict. However, if I make a new project (not from CMake, but manually) and do the include as above, VS will not find B.h. I.e.:
// In A.cpp (non-CMake project version)
#include "B.h" // Error: File not found (VS does not search the
//sub-directory when name is surrounded by "").
#include "dir/B.h" // Works: sub-directory specified.
The CMake file uses GLOB_RECURSE (which I assume is the reason the above works, please correct me if I'm wrong), and simplified it looks something like this:
cmake_minimum_required (VERSION 2.6)
project (cmake_test)
file(GLOB_RECURSE lib_SRCS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp *.h)
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/dir
)
add_library(lib STATIC
${lib_SRCS}
)
target_link_libraries(lib)
I've been examining the difference of the solution generated by CMake and the one I manually created, but I can't seem to find it.
My question is, in other words, how I could accomplish having VS find my B.h without the relative path included as the solution generated with CMake displays, without actually using CMake (such as by some option or configuration in my Visual Studio Project).
Upvotes: 1
Views: 1031
Reputation: 3975
The part that makes it work is
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/dir
)
Your dir/
directory is added to the include directories. In Visual Studio you need to go to project properties at C/C++->General->Additional Include Directories
and add dir/
.
Upvotes: 2