kpu / kenlm

KenLM: Faster and Smaller Language Model Queries
http://kheafield.com/code/kenlm/
Other
2.5k stars 513 forks source link

Best way to add kenlm to your own C++ project using Cmake? #212

Open digital10111 opened 5 years ago

kpu commented 5 years ago

https://cmake.org/cmake/help/latest/module/ExternalProject.html

iamilyasedunov commented 3 years ago

add_subdirectory can be used for build with MSVC 17 x64 compiler, C++11.

# CMakeLists.txt file
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
project(test)

# set(Boost_DEBUG 1)         # for build debug
set(Boost_LIB_PREFIX lib)     # check in ur boost root dir
set(Boost_COMPILER  "-vc") #depends on ur compiler for boost install

add_subdirectory("path/to/kenlm")
add_library(lib_name STATIC ${sources})
target_include_directories(lib_name ${includes} ${Boost_INCLUDE_DIRS} path/to/kenlm)
target_link_libraries(lib_name kenlm ${other_libs})

add_executable(test ${src})
target_link_libraries(test lib_name)
set_property(TARGET test PROPERTY CXX_STANDARD 11)

Before building you need to install boost. kenlm require Eigen3, ZLIB, BZip2, LibLZMA, but for my task i can build app without these dependencies (although i have a lot of errors on kenlm building, but my app is builded)

And in ur project path:

mkdir build
cd build
cmake -G "Visual Studio 15 2017" -A x64 ..
cmake --build . --config Release