Are CMake GLOB and source_group compatible?-Collection of common programming errors

I’m using CMake 2.8.1 (on Windows) with the "Visual Studio 10" generator. GLOB and source_group don’t seem to work together. Is there a way to get this to work?

I use file( GLOB ... ) to create a list of .cpp files and then use source_group to create a filter in the generated Visual Studio project:

# C:\Users\My Name\hello\CMakeLists.txt
cmake_minimum_required( VERSION 2.8 )
project( hello_proj )
file( GLOB HELLO_SRCS *.cpp )
message( "HELLO_SRCS="${HELLO_SRCS} )
#source_group( hello_group ${HELLO_SRCS} ) #line 6: uncomment to get error
add_executable( hello_exec ${HELLO_SRCS} )

with line 6 commented out, the project is generated fine:

C:\Users\My Name\hello>cmake .
HELLO_SRCS=C:/Users/My Name/hello/hello.cppC:/Users/My Name/hello/print_line.cpp
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/My Name/hello

with line 6 un-commented, I get an error:

C:\Users\My Name\hello>cmake .
HELLO_SRCS=C:/Users/My Name/hello/hello.cppC:/Users/My Name/hello/print_line.cpp
CMake Error at CMakeLists.txt:6 (source_group):
  source_group Unknown argument "C:/Users/My Name/hello/hello.cpp".
  Perhaps the FILES keyword is missing.



-- Configuring incomplete, errors occurred!

I notice that output value of ${HELLO_SRCS} does not seem to contain any delimiters between the file names, nor does it have quotes or other delimiters wrapping the file names which contain spaces. Does that have anything to do with my problem? Renaming all directories to avoid spaces is not really an option.

  1. As the error message says: Perhaps the FILES keyword is missing.

    source_group( hello_group ${HELLO_SRCS} )
    

    Should be:

    source_group( hello_group FILES ${HELLO_SRCS} )
    

Originally posted 2013-11-09 23:12:10.