0

Is the only way to get the headers to show up in the Visual Studio project by including them via add_library? If so, would that duplicate the build files?

Below is a snippet. The project compiles fine because target_include_directories is providing the headers as well as the source, but only the source files show up in Visual Studio. I can see my headers show up as "External Dependencies" but it's annoying to access them that way. Thus, I'm considering just adding them in add_library, but I fear I might be going about this wrong.

add_library (Foo SHARED
    # Headers here
    src/foo.cpp
)

target_include_directories(Foo
    PUBLIC
        $<INSTALL_INTERFACE:include>
        $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
    PRIVATE
        ${CMAKE_CURRENT_SOURCE_DIR}/src
)
3
  • 1
    It's exactly - you add headers to add_library to see it in IDE. Commented Aug 5, 2019 at 21:32
  • Indeed, thank you both. Commented Aug 5, 2019 at 21:35
  • If so, would that duplicate the build files? It does not. I have done this for over a decade now with Visual Studio. Commented Aug 5, 2019 at 21:39

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.