[CMake] Adding non-compiled files to project?

Timenkov Yuri ytimenkov at parallels.com
Mon Jun 23 11:36:53 EDT 2008


On Monday 23 June 2008 19:22:28 Mike Arthur wrote:
> It seems that the CMake Visual Studio 2008 project generator won't add any 
> source files that it doesn't use in a add_executable or add_library call. 
> I've tried manually adding others using source_group but this doesn't seem to 
> make any difference.
> 
> How do I add e.g. headers to my projects?
Just add them to corresponding target. CMake won't try to compile them if they don't have source file extension. If file has a source file extension, you should set source files property HEADER_FILE_ONLY to true:
ex:

set(MyLib_HDRS file1.h)
set(MyLib_SRCS file1.cpp)
set(MyLib_Linux_HDRS file1_lin.h)
set(MyLib_Linux_SRCS file1_lin.cpp)

source_group("Linux Sources" FILES ${MyLib_Linux_SRCS})
source_group("Linux Headers" FILES ${MyLib_Linux_HDRS})

set_source_files_properties(${MyLib_Linux_HDRS} PROPERTIES HEADER_FILE_ONLY TRUE)

add_library(MyLib ${MyLib_HDRS} ${MyLib_SRCS} ${MyLib_Linux_HDRS} ${MyLib_Linux_SRCS})

This is convenient if you want to edit all files on windows, or search in whole solution.


More information about the CMake mailing list