From 81f2bce775bc7e7392b51538b94a0d62d6ab15b4 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Tue, 4 Apr 2023 19:27:21 +0200 Subject: [PATCH] build: cmake cleanup - Change libtermkeyCMakeLists.txt to LibtermkeyCMakeLists.txt - Remove duplicate mark_as_advanced calls in FindLibuv.cmake - Fix "Enabling Clang sanitizer" messages as it's no longer clang-only - Simplify parser installation syntax - Rename tree-sitter to treesitter --- cmake.deps/CMakeLists.txt | 5 -- cmake.deps/cmake/BuildLibtermkey.cmake | 2 +- cmake.deps/cmake/BuildTreesitter.cmake | 6 +-- cmake.deps/cmake/BuildTreesitterParsers.cmake | 53 ++++++++----------- ...MakeLists.txt => LibtermkeyCMakeLists.txt} | 0 cmake.deps/cmake/TreesitterCMakeLists.txt | 2 +- cmake/FindLibuv.cmake | 2 - src/nvim/CMakeLists.txt | 6 +-- 8 files changed, 29 insertions(+), 47 deletions(-) rename cmake.deps/cmake/{libtermkeyCMakeLists.txt => LibtermkeyCMakeLists.txt} (100%) diff --git a/cmake.deps/CMakeLists.txt b/cmake.deps/CMakeLists.txt index afa0e447fe..fb639e4801 100644 --- a/cmake.deps/CMakeLists.txt +++ b/cmake.deps/CMakeLists.txt @@ -187,19 +187,14 @@ set(LIBICONV_SHA256 ccf536620a45458d26ba83887a983b96827001e92a13847b45e4925cc891 set(TREESITTER_C_URL https://github.com/tree-sitter/tree-sitter-c/archive/v0.20.2.tar.gz) set(TREESITTER_C_SHA256 af66fde03feb0df4faf03750102a0d265b007e5d957057b6b293c13116a70af2 ) - set(TREESITTER_LUA_URL https://github.com/MunifTanjim/tree-sitter-lua/archive/v0.0.14.tar.gz) set(TREESITTER_LUA_SHA256 930d0370dc15b66389869355c8e14305b9ba7aafd36edbfdb468c8023395016d) - set(TREESITTER_VIM_URL https://github.com/vigoux/tree-sitter-viml/archive/e39a7bbcfdcfc7900629962b785c7e14503ae590.tar.gz) set(TREESITTER_VIM_SHA256 7ca85fa1a5a9e4d057ff3b7ae53d13d31371973e734ada87a83f3f6cbe9c0e32) - set(TREESITTER_VIMDOC_URL https://github.com/neovim/tree-sitter-vimdoc/archive/v2.0.0.tar.gz) set(TREESITTER_VIMDOC_SHA256 1ff8f4afd3a9599dd4c3ce87c155660b078c1229704d1a254433e33794b8f274) - set(TREESITTER_QUERY_URL https://github.com/nvim-treesitter/tree-sitter-query/archive/v0.1.0.tar.gz) set(TREESITTER_QUERY_SHA256 e2b806f80e8bf1c4f4e5a96248393fe6622fc1fc6189d6896d269658f67f914c) - set(TREESITTER_URL https://github.com/tree-sitter/tree-sitter/archive/v0.20.8.tar.gz) set(TREESITTER_SHA256 6181ede0b7470bfca37e293e7d5dc1d16469b9485d13f13a605baec4a8b1f791) diff --git a/cmake.deps/cmake/BuildLibtermkey.cmake b/cmake.deps/cmake/BuildLibtermkey.cmake index 0f10c98194..0d2b66a060 100644 --- a/cmake.deps/cmake/BuildLibtermkey.cmake +++ b/cmake.deps/cmake/BuildLibtermkey.cmake @@ -4,7 +4,7 @@ ExternalProject_Add(libtermkey DOWNLOAD_NO_PROGRESS TRUE DOWNLOAD_DIR ${DEPS_DOWNLOAD_DIR}/libtermkey PATCH_COMMAND ${CMAKE_COMMAND} -E copy - ${CMAKE_CURRENT_SOURCE_DIR}/cmake/libtermkeyCMakeLists.txt + ${CMAKE_CURRENT_SOURCE_DIR}/cmake/LibtermkeyCMakeLists.txt ${DEPS_BUILD_DIR}/src/libtermkey/CMakeLists.txt CMAKE_ARGS ${DEPS_CMAKE_ARGS} -D CMAKE_SHARED_LIBRARY_LINK_C_FLAGS="" # Hack to avoid -rdynamic in Mingw diff --git a/cmake.deps/cmake/BuildTreesitter.cmake b/cmake.deps/cmake/BuildTreesitter.cmake index 837c1cbcb7..da5d212520 100644 --- a/cmake.deps/cmake/BuildTreesitter.cmake +++ b/cmake.deps/cmake/BuildTreesitter.cmake @@ -1,11 +1,11 @@ -ExternalProject_Add(tree-sitter +ExternalProject_Add(treesitter URL ${TREESITTER_URL} URL_HASH SHA256=${TREESITTER_SHA256} DOWNLOAD_NO_PROGRESS TRUE - DOWNLOAD_DIR ${DEPS_DOWNLOAD_DIR}/tree-sitter + DOWNLOAD_DIR ${DEPS_DOWNLOAD_DIR}/treesitter INSTALL_DIR ${DEPS_INSTALL_DIR} PATCH_COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/cmake/TreesitterCMakeLists.txt - ${DEPS_BUILD_DIR}/src/tree-sitter/CMakeLists.txt + ${DEPS_BUILD_DIR}/src/treesitter/CMakeLists.txt CMAKE_ARGS ${DEPS_CMAKE_ARGS} CMAKE_CACHE_ARGS ${DEPS_CMAKE_CACHE_ARGS}) diff --git a/cmake.deps/cmake/BuildTreesitterParsers.cmake b/cmake.deps/cmake/BuildTreesitterParsers.cmake index ef7d521249..56c8a5a7c6 100644 --- a/cmake.deps/cmake/BuildTreesitterParsers.cmake +++ b/cmake.deps/cmake/BuildTreesitterParsers.cmake @@ -1,14 +1,29 @@ +# Helper function to download treesitter parsers +# +# Single value arguments: +# LANG - Parser language +# CMAKE_FILE - Cmake file to build the parser with. Defaults to +# TreesitterParserCMakeLists.txt. function(BuildTSParser) cmake_parse_arguments(TS "" - "LANG;URL;SHA256;CMAKE_FILE" + "LANG;CMAKE_FILE" "" ${ARGN}) + if(NOT TS_CMAKE_FILE) + set(TS_CMAKE_FILE TreesitterParserCMakeLists.txt) + endif() + set(NAME treesitter-${TS_LANG}) + string(TOUPPER "TREESITTER_${TS_LANG}_URL" URL_VARNAME) + set(URL ${${URL_VARNAME}}) + string(TOUPPER "TREESITTER_${TS_LANG}_SHA256" HASH_VARNAME) + set(HASH ${${HASH_VARNAME}}) + ExternalProject_Add(${NAME} - URL ${TS_URL} - URL_HASH SHA256=${TS_SHA256} + URL ${URL} + URL_HASH SHA256=${HASH} DOWNLOAD_NO_PROGRESS TRUE DOWNLOAD_DIR ${DEPS_DOWNLOAD_DIR}/${NAME} PATCH_COMMAND ${CMAKE_COMMAND} -E copy @@ -19,32 +34,6 @@ function(BuildTSParser) CMAKE_CACHE_ARGS ${DEPS_CMAKE_CACHE_ARGS}) endfunction() -BuildTSParser( - LANG c - URL ${TREESITTER_C_URL} - SHA256 ${TREESITTER_C_SHA256} - CMAKE_FILE TreesitterParserCMakeLists.txt) - -BuildTSParser( - LANG lua - URL ${TREESITTER_LUA_URL} - SHA256 ${TREESITTER_LUA_SHA256} - CMAKE_FILE TreesitterParserCMakeLists.txt) - -BuildTSParser( - LANG vim - URL ${TREESITTER_VIM_URL} - SHA256 ${TREESITTER_VIM_SHA256} - CMAKE_FILE TreesitterParserCMakeLists.txt) - -BuildTSParser( - LANG vimdoc - URL ${TREESITTER_VIMDOC_URL} - SHA256 ${TREESITTER_VIMDOC_SHA256} - CMAKE_FILE TreesitterParserCMakeLists.txt) - -BuildTSParser( - LANG query - URL ${TREESITTER_QUERY_URL} - SHA256 ${TREESITTER_QUERY_SHA256} - CMAKE_FILE TreesitterParserCMakeLists.txt) +foreach(lang c lua vim vimdoc query) + BuildTSParser(LANG ${lang}) +endforeach() diff --git a/cmake.deps/cmake/libtermkeyCMakeLists.txt b/cmake.deps/cmake/LibtermkeyCMakeLists.txt similarity index 100% rename from cmake.deps/cmake/libtermkeyCMakeLists.txt rename to cmake.deps/cmake/LibtermkeyCMakeLists.txt diff --git a/cmake.deps/cmake/TreesitterCMakeLists.txt b/cmake.deps/cmake/TreesitterCMakeLists.txt index 9017436ef5..e9728a4093 100644 --- a/cmake.deps/cmake/TreesitterCMakeLists.txt +++ b/cmake.deps/cmake/TreesitterCMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.10) -project(tree-sitter C) +project(treesitter C) add_library(tree-sitter lib/src/lib.c) target_include_directories(tree-sitter diff --git a/cmake/FindLibuv.cmake b/cmake/FindLibuv.cmake index 0f6e80d915..0cf8da3061 100644 --- a/cmake/FindLibuv.cmake +++ b/cmake/FindLibuv.cmake @@ -4,8 +4,6 @@ list(APPEND LIBUV_NAMES uv_a uv) find_library(LIBUV_LIBRARY NAMES ${LIBUV_NAMES}) -mark_as_advanced(LIBUV_INCLUDE_DIR LIBUV_LIBRARY) - set(LIBUV_LIBRARIES ${LIBUV_LIBRARY}) set(LIBUV_INCLUDE_DIRS ${LIBUV_INCLUDE_DIR}) diff --git a/src/nvim/CMakeLists.txt b/src/nvim/CMakeLists.txt index c0466e3de9..9695c64889 100755 --- a/src/nvim/CMakeLists.txt +++ b/src/nvim/CMakeLists.txt @@ -794,7 +794,7 @@ target_compile_definitions(libnvim PRIVATE MAKE_LIB) target_link_libraries(libnvim PRIVATE main_lib PUBLIC libuv) if(ENABLE_ASAN_UBSAN) - message(STATUS "Enabling Clang address sanitizer and undefined behavior sanitizer for nvim.") + message(STATUS "Enabling address sanitizer and undefined behavior sanitizer for nvim.") if(CI_BUILD) # Try to recover from all sanitize issues so we get reports about all failures target_compile_options(nvim PRIVATE -fsanitize-recover=all) @@ -808,7 +808,7 @@ if(ENABLE_ASAN_UBSAN) -fsanitize=undefined) target_link_libraries(nvim PRIVATE -fsanitize=address -fsanitize=undefined) elseif(ENABLE_MSAN) - message(STATUS "Enabling Clang memory sanitizer for nvim.") + message(STATUS "Enabling memory sanitizer for nvim.") target_compile_options(nvim PRIVATE -fsanitize=memory -fsanitize-memory-track-origins @@ -816,7 +816,7 @@ elseif(ENABLE_MSAN) -fno-optimize-sibling-calls) target_link_libraries(nvim PRIVATE -fsanitize=memory -fsanitize-memory-track-origins) elseif(ENABLE_TSAN) - message(STATUS "Enabling Clang thread sanitizer for nvim.") + message(STATUS "Enabling thread sanitizer for nvim.") target_compile_options(nvim PRIVATE -fsanitize=thread -fPIE) target_link_libraries(nvim PRIVATE -fsanitize=thread) endif()