我目前正在使用递归make和autotools,我正在寻找迁移到CMake的项目看起来像这样:
lx/ (project root)
src/
lx.c (contains main method)
conf.c
util/
str.c
str.h
etc.c
etc.h
server/
server.c
server.h
request.c
request.h
js/
js.c
js.h
interp.c
interp.h
bin/
lx (executable)
Run Code Online (Sandbox Code Playgroud)
我该怎么办呢?
DLR*_*ave 75
如果没有任何源高于lx/src目录,那么就不需要lx/CMakeLists.txt文件.如果有,它应该看起来像这样:
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
project(lx)
add_subdirectory(src)
add_subdirectory(dir1)
add_subdirectory(dir2)
# And possibly other commands dealing with things
# directly in the "lx" directory
Run Code Online (Sandbox Code Playgroud)
...在库依赖顺序中添加子目录的位置.应首先添加依赖于其他任何内容的库,然后添加依赖于这些库的库,依此类推.
LX/SRC /的CMakeLists.txt
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
project(lx_exe)
add_subdirectory(util)
add_subdirectory(js)
add_subdirectory(server)
set(lx_source_files conf.c lx.c)
add_executable(lx ${lx_source_files})
target_link_libraries(lx server)
# also transitively gets the "js" and "util" dependencies
Run Code Online (Sandbox Code Playgroud)
LX/SRC/UTIL /的CMakeLists.txt
set(util_source_files
etc.c
etc.h
str.c
str.h
)
add_library(util ${util_source_files})
Run Code Online (Sandbox Code Playgroud)
LX/SRC/JS /的CMakeLists.txt
set(js_source_files
interp.c
interp.h
js.c
js.h
)
add_library(js ${js_source_files})
target_link_libraries(js util)
Run Code Online (Sandbox Code Playgroud)
LX/src目录/服务器/的CMakeLists.txt
set(server_source_files
request.c
request.h
server.c
server.h
)
add_library(server ${server_source_files})
target_link_libraries(server js)
# also transitively gets the "util" dependency
Run Code Online (Sandbox Code Playgroud)
然后,在命令提示符下:
mkdir lx/bin
cd lx/bin
cmake ..
# or "cmake ../src" if the top level
# CMakeLists.txt is in lx/src
make
Run Code Online (Sandbox Code Playgroud)
默认情况下,lx可执行文件将使用此精确布局结束在"lx/bin/src"目录中.您可以使用RUNTIME_OUTPUT_DIRECTORY目标属性和set_property命令控制最终的目录.
http://www.cmake.org/cmake/help/cmake-2-8-docs.html#prop_tgt:RUNTIME_OUTPUT_DIRECTORY
http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command:set_property
如果通过add_library将lib构建为CMake目标,则通过CMake目标名称引用target_link_libraries libs,否则通过库文件的完整路径引用.
另请参见"cmake --help-command target_link_libraries"或任何其他cmake命令的输出,以及此处的cmake命令的完整联机文档:
http://www.cmake.org/cmake/help/cmake-2-8-docs.html#section_Commands
http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command:target_link_libraries
| 归档时间: |
|
| 查看次数: |
31239 次 |
| 最近记录: |