Skip to content

Commit

Permalink
Add python/CMakeLists
Browse files Browse the repository at this point in the history
  • Loading branch information
xantares committed May 13, 2020
1 parent c3e4b77 commit 573d679
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,8 @@ include_directories(
add_subdirectory(util)
add_subdirectory(lm)

option (ENABLE_PYTHON "python bindings" OFF)
if(ENABLE_PYTHON)
add_subdirectory(python)
endif()

1 change: 1 addition & 0 deletions lm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ if (NOT MSVC)
endif()

add_library(kenlm ${KENLM_LM_SOURCE} ${KENLM_LM_COMMON_SOURCE})
set_target_properties(kenlm PROPERTIES POSITION_INDEPENDENT_CODE ON)
target_link_libraries(kenlm kenlm_util ${Boost_LIBRARIES} ${THREADS})

set(KENLM_MAX_ORDER 6 CACHE STRING "Maximum supported ngram order")
Expand Down
28 changes: 28 additions & 0 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
find_package(PythonInterp REQUIRED)
find_package(PythonLibs ${PYTHON_VERSION_STRING} EXACT REQUIRED)
include_directories(${PYTHON_INCLUDE_DIRS})

add_library(kenlm_python MODULE kenlm.cpp score_sentence.cc)
set_target_properties(kenlm_python PROPERTIES OUTPUT_NAME kenlm)
set_target_properties(kenlm_python PROPERTIES PREFIX "")

if(APPLE)
set_target_properties(kenlm_python PROPERTIES SUFFIX ".so")
elseif(WIN32)
set_target_properties(kenlm_python PROPERTIES SUFFIX ".pyd")
endif()

target_link_libraries(kenlm_python kenlm)
if(WIN32)
target_link_libraries(kenlm_python ${PYTHON_LIBRARIES})
elseif(APPLE)
set_target_properties(kenlm_python PROPERTIES LINK_FLAGS "-undefined dynamic_lookup")
endif()

if (WIN32)
set (PYTHON_SITE_PACKAGES Lib/site-packages)
else ()
set (PYTHON_SITE_PACKAGES lib/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/site-packages)
endif ()

install(TARGETS kenlm_python DESTINATION ${PYTHON_SITE_PACKAGES})
1 change: 1 addition & 0 deletions util/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ endif()

# Group these objects together for later use.
add_library(kenlm_util ${KENLM_UTIL_DOUBLECONVERSION_SOURCE} ${KENLM_UTIL_STREAM_SOURCE} ${KENLM_UTIL_SOURCE})
set_target_properties(kenlm_util PROPERTIES POSITION_INDEPENDENT_CODE ON)
target_link_libraries(kenlm_util ${Boost_LIBRARIES} ${READ_COMPRESSED_LIBS} ${THREADS} ${TIMER_LINK})

AddExes(EXES probing_hash_table_benchmark
Expand Down

0 comments on commit 573d679

Please sign in to comment.