cmake中执行shell命令,有两种形式:execute_process,和add_custom_command。
其中add_custom_command可以实现复杂的逻辑命令。
自定义cmake的命令,有两种形式:add_custom_command(OUTPUT .....) 和 add_custom_command(TARGET ......)
错误1:
使用 cmake -P 调试 带有add_custom_command(...) 的脚本,会提示:add_executable command is not scriptable
cmake -P CMakeLists.txt CMake Error at CMakeLists.txt:6 (add_executable): add_executable command is not scriptable
对策:cmake ./ 直接运行。将脚本include进CMakeLists.txt
错误2
对策:在脚本中,增加 cmake_minimum_required(VERSION 3.10)