我在执行其他操作之前 CMake 执行进程时遇到问题。
下面的代码片段显示了这种情况:
if(NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}/generated")
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/generated")
execute_process(
# This tool generates library sources, which are not known before
COMMAND "source_file_generator_command"
# This tool iterates over the generated source tree and creates
# a proper CMakeLists.txt in the 'generated' directory from the
# source files found there
COMMAND "cmake_lists_generator_command"
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/generated"
)
endif()
# At this point the generated subdirectory (with the also
# generated CMakeLists.txt file) shall be included
add_subdirectory(
"${CMAKE_CURRENT_BINARY_DIR}/generated"
"${CMAKE_CURRENT_BINARY_DIR}/generated_build"
)
# But the 'add_subdirectory' statement fails due to non-existing
# CMakeLists.txt in the 'generated' source directory at this point
如上所述,问题在于,应添加的子目录中的 CMakeLists.txt 文件是在第一次 CMake 运行期间由特殊脚本动态生成的(生成的源之前未知)。从字面上看,我需要 CMake 等待 if/else 块中的所有语句都执行完毕,并处理 add_subdirectory 语句,而不是等到一切完成(生成 CMakeLists.txt)。对于这样的用例有适当的解决方案吗?
感谢您的帮助,
Felix
当几个COMMAND
s for execute_process
被使用,它们被执行in pipe。来自描述 https://cmake.org/cmake/help/v3.0/command/execute_process.html此 CMake 命令的:
使用每个进程的标准输出运行给定的一个或多个命令序列piped到下一个的标准输入。
如果你想要真实顺序的执行命令时,您需要使用一通电话execute_process
每个命令:
execute_process(
COMMAND "source_file_generator_command"
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/generated"
)
execute_process(
COMMAND "cmake_lists_generator_command"
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/generated"
)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)