Skip to content

Commit

Permalink
Switch to cmake
Browse files Browse the repository at this point in the history
  • Loading branch information
nixprime committed Jun 3, 2015
1 parent 3f8b180 commit 48e8403
Show file tree
Hide file tree
Showing 8 changed files with 371 additions and 58 deletions.
37 changes: 37 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
cmake_minimum_required(VERSION 2.8.3)

project(cpsm)
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR})
include_directories(${PROJECT_SOURCE_DIR}/src)
list(APPEND CMAKE_CXX_FLAGS "-std=c++11")
set(CMAKE_BUILD_TYPE RelWithDebInfo)

set(Boost_USE_MULTITHREADED ON)
find_package(Boost REQUIRED COMPONENTS program_options)
include_directories(${Boost_INCLUDE_DIRS})

find_package(ICU)
if(ICU_FOUND)
include_directories(${ICU_INCLUDE_DIRS})
add_definitions(-DCPSM_CONFIG_ICU=1)
endif()

find_package(PythonLibs REQUIRED)
include_directories(${PYTHON_INCLUDE_DIRS})

add_library(cpsm_core src/matcher.cc src/path_util.cc src/str_util.cc)
target_link_libraries(cpsm_core ${Boost_LIBRARIES})
if(ICU_FOUND)
target_link_libraries(cpsm_core ${ICU_LIBRARIES})
endif()
set_target_properties(cpsm_core PROPERTIES COMPILE_FLAGS "-fPIC")

add_library(cpsm_py SHARED src/ctrlp_util.cc src/python_extension_main.cc)
target_link_libraries(cpsm_py cpsm_core ${PYTHON_LIBRARY})
set_target_properties(cpsm_py PROPERTIES PREFIX "" SUFFIX ".so")
install(TARGETS cpsm_py DESTINATION ${PROJECT_SOURCE_DIR}/autoload)
install(TARGETS cpsm_py DESTINATION ${PROJECT_SOURCE_DIR}/test)

add_executable(matcher_test src/matcher_test.cc)
target_link_libraries(matcher_test cpsm_core)
install(TARGETS matcher_test DESTINATION ${PROJECT_SOURCE_DIR}/test)
313 changes: 313 additions & 0 deletions FindICU.cmake

Large diffs are not rendered by default.

8 changes: 0 additions & 8 deletions Makefile

This file was deleted.

8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ Requirements

- Vim 7.4, compiled with the `+python` flag.

- Python headers (Ubuntu: package `python-dev`).

- A C++ compiler supporting C++11.

- Boost (Ubuntu: package `libboost-all-dev`).

- ICU (Ubuntu: package `libicu-dev`).
- CMake (Ubuntu: package `cmake`).

- Python headers (Ubuntu: package `python-dev`).

- Optional, required for Unicode support: ICU (Ubuntu: package `libicu-dev`).

Installation
------------
Expand Down
19 changes: 8 additions & 11 deletions autoload/cpsm.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,21 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import os.path
import sys
import vim

script_dir = vim.eval("s:script_dir")
python_dir = os.path.join(script_dir, "..", "python")
sys.path.append(python_dir)
import cpsm
sys.path.append(script_dir)
import cpsm_py

def ctrlp_match():
# TODO: a:regex is unimplemented.
results = cpsm.ctrlp_match(vim.eval("a:items"), vim.eval("a:str"),
limit=int(vim.eval("a:limit")),
mmode=vim.eval("a:mmode"),
ispath=int(vim.eval("a:ispath")),
crfile=vim.eval("a:crfile"),
max_threads=int(vim.eval("g:cpsm_max_threads")),
unicode=int(vim.eval("g:cpsm_unicode")))
results = cpsm_py.ctrlp_match(
vim.eval("a:items"), vim.eval("a:str"),
limit=int(vim.eval("a:limit")), mmode=vim.eval("a:mmode"),
ispath=int(vim.eval("a:ispath")), crfile=vim.eval("a:crfile"),
max_threads=int(vim.eval("g:cpsm_max_threads")),
unicode=int(vim.eval("g:cpsm_unicode")))
# Escape backslashes and ".
vim.command("let s:results = [%s]" % ",".join(
'"%s"' % r.replace("\\", "\\\\").replace('"', '\\"')
Expand Down
9 changes: 6 additions & 3 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ set -o errexit
set -o nounset
set -o pipefail

python setup.py build
mkdir -p python/
cp build/lib*/* python/
mkdir -p build
{
cd build
cmake ..
make -j $(grep -c processor /proc/cpuinfo) install
}
31 changes: 0 additions & 31 deletions setup.py

This file was deleted.

4 changes: 2 additions & 2 deletions src/python_extension_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,11 @@ static PyObject* cpsm_ctrlp_match(PyObject* self, PyObject* args,
}
}

static PyMethodDef cpsm_methods[] = {
static PyMethodDef cpsm_py_methods[] = {
{"ctrlp_match", reinterpret_cast<PyCFunction>(cpsm_ctrlp_match),
METH_VARARGS | METH_KEYWORDS,
"Match strings with a CtrlP-compatible interface"},
{nullptr, nullptr, 0, nullptr}};

PyMODINIT_FUNC initcpsm() { Py_InitModule("cpsm", cpsm_methods); }
PyMODINIT_FUNC initcpsm_py() { Py_InitModule("cpsm_py", cpsm_py_methods); }
}

0 comments on commit 48e8403

Please sign in to comment.