0
如果用戶在cmake-gui
中選擇$ {DO_HTML}開關,我希望有條件地包含目標docs_html
到ALL
。沒有這個醜陋的代碼重複如何做?如何有條件地將所有選項添加到add_custom_target()?
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 repeat 2
DEPENDS ${HTML_DIR}/index.html
)
endif()