Merge #8464 from justinmk/cmake-findpkg-required

This commit is contained in:
Justin M. Keyes 2018-06-06 01:52:29 +02:00 committed by GitHub
commit 36ac80d5dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 110 additions and 25 deletions

2
.gitignore vendored
View File

@ -1,5 +1,7 @@
# Tools # Tools
.ropeproject/ .ropeproject/
# Visual Studio
/.vs/
# Build/deps dir # Build/deps dir
/build/ /build/

View File

@ -53,6 +53,7 @@ jobs:
compiler: clang compiler: clang
env: > env: >
CLANG_SANITIZER=ASAN_UBSAN CLANG_SANITIZER=ASAN_UBSAN
# Use Lua so that ASAN can test our embedded Lua support. 8fec4d53d0f6
CMAKE_FLAGS="$CMAKE_FLAGS -DPREFER_LUA=ON" CMAKE_FLAGS="$CMAKE_FLAGS -DPREFER_LUA=ON"
sudo: true sudo: true
- os: linux - os: linux

View File

@ -13,9 +13,9 @@ include(PreventInTreeBuilds)
# Prefer our bundled versions of dependencies. # Prefer our bundled versions of dependencies.
if(DEFINED ENV{DEPS_BUILD_DIR}) if(DEFINED ENV{DEPS_BUILD_DIR})
set(DEPS_PREFIX "$ENV{DEPS_BUILD_DIR}/usr" CACHE PATH "Path prefix for finding dependencies") set(DEPS_PREFIX "$ENV{DEPS_BUILD_DIR}/usr" CACHE PATH "Path prefix for finding dependencies")
else() else()
set(DEPS_PREFIX "${CMAKE_CURRENT_SOURCE_DIR}/.deps/usr" CACHE PATH "Path prefix for finding dependencies") set(DEPS_PREFIX "${CMAKE_CURRENT_SOURCE_DIR}/.deps/usr" CACHE PATH "Path prefix for finding dependencies")
endif() endif()
if(CMAKE_CROSSCOMPILING AND NOT UNIX) if(CMAKE_CROSSCOMPILING AND NOT UNIX)
list(INSERT CMAKE_FIND_ROOT_PATH 0 ${DEPS_PREFIX}) list(INSERT CMAKE_FIND_ROOT_PATH 0 ${DEPS_PREFIX})
@ -53,6 +53,14 @@ if(WIN32 OR CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set(USE_FNAME_CASE TRUE) set(USE_FNAME_CASE TRUE)
endif() endif()
option(ENABLE_LIBINTL "enable libintl" ON)
if(MSVC)
add_definitions(-DDYNAMIC_ICONV)
option(ENABLE_LIBICONV "enable libiconv" OFF)
else()
option(ENABLE_LIBICONV "enable libiconv" ON)
endif()
# Set default build type. # Set default build type.
if(NOT CMAKE_BUILD_TYPE) if(NOT CMAKE_BUILD_TYPE)
message(STATUS "CMAKE_BUILD_TYPE not given, defaulting to 'Debug'.") message(STATUS "CMAKE_BUILD_TYPE not given, defaulting to 'Debug'.")
@ -331,6 +339,7 @@ if(PREFER_LUA)
find_package(Lua REQUIRED) find_package(Lua REQUIRED)
set(LUA_PREFERRED_INCLUDE_DIRS ${LUA_INCLUDE_DIR}) set(LUA_PREFERRED_INCLUDE_DIRS ${LUA_INCLUDE_DIR})
set(LUA_PREFERRED_LIBRARIES ${LUA_LIBRARIES}) set(LUA_PREFERRED_LIBRARIES ${LUA_LIBRARIES})
# Passive (not REQUIRED): if LUAJIT_FOUND is not set, nvim-test is skipped.
find_package(LuaJit) find_package(LuaJit)
else() else()
find_package(LuaJit REQUIRED) find_package(LuaJit REQUIRED)
@ -399,31 +408,30 @@ if((CLANG_ASAN_UBSAN OR CLANG_MSAN OR CLANG_TSAN) AND NOT CMAKE_C_COMPILER_ID MA
message(FATAL_ERROR "Sanitizers are only supported for Clang.") message(FATAL_ERROR "Sanitizers are only supported for Clang.")
endif() endif()
if(CMAKE_SYSTEM_NAME MATCHES "OpenBSD|FreeBSD") if(CMAKE_SYSTEM_NAME MATCHES "OpenBSD|FreeBSD|Windows") # see #5318
message(STATUS "detected OpenBSD/FreeBSD; disabled jemalloc. #5318") message(STATUS "skipping jemalloc on this system: ${CMAKE_SYSTEM_NAME}")
option(ENABLE_JEMALLOC "enable jemalloc" OFF) option(ENABLE_JEMALLOC "enable jemalloc" OFF)
else() else()
option(ENABLE_JEMALLOC "enable jemalloc" ON) option(ENABLE_JEMALLOC "enable jemalloc" ON)
endif() endif()
if (ENABLE_JEMALLOC) if(ENABLE_JEMALLOC)
if(CLANG_ASAN_UBSAN OR CLANG_MSAN OR CLANG_TSAN) if(CLANG_ASAN_UBSAN OR CLANG_MSAN OR CLANG_TSAN)
message(STATUS "Sanitizers have been enabled; don't use jemalloc.") message(STATUS "Sanitizers have been enabled; don't use jemalloc.")
else() else()
find_package(JeMalloc) find_package(JeMalloc REQUIRED)
if(JEMALLOC_FOUND) include_directories(SYSTEM ${JEMALLOC_INCLUDE_DIRS})
include_directories(SYSTEM ${JEMALLOC_INCLUDE_DIRS})
endif()
endif() endif()
endif() endif()
find_package(LibIntl) if(ENABLE_LIBINTL)
if(LibIntl_FOUND) # LibIntl (not Intl) selects our FindLibIntl.cmake script. #8464
find_package(LibIntl REQUIRED)
include_directories(SYSTEM ${LibIntl_INCLUDE_DIRS}) include_directories(SYSTEM ${LibIntl_INCLUDE_DIRS})
endif() endif()
find_package(Iconv) if(ENABLE_LIBICONV)
if(Iconv_FOUND) find_package(Iconv REQUIRED)
include_directories(SYSTEM ${Iconv_INCLUDE_DIRS}) include_directories(SYSTEM ${Iconv_INCLUDE_DIRS})
endif() endif()

View File

@ -34,9 +34,8 @@ if (LibIntl_INCLUDE_DIR)
set(CMAKE_REQUIRED_INCLUDES "${LibIntl_INCLUDE_DIR}") set(CMAKE_REQUIRED_INCLUDES "${LibIntl_INCLUDE_DIR}")
endif() endif()
# This is required because some operating systems don't have a separate # On some systems (linux+glibc) libintl is passively available.
# libintl--it is built into glibc. So we only need to specify the library # So only specify the library if one was found.
# if one was actually found.
if (LibIntl_LIBRARY) if (LibIntl_LIBRARY)
set(CMAKE_REQUIRED_LIBRARIES "${LibIntl_LIBRARY}") set(CMAKE_REQUIRED_LIBRARIES "${LibIntl_LIBRARY}")
endif() endif()
@ -53,6 +52,13 @@ int main(int argc, char** argv) {
}" HAVE_WORKING_LIBINTL) }" HAVE_WORKING_LIBINTL)
if (HAVE_WORKING_LIBINTL) if (HAVE_WORKING_LIBINTL)
# On some systems (linux+glibc) libintl is passively available.
# If HAVE_WORKING_LIBINTL then we consider the requirement satisfied.
# Unset REQUIRED so that libfind_process(LibIntl) can proceed.
if(LibIntl_FIND_REQUIRED)
unset(LibIntl_FIND_REQUIRED)
endif()
check_variable_exists(_nl_msg_cat_cntr HAVE_NL_MSG_CAT_CNTR) check_variable_exists(_nl_msg_cat_cntr HAVE_NL_MSG_CAT_CNTR)
endif() endif()

18
makedeps.bat Normal file
View File

@ -0,0 +1,18 @@
echo off
if not defined VS150COMNTOOLS (
echo error: missing VS150COMNTOOLS environment variable.
echo Run this script from the 'Developer Command Prompt'.
exit /b 1
)
echo on
set CMAKE=%VS150COMNTOOLS%\..\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe
mkdir .deps
cd .deps
"%CMAKE%" -G "Visual Studio 15 2017" "-DCMAKE_BUILD_TYPE=RelWithDebInfo" ..\third-party\
"%CMAKE%" --build . --config RelWithDebInfo -- "/verbosity:normal"
cd ..

View File

@ -457,6 +457,8 @@ if(WIN32)
COMMAND ${CMAKE_COMMAND} -E copy "${DEPS_PREFIX}/bin/Qt5Widgets.dll" ${PROJECT_BINARY_DIR}/windows_runtime_deps/ COMMAND ${CMAKE_COMMAND} -E copy "${DEPS_PREFIX}/bin/Qt5Widgets.dll" ${PROJECT_BINARY_DIR}/windows_runtime_deps/
COMMAND ${CMAKE_COMMAND} -E copy "${DEPS_PREFIX}/bin/winpty.dll" ${PROJECT_BINARY_DIR}/windows_runtime_deps/ COMMAND ${CMAKE_COMMAND} -E copy "${DEPS_PREFIX}/bin/winpty.dll" ${PROJECT_BINARY_DIR}/windows_runtime_deps/
COMMAND ${CMAKE_COMMAND} -E copy "${DEPS_PREFIX}/bin/libiconv-2.dll" ${PROJECT_BINARY_DIR}/windows_runtime_deps/
COMMAND ${CMAKE_COMMAND} -E copy "${DEPS_PREFIX}/bin/platforms/qwindows.dll" ${PROJECT_BINARY_DIR}/windows_runtime_deps/platforms/ COMMAND ${CMAKE_COMMAND} -E copy "${DEPS_PREFIX}/bin/platforms/qwindows.dll" ${PROJECT_BINARY_DIR}/windows_runtime_deps/platforms/
) )
add_dependencies(nvim_runtime_deps external_blobs) add_dependencies(nvim_runtime_deps external_blobs)
@ -484,7 +486,9 @@ set_property(
APPEND_STRING PROPERTY COMPILE_FLAGS " -DMAKE_LIB " APPEND_STRING PROPERTY COMPILE_FLAGS " -DMAKE_LIB "
) )
if(LUAJIT_FOUND) if(NOT LUAJIT_FOUND)
message(STATUS "luajit not found, skipping nvim-test (unit tests) target")
else()
set(NVIM_TEST_LINK_LIBRARIES ${NVIM_LINK_LIBRARIES} ${LUAJIT_LIBRARIES}) set(NVIM_TEST_LINK_LIBRARIES ${NVIM_LINK_LIBRARIES} ${LUAJIT_LIBRARIES})
add_library( add_library(
nvim-test nvim-test

View File

@ -37,6 +37,8 @@
#ifdef HAVE_LOCALE_H #ifdef HAVE_LOCALE_H
# include <locale.h> # include <locale.h>
#endif #endif
#include "nvim/eval.h"
#include "nvim/path.h"
#include "nvim/iconv.h" #include "nvim/iconv.h"
#include "nvim/mbyte.h" #include "nvim/mbyte.h"
#include "nvim/charset.h" #include "nvim/charset.h"
@ -72,6 +74,9 @@ struct interval {
# include "unicode_tables.generated.h" # include "unicode_tables.generated.h"
#endif #endif
char_u e_loadlib[] = "E370: Could not load library %s";
char_u e_loadfunc[] = "E448: Could not load library function %s";
// To speed up BYTELEN(); keep a lookup table to quickly get the length in // To speed up BYTELEN(); keep a lookup table to quickly get the length in
// bytes of a UTF-8 character from the first byte of a UTF-8 string. Bytes // bytes of a UTF-8 character from the first byte of a UTF-8 string. Bytes
// which are illegal when used as the first byte have a 1. The NUL byte has // which are illegal when used as the first byte have a 1. The NUL byte has
@ -2038,9 +2043,10 @@ void * my_iconv_open(char_u *to, char_u *from)
return (void *)-1; /* detected a broken iconv() previously */ return (void *)-1; /* detected a broken iconv() previously */
#ifdef DYNAMIC_ICONV #ifdef DYNAMIC_ICONV
/* Check if the iconv.dll can be found. */ // Check if the iconv.dll can be found.
if (!iconv_enabled(true)) if (!iconv_enabled(true)) {
return (void *)-1; return (void *)-1;
}
#endif #endif
fd = iconv_open((char *)enc_skip(to), (char *)enc_skip(from)); fd = iconv_open((char *)enc_skip(to), (char *)enc_skip(from));
@ -2162,7 +2168,7 @@ static HINSTANCE hMsvcrtDLL = 0;
# ifndef DYNAMIC_ICONV_DLL # ifndef DYNAMIC_ICONV_DLL
# define DYNAMIC_ICONV_DLL "iconv.dll" # define DYNAMIC_ICONV_DLL "iconv.dll"
# define DYNAMIC_ICONV_DLL_ALT "libiconv.dll" # define DYNAMIC_ICONV_DLL_ALT "libiconv-2.dll"
# endif # endif
# ifndef DYNAMIC_MSVCRT_DLL # ifndef DYNAMIC_MSVCRT_DLL
# define DYNAMIC_MSVCRT_DLL "msvcrt.dll" # define DYNAMIC_MSVCRT_DLL "msvcrt.dll"
@ -2208,6 +2214,35 @@ static void * get_iconv_import_func(HINSTANCE hInst,
return NULL; return NULL;
} }
// Load library "name".
HINSTANCE vimLoadLib(char *name)
{
HINSTANCE dll = NULL;
// NOTE: Do not use mch_dirname() and mch_chdir() here, they may call
// vimLoadLib() recursively, which causes a stack overflow.
WCHAR old_dirw[MAXPATHL];
// Path to exe dir.
char *buf = xstrdup((char *)get_vim_var_str(VV_PROGPATH));
// ptrdiff_t len = ;
// assert(len > 0);
buf[path_tail_with_sep(buf) - buf] = '\0';
if (GetCurrentDirectoryW(MAXPATHL, old_dirw) != 0) {
// Change directory to where the executable is, both to make
// sure we find a .dll there and to avoid looking for a .dll
// in the current directory.
SetCurrentDirectory((LPCSTR)buf);
// TODO(justinmk): use uv_dlopen instead. see os_libcall
dll = LoadLibrary(name);
SetCurrentDirectoryW(old_dirw);
}
return dll;
}
/* /*
* Try opening the iconv.dll and return TRUE if iconv() can be used. * Try opening the iconv.dll and return TRUE if iconv() can be used.
*/ */
@ -2255,10 +2290,13 @@ bool iconv_enabled(bool verbose)
void iconv_end(void) void iconv_end(void)
{ {
if (hIconvDLL != 0) if (hIconvDLL != 0) {
// TODO(justinmk): use uv_dlclose instead.
FreeLibrary(hIconvDLL); FreeLibrary(hIconvDLL);
if (hMsvcrtDLL != 0) }
if (hMsvcrtDLL != 0) {
FreeLibrary(hMsvcrtDLL); FreeLibrary(hMsvcrtDLL);
}
hIconvDLL = 0; hIconvDLL = 0;
hMsvcrtDLL = 0; hMsvcrtDLL = 0;
} }

View File

@ -59,7 +59,6 @@
#define BACKSLASH_IN_FILENAME #define BACKSLASH_IN_FILENAME
#ifdef _MSC_VER #ifdef _MSC_VER
typedef SSIZE_T ssize_t;
typedef int mode_t; typedef int mode_t;
#endif #endif

View File

@ -1,4 +1,4 @@
find_package(Gettext) find_package(Gettext REQUIRED)
find_program(XGETTEXT_PRG xgettext) find_program(XGETTEXT_PRG xgettext)
find_program(ICONV_PRG iconv) find_program(ICONV_PRG iconv)

View File

@ -157,16 +157,22 @@ set(WINGUI_SHA256 260efc686423e2529360b6a45c8e241fbbf276c8de6b04d44f45ab5b6fe8df
set(WIN32YANK_X86_URL https://github.com/equalsraf/win32yank/releases/download/v0.0.4/win32yank-x86.zip) set(WIN32YANK_X86_URL https://github.com/equalsraf/win32yank/releases/download/v0.0.4/win32yank-x86.zip)
set(WIN32YANK_X86_SHA256 62f34e5a46c5d4a7b3f3b512e1ff7b77fedd432f42581cbe825233a996eed62c) set(WIN32YANK_X86_SHA256 62f34e5a46c5d4a7b3f3b512e1ff7b77fedd432f42581cbe825233a996eed62c)
set(WIN32YANK_X86_64_URL https://github.com/equalsraf/win32yank/releases/download/v0.0.4/win32yank-x64.zip) set(WIN32YANK_X86_64_URL https://github.com/equalsraf/win32yank/releases/download/v0.0.4/win32yank-x64.zip)
set(WIN32YANK_X86_64_SHA256 33a747a92da60fb65e668edbf7661d3d902411a2d545fe9dc08623cecd142a20) set(WIN32YANK_X86_64_SHA256 33a747a92da60fb65e668edbf7661d3d902411a2d545fe9dc08623cecd142a20)
set(WINPTY_URL https://github.com/rprichard/winpty/releases/download/0.4.3/winpty-0.4.3-msvc2015.zip) set(WINPTY_URL https://github.com/rprichard/winpty/releases/download/0.4.3/winpty-0.4.3-msvc2015.zip)
set(WINPTY_SHA256 35a48ece2ff4acdcbc8299d4920de53eb86b1fb41e64d2fe5ae7898931bcee89) set(WINPTY_SHA256 35a48ece2ff4acdcbc8299d4920de53eb86b1fb41e64d2fe5ae7898931bcee89)
# gettext source (for building/linking, does NOT provide tools like msgmerge.exe)
set(GETTEXT_URL https://ftp.gnu.org/pub/gnu/gettext/gettext-0.19.8.1.tar.gz) set(GETTEXT_URL https://ftp.gnu.org/pub/gnu/gettext/gettext-0.19.8.1.tar.gz)
set(GETTEXT_SHA256 ff942af0e438ced4a8b0ea4b0b6e0d6d657157c5e2364de57baa279c1c125c43) set(GETTEXT_SHA256 ff942af0e438ced4a8b0ea4b0b6e0d6d657157c5e2364de57baa279c1c125c43)
# gettext binary (for tools like msgmerge.exe)
set(GETTEXT_X86_URL https://github.com/mlocati/gettext-iconv-windows/releases/download/v0.19.8.1-v1.15/gettext0.19.8.1-iconv1.15-shared-32.zip)
set(GETTEXT_X86_SHA256 b7d8fe2d038950bc0447d664db614ebfc3100a1ba962a959d78e41bc708a2140)
set(GETTEXT_X86_64_URL https://github.com/mlocati/gettext-iconv-windows/releases/download/v0.19.8.1-v1.15/gettext0.19.8.1-iconv1.15-shared-64.zip)
set(GETTEXT_X86_64_SHA256 c8ed2897438efc0a511892c2b38b623ef0c9092aced2acbd3f3daf2f12ba70b4)
if(USE_BUNDLED_UNIBILIUM) if(USE_BUNDLED_UNIBILIUM)
include(BuildUnibilium) include(BuildUnibilium)
endif() endif()
@ -229,6 +235,9 @@ if(WIN32)
GetBinaryDep(TARGET "win32yank_${TARGET_ARCH}" GetBinaryDep(TARGET "win32yank_${TARGET_ARCH}"
INSTALL_COMMAND ${CMAKE_COMMAND} -E copy win32yank.exe ${DEPS_INSTALL_DIR}/bin) INSTALL_COMMAND ${CMAKE_COMMAND} -E copy win32yank.exe ${DEPS_INSTALL_DIR}/bin)
GetBinaryDep(TARGET "gettext_${TARGET_ARCH}"
INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_directory bin ${DEPS_INSTALL_DIR}/bin)
if("${TARGET_ARCH}" STREQUAL "X86_64") if("${TARGET_ARCH}" STREQUAL "X86_64")
set(TARGET_ARCH x64) set(TARGET_ARCH x64)
elseif(TARGET_ARCH STREQUAL "X86") elseif(TARGET_ARCH STREQUAL "X86")