From dd9e5a3d7a829cd057cc9ea0865cd3fc9d9d2054 Mon Sep 17 00:00:00 2001 From: oakes Date: Sun, 30 Nov 2014 21:22:46 -0500 Subject: [PATCH] Allow building as a static -fPIC library --- CMakeLists.txt | 2 ++ Makefile | 5 ++++- src/nvim/CMakeLists.txt | 8 ++++++++ src/nvim/main.c | 4 ++++ 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d2b5217658..20d653a082 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -185,6 +185,8 @@ set(CMAKE_THREAD_PREFER_PTHREAD ON) find_package(Threads REQUIRED) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) # Find Lua interpreter include(LuaHelpers) diff --git a/Makefile b/Makefile index 5f551d4ed5..c675965048 100644 --- a/Makefile +++ b/Makefile @@ -51,6 +51,9 @@ all: nvim nvim: build/.ran-cmake deps +$(BUILD_CMD) -C build +libnvim: build/.ran-cmake deps + +$(BUILD_CMD) -C build libnvim + cmake: touch CMakeLists.txt $(MAKE) build/.ran-cmake @@ -95,4 +98,4 @@ distclean: clean install: | nvim +$(BUILD_CMD) -C build install -.PHONY: test functionaltest unittest clean distclean nvim cmake deps install +.PHONY: test functionaltest unittest clean distclean nvim libnvim cmake deps install diff --git a/src/nvim/CMakeLists.txt b/src/nvim/CMakeLists.txt index 8c05c6a2b2..8c0979026a 100644 --- a/src/nvim/CMakeLists.txt +++ b/src/nvim/CMakeLists.txt @@ -208,6 +208,14 @@ if(SANITIZE) set_property(TARGET nvim APPEND_STRING PROPERTY LINK_FLAGS "-fsanitize=address -fsanitize=undefined ") endif() +add_library(libnvim STATIC EXCLUDE_FROM_ALL ${NEOVIM_GENERATED_SOURCES} + ${NEOVIM_SOURCES} ${NEOVIM_HEADERS}) +target_link_libraries(libnvim ${NVIM_LINK_LIBRARIES}) +set_target_properties(libnvim PROPERTIES + POSITION_INDEPENDENT_CODE ON + OUTPUT_NAME nvim) +set_property(TARGET libnvim APPEND_STRING PROPERTY COMPILE_FLAGS " -DMAKE_LIB ") + add_library(nvim-test MODULE EXCLUDE_FROM_ALL ${NEOVIM_GENERATED_SOURCES} ${NEOVIM_SOURCES} ${NEOVIM_HEADERS}) target_link_libraries(nvim-test ${NVIM_LINK_LIBRARIES}) diff --git a/src/nvim/main.c b/src/nvim/main.c index c806431872..8c6df6a212 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -194,7 +194,11 @@ void early_init(void) } #ifndef NO_VIM_MAIN /* skip this for unittests */ +#ifdef MAKE_LIB +int nvim_main(int argc, char **argv) +#else int main(int argc, char **argv) +#endif { char_u *fname = NULL; /* file name from command line */ mparm_T params; /* various parameters passed between