cmake:检查文件是否在构建时而不是在cmake配置期间存在 [英] cmake: check if file exists at build time rather than during cmake configuration
本文介绍了cmake:检查文件是否在构建时而不是在cmake配置期间存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个自定义生成命令,需要检查某个文件是否存在.我尝试使用
I have a custom build command that needs to check if a certain file exists. I tried using
IF(EXISTS "/the/file")
...
ELSE()
...
ENDIF()
但是该测试仅被评估一次;第一次运行cmake时.每次制作完成后,我都需要它来执行测试.接通时间检查的方法是什么?谢谢.
but that test is only evaluated one; when cmake is first run. I need it to perform the test every time a make is done. What's the method to check at make-time? Thanks.
推荐答案
您可以使用 add_custom_command
使用 -P
命令行选项.
You can use add_custom_command
to invoke CMake itself in script mode by using the -P
command line option.
所以您的命令将类似于:
So your command would be something like:
set(FileToCheck "/the/file")
add_custom_command(TARGET MyExe
POST_BUILD
COMMAND ${CMAKE_COMMAND}
-DFileToCheck=${FileToCheck}
-P ${CMAKE_CURRENT_SOURCE_DIR}/check.cmake
COMMENT "Checking if ${FileToCheck} exists...")
和您的脚本文件"check.cmake"类似于:
and your script file "check.cmake" would be something like:
if(EXISTS ${FileToCheck})
message("${FileToCheck} exists.")
else()
message("${FileToCheck} doesn't exist.")
endif()
这篇关于cmake:检查文件是否在构建时而不是在cmake配置期间存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文