2010-06-01 78 views
1

我在使用CMake 2.8.1(在Windows上)使用"Visual Studio 10"生成器。 GLOBsource_group似乎沒有一起工作。有沒有辦法讓這個工作?CMake GLOB和source_group是否兼容?

我用file(GLOB ...)創建的.cpp文件的列表,然後使用source_group在生成的Visual Studio項目創建一個過濾

# 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}) 

與註釋掉線6條,被罰款產生的項目:

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 

與6號線取消註釋,我得到一個錯誤:

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! 

我注意到${HELLO_SRCS}的輸出值似乎沒有在文件名之間包含任何分隔符,也沒有引號或其他包含包含空格的文件名的分隔符。這與我的問題有什麼關係?重命名所有目錄以避免空格並不是真正的選擇。

回答

7

由於錯誤消息說:也許FILES關鍵字丟失。

source_group(hello_group ${HELLO_SRCS}) 

應該是:

source_group(hello_group FILES ${HELLO_SRCS})