Skip to content

Commit

Permalink
Use cmake for pthreads and rt fixes kpu#301
Browse files Browse the repository at this point in the history
  • Loading branch information
kpu committed Sep 17, 2020
1 parent 01c49fe commit 1c50076
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 39 deletions.
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 2.6)
cmake_minimum_required(VERSION 3.1)

# Define a single cmake project
project(kenlm)
Expand Down Expand Up @@ -79,6 +79,9 @@ include_directories(
${Boost_INCLUDE_DIRS}
)

set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)

# Process subdirectories
add_subdirectory(util)
add_subdirectory(lm)
Expand Down
8 changes: 2 additions & 6 deletions lm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,9 @@ set(KENLM_LM_SOURCE
#
add_subdirectory(common)

if (NOT MSVC)
set(THREADS pthread)
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})
target_link_libraries(kenlm kenlm_util ${Boost_LIBRARIES} Threads::Threads)

set(KENLM_MAX_ORDER 6 CACHE STRING "Maximum supported ngram order")
target_compile_definitions(kenlm PUBLIC -DKENLM_MAX_ORDER=${KENLM_MAX_ORDER})
Expand All @@ -54,7 +50,7 @@ set(EXE_LIST
kenlm_benchmark
)

set(LM_LIBS kenlm kenlm_util ${Boost_LIBRARIES} ${THREADS})
set(LM_LIBS kenlm kenlm_util ${Boost_LIBRARIES} Threads::Threads)

AddExes(EXES ${EXE_LIST}
LIBRARIES ${LM_LIBS})
Expand Down
12 changes: 4 additions & 8 deletions lm/builder/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,12 @@ set(KENLM_BUILDER_SOURCE
#
add_library(kenlm_builder ${KENLM_BUILDER_SOURCE})

target_link_libraries(kenlm_builder kenlm kenlm_util ${Boost_LIBRARIES} ${THREADS})

if (NOT MSVC)
set(THREADS pthread)
endif()
target_link_libraries(kenlm_builder kenlm kenlm_util ${Boost_LIBRARIES} Threads::Threads)

AddExes(EXES lmplz
LIBRARIES kenlm_builder kenlm kenlm_util ${Boost_LIBRARIES} ${THREADS})
LIBRARIES kenlm_builder kenlm kenlm_util ${Boost_LIBRARIES} Threads::Threads)
AddExes(EXES count_ngrams
LIBRARIES kenlm_builder kenlm kenlm_util ${Boost_LIBRARIES} ${THREADS})
LIBRARIES kenlm_builder kenlm kenlm_util ${Boost_LIBRARIES} Threads::Threads)

if(BUILD_TESTING)

Expand All @@ -48,5 +44,5 @@ if(BUILD_TESTING)
)

AddTests(TESTS ${KENLM_BOOST_TESTS_LIST}
LIBRARIES kenlm_builder kenlm kenlm_util ${Boost_LIBRARIES} ${THREADS})
LIBRARIES kenlm_builder kenlm kenlm_util ${Boost_LIBRARIES} Threads::Threads)
endif()
4 changes: 0 additions & 4 deletions lm/filter/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ set(KENLM_FILTER_SOURCE
add_library(kenlm_filter ${KENLM_FILTER_SOURCE})
target_link_libraries(kenlm_filter kenlm_util)

if (NOT MSVC)
set(THREADS pthread)
endif()

AddExes(EXES filter phrase_table_vocab
LIBRARIES kenlm_filter kenlm)

8 changes: 2 additions & 6 deletions lm/interpolate/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,15 @@ if(EIGEN3_FOUND)
interpolate
streaming_example)

if (NOT MSVC)
set(THREADS pthread)
endif()

set(KENLM_INTERPOLATE_LIBS
set(KENLM_INTERPOLATE_LIBS
kenlm_interpolate)

AddExes(EXES ${KENLM_INTERPOLATE_EXES}
LIBRARIES ${KENLM_INTERPOLATE_LIBS})

if(BUILD_TESTING)
AddTests(TESTS backoff_reunification_test bounded_sequence_encoding_test merge_vocab_test normalize_test tune_derivatives_test
LIBRARIES ${KENLM_INTERPOLATE_LIBS} pthread)
LIBRARIES ${KENLM_INTERPOLATE_LIBS} Threads::Threads)

# tune_instances_test needs an extra command line parameter
KenLMAddTest(TEST tune_instances_test
Expand Down
18 changes: 5 additions & 13 deletions util/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,23 +57,15 @@ set_source_files_properties(file_piece_test.cc PROPERTIES COMPILE_FLAGS ${READ_C
add_subdirectory(double-conversion)
add_subdirectory(stream)

if (UNIX AND NOT APPLE)
set(TIMER_LINK rt)
else()
set(TIMER_LINK)
endif()

if (NOT MSVC)
set(THREADS pthread)
endif()
find_library(LIBRT rt)

# 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})
target_link_libraries(kenlm_util ${Boost_LIBRARIES} ${READ_COMPRESSED_LIBS} Threads::Threads ${LIBRT})

AddExes(EXES probing_hash_table_benchmark
LIBRARIES kenlm_util ${Boost_LIBRARIES} ${THREADS})
LIBRARIES kenlm_util ${Boost_LIBRARIES} Threads::Threads)

# Only compile and run unit tests if tests should be run
if(BUILD_TESTING)
Expand All @@ -92,10 +84,10 @@ if(BUILD_TESTING)
)

AddTests(TESTS ${KENLM_BOOST_TESTS_LIST}
LIBRARIES kenlm_util ${Boost_LIBRARIES} ${THREADS})
LIBRARIES kenlm_util ${Boost_LIBRARIES} Threads::Threads)

# file_piece_test requires an extra command line parameter
KenLMAddTest(TEST file_piece_test
LIBRARIES kenlm_util ${Boost_LIBRARIES} ${THREADS}
LIBRARIES kenlm_util ${Boost_LIBRARIES} Threads::Threads
TEST_ARGS ${CMAKE_CURRENT_SOURCE_DIR}/file_piece.cc)
endif()
2 changes: 1 addition & 1 deletion util/stream/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ if(BUILD_TESTING)
)

AddTests(TESTS ${KENLM_BOOST_TESTS_LIST}
LIBRARIES kenlm_util ${Boost_LIBRARIES} pthread)
LIBRARIES kenlm_util ${Boost_LIBRARIES} Threads::Threads)
endif()

0 comments on commit 1c50076

Please sign in to comment.