blob: 87fc200542b67f6587e439b3dffcc7b110114890 [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 Kupietz6afb3522021-03-22 17:22:55 +01003set(CMAKE_VERBOSE_MAKEFILE on)
Marc Kupietz61485ad2023-12-22 16:16:59 +01004if (CMAKE_BUILD_TYPE MATCHES Debug)
5 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -lm -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")
6else ()
7 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -lm -pthread -O3 -march=native -mtune=native -Wall -funroll-loops")
8endif ()
Marc Kupietz5846b332025-02-10 17:16:31 +01009
10# First, try to find static versions
11find_library(ZLIB_STATIC NAMES libz.a)
12find_library(BZ2_STATIC NAMES libbz2.a)
13find_library(LZ4_STATIC NAMES liblz4.a)
14find_library(ZSTD_STATIC NAMES libzstd.a)
Marc Kupietz803fff12025-02-10 17:32:26 +010015find_library(SNAPPY_STATIC NAMES libsnappy.a)
Marc Kupietzd4120f12025-02-10 18:20:06 +010016find_library(STDC++_STATIC NAMES libstdc++.a)
Marc Kupietz5846b332025-02-10 17:16:31 +010017
18# Set each library, preferring static if found
Marc Kupietz803fff12025-02-10 17:32:26 +010019set(ADDITIONAL_LIBS ${ADDITIONAL_LIBS} pthread rt)
20
Marc Kupietz5846b332025-02-10 17:16:31 +010021if(ZLIB_STATIC)
22 set(ADDITIONAL_LIBS ${ADDITIONAL_LIBS} ${ZLIB_STATIC})
23else()
24 set(ADDITIONAL_LIBS ${ADDITIONAL_LIBS} z)
25endif()
26
27if(BZ2_STATIC)
28 set(ADDITIONAL_LIBS ${ADDITIONAL_LIBS} ${BZ2_STATIC})
29else()
30 set(ADDITIONAL_LIBS ${ADDITIONAL_LIBS} bz2)
31endif()
32
33if(LZ4_STATIC)
34 set(ADDITIONAL_LIBS ${ADDITIONAL_LIBS} ${LZ4_STATIC})
35else()
36 set(ADDITIONAL_LIBS ${ADDITIONAL_LIBS} lz4)
37endif()
38
39if(ZSTD_STATIC)
40 set(ADDITIONAL_LIBS ${ADDITIONAL_LIBS} ${ZSTD_STATIC})
41else()
42 set(ADDITIONAL_LIBS ${ADDITIONAL_LIBS} zstd)
43endif()
44
Marc Kupietz803fff12025-02-10 17:32:26 +010045if(SNAPPY_STATIC)
46 set(ADDITIONAL_LIBS ${ADDITIONAL_LIBS} ${SNAPPY_STATIC})
47else()
48 set(ADDITIONAL_LIBS ${ADDITIONAL_LIBS} snappy)
49endif()
50
Marc Kupietzd4120f12025-02-10 18:20:06 +010051if(STDC++_STATIC)
52 set(ADDITIONAL_LIBS ${ADDITIONAL_LIBS} ${STDC++_STATIC})
53else()
54 set(ADDITIONAL_LIBS ${ADDITIONAL_LIBS} stdc++)
55endif()
56
57set(ADDITIONAL_LIBS ${ADDITIONAL_LIBS} dl)
Marc Kupietz5846b332025-02-10 17:16:31 +010058
Marc Kupietz6afb3522021-03-22 17:22:55 +010059include(GNUInstallDirs)
60
61include_directories(/usr/local/include;/usr/local/kl/include)
62link_directories(/usr/local/kl/lib;/usr/local/lib;/usr/local/lib64)
63
64find_library(COLLOCATORDB libcollocatordb_static.a REQUIRED)
65if (NOT COLLOCATORDB)
66 message(FATAL_ERROR "No libcollocatordb_static.a found. Please install from https://korap.ids-mannheim.de/gerrit/plugins/gitiles/private/collocatordb")
67endif ()
68
69find_library(ROCKSDB librocksdb.a REQUIRED)
70if (NOT ROCKSDB)
71 message(FATAL_ERROR "No librocksdb.a found. Please install like suggested here https://korap.ids-mannheim.de/gerrit/plugins/gitiles/private/collocatordb#install-rocksdb-and-prerequisites")
72endif ()
73
74file(GLOB APP_SOURCES ${CMAKE_SOURCE_DIR}/src/*.c)
75foreach (mysourcefile ${APP_SOURCES})
76 # I used a simple string replace, to cut off .cpp.
77 string(REPLACE ".c" "" myname ${mysourcefile})
78 string(REGEX REPLACE ".*/" "" myname ${myname})
79 add_executable(${myname} ${mysourcefile})
80 # Make sure YourLib is linked to each app
81 if (${myname} MATCHES "derek")
82 target_link_libraries(${myname} ${COLLOCATORDB} ${ROCKSDB} ${ADDITIONAL_LIBS})
83 endif ()
84endforeach (mysourcefile ${APP_SOURCES})
Marc Kupietz31e2e312021-03-22 17:22:57 +010085
86enable_testing()
87find_program(BASH_PROGRAM bash)
88if (BASH_PROGRAM)
89 add_test(type-3-test ${BASH_PROGRAM} ${CMAKE_CURRENT_SOURCE_DIR}/tests/test-type-3.sh)
90else ()
91 message(SEND_ERROR "Cannot find bash, needed for testing")
92endif ()