blob: c6377a28e6fa180c3bec0d6184720f80bec7462e [file] [log] [blame]
Marc Kupietz6afb3522021-03-22 17:22:55 +01001cmake_minimum_required(VERSION 3.9)
Marc Kupietzd724abd2024-10-21 18:41:25 +02002project(dereko2vec VERSION 0.9.1 DESCRIPTION "Fork from wang2vec with extensions for re-training and count based models")
Marc Kupietz8b169772025-02-10 20:55:47 +01003option(STATIC_DEREKO2VEC "Build dereko2vec as a static binary" OFF)
4
Marc Kupietz6afb3522021-03-22 17:22:55 +01005set(CMAKE_VERBOSE_MAKEFILE on)
Marc Kupietz61485ad2023-12-22 16:16:59 +01006if (CMAKE_BUILD_TYPE MATCHES Debug)
Marc Kupietz8b169772025-02-10 20:55:47 +01007 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O0 -Wall -Wextra -Wno-unused-parameter -Wno-unused-variable -Wno-unused-function -Wno-unused-but-set-variable -Wno-unused-but-set-parameter -Wno-unused-value -Wno-unused-result")
Marc Kupietz61485ad2023-12-22 16:16:59 +01008else ()
Marc Kupietz8b169772025-02-10 20:55:47 +01009 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 -march=native -mtune=native -Wall -funroll-loops")
Marc Kupietz61485ad2023-12-22 16:16:59 +010010endif ()
Marc Kupietz8b169772025-02-10 20:55:47 +010011set(ADDITIONAL_LIBS ${ADDITIONAL_LIBS} m pthread rt snappy z bz2 lz4 zstd stdc++ dl)
Marc Kupietz6afb3522021-03-22 17:22:55 +010012include(GNUInstallDirs)
13
14include_directories(/usr/local/include;/usr/local/kl/include)
15link_directories(/usr/local/kl/lib;/usr/local/lib;/usr/local/lib64)
16
Marc Kupietz46cad402026-08-02 07:23:05 +020017# A static dereko2vec needs everything as a static library. An ordinary build
18# takes the shared ones, and it has to take them explicitly: a leftover static
19# library below /usr/local would otherwise win over the shared library of the
20# distribution, because cmake weighs the search path higher than the suffix.
21# Set -DCOLLOCATORDB=<path> or -DROCKSDB=<path> to pick specific ones.
22if (STATIC_DEREKO2VEC)
23 find_library(COLLOCATORDB libcollocatordb_static.a)
24 find_library(ROCKSDB librocksdb.a)
25else ()
26 set(_dereko2vec_lib_suffixes ${CMAKE_FIND_LIBRARY_SUFFIXES})
27 set(CMAKE_FIND_LIBRARY_SUFFIXES ".so")
28 find_library(COLLOCATORDB NAMES collocatordb)
29 find_library(ROCKSDB NAMES rocksdb)
30 set(CMAKE_FIND_LIBRARY_SUFFIXES ${_dereko2vec_lib_suffixes})
Marc Kupietz6afb3522021-03-22 17:22:55 +010031endif ()
32
Marc Kupietz46cad402026-08-02 07:23:05 +020033if (NOT COLLOCATORDB)
34 message(FATAL_ERROR "No collocatordb found. Please install it from "
35 "https://korap.ids-mannheim.de/gerrit/plugins/gitiles/ids-kl/collocatordb"
36 " - a static dereko2vec needs libcollocatordb_static.a, otherwise "
37 "libcollocatordb.so is enough.")
Marc Kupietz6afb3522021-03-22 17:22:55 +010038endif ()
Marc Kupietzf2aa92e2026-07-31 14:48:02 +090039if (NOT ROCKSDB)
Marc Kupietz46cad402026-08-02 07:23:05 +020040 message(FATAL_ERROR "No rocksdb found. Install the rocksdb development "
41 "package of your distribution, e.g. librocksdb-dev or rocksdb-devel.")
Marc Kupietzf2aa92e2026-07-31 14:48:02 +090042endif ()
Marc Kupietz46cad402026-08-02 07:23:05 +020043message(STATUS "Using collocatordb ${COLLOCATORDB}")
44message(STATUS "Using RocksDB ${ROCKSDB}")
Marc Kupietz6afb3522021-03-22 17:22:55 +010045
46file(GLOB APP_SOURCES ${CMAKE_SOURCE_DIR}/src/*.c)
47foreach (mysourcefile ${APP_SOURCES})
48 # I used a simple string replace, to cut off .cpp.
49 string(REPLACE ".c" "" myname ${mysourcefile})
50 string(REGEX REPLACE ".*/" "" myname ${myname})
51 add_executable(${myname} ${mysourcefile})
52 # Make sure YourLib is linked to each app
53 if (${myname} MATCHES "derek")
54 target_link_libraries(${myname} ${COLLOCATORDB} ${ROCKSDB} ${ADDITIONAL_LIBS})
Marc Kupietz8b169772025-02-10 20:55:47 +010055 if(STATIC_DEREKO2VEC)
56 set_target_properties(${myname} PROPERTIES LINK_FLAGS "-static")
57 endif()
58 else ()
59 target_link_libraries(${myname} m pthread)
Marc Kupietz6afb3522021-03-22 17:22:55 +010060 endif ()
61endforeach (mysourcefile ${APP_SOURCES})
Marc Kupietz31e2e312021-03-22 17:22:57 +010062
Marc Kupietz46cad402026-08-02 07:23:05 +020063# Only the two that are used outside of a build directory: the trainer and the
64# converter that writes the memory mappable form derekovecs maps. The remaining
65# programs keep the generic names they inherited from word2vec, like distance
66# or kmeans_txt, which have no business in a directory on everybody's PATH.
Marc Kupietz4314a1c2026-08-02 07:32:43 +020067#
68# The installed dereko2vec gets the directory of the collocatordb it was linked
69# against as its rpath. An installation below /usr/local is not in the search
70# path of the loader by default, and without this it only starts with
71# LD_LIBRARY_PATH set.
72if (NOT STATIC_DEREKO2VEC)
73 get_filename_component(COLLOCATORDB_LIBDIR "${COLLOCATORDB}" DIRECTORY)
74 list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${COLLOCATORDB_LIBDIR}" isSystemLibDir)
75 if ("${isSystemLibDir}" STREQUAL "-1")
76 set_target_properties(dereko2vec PROPERTIES INSTALL_RPATH "${COLLOCATORDB_LIBDIR}")
77 endif ()
78endif ()
Marc Kupietz46cad402026-08-02 07:23:05 +020079install(TARGETS dereko2vec vecs2mmap RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
80
Marc Kupietz31e2e312021-03-22 17:22:57 +010081enable_testing()
82find_program(BASH_PROGRAM bash)
83if (BASH_PROGRAM)
84 add_test(type-3-test ${BASH_PROGRAM} ${CMAKE_CURRENT_SOURCE_DIR}/tests/test-type-3.sh)
85else ()
86 message(SEND_ERROR "Cannot find bash, needed for testing")
87endif ()