我在"Visual Studio 10"生成器上使用CMake 2.8.1(在Windows上).GLOB并且source_group似乎没有一起工作.有没有办法让这个工作?
我file( GLOB ... )用来创建.cpp文件列表,然后用于在生成的Visual Studio项目中source_group创建过滤器:
# 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} )
Run Code Online (Sandbox Code Playgroud)
第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
Run Code Online (Sandbox Code Playgroud)
第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!
Run Code Online (Sandbox Code Playgroud)
我注意到输出值${HELLO_SRCS}似乎不包含文件名之间的任何分隔符,也没有包含空格的文件名的引号或其他分隔符.这与我的问题有什么关系吗?重命名所有目录以避免空格不是一个真正的选择.
正如错误消息所示:可能缺少FILES关键字.
source_group( hello_group ${HELLO_SRCS} )
Run Code Online (Sandbox Code Playgroud)
应该:
source_group( hello_group FILES ${HELLO_SRCS} )
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3210 次 |
| 最近记录: |