views:

1460

answers:

3

Hi,

I'm building a cmake based build system for our product. The problem is that Visual Studio project, generated by cmake, doesn't display header files in solution browser.

What I need to add in CMakeList.txt to list header files? The preferred solution is where no need to list each particular header file.

Solution Here is a solution I came with:

file(GLOB_RECURSE INCS "*.h")
add_library(myLib ${SRCS} ${INCS})

Thanks Dima

+1  A: 

Um, I know next to nothing about CMake, but some project I have looked at uses

set(SOURCE
  foo.cpp
  bar.cpp
)

set(HEADERS
  foo.h
  bar.h
)

in its CMakeLists.txt file.

Would that help?

sbi
What I do with SOURCE variable? Is there an option to glob all header files (e.g. *.h)?
dimba
Sorry, I meant HEADER variable. It's user defined variable, so I need to know where it is used.
dimba
+4  A: 

Just add the header files along with the source files:

PROJECT (Test)

ADD_EXECUTABLE(Test test.cpp test.h)

Or using variables:

PROJECT (Test)

SET(SOURCE
  test.cpp
)

SET(HEADERS
  test.h
)

ADD_EXECUTABLE(Test ${SOURCE} ${HEADERS})
tim_hutton
+1  A: 

The basic trick to this is to add the header files to one of the targets (either executable or library). This is particularly irritating because cmake already knows all the header file dependencies and should take care of this for us. You can organize it further using the source_group command:

  source_group("My Headers" FILES ${MY_HDRS})

Note that you have to do the same thing in Xcode too.

Simeon Fitch