neovim/runtime/CMakeLists.txt
bfredl 30632dd21a refactor(build): make installation of runtime/ more effective
Currently files to install in runtime/ is detected by recursive glob
pattern which has two problems:

- cmake needs to do a of work at config time and
  build/runtime/cmake_install.cmake becomes HUGE (2.5MB, biggest config file)
- we need to explicitly specify each file suffix used in the entire
  runtime, which is duplication of information.

These globs specify every single file in a subdirectory.
Thus, we can just install every runtime/ subdirectory as a single
install command. Furthermore, at the top-level, only .vim and .lua files
need to be installed.

Further possible refactor: we could move files which does not belong
in $PREFIX/runtime out of $REPO/runtime. Then runtime could be installed
with a single install_helper(DIRECTORY ...) command.
2023-03-07 20:16:52 +01:00

133 lines
4.6 KiB
CMake

set(SYN_VIM_GENERATOR ${PROJECT_SOURCE_DIR}/scripts/genvimvim.lua)
set(GENERATED_RUNTIME_DIR ${PROJECT_BINARY_DIR}/runtime)
set(GENERATED_SYN_VIM ${GENERATED_RUNTIME_DIR}/syntax/vim/generated.vim)
set(GENERATED_HELP_TAGS ${GENERATED_RUNTIME_DIR}/doc/tags)
set(GENERATED_PACKAGE_DIR ${GENERATED_RUNTIME_DIR}/pack/dist/opt)
set(FUNCS_DATA ${PROJECT_BINARY_DIR}/funcs_data.mpack)
file(MAKE_DIRECTORY ${GENERATED_RUNTIME_DIR})
file(MAKE_DIRECTORY ${GENERATED_RUNTIME_DIR}/syntax)
file(MAKE_DIRECTORY ${GENERATED_RUNTIME_DIR}/syntax/vim)
add_custom_command(OUTPUT ${GENERATED_SYN_VIM}
COMMAND ${LUA_PRG} ${SYN_VIM_GENERATOR}
${PROJECT_SOURCE_DIR}/src/nvim ${GENERATED_SYN_VIM} ${FUNCS_DATA}
DEPENDS
${SYN_VIM_GENERATOR}
${PROJECT_SOURCE_DIR}/src/nvim/ex_cmds.lua
${PROJECT_SOURCE_DIR}/src/nvim/auevents.lua
${PROJECT_SOURCE_DIR}/src/nvim/options.lua
${PROJECT_SOURCE_DIR}/src/nvim/eval.c
${FUNCS_DATA}
)
glob_wrapper(PACKAGES ${PROJECT_SOURCE_DIR}/runtime/pack/dist/opt/*)
set(GENERATED_PACKAGE_TAGS)
foreach(PACKAGE ${PACKAGES})
get_filename_component(PACKNAME ${PACKAGE} NAME)
glob_wrapper("${PACKNAME}_DOC_FILES" ${PACKAGE}/doc/*.txt)
if(${PACKNAME}_DOC_FILES)
file(MAKE_DIRECTORY ${GENERATED_PACKAGE_DIR}/${PACKNAME})
add_custom_command(OUTPUT "${GENERATED_PACKAGE_DIR}/${PACKNAME}/doc/tags"
COMMAND ${CMAKE_COMMAND} -E copy_directory
${PACKAGE} ${GENERATED_PACKAGE_DIR}/${PACKNAME}
COMMAND "${PROJECT_BINARY_DIR}/bin/nvim"
-u NONE -i NONE -e --headless -c "helptags doc" -c quit
DEPENDS
nvim
nvim_runtime_deps
WORKING_DIRECTORY "${GENERATED_PACKAGE_DIR}/${PACKNAME}"
)
set("${PACKNAME}_DOC_NAMES")
foreach(DF "${${PACKNAME}_DOC_FILES}")
get_filename_component(F ${DF} NAME)
list(APPEND "${PACKNAME}_DOC_NAMES" ${GENERATED_PACKAGE_DIR}/${PACKNAME}/doc/${F})
endforeach()
install_helper(
FILES ${GENERATED_PACKAGE_DIR}/${PACKNAME}/doc/tags "${${PACKNAME}_DOC_NAMES}"
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/nvim/runtime/pack/dist/opt/${PACKNAME}/doc)
list(APPEND GENERATED_PACKAGE_TAGS "${GENERATED_PACKAGE_DIR}/${PACKNAME}/doc/tags")
endif()
endforeach()
glob_wrapper(DOCFILES ${PROJECT_SOURCE_DIR}/runtime/doc/*.txt)
set(BUILDDOCFILES)
foreach(DF ${DOCFILES})
get_filename_component(F ${DF} NAME)
list(APPEND BUILDDOCFILES ${GENERATED_RUNTIME_DIR}/doc/${F})
endforeach()
add_custom_command(OUTPUT ${GENERATED_HELP_TAGS}
COMMAND ${CMAKE_COMMAND} -E remove_directory doc
COMMAND ${CMAKE_COMMAND} -E copy_directory
${PROJECT_SOURCE_DIR}/runtime/doc doc
COMMAND "${PROJECT_BINARY_DIR}/bin/nvim"
-u NONE -i NONE -e --headless -c "helptags ++t doc" -c quit
DEPENDS
nvim
nvim_runtime_deps
WORKING_DIRECTORY "${GENERATED_RUNTIME_DIR}"
)
# TODO: This doesn't work. wait for "nvim -l" to land?
add_custom_target(doc_html
COMMAND "${PROJECT_BINARY_DIR}/bin/nvim"
-V1 -es --clean -c "lua require('scripts.gen_help_html').gen('./build/runtime/doc', './build/doc_html', nil, 'todo_commit_id')" -c "0cq"
DEPENDS
${GENERATED_HELP_TAGS}
WORKING_DIRECTORY "${GENERATED_RUNTIME_DIR}/doc"
)
add_custom_target(
runtime ALL
DEPENDS
${GENERATED_SYN_VIM}
${GENERATED_HELP_TAGS}
${GENERATED_PACKAGE_TAGS}
)
# CMake is painful here. It will create the destination using the user's
# current umask, and we don't want that. And we don't just want to install
# the target directory, as it will mess with existing permissions. So this
# seems like the best compromise. If we create it, then everyone can see it.
# If it's preexisting, leave it alone.
install_helper(
FILES ${GENERATED_HELP_TAGS} ${BUILDDOCFILES}
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/nvim/runtime/doc)
install_helper(
FILES ${GENERATED_SYN_VIM}
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/nvim/runtime/syntax/vim)
if(NOT APPLE)
install_helper(
FILES ${CMAKE_CURRENT_SOURCE_DIR}/nvim.desktop
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/applications)
endif()
install_helper(
FILES ${CMAKE_CURRENT_SOURCE_DIR}/nvim.png
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/128x128/apps)
glob_wrapper(RUNTIME_ROOT_FILES *.vim *.lua *.ico)
install_helper(FILES ${RUNTIME_ROOT_FILES}
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/nvim/runtime/)
glob_wrapper(RUNTIME_DIRS */)
foreach(D ${RUNTIME_DIRS})
if(IS_DIRECTORY ${D})
install_helper(DIRECTORY ${D}
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/nvim/runtime/)
endif()
endforeach()
# only foo.sh script in runtime/
install_helper(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/macros/less.sh DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/nvim/runtime/macros/)