我想在我的自定义命令中利用Ninja的“ job pools”;最终在cmake 3.15.0中直接受支持。许多/大多数人不会使用此版本,因此我想简单地添加此支持,而无需任何人更新其cmake版本。
一个更普遍的问题是...
“指定自定义命令的条件子句的最佳方法是什么?”
add_custom_command(
OUTPUT foo
COMMAND ${CMAKE_COMMAND} -E touch foo
if("${CMAKE_VERSION}" STRGREATER_EQUAL "3.15.0") # <-- syntax error
JOB_POOL my_job_pool # <-- syntax error
endif() # <-- syntax error
VERBATIM
)
也许...?
if("${CMAKE_VERSION}" STRGREATER_EQUAL "3.15.0")
set(USE_JOB_POOL JOB_POOL my_job_pool)
endif()
add_custom_command(
OUTPUT foo
COMMAND ${CMAKE_COMMAND} -E touch foo
${USE_JOB_POOL}
VERBATIM
)
还是...?
add_custom_command(
OUTPUT foo
COMMAND ${CMAKE_COMMAND} -E touch foo
$<IF:$<VERSION_GREATER_EQUAL:${CMAKE_VERSION},3.15.0>:JOB_POOL my_job_pool>
VERBATIM
)
答案 0 :(得分:0)
根据@Tsyvarev,我的方法是合理的。在我的“有效”代码中,我实现了类似的内容:
set(USE_JOB_POOL 0)
if("${CMAKE_GENERATOR}" STREQUAL "Ninja" AND
"${CMAKE_VERSION}" STRGREATER_EQUAL "3.15.0")
set(USE_JOB_POOL JOB_POOL my_job_pool)
endif()
...
add_custom_command(
OUTPUT foo
COMMAND ${CMAKE_COMMAND} -E touch foo
$<${JOB_POOL}:${JOB_POOL}>
VERBATIM
)