| 1 |
cmake_minimum_required(VERSION 3.17.0 FATAL_ERROR) |
| 2 |
|
| 3 |
if (NOT BASIC_PROJECT_CONFIG_DONE) |
| 4 |
message(FATAL_ERROR "Before including the ShellCompletion module, the BasicConfig module must be included.") |
| 5 |
endif () |
| 6 |
|
| 7 |
option(SHELL_COMPLETION_ENABLED "controls whether shell completion is enabled in general" ON) |
| 8 |
option(BASH_COMPLETION_ENABLED "controls whether shell completion for bash is enabled" ON) |
| 9 |
if (NOT SHELL_COMPLETION_ENABLED) |
| 10 |
return() |
| 11 |
endif () |
| 12 |
|
| 13 |
# add bash completion (currently the only supported shell completion) |
| 14 |
if (BASH_COMPLETION_ENABLED) |
| 15 |
# make install destination configurable |
| 16 |
set(BASH_COMPLETION_INSTALL_DIR |
| 17 |
"${CMAKE_INSTALL_DATAROOTDIR}/bash-completion" |
| 18 |
CACHE STRING "sets the directory to install Bash completion files to") |
| 19 |
|
| 20 |
# find bash-completion.sh template |
| 21 |
include(TemplateFinder) |
| 22 |
find_template_file("bash-completion.sh" CPP_UTILITIES BASH_COMPLETION_TEMPLATE_FILE) |
| 23 |
|
| 24 |
# generate wrapper script for bash completion |
| 25 |
configure_file("${BASH_COMPLETION_TEMPLATE_FILE}" |
| 26 |
"${CMAKE_CURRENT_BINARY_DIR}/bash-completion/completions/${META_TARGET_NAME}" @ONLY) |
| 27 |
|
| 28 |
# add install target bash completion |
| 29 |
if (NOT META_NO_INSTALL_TARGETS AND ENABLE_INSTALL_TARGETS) |
| 30 |
install( |
| 31 |
DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bash-completion/completions" |
| 32 |
DESTINATION "${BASH_COMPLETION_INSTALL_DIR}" |
| 33 |
COMPONENT bash-completion) |
| 34 |
if (NOT TARGET install-bash-completion) |
| 35 |
add_custom_target(install-bash-completion COMMAND "${CMAKE_COMMAND}" -DCMAKE_INSTALL_COMPONENT=bash-completion |
| 36 |
-P "${CMAKE_BINARY_DIR}/cmake_install.cmake") |
| 37 |
endif () |
| 38 |
endif () |
| 39 |
|
| 40 |
message(STATUS "Generating files for bash completion.") |
| 41 |
endif () |