Adding data files to cmake-generated projects

2019-06-22 08:10发布

问题:

I have a project where the source files are in source/ and some shader files in data/ (those are not compiled, but instead loaded by the code). I'd like these files to show up in my CMake-generated VS2010 project files so I can edit them comfortably. What's a good way to do this? Ideally, they'd be in a separate project, but anything that works is good.

Thanks!

回答1:

I can't comment (reputation too low) but is this what you want ? http://www.cmake.org/pipermail/cmake/2006-May/009291.html

EDIT: if the above link stops working at some time, the idea is to add the files to Visual Studio like an ordinary source file. Since the IDE has no compile tool associated with it, it will be ignored. Quoting the list's discussion:

You could add arbitrary files to a target - as long as VS has no "automatic" rule to compile them (e.g. .cc, .cpp etc) I am adding .html files to libraries/executable or using a dummy target e.g:

ADD_EXECUTABLE(dummy dummy.cpp "${CMAKE_CURRENT_BINARY_DIR}/Doc/index.html")

SOURCE_GROUP command may be useful, too.

and also

I think you have to take care that they are added only to VS IDE generator builds, in particular NOT to makefiles.

Thus we are using something like this:

IF    (CMAKE_BUILD_TOOL MATCHES "(msdev|devenv)")
  ADD_EXECUTABLE( hello ${SOURCES} ${HEADER} ${DOC})
ELSE  (CMAKE_BUILD_TOOL MATCHES "(msdev|devenv)")
  ADD_EXECUTABLE( hello ${SOURCES} )
ENDIF (CMAKE_BUILD_TOOL MATCHES "(msdev|devenv)")

Credit to Jan Woetzel