Create BuildUtf8proc.cmake and FindUtf8proc.cmake

Using advanced search and replace technology
This commit is contained in:
Björn Linse 2019-06-06 14:13:10 +02:00
parent 0e0beef85e
commit b871100be7
5 changed files with 137 additions and 27 deletions

View File

@ -375,6 +375,13 @@ include_directories(SYSTEM ${MSGPACK_INCLUDE_DIRS})
find_package(LibLUV 1.30.0 REQUIRED)
include_directories(SYSTEM ${LIBLUV_INCLUDE_DIRS})
find_package(Utf8proc REQUIRED)
include_directories(SYSTEM ${UTF8PROC_INCLUDE_DIRS})
if(WIN32)
add_definitions(-DUTF8PROC_STATIC)
endif()
# Note: The test lib requires LuaJIT; it will be skipped if LuaJIT is missing.
option(PREFER_LUA "Prefer Lua over LuaJIT in the nvim executable." OFF)
@ -405,11 +412,6 @@ if(MSGPACK_HAS_FLOAT32)
add_definitions(-DNVIM_MSGPACK_HAS_FLOAT32)
endif()
set(TREESITTER_PATH "${DEPS_BUILD_DIR}/build/src/treesitter")
set(TREESITTER_C_PATH "${DEPS_BUILD_DIR}/build/src/treesitter-c")
set(TREESITTER_JAVASCRIPT_PATH "${DEPS_BUILD_DIR}/build/src/treesitter-javascript")
set(LIBUTF8PROC_INCLUDE_DIRS ${DEPS_BUILD_DIR}/build/src/utf8proc)
option(FEAT_TUI "Enable the Terminal UI" ON)
if(FEAT_TUI)

54
cmake/FindUtf8proc.cmake Normal file
View File

@ -0,0 +1,54 @@
# - Try to find utf8proc
# Once done this will define
# UTF8PROC_FOUND - System has utf8proc
# UTF8PROC_INCLUDE_DIRS - The utf8proc include directories
# UTF8PROC_LIBRARIES - The libraries needed to use utf8proc
if(NOT USE_BUNDLED_UTF8PROC)
find_package(PkgConfig)
if (PKG_CONFIG_FOUND)
pkg_check_modules(PC_UTF8PROC QUIET utf8proc)
endif()
else()
set(PC_UTF8PROC_INCLUDEDIR)
set(PC_UTF8PROC_INCLUDE_DIRS)
set(PC_UTF8PROC_LIBDIR)
set(PC_UTF8PROC_LIBRARY_DIRS)
set(LIMIT_SEARCH NO_DEFAULT_PATH)
endif()
set(UTF8PROC_DEFINITIONS ${PC_UTF8PROC_CFLAGS_OTHER})
find_path(UTF8PROC_INCLUDE_DIR utf8proc.h
PATHS ${PC_UTF8PROC_INCLUDEDIR} ${PC_UTF8PROC_INCLUDE_DIRS}
${LIMIT_SEARCH})
# If we're asked to use static linkage, add libutf8proc.a as a preferred library name.
if(UTF8PROC_USE_STATIC)
list(APPEND UTF8PROC_NAMES
"${CMAKE_STATIC_LIBRARY_PREFIX}utf8proc${CMAKE_STATIC_LIBRARY_SUFFIX}")
if(MSVC)
list(APPEND UTF8PROC_NAMES
"${CMAKE_STATIC_LIBRARY_PREFIX}utf8proc_static${CMAKE_STATIC_LIBRARY_SUFFIX}")
endif()
endif()
list(APPEND UTF8PROC_NAMES utf8proc)
if(MSVC)
list(APPEND UTF8PROC_NAMES utf8proc_static)
endif()
find_library(UTF8PROC_LIBRARY NAMES ${UTF8PROC_NAMES}
HINTS ${PC_UTF8PROC_LIBDIR} ${PC_UTF8PROC_LIBRARY_DIRS}
${LIMIT_SEARCH})
set(UTF8PROC_LIBRARIES ${UTF8PROC_LIBRARY})
set(UTF8PROC_INCLUDE_DIRS ${UTF8PROC_INCLUDE_DIR})
include(FindPackageHandleStandardArgs)
# handle the QUIETLY and REQUIRED arguments and set UTF8PROC_FOUND to TRUE
# if all listed variables are TRUE
find_package_handle_standard_args(Utf8proc DEFAULT_MSG
UTF8PROC_LIBRARY UTF8PROC_INCLUDE_DIR)
mark_as_advanced(UTF8PROC_INCLUDE_DIR UTF8PROC_LIBRARY)

View File

@ -74,8 +74,6 @@ include_directories(${GENERATED_DIR})
include_directories(${CACHED_GENERATED_DIR})
include_directories(${GENERATED_INCLUDES_DIR})
include_directories(${LIBUTF8PROC_INCLUDE_DIRS})
file(MAKE_DIRECTORY ${TOUCHES_DIR})
file(MAKE_DIRECTORY ${GENERATED_DIR})
file(MAKE_DIRECTORY ${GENERATED_INCLUDES_DIR})
@ -88,8 +86,9 @@ file(GLOB XDIFF_SOURCES xdiff/*.c)
file(GLOB XDIFF_HEADERS xdiff/*.h)
# when LIBUTF8PROC build is fixed, don't use lib.c with amalgamated utf8proc.c
#file(GLOB TS_SOURCES tree_sitter/*.c)
file(GLOB TS_SOURCES ../tree_sitter/lib.c)
file(GLOB TS_SOURCES ../tree_sitter/*.c)
file(GLOB TS_SOURCE_AMALGAM ../tree_sitter/lib.c)
list(REMOVE_ITEM TS_SOURCES ${TS_SOURCE_AMALGAM})
foreach(subdir
os
@ -402,6 +401,7 @@ list(APPEND NVIM_LINK_LIBRARIES
${LIBVTERM_LIBRARIES}
${LIBTERMKEY_LIBRARIES}
${UNIBILIUM_LIBRARIES}
${UTF8PROC_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
)

View File

@ -35,6 +35,7 @@ option(USE_BUNDLED_LIBTERMKEY "Use the bundled libtermkey." ${USE_BUNDLED})
option(USE_BUNDLED_LIBVTERM "Use the bundled libvterm." ${USE_BUNDLED})
option(USE_BUNDLED_LIBUV "Use the bundled libuv." ${USE_BUNDLED})
option(USE_BUNDLED_MSGPACK "Use the bundled msgpack." ${USE_BUNDLED})
option(USE_BUNDLED_UTF8PROC "Use the bundled utf8proc." ${USE_BUNDLED})
option(USE_BUNDLED_LUAJIT "Use the bundled version of luajit." ${USE_BUNDLED})
option(USE_BUNDLED_LUAROCKS "Use the bundled version of luarocks." ${USE_BUNDLED})
option(USE_BUNDLED_LUV "Use the bundled version of luv." ${USE_BUNDLED})
@ -249,8 +250,9 @@ if(USE_BUNDLED_LIBICONV)
include(BuildLibiconv)
endif()
# TODO: build it as a normal lib, so it can be used as a distro lib when available
include(BuildUtf8proc)
if(USE_BUNDLED_UTF8PROC)
include(BuildUtf8proc)
endif()
if(WIN32)
include(GetBinaryDeps)

View File

@ -1,16 +1,68 @@
ExternalProject_Add(utf8proc
PREFIX ${DEPS_BUILD_DIR}
URL ${UTF8PROC_URL}
DOWNLOAD_DIR ${DEPS_DOWNLOAD_DIR}/utf8proc
DOWNLOAD_COMMAND ${CMAKE_COMMAND}
-DPREFIX=${DEPS_BUILD_DIR}
-DDOWNLOAD_DIR=${DEPS_DOWNLOAD_DIR}/utf8proc
-DURL=${UTF8PROC_URL}
-DEXPECTED_SHA256=${UTF8PROC_SHA256}
-DTARGET=utf8proc
-DUSE_EXISTING_SRC_DIR=${USE_EXISTING_SRC_DIR}
-P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/DownloadAndExtractFile.cmake
CONFIGURE_COMMAND true
BUILD_COMMAND true
INSTALL_COMMAND true
)
include(CMakeParseArguments)
# BuildUtf8proc(CONFIGURE_COMMAND ... BUILD_COMMAND ... INSTALL_COMMAND ...)
# Reusable function to build utf8proc, wraps ExternalProject_Add.
# Failing to pass a command argument will result in no command being run
function(BuildUtf8proc)
cmake_parse_arguments(_utf8proc
""
""
"CONFIGURE_COMMAND;BUILD_COMMAND;INSTALL_COMMAND"
${ARGN})
if(NOT _utf8proc_CONFIGURE_COMMAND AND NOT _utf8proc_BUILD_COMMAND
AND NOT _utf8proc_INSTALL_COMMAND)
message(FATAL_ERROR "Must pass at least one of CONFIGURE_COMMAND, BUILD_COMMAND, INSTALL_COMMAND")
endif()
ExternalProject_Add(utf8proc
PREFIX ${DEPS_BUILD_DIR}
URL ${UTF8PROC_URL}
DOWNLOAD_DIR ${DEPS_DOWNLOAD_DIR}/utf8proc
DOWNLOAD_COMMAND ${CMAKE_COMMAND}
-DPREFIX=${DEPS_BUILD_DIR}
-DDOWNLOAD_DIR=${DEPS_DOWNLOAD_DIR}/utf8proc
-DURL=${UTF8PROC_URL}
-DEXPECTED_SHA256=${UTF8PROC_SHA256}
-DTARGET=utf8proc
-DUSE_EXISTING_SRC_DIR=${USE_EXISTING_SRC_DIR}
-P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/DownloadAndExtractFile.cmake
CONFIGURE_COMMAND "${_utf8proc_CONFIGURE_COMMAND}"
BUILD_COMMAND "${_utf8proc_BUILD_COMMAND}"
INSTALL_COMMAND "${_utf8proc_INSTALL_COMMAND}")
endfunction()
set(UTF8PROC_CONFIGURE_COMMAND ${CMAKE_COMMAND} ${DEPS_BUILD_DIR}/src/utf8proc
-DCMAKE_INSTALL_PREFIX=${DEPS_INSTALL_DIR}
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
"-DCMAKE_C_FLAGS:STRING=${CMAKE_C_COMPILER_ARG1} -fPIC"
-DCMAKE_GENERATOR=${CMAKE_GENERATOR})
set(UTF8PROC_BUILD_COMMAND ${CMAKE_COMMAND} --build . --config ${CMAKE_BUILD_TYPE})
set(UTF8PROC_INSTALL_COMMAND ${CMAKE_COMMAND} --build . --target install --config ${CMAKE_BUILD_TYPE})
if(MINGW AND CMAKE_CROSSCOMPILING)
get_filename_component(TOOLCHAIN ${CMAKE_TOOLCHAIN_FILE} REALPATH)
set(UTF8PROC_CONFIGURE_COMMAND ${CMAKE_COMMAND} ${DEPS_BUILD_DIR}/src/utf8proc
-DCMAKE_INSTALL_PREFIX=${DEPS_INSTALL_DIR}
# Pass toolchain
-DCMAKE_TOOLCHAIN_FILE=${TOOLCHAIN}
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
# Hack to avoid -rdynamic in Mingw
-DCMAKE_SHARED_LIBRARY_LINK_C_FLAGS="")
elseif(MSVC)
# Same as Unix without fPIC
set(UTF8PROC_CONFIGURE_COMMAND ${CMAKE_COMMAND} ${DEPS_BUILD_DIR}/src/utf8proc
-DCMAKE_INSTALL_PREFIX=${DEPS_INSTALL_DIR}
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
"-DCMAKE_C_FLAGS:STRING=${CMAKE_C_COMPILER_ARG1}"
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
# Make sure we use the same generator, otherwise we may
# accidentaly end up using different MSVC runtimes
-DCMAKE_GENERATOR=${CMAKE_GENERATOR})
endif()
BuildUtf8proc(CONFIGURE_COMMAND ${UTF8PROC_CONFIGURE_COMMAND}
BUILD_COMMAND ${UTF8PROC_BUILD_COMMAND}
INSTALL_COMMAND ${UTF8PROC_INSTALL_COMMAND})