Skip to content

Commit

Permalink
build: cmake cleanup (neovim#22251)
Browse files Browse the repository at this point in the history
- Remove unused code
- Use consistent casing. Variable names such as LibLuV_LIBRARIES is
  needlessly jarring, even if the name might be technically correct.
- Use title casing for packages. find_package(unibilium) requires the
  find_module to be named "Findunibilium.cmake", which makes it harder
  to spot when scanning the files. Instead, use "Unibilium".
  • Loading branch information
dundargoc authored Mar 2, 2023
1 parent f449121 commit 4cf4ae9
Show file tree
Hide file tree
Showing 22 changed files with 140 additions and 152 deletions.
8 changes: 3 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ include(Util)

set(TOUCHES_DIR ${PROJECT_BINARY_DIR}/touches)

set_property(GLOBAL PROPERTY USE_FOLDERS ON)

find_program(CCACHE_PRG ccache)
if(CCACHE_PRG)
set(CMAKE_C_COMPILER_LAUNCHER ${CMAKE_COMMAND} -E env CCACHE_SLOPPINESS=pch_defines,time_macros ${CCACHE_PRG})
Expand Down Expand Up @@ -72,7 +70,7 @@ endif()

list(INSERT CMAKE_PREFIX_PATH 0 ${DEPS_PREFIX})

if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
if(APPLE)
# If the macOS deployment target is not set manually (via $MACOSX_DEPLOYMENT_TARGET),
# fall back to local system version. Needs to be done both here and in cmake.deps.
if(NOT CMAKE_OSX_DEPLOYMENT_TARGET)
Expand All @@ -84,7 +82,7 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
message(STATUS "Using deployment target ${CMAKE_OSX_DEPLOYMENT_TARGET}")
endif()

if(WIN32 OR CMAKE_SYSTEM_NAME STREQUAL "Darwin")
if(WIN32 OR APPLE)
# Ignore case when comparing filenames on Windows and Mac.
set(CASE_INSENSITIVE_FILENAME TRUE)
# Enable fixing case-insensitive filenames for Windows and Mac.
Expand Down Expand Up @@ -259,7 +257,7 @@ add_glob_target(
TARGET lintsh
COMMAND ${SHELLCHECK_PRG}
FLAGS -x -a
GLOB_DIRS scripts ci
GLOB_DIRS scripts
GLOB_PAT *.sh
EXCLUDE
scripts/pvscheck.sh
Expand Down
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ ifeq (,$(BUILD_TOOL))
endif
endif


# Only need to handle Ninja here. Make will inherit the VERBOSE variable, and the -j, -l, and -n flags.
ifeq ($(CMAKE_GENERATOR),Ninja)
ifneq ($(VERBOSE),)
Expand Down
3 changes: 1 addition & 2 deletions cmake.deps/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ endif()

# If the macOS deployment target is not set manually (via $MACOSX_DEPLOYMENT_TARGET),
# fall back to local system version. Needs to be done here and in top-level CMakeLists.txt.
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
if(APPLE)
if(NOT CMAKE_OSX_DEPLOYMENT_TARGET)
execute_process(COMMAND sw_vers -productVersion
OUTPUT_VARIABLE MACOS_VERSION
Expand Down Expand Up @@ -156,7 +156,6 @@ set(LIBTERMKEY_SHA256 6945bd3c4aaa83da83d80a045c5563da4edd7d0374c62c0d35aec09eb3
set(LIBVTERM_URL https://www.leonerd.org.uk/code/libvterm/libvterm-0.3.1.tar.gz)
set(LIBVTERM_SHA256 25a8ad9c15485368dfd0a8a9dca1aec8fea5c27da3fa74ec518d5d3787f0c397)

set(LUV_VERSION 1.44.2-1)
set(LUV_URL https://github.com/luvit/luv/archive/e8e7b7e13225348a8806118a3ea9e021383a9536.tar.gz)
set(LUV_SHA256 531dfbcb6fffe3fdfa806860b39035e54b07ee1ff3bb2af813e175febf7e9ccc)

Expand Down
2 changes: 1 addition & 1 deletion cmake.deps/cmake/BuildLua.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
set(LUA_TARGET linux)
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
elseif(APPLE)
set(LUA_TARGET macosx)
elseif(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
set(LUA_TARGET freebsd)
Expand Down
4 changes: 2 additions & 2 deletions cmake.deps/cmake/BuildLuajit.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function(BuildLuajit)
endfunction()

check_c_compiler_flag(-fno-stack-check HAS_NO_STACK_CHECK)
if(CMAKE_SYSTEM_NAME MATCHES "Darwin" AND HAS_NO_STACK_CHECK)
if(APPLE AND HAS_NO_STACK_CHECK)
set(NO_STACK_CHECK "CFLAGS+=-fno-stack-check")
else()
set(NO_STACK_CHECK "")
Expand All @@ -58,7 +58,7 @@ set(BUILDCMD_UNIX ${MAKE_PRG} -j CFLAGS=-fPIC

# Setting MACOSX_DEPLOYMENT_TARGET is mandatory for LuaJIT; use version set by
# cmake.deps/CMakeLists.txt (either environment variable or current system version).
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
if(APPLE)
set(DEPLOYMENT_TARGET "MACOSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET}")
endif()

Expand Down
2 changes: 1 addition & 1 deletion cmake.deps/cmake/BuildLuarocks.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ if(UNIX)
list(APPEND LUAROCKS_OPTS
--with-lua=${DEPS_INSTALL_DIR})
else()
find_package(LuaJit)
find_package(Luajit)
if(LUAJIT_FOUND)
list(APPEND LUAROCKS_OPTS
--with-lua-include=${LUAJIT_INCLUDE_DIRS}
Expand Down
6 changes: 2 additions & 4 deletions cmake.deps/cmake/BuildLuv.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ if(USE_BUNDLED_LUAJIT)
elseif(USE_BUNDLED_LUA)
list(APPEND LUV_CMAKE_ARGS -D WITH_LUA_ENGINE=Lua)
else()
find_package(LuaJit)
find_package(Luajit)
if(LUAJIT_FOUND)
list(APPEND LUV_CMAKE_ARGS -D WITH_LUA_ENGINE=LuaJit)
else()
Expand All @@ -23,9 +23,7 @@ else()
endif()

if(USE_BUNDLED_LIBUV)
list(APPEND LUV_CMAKE_ARGS
-D CMAKE_PREFIX_PATH=${DEPS_INSTALL_DIR}
-D LIBUV_LIBRARIES=uv_a)
list(APPEND LUV_CMAKE_ARGS -D CMAKE_PREFIX_PATH=${DEPS_INSTALL_DIR})
endif()

list(APPEND LUV_CMAKE_ARGS
Expand Down
6 changes: 6 additions & 0 deletions cmake/FindIconv.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,9 @@ find_library(ICONV_LIBRARY NAMES iconv libiconv)
find_package_handle_standard_args(Iconv DEFAULT_MSG
ICONV_INCLUDE_DIR)
mark_as_advanced(ICONV_INCLUDE_DIR ICONV_LIBRARY)

add_library(iconv INTERFACE)
target_include_directories(iconv SYSTEM BEFORE INTERFACE ${ICONV_INCLUDE_DIR})
if(ICONV_LIBRARY)
target_link_libraries(iconv INTERFACE ${ICONV_LIBRARY})
endif()
5 changes: 0 additions & 5 deletions cmake/FindLibTermkey.cmake

This file was deleted.

36 changes: 18 additions & 18 deletions cmake/FindLibIntl.cmake → cmake/FindLibintl.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,40 @@ include(CheckVariableExists)

# Append custom gettext path to CMAKE_PREFIX_PATH
# if installed via Mac Homebrew
if (CMAKE_HOST_APPLE)
find_program(HOMEBREW_PROG brew)
if (EXISTS ${HOMEBREW_PROG})
execute_process(COMMAND ${HOMEBREW_PROG} --prefix gettext
if (APPLE)
find_program(HOMEBREW_PRG brew)
if (EXISTS ${HOMEBREW_PRG})
execute_process(COMMAND ${HOMEBREW_PRG} --prefix gettext
OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE HOMEBREW_GETTEXT_PREFIX)
list(APPEND CMAKE_PREFIX_PATH "${HOMEBREW_GETTEXT_PREFIX}")
endif()
endif()

find_path(LibIntl_INCLUDE_DIR
find_path(LIBINTL_INCLUDE_DIR
NAMES libintl.h
PATH_SUFFIXES gettext
)

find_library(LibIntl_LIBRARY
find_library(LIBINTL_LIBRARY
NAMES intl libintl
)

if (LibIntl_INCLUDE_DIR)
list(APPEND CMAKE_REQUIRED_INCLUDES "${LibIntl_INCLUDE_DIR}")
if (LIBINTL_INCLUDE_DIR)
list(APPEND CMAKE_REQUIRED_INCLUDES "${LIBINTL_INCLUDE_DIR}")
endif()
# On some systems (linux+glibc) libintl is passively available.
# So only specify the library if one was found.
if (LibIntl_LIBRARY)
list(APPEND CMAKE_REQUIRED_LIBRARIES "${LibIntl_LIBRARY}")
if (LIBINTL_LIBRARY)
list(APPEND CMAKE_REQUIRED_LIBRARIES "${LIBINTL_LIBRARY}")
endif()
if (MSVC)
list(APPEND CMAKE_REQUIRED_LIBRARIES ${ICONV_LIBRARY})
endif()

# On macOS, if libintl is a static library then we also need
# to link libiconv and CoreFoundation.
get_filename_component(LibIntl_EXT "${LibIntl_LIBRARY}" EXT)
get_filename_component(LibIntl_EXT "${LIBINTL_LIBRARY}" EXT)
if (APPLE AND (LibIntl_EXT STREQUAL ".a"))
set(LibIntl_STATIC TRUE)
find_library(CoreFoundation_FRAMEWORK CoreFoundation)
Expand All @@ -59,14 +59,14 @@ endif()
if (LibIntl_STATIC)
list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES "${ICONV_LIBRARY}" "${CoreFoundation_FRAMEWORK}")
endif()
if (LibIntl_INCLUDE_DIR)
list(REMOVE_ITEM CMAKE_REQUIRED_INCLUDES "${LibIntl_INCLUDE_DIR}")
if (LIBINTL_INCLUDE_DIR)
list(REMOVE_ITEM CMAKE_REQUIRED_INCLUDES "${LIBINTL_INCLUDE_DIR}")
endif()
if (LibIntl_LIBRARY)
list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES "${LibIntl_LIBRARY}")
if (LIBINTL_LIBRARY)
list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES "${LIBINTL_LIBRARY}")
endif()

set(REQUIRED_VARIABLES LibIntl_LIBRARY LIBTERMKEY_INCLUDE_DIR)
set(REQUIRED_VARIABLES LIBINTL_LIBRARY LIBINTL_INCLUDE_DIR)
if (HAVE_WORKING_LIBINTL)
# On some systems (linux+glibc) libintl is passively available.
# If HAVE_WORKING_LIBINTL then we consider the requirement satisfied.
Expand All @@ -75,6 +75,6 @@ if (HAVE_WORKING_LIBINTL)
check_variable_exists(_nl_msg_cat_cntr HAVE_NL_MSG_CAT_CNTR)
endif()

find_package_handle_standard_args(LibIntl DEFAULT_MSG
find_package_handle_standard_args(Libintl DEFAULT_MSG
${REQUIRED_VARIABLES})
mark_as_advanced(LIBTERMKEY_INCLUDE_DIR LIBTERMKEY_LIBRARY)
mark_as_advanced(LIBINTL_LIBRARY LIBINTL_INCLUDE_DIR)
2 changes: 1 addition & 1 deletion cmake/FindLibLUV.cmake → cmake/FindLibluv.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ find_library(LIBLUV_LIBRARY NAMES ${LIBLUV_NAMES})
set(LIBLUV_LIBRARIES ${LIBLUV_LIBRARY})
set(LIBLUV_INCLUDE_DIRS ${LIBLUV_INCLUDE_DIR})

find_package_handle_standard_args(LibLUV DEFAULT_MSG
find_package_handle_standard_args(Libluv DEFAULT_MSG
LIBLUV_LIBRARY LIBLUV_INCLUDE_DIR)

mark_as_advanced(LIBLUV_INCLUDE_DIR LIBLUV_LIBRARY)
9 changes: 9 additions & 0 deletions cmake/FindLibtermkey.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
find_path(LIBTERMKEY_INCLUDE_DIR termkey.h)
find_library(LIBTERMKEY_LIBRARY NAMES termkey)
find_package_handle_standard_args(Libtermkey DEFAULT_MSG
LIBTERMKEY_LIBRARY LIBTERMKEY_INCLUDE_DIR)
mark_as_advanced(LIBTERMKEY_INCLUDE_DIR LIBTERMKEY_LIBRARY)

add_library(libtermkey INTERFACE)
target_include_directories(libtermkey SYSTEM BEFORE INTERFACE ${LIBTERMKEY_INCLUDE_DIR})
target_link_libraries(libtermkey INTERFACE ${LIBTERMKEY_LIBRARY})
2 changes: 1 addition & 1 deletion cmake/FindLibUV.cmake → cmake/FindLibuv.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ if(Threads_FOUND)
list(APPEND LIBUV_LIBRARIES ${CMAKE_THREAD_LIBS_INIT})
endif()

find_package_handle_standard_args(LibUV DEFAULT_MSG
find_package_handle_standard_args(Libuv DEFAULT_MSG
LIBUV_LIBRARY LIBUV_INCLUDE_DIR)

mark_as_advanced(LIBUV_INCLUDE_DIR LIBUV_LIBRARY)
2 changes: 1 addition & 1 deletion cmake/Findlibvterm.cmake → cmake/FindLibvterm.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ if(LIBVTERM_INCLUDE_DIR AND EXISTS "${LIBVTERM_INCLUDE_DIR}/vterm.h")
set(VTERM_VERSION ${VTERM_VERSION_MAJOR}.${VTERM_VERSION_MINOR})
endif()

find_package_handle_standard_args(libvterm
find_package_handle_standard_args(Libvterm
REQUIRED_VARS LIBVTERM_INCLUDE_DIR LIBVTERM_LIBRARY
VERSION_VAR VTERM_VERSION)

Expand Down
2 changes: 1 addition & 1 deletion cmake/FindLuaJit.cmake → cmake/FindLuajit.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ find_library(LUAJIT_LIBRARY NAMES ${LUAJIT_NAMES})
set(LUAJIT_LIBRARIES ${LUAJIT_LIBRARY})
set(LUAJIT_INCLUDE_DIRS ${LUAJIT_INCLUDE_DIR})

find_package_handle_standard_args(LuaJit DEFAULT_MSG
find_package_handle_standard_args(Luajit DEFAULT_MSG
LUAJIT_LIBRARY LUAJIT_INCLUDE_DIR)

mark_as_advanced(LUAJIT_INCLUDE_DIR LUAJIT_LIBRARY)
22 changes: 19 additions & 3 deletions cmake/FindMsgpack.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,25 @@ find_library(MSGPACK_LIBRARY NAMES ${MSGPACK_NAMES}

mark_as_advanced(MSGPACK_INCLUDE_DIR MSGPACK_LIBRARY)

set(MSGPACK_LIBRARIES ${MSGPACK_LIBRARY})
set(MSGPACK_INCLUDE_DIRS ${MSGPACK_INCLUDE_DIR})

find_package_handle_standard_args(Msgpack
REQUIRED_VARS MSGPACK_LIBRARY MSGPACK_INCLUDE_DIR
VERSION_VAR MSGPACK_VERSION_STRING)

add_library(msgpack INTERFACE)
target_include_directories(msgpack SYSTEM BEFORE INTERFACE ${MSGPACK_INCLUDE_DIR})
target_link_libraries(msgpack INTERFACE ${MSGPACK_LIBRARY})

list(APPEND CMAKE_REQUIRED_INCLUDES "${MSGPACK_INCLUDE_DIR}")
check_c_source_compiles("
#include <msgpack.h>
int
main(void)
{
return MSGPACK_OBJECT_FLOAT32;
}
" MSGPACK_HAS_FLOAT32)
list(REMOVE_ITEM CMAKE_REQUIRED_INCLUDES "${MSGPACK_INCLUDE_DIR}")
if(MSGPACK_HAS_FLOAT32)
target_compile_definitions(msgpack INTERFACE NVIM_MSGPACK_HAS_FLOAT32)
endif()
5 changes: 0 additions & 5 deletions cmake/FindTreeSitter.cmake

This file was deleted.

40 changes: 40 additions & 0 deletions cmake/FindTreesitter.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
find_path(TREESITTER_INCLUDE_DIR tree_sitter/api.h)
find_library(TREESITTER_LIBRARY NAMES tree-sitter)
find_package_handle_standard_args(Treesitter DEFAULT_MSG
TREESITTER_LIBRARY TREESITTER_INCLUDE_DIR)
mark_as_advanced(TREESITTER_LIBRARY TREESITTER_INCLUDE_DIR)

add_library(treesitter INTERFACE)
target_include_directories(treesitter SYSTEM BEFORE INTERFACE ${TREESITTER_INCLUDE_DIR})
target_link_libraries(treesitter INTERFACE ${TREESITTER_LIBRARY})

list(APPEND CMAKE_REQUIRED_INCLUDES "${TREESITTER_INCLUDE_DIR}")
list(APPEND CMAKE_REQUIRED_LIBRARIES "${TREESITTER_LIBRARY}")
check_c_source_compiles("
#include <tree_sitter/api.h>
int
main(void)
{
TSQueryCursor *cursor = ts_query_cursor_new();
ts_query_cursor_set_match_limit(cursor, 32);
return 0;
}
" TS_HAS_SET_MATCH_LIMIT)
if(TS_HAS_SET_MATCH_LIMIT)
target_compile_definitions(treesitter INTERFACE NVIM_TS_HAS_SET_MATCH_LIMIT)
endif()
check_c_source_compiles("
#include <stdlib.h>
#include <tree_sitter/api.h>
int
main(void)
{
ts_set_allocator(malloc, calloc, realloc, free);
return 0;
}
" TS_HAS_SET_ALLOCATOR)
if(TS_HAS_SET_ALLOCATOR)
target_compile_definitions(treesitter INTERFACE NVIM_TS_HAS_SET_ALLOCATOR)
endif()
list(REMOVE_ITEM CMAKE_REQUIRED_INCLUDES "${TREESITTER_INCLUDE_DIR}")
list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES "${TREESITTER_LIBRARY}")
2 changes: 1 addition & 1 deletion cmake/Findunibilium.cmake → cmake/FindUnibilium.cmake
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
find_path(UNIBILIUM_INCLUDE_DIR unibilium.h)
find_library(UNIBILIUM_LIBRARY unibilium)

find_package_handle_standard_args(unibilium
find_package_handle_standard_args(Unibilium
REQUIRED_VARS UNIBILIUM_INCLUDE_DIR UNIBILIUM_LIBRARY)

add_library(unibilium INTERFACE)
Expand Down
Loading

0 comments on commit 4cf4ae9

Please sign in to comment.