How to conditionally add ALL option to add_custom_target()?
问题 I would like to conditionally include the target docs_html to ALL if user selects ${DO_HTML} switch in cmake-gui . How to do without this ugly code repetition? cmake_minimum_required(VERSION 3.3 FATAL_ERROR) project(docs) set(DO_HTML 1 CACHE BOOL "Whether generate documentation in static HTML") if (${DO_HTML}) #This command doesn't work: # add_dependencies(ALL docs_html) add_custom_target(docs_html ALL #Code repeat 1 DEPENDS ${HTML_DIR}/index.html ) else() add_custom_target(docs_html #Code