cpp-utilities/cmake/modules/ShellCompletion.cmake

36 lines
1.4 KiB
CMake
Raw Normal View History

2017-02-11 02:30:46 +01:00
if(NOT BASIC_PROJECT_CONFIG_DONE)
message(FATAL_ERROR "Before including the ShellCompletion module, the BasicConfig module must be included.")
endif()
2016-07-10 00:16:24 +02:00
option(SHELL_COMPLETION_ENABLED "controls whether shell completion is enabled in general" ON)
option(BASH_COMPLETION_ENABLED "controls whether shell completion for bash is enabled" ON)
2016-07-03 22:36:48 +02:00
2016-07-10 00:16:24 +02:00
if(SHELL_COMPLETION_ENABLED)
2016-07-03 22:36:48 +02:00
# add bash completion (currently the only supported shell completion)
2016-07-10 00:16:24 +02:00
if(BASH_COMPLETION_ENABLED)
2016-07-03 22:36:48 +02:00
# find bash-completion.sh template
include(TemplateFinder)
find_template_file("bash-completion.sh" CPP_UTILITIES BASH_COMPLETION_TEMPLATE_FILE)
# generate wrapper script for bash completion
configure_file(
"${BASH_COMPLETION_TEMPLATE_FILE}"
"${CMAKE_CURRENT_BINARY_DIR}/bash-completion/completions/${META_PROJECT_NAME}"
@ONLY
)
# add install target bash completion
install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bash-completion/completions"
2016-09-12 00:09:54 +02:00
DESTINATION "share/bash-completion"
2016-07-03 22:36:48 +02:00
COMPONENT bash-completion
)
if(NOT TARGET install-bash-completion)
add_custom_target(install-bash-completion
COMMAND "${CMAKE_COMMAND}" -DCMAKE_INSTALL_COMPONENT=bash-completion -P "${CMAKE_BINARY_DIR}/cmake_install.cmake"
)
endif()
2016-07-10 00:16:24 +02:00
message(STATUS "Generating files for bash completion.")
2016-07-03 22:36:48 +02:00
endif()
endif()