blob: f6faee71383f32d8d3cea1b35df6b51336fe85a8 [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
17find_library(COLLOCATORDB libcollocatordb_static.a REQUIRED)
18if (NOT COLLOCATORDB)
19 message(FATAL_ERROR "No libcollocatordb_static.a found. Please install from https://korap.ids-mannheim.de/gerrit/plugins/gitiles/private/collocatordb")
20endif ()
21
Marc Kupietzf2aa92e2026-07-31 14:48:02 +090022# No version pin, so that the rocksdb of the distribution can be used. A static
23# build needs the static library, otherwise a shared one will do as well.
24if (STATIC_DEREKO2VEC)
25 find_library(ROCKSDB librocksdb.a REQUIRED)
26else ()
27 find_library(ROCKSDB NAMES rocksdb REQUIRED)
Marc Kupietz6afb3522021-03-22 17:22:55 +010028endif ()
Marc Kupietzf2aa92e2026-07-31 14:48:02 +090029if (NOT ROCKSDB)
30 message(FATAL_ERROR "No rocksdb found. Install the rocksdb development package of your distribution, e.g. librocksdb-dev or rocksdb-devel.")
31endif ()
32message(STATUS "Using RocksDB library ${ROCKSDB}")
Marc Kupietz6afb3522021-03-22 17:22:55 +010033
34file(GLOB APP_SOURCES ${CMAKE_SOURCE_DIR}/src/*.c)
35foreach (mysourcefile ${APP_SOURCES})
36 # I used a simple string replace, to cut off .cpp.
37 string(REPLACE ".c" "" myname ${mysourcefile})
38 string(REGEX REPLACE ".*/" "" myname ${myname})
39 add_executable(${myname} ${mysourcefile})
40 # Make sure YourLib is linked to each app
41 if (${myname} MATCHES "derek")
42 target_link_libraries(${myname} ${COLLOCATORDB} ${ROCKSDB} ${ADDITIONAL_LIBS})
Marc Kupietz8b169772025-02-10 20:55:47 +010043 if(STATIC_DEREKO2VEC)
44 set_target_properties(${myname} PROPERTIES LINK_FLAGS "-static")
45 endif()
46 else ()
47 target_link_libraries(${myname} m pthread)
Marc Kupietz6afb3522021-03-22 17:22:55 +010048 endif ()
49endforeach (mysourcefile ${APP_SOURCES})
Marc Kupietz31e2e312021-03-22 17:22:57 +010050
51enable_testing()
52find_program(BASH_PROGRAM bash)
53if (BASH_PROGRAM)
54 add_test(type-3-test ${BASH_PROGRAM} ${CMAKE_CURRENT_SOURCE_DIR}/tests/test-type-3.sh)
55else ()
56 message(SEND_ERROR "Cannot find bash, needed for testing")
57endif ()