| Marc Kupietz | 6afb352 | 2021-03-22 17:22:55 +0100 | [diff] [blame] | 1 | cmake_minimum_required(VERSION 3.9) |
| Marc Kupietz | d724abd | 2024-10-21 18:41:25 +0200 | [diff] [blame] | 2 | project(dereko2vec VERSION 0.9.1 DESCRIPTION "Fork from wang2vec with extensions for re-training and count based models") |
| Marc Kupietz | 8b16977 | 2025-02-10 20:55:47 +0100 | [diff] [blame] | 3 | option(STATIC_DEREKO2VEC "Build dereko2vec as a static binary" OFF) |
| 4 | |
| Marc Kupietz | 6afb352 | 2021-03-22 17:22:55 +0100 | [diff] [blame] | 5 | set(CMAKE_VERBOSE_MAKEFILE on) |
| Marc Kupietz | 61485ad | 2023-12-22 16:16:59 +0100 | [diff] [blame] | 6 | if (CMAKE_BUILD_TYPE MATCHES Debug) |
| Marc Kupietz | 8b16977 | 2025-02-10 20:55:47 +0100 | [diff] [blame] | 7 | 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 Kupietz | 61485ad | 2023-12-22 16:16:59 +0100 | [diff] [blame] | 8 | else () |
| Marc Kupietz | 8b16977 | 2025-02-10 20:55:47 +0100 | [diff] [blame] | 9 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 -march=native -mtune=native -Wall -funroll-loops") |
| Marc Kupietz | 61485ad | 2023-12-22 16:16:59 +0100 | [diff] [blame] | 10 | endif () |
| Marc Kupietz | 8b16977 | 2025-02-10 20:55:47 +0100 | [diff] [blame] | 11 | set(ADDITIONAL_LIBS ${ADDITIONAL_LIBS} m pthread rt snappy z bz2 lz4 zstd stdc++ dl) |
| Marc Kupietz | 6afb352 | 2021-03-22 17:22:55 +0100 | [diff] [blame] | 12 | include(GNUInstallDirs) |
| 13 | |
| 14 | include_directories(/usr/local/include;/usr/local/kl/include) |
| 15 | link_directories(/usr/local/kl/lib;/usr/local/lib;/usr/local/lib64) |
| 16 | |
| Marc Kupietz | 46cad40 | 2026-08-02 07:23:05 +0200 | [diff] [blame] | 17 | # 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. |
| 22 | if (STATIC_DEREKO2VEC) |
| 23 | find_library(COLLOCATORDB libcollocatordb_static.a) |
| 24 | find_library(ROCKSDB librocksdb.a) |
| 25 | else () |
| 26 | set(_dereko2vec_lib_suffixes ${CMAKE_FIND_LIBRARY_SUFFIXES}) |
| Marc Kupietz | 2072f29 | 2026-08-02 07:38:44 +0200 | [diff] [blame^] | 27 | set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_SHARED_LIBRARY_SUFFIX}) |
| Marc Kupietz | 46cad40 | 2026-08-02 07:23:05 +0200 | [diff] [blame] | 28 | find_library(COLLOCATORDB NAMES collocatordb) |
| 29 | find_library(ROCKSDB NAMES rocksdb) |
| 30 | set(CMAKE_FIND_LIBRARY_SUFFIXES ${_dereko2vec_lib_suffixes}) |
| Marc Kupietz | 6afb352 | 2021-03-22 17:22:55 +0100 | [diff] [blame] | 31 | endif () |
| 32 | |
| Marc Kupietz | 46cad40 | 2026-08-02 07:23:05 +0200 | [diff] [blame] | 33 | if (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 Kupietz | 6afb352 | 2021-03-22 17:22:55 +0100 | [diff] [blame] | 38 | endif () |
| Marc Kupietz | f2aa92e | 2026-07-31 14:48:02 +0900 | [diff] [blame] | 39 | if (NOT ROCKSDB) |
| Marc Kupietz | 46cad40 | 2026-08-02 07:23:05 +0200 | [diff] [blame] | 40 | message(FATAL_ERROR "No rocksdb found. Install the rocksdb development " |
| 41 | "package of your distribution, e.g. librocksdb-dev or rocksdb-devel.") |
| Marc Kupietz | f2aa92e | 2026-07-31 14:48:02 +0900 | [diff] [blame] | 42 | endif () |
| Marc Kupietz | 46cad40 | 2026-08-02 07:23:05 +0200 | [diff] [blame] | 43 | message(STATUS "Using collocatordb ${COLLOCATORDB}") |
| 44 | message(STATUS "Using RocksDB ${ROCKSDB}") |
| Marc Kupietz | 6afb352 | 2021-03-22 17:22:55 +0100 | [diff] [blame] | 45 | |
| 46 | file(GLOB APP_SOURCES ${CMAKE_SOURCE_DIR}/src/*.c) |
| 47 | foreach (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 Kupietz | 8b16977 | 2025-02-10 20:55:47 +0100 | [diff] [blame] | 55 | if(STATIC_DEREKO2VEC) |
| 56 | set_target_properties(${myname} PROPERTIES LINK_FLAGS "-static") |
| 57 | endif() |
| 58 | else () |
| 59 | target_link_libraries(${myname} m pthread) |
| Marc Kupietz | 6afb352 | 2021-03-22 17:22:55 +0100 | [diff] [blame] | 60 | endif () |
| 61 | endforeach (mysourcefile ${APP_SOURCES}) |
| Marc Kupietz | 31e2e31 | 2021-03-22 17:22:57 +0100 | [diff] [blame] | 62 | |
| Marc Kupietz | 46cad40 | 2026-08-02 07:23:05 +0200 | [diff] [blame] | 63 | # 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 Kupietz | 4314a1c | 2026-08-02 07:32:43 +0200 | [diff] [blame] | 67 | # |
| 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. |
| 72 | if (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 () |
| 78 | endif () |
| Marc Kupietz | 46cad40 | 2026-08-02 07:23:05 +0200 | [diff] [blame] | 79 | install(TARGETS dereko2vec vecs2mmap RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) |
| 80 | |
| Marc Kupietz | 31e2e31 | 2021-03-22 17:22:57 +0100 | [diff] [blame] | 81 | enable_testing() |
| 82 | find_program(BASH_PROGRAM bash) |
| 83 | if (BASH_PROGRAM) |
| 84 | add_test(type-3-test ${BASH_PROGRAM} ${CMAKE_CURRENT_SOURCE_DIR}/tests/test-type-3.sh) |
| 85 | else () |
| 86 | message(SEND_ERROR "Cannot find bash, needed for testing") |
| 87 | endif () |