From 1073723b1d3aef6153225f6a6ac80f607c8423c2 Mon Sep 17 00:00:00 2001 From: jacobkahn Date: Sun, 16 May 2021 13:35:27 -0700 Subject: CMake improvements/fixes for old versions - Fix CMake going back to 3.1 -- (https://cmake.org/Bug/view.php?id=14444) - Moves `install` calls back to the directories where their librari targets are created - Make non-transitive dependencies private (compression libs, etc) rather than using generator expressions - Install auxiliary libraries (besides kenlm/kenlm_util) - Gate compression lib deps in kenlmConfig by whether they were found at compile time --- CMakeLists.txt | 10 +--------- cmake/kenlmConfig.cmake.in | 14 +++++++++++--- lm/CMakeLists.txt | 10 +++++++++- lm/builder/CMakeLists.txt | 8 ++++++++ lm/filter/CMakeLists.txt | 7 +++++++ lm/interpolate/CMakeLists.txt | 8 ++++++++ util/CMakeLists.txt | 36 +++++++++++++++++++++++------------- 7 files changed, 67 insertions(+), 26 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 64a9830..1a3d102 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -111,15 +111,7 @@ if(ENABLE_PYTHON) add_subdirectory(python) endif() -# Asset installation -install( - TARGETS kenlm kenlm_util - EXPORT kenlmTargets - RUNTIME DESTINATION bin - LIBRARY DESTINATION lib - ARCHIVE DESTINATION lib -) - +# Install targets install(EXPORT kenlmTargets FILE kenlmTargets.cmake NAMESPACE kenlm:: diff --git a/cmake/kenlmConfig.cmake.in b/cmake/kenlmConfig.cmake.in index d81e686..0fbf0c6 100644 --- a/cmake/kenlmConfig.cmake.in +++ b/cmake/kenlmConfig.cmake.in @@ -4,8 +4,16 @@ include(CMakeFindDependencyMacro) find_dependency(Boost) find_dependency(Threads) -find_dependency(ZLIB) -find_dependency(BZip2) -find_dependency(LibLZMA) + +# Compression libs +if (@ZLIB_FOUND@) + find_dependency(ZLIB) +endif() +if (@BZIP2_FOUND@) + find_dependency(BZip2) +endif() +if (@LIBLZMA_FOUND@) + find_dependency(LibLZMA) +endif() include("${CMAKE_CURRENT_LIST_DIR}/kenlmTargets.cmake") diff --git a/lm/CMakeLists.txt b/lm/CMakeLists.txt index 9ec18a5..36d83cf 100644 --- a/lm/CMakeLists.txt +++ b/lm/CMakeLists.txt @@ -48,10 +48,18 @@ set(EXE_LIST fragment build_binary kenlm_benchmark - ) +) set(LM_LIBS kenlm kenlm_util Threads::Threads) +install( + TARGETS kenlm + EXPORT kenlmTargets + RUNTIME DESTINATION bin + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib +) + AddExes(EXES ${EXE_LIST} LIBRARIES ${LM_LIBS}) diff --git a/lm/builder/CMakeLists.txt b/lm/builder/CMakeLists.txt index 4f23a4a..ae07d11 100644 --- a/lm/builder/CMakeLists.txt +++ b/lm/builder/CMakeLists.txt @@ -35,6 +35,14 @@ AddExes(EXES lmplz AddExes(EXES count_ngrams LIBRARIES kenlm_builder kenlm kenlm_util Threads::Threads) +install( + TARGETS kenlm_builder + EXPORT kenlmTargets + RUNTIME DESTINATION bin + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib +) + if(BUILD_TESTING) # Explicitly list the Boost test files to be compiled diff --git a/lm/filter/CMakeLists.txt b/lm/filter/CMakeLists.txt index 4f5d650..6fd551d 100644 --- a/lm/filter/CMakeLists.txt +++ b/lm/filter/CMakeLists.txt @@ -28,3 +28,10 @@ target_link_libraries(kenlm_filter PUBLIC kenlm_util) AddExes(EXES filter phrase_table_vocab LIBRARIES kenlm_filter kenlm) +install( + TARGETS kenlm_filter + EXPORT kenlmTargets + RUNTIME DESTINATION bin + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib +) diff --git a/lm/interpolate/CMakeLists.txt b/lm/interpolate/CMakeLists.txt index c5c7fd2..f83b16e 100644 --- a/lm/interpolate/CMakeLists.txt +++ b/lm/interpolate/CMakeLists.txt @@ -36,6 +36,14 @@ if(ENABLE_INTERPOLATE) AddExes(EXES ${KENLM_INTERPOLATE_EXES} LIBRARIES ${KENLM_INTERPOLATE_LIBS}) + install( + TARGETS kenlm_interpolate + EXPORT kenlmTargets + RUNTIME DESTINATION bin + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib + ) + if(BUILD_TESTING) AddTests(TESTS backoff_reunification_test bounded_sequence_encoding_test merge_vocab_test normalize_test tune_derivatives_test LIBRARIES ${KENLM_INTERPOLATE_LIBS} Threads::Threads) diff --git a/util/CMakeLists.txt b/util/CMakeLists.txt index a4ece57..10741a0 100644 --- a/util/CMakeLists.txt +++ b/util/CMakeLists.txt @@ -31,26 +31,31 @@ if (WIN32) set(KENLM_UTIL_SOURCE ${KENLM_UTIL_SOURCE} getopt.c) endif() +# This directory has children that need to be processed +add_subdirectory(double-conversion) +add_subdirectory(stream) + +add_library(kenlm_util ${KENLM_UTIL_DOUBLECONVERSION_SOURCE} ${KENLM_UTIL_STREAM_SOURCE} ${KENLM_UTIL_SOURCE}) + set(READ_COMPRESSED_FLAGS) -set(READ_COMPRESSED_LIBS) find_package(ZLIB) if (ZLIB_FOUND) set(READ_COMPRESSED_FLAGS "${READ_COMPRESSED_FLAGS} -DHAVE_ZLIB") - set(READ_COMPRESSED_LIBS ${READ_COMPRESSED_LIBS} ${ZLIB_LIBRARIES}) + target_link_libraries(kenlm_util PRIVATE ${ZLIB_LIBRARIES}) include_directories(${ZLIB_INCLUDE_DIR}) endif() find_package(BZip2) if (BZIP2_FOUND) set(READ_COMPRESSED_FLAGS "${READ_COMPRESSED_FLAGS} -DHAVE_BZLIB") - set(READ_COMPRESSED_LIBS ${READ_COMPRESSED_LIBS} ${BZIP2_LIBRARIES}) + target_link_libraries(kenlm_util PRIVATE ${BZIP2_LIBRARIES}) include_directories(${BZIP2_INCLUDE_DIR}) endif() find_package(LibLZMA) if (LIBLZMA_FOUND) set(READ_COMPRESSED_FLAGS "${READ_COMPRESSED_FLAGS} -DHAVE_XZLIB") - set(READ_COMPRESSED_LIBS ${READ_COMPRESSED_LIBS} ${LIBLZMA_LIBRARIES}) + target_link_libraries(kenlm_util PRIVATE ${LIBLZMA_LIBRARIES}) include_directories(${LIBLZMA_INCLUDE_DIRS}) endif() if (NOT "${READ_COMPRESSED_FLAGS}" STREQUAL "") @@ -59,10 +64,6 @@ if (NOT "${READ_COMPRESSED_FLAGS}" STREQUAL "") set_source_files_properties(file_piece_test.cc PROPERTIES COMPILE_FLAGS ${READ_COMPRESSED_FLAGS}) endif() -# This directory has children that need to be processed -add_subdirectory(double-conversion) -add_subdirectory(stream) - if(UNIX) include(CheckLibraryExists) check_library_exists(rt clock_gettime "clock_gettime from librt" HAVE_CLOCKGETTIME_RT) @@ -78,13 +79,22 @@ if(UNIX) 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 PUBLIC +target_link_libraries(kenlm_util + PUBLIC + # Boost is required for building binaries and tests "$" - "$" - $ - $) + PRIVATE + Threads::Threads + ${RT}) + +install( + TARGETS kenlm_util + EXPORT kenlmTargets + RUNTIME DESTINATION bin + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib +) if (NOT WIN32) AddExes(EXES probing_hash_table_benchmark -- cgit v1.2.3