0

I want to take advantage of Ninja's "job pools" in my custom commands; something finally directly supported in cmake 3.15.0. Many/most people won't have this version, so I would like to simply ADD this support without requiring that anyone update their cmake version.

A more general question is...

"What's the best way to specify a conditional clause of a custom command …?"

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
  )

Maybe...?

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
  )

Or...?

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
  )
Lance E.T. Compte
  • 932
  • 1
  • 11
  • 33
  • 1
    Both second and third ways are correct. Which one is used is up to you. – Tsyvarev Jun 28 '19 at 04:55
  • I forgot all about this post and a few months later, came back to attack the problem. My efforts are captured here: https://stackoverflow.com/questions/57896852/cmake-3-15-adding-job-pool-to-add-custom-command-sometimes – Lance E.T. Compte Sep 19 '19 at 18:31

1 Answers1

0

According to @Tsyvarev, my approach is reasonable. In my code, which "works", I implemented something similar to this:

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
  )
Lance E.T. Compte
  • 932
  • 1
  • 11
  • 33