From 21c9db1861825cdc7f89e90bf166115a2581b663 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Fri, 1 Jun 2018 20:17:24 +0200 Subject: build/CMake: find_package(… REQUIRED) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit "Always use `find_package` with `REQUIRED`." - We make an exception for LuaJit (not REQUIRED): the `nvim-test` target is included only if we can find LuaJit. This is partially a cargo-cult (reference below), but it uncovered at least one problem: `find_package(LibIntl REQUIRED)` fails on my vanilla ubuntu 16.04 system. ref: https://schneide.blog/2017/11/06/4-tips-for-better-cmake/ > optional dependencies is nice, but skipping on REQUIRED is not the way > you want to do it. In the worst case, some of your features will just > not work if those packages are not found, with no explanation > whatsoever. Instead, use explicit feature-toggles (e.g. using option()) > that either skip the find_package call or use it with REQUIRED, so the > user will know that another lib is needed for this feature. --- src/nvim/CMakeLists.txt | 4 +++- src/nvim/po/CMakeLists.txt | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/nvim/CMakeLists.txt b/src/nvim/CMakeLists.txt index 2d803792c8..bdedce8076 100644 --- a/src/nvim/CMakeLists.txt +++ b/src/nvim/CMakeLists.txt @@ -484,7 +484,9 @@ set_property( 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}) add_library( nvim-test diff --git a/src/nvim/po/CMakeLists.txt b/src/nvim/po/CMakeLists.txt index 94cc63baea..a7b910f0eb 100644 --- a/src/nvim/po/CMakeLists.txt +++ b/src/nvim/po/CMakeLists.txt @@ -1,4 +1,4 @@ -find_package(Gettext) +find_package(Gettext REQUIRED) find_program(XGETTEXT_PRG xgettext) find_program(ICONV_PRG iconv) -- cgit From 7303dd3e54d6f2b2e4afd0acff2b6602ed2d60cf Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Tue, 5 Jun 2018 09:37:35 +0200 Subject: win/build: download iconv, gettext tools - We need the gettext tools (msgmerge.exe) because these aren't built when we build from source (not trivial). - We can use the pre-built libiconv-2.dll for DYNAMIC_ICONV_DLL. --- src/nvim/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src') diff --git a/src/nvim/CMakeLists.txt b/src/nvim/CMakeLists.txt index bdedce8076..65c3c6bbb9 100644 --- a/src/nvim/CMakeLists.txt +++ b/src/nvim/CMakeLists.txt @@ -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/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/ ) add_dependencies(nvim_runtime_deps external_blobs) -- cgit From b7032cf1e302c1826b9d24d2da13608be2ce688b Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Tue, 5 Jun 2018 14:34:51 -0400 Subject: win: enable DYNAMIC_ICONV --- src/nvim/mbyte.c | 48 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 43 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/nvim/mbyte.c b/src/nvim/mbyte.c index a52ab9f5d3..05e326104b 100644 --- a/src/nvim/mbyte.c +++ b/src/nvim/mbyte.c @@ -37,6 +37,8 @@ #ifdef HAVE_LOCALE_H # include #endif +#include "nvim/eval.h" +#include "nvim/path.h" #include "nvim/iconv.h" #include "nvim/mbyte.h" #include "nvim/charset.h" @@ -72,6 +74,9 @@ struct interval { # include "unicode_tables.generated.h" #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 // 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 @@ -2038,9 +2043,10 @@ void * my_iconv_open(char_u *to, char_u *from) return (void *)-1; /* detected a broken iconv() previously */ #ifdef DYNAMIC_ICONV - /* Check if the iconv.dll can be found. */ - if (!iconv_enabled(true)) + // Check if the iconv.dll can be found. + if (!iconv_enabled(true)) { return (void *)-1; + } #endif fd = iconv_open((char *)enc_skip(to), (char *)enc_skip(from)); @@ -2162,7 +2168,7 @@ static HINSTANCE hMsvcrtDLL = 0; # ifndef DYNAMIC_ICONV_DLL # define DYNAMIC_ICONV_DLL "iconv.dll" -# define DYNAMIC_ICONV_DLL_ALT "libiconv.dll" +# define DYNAMIC_ICONV_DLL_ALT "libiconv-2.dll" # endif # ifndef DYNAMIC_MSVCRT_DLL # define DYNAMIC_MSVCRT_DLL "msvcrt.dll" @@ -2208,6 +2214,35 @@ static void * get_iconv_import_func(HINSTANCE hInst, 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. */ @@ -2255,10 +2290,13 @@ bool iconv_enabled(bool verbose) void iconv_end(void) { - if (hIconvDLL != 0) + if (hIconvDLL != 0) { + // TODO(justinmk): use uv_dlclose instead. FreeLibrary(hIconvDLL); - if (hMsvcrtDLL != 0) + } + if (hMsvcrtDLL != 0) { FreeLibrary(hMsvcrtDLL); + } hIconvDLL = 0; hMsvcrtDLL = 0; } -- cgit From ec29eeef4331157078bd34fac4b2b43a63a39caf Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Tue, 5 Jun 2018 17:41:22 -0400 Subject: win/build: avoid "C4142: benign redefinition of type" ssize_t is already typedef's by libuv:uv-win.h --- src/nvim/os/win_defs.h | 1 - 1 file changed, 1 deletion(-) (limited to 'src') diff --git a/src/nvim/os/win_defs.h b/src/nvim/os/win_defs.h index db93f016bf..356094baa1 100644 --- a/src/nvim/os/win_defs.h +++ b/src/nvim/os/win_defs.h @@ -59,7 +59,6 @@ #define BACKSLASH_IN_FILENAME #ifdef _MSC_VER -typedef SSIZE_T ssize_t; typedef int mode_t; #endif -- cgit