cpp-utilities/cmake/modules/ShellCompletion.cmake

42 lines
1.8 KiB
CMake
Raw Normal View History

2020-01-10 17:58:41 +01:00
cmake_minimum_required(VERSION 3.3.0 FATAL_ERROR)
2019-02-06 17:30:52 +01:00
if (NOT BASIC_PROJECT_CONFIG_DONE)
2017-02-11 02:30:46 +01:00
message(FATAL_ERROR "Before including the ShellCompletion module, the BasicConfig module must be included.")
2019-02-06 17:30:52 +01:00
endif ()
2017-02-11 02:30:46 +01:00
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)
2019-02-06 17:30:52 +01:00
if (NOT SHELL_COMPLETION_ENABLED)
2018-02-21 23:00:32 +01:00
return()
2019-02-06 17:30:52 +01:00
endif ()
2016-07-03 22:36:48 +02:00
2018-02-21 23:00:32 +01:00
# add bash completion (currently the only supported shell completion)
2019-02-06 17:30:52 +01:00
if (BASH_COMPLETION_ENABLED)
# make install destination configurable
set(BASH_COMPLETION_INSTALL_DIR
"${CMAKE_INSTALL_DATAROOTDIR}/bash-completion"
CACHE STRING "sets the directory to install Bash completion files to")
2018-02-21 23:00:32 +01:00
# find bash-completion.sh template
include(TemplateFinder)
find_template_file("bash-completion.sh" CPP_UTILITIES BASH_COMPLETION_TEMPLATE_FILE)
2016-07-03 22:36:48 +02:00
2018-02-21 23:00:32 +01:00
# generate wrapper script for bash completion
2019-02-06 17:30:52 +01:00
configure_file("${BASH_COMPLETION_TEMPLATE_FILE}"
"${CMAKE_CURRENT_BINARY_DIR}/bash-completion/completions/${META_TARGET_NAME}" @ONLY)
2016-07-03 22:36:48 +02:00
2018-02-21 23:00:32 +01:00
# add install target bash completion
2019-02-06 17:30:52 +01:00
if (NOT META_NO_INSTALL_TARGETS AND ENABLE_INSTALL_TARGETS)
2019-11-30 17:58:01 +01:00
install(
DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bash-completion/completions"
DESTINATION "${BASH_COMPLETION_INSTALL_DIR}"
2019-11-30 17:58:01 +01:00
COMPONENT bash-completion)
2019-02-06 17:30:52 +01:00
if (NOT TARGET install-bash-completion)
2019-11-30 17:58:01 +01:00
add_custom_target(install-bash-completion COMMAND "${CMAKE_COMMAND}" -DCMAKE_INSTALL_COMPONENT=bash-completion
-P "${CMAKE_BINARY_DIR}/cmake_install.cmake")
2019-02-06 17:30:52 +01:00
endif ()
endif ()
2018-02-21 23:00:32 +01:00
message(STATUS "Generating files for bash completion.")
2019-02-06 17:30:52 +01:00
endif ()