我想做这样的事情:
$ cmake -E "find_package(Boost)"
看它是成功还是失败? (即。所以我可以对项目进行一些依赖检查,并尝试在cmake实际运行CMakeLists.txt之前安装所有这些。
我知道cmake已经有了-E标志但是当我运行它时我只得到一小部分可用命令:
Usage: cmake -E [command] [arguments ...]
Available commands:
chdir dir cmd [args]... - run command in a given directory
compare_files file1 file2 - check if file1 is same as file2
copy file destination - copy file to destination (either file or directory)
copy_directory source destination - copy directory 'source' content to directory 'destination'
copy_if_different in-file out-file - copy file if input has changed
echo [string]... - displays arguments as text
echo_append [string]... - displays arguments as text but no new line
environment - display the current environment
make_directory dir - create a directory
md5sum file1 [...] - compute md5sum of files
remove [-f] file1 file2 ... - remove the file(s), use -f to force it
remove_directory dir - remove a directory and its contents
rename oldname newname - rename a file or directory (on one volume)
tar [cxt][vfz][cvfj] file.tar [file/dir1 file/dir2 ...]
- create or extract a tar or zip archive
time command [args] ... - run command and return elapsed time
touch file - touch a file.
touch_nocreate file - touch a file but do not create it.
Available on UNIX only:
create_symlink old new - create a symbolic link new -> old
答案 0 :(得分:2)
有-P <source.cmake>
标志,将CMake置于脚本处理模式。您可以使用
execute_process(COMMAND ${CMAKE_PROGRAM} -P yourscript.cmake)
但是从你的find_package(Boost)
拨打CMakeLists.txt
是没有错的,因为如果没有发现Boost没有立即失败,但是你提供检查这个的方法并做点别的事。
所有依赖性检查都应该在CMakeLists.txt
内部而不是外部脚本中完成。