Switch to cmake
Change-Id: I6543259b210b1a87c0b4f627927245407bac3f06
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..5af5296
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,9 @@
+.idea/
+build/
+cmake-build-debug/
+lib/
+bin/
+.*~
+.*\.log
+.*LOG
+LOG.*
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..3e5bccc
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,31 @@
+cmake_minimum_required(VERSION 3.9)
+project(dereko2vec VERSION 0.9.0 DESCRIPTION "Fork from wang2vec with extensions for re-training and count based models")
+set(CMAKE_VERBOSE_MAKEFILE on)
+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -lm -pthread -O3 -march=native -mtune=native -Wall -funroll-loops")
+set(ADDITIONAL_LIBS pthread rt snappy z bz2 lz4 zstd stdc++ dl)
+include(GNUInstallDirs)
+
+include_directories(/usr/local/include;/usr/local/kl/include)
+link_directories(/usr/local/kl/lib;/usr/local/lib;/usr/local/lib64)
+
+find_library(COLLOCATORDB libcollocatordb_static.a REQUIRED)
+if (NOT COLLOCATORDB)
+ message(FATAL_ERROR "No libcollocatordb_static.a found. Please install from https://korap.ids-mannheim.de/gerrit/plugins/gitiles/private/collocatordb")
+endif ()
+
+find_library(ROCKSDB librocksdb.a REQUIRED)
+if (NOT ROCKSDB)
+ 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")
+endif ()
+
+file(GLOB APP_SOURCES ${CMAKE_SOURCE_DIR}/src/*.c)
+foreach (mysourcefile ${APP_SOURCES})
+ # I used a simple string replace, to cut off .cpp.
+ string(REPLACE ".c" "" myname ${mysourcefile})
+ string(REGEX REPLACE ".*/" "" myname ${myname})
+ add_executable(${myname} ${mysourcefile})
+ # Make sure YourLib is linked to each app
+ if (${myname} MATCHES "derek")
+ target_link_libraries(${myname} ${COLLOCATORDB} ${ROCKSDB} ${ADDITIONAL_LIBS})
+ endif ()
+endforeach (mysourcefile ${APP_SOURCES})
diff --git a/makefile b/makefile
deleted file mode 100644
index 7e1a887..0000000
--- a/makefile
+++ /dev/null
@@ -1,37 +0,0 @@
-CC = gcc
-#Using -Ofast instead of -O3 might result in faster code, but is supported only by newer GCC versions
-CFLAGS = -lm -pthread -O3 -march=native -mtune=native -Wall -funroll-loops
-#CFLAGS = -m64 -march=k8 -mtune=k8 -lm -pthread -O3 -Wall -funroll-loops
-STATICCDB=/usr/local/lib64
-ROCKSDB=/usr/local/lib
-
-all: word2vec word2vec1 cngram2vec weightedWord2vec wordless2vec word2phrase distance word-analogy compute-accuracy distance_txt distance_fast kmeans_txt
-
-word2vec : word2vecExt.c makefile $(STATICCDB)/libcollocatordb_static.a
- $(CC) $(CFLAGS) word2vecExt.c $(STATICCDB)/libcollocatordb_static.a $(ROCKSDB)/librocksdb.a -o word2vec -I$(STATICCDB) -L$(STATICCDB) -L/usr/local/lib -ldl -lstdc++ -lm -lrt -lsnappy -lz -lbz2 -llz4 -lzstd
-
-word2vec1 : word2vecExt1.c makefile $(STATICCDB)/libcollocatordb_static.a
- $(CC) $(CFLAGS) word2vecExt1.c $(STATICCDB)/libcollocatordb_static.a $(ROCKSDB)/librocksdb.a -o word2vec1 -I$(STATICCDB) -L$(STATICCDB) -L/usr/local/lib -ldl -lstdc++ -lm -lrt -lsnappy -lz -lbz2 -llz4 -lzstd
-
-weightedWord2vec : weightedWord2vec.c
- $(CC) weightedWord2vec.c -o weightedWord2vec $(CFLAGS)
-cngram2vec : cngram2vec.c
- $(CC) cngram2vec.c -o cngram2vec $(CFLAGS)
-wordless2vec : wordless2vec.c
- $(CC) wordless2vec.c -o wordless2vec $(CFLAGS)
-word2phrase : word2phrase.c
- $(CC) word2phrase.c -o word2phrase $(CFLAGS)
-distance : distance.c
- $(CC) distance.c -o distance $(CFLAGS)
-distance_txt : distance_txt.c
- $(CC) distance_txt.c -o distance_txt $(CFLAGS)
-distance_fast : distance_fast.c
- $(CC) distance_fast.c -o distance_fast $(CFLAGS)
-kmeans_txt : kmeans_txt.c
- $(CC) kmeans_txt.c -o kmeans_txt $(CFLAGS)
-word-analogy : word-analogy.c
- $(CC) word-analogy.c -o word-analogy $(CFLAGS)
-compute-accuracy : compute-accuracy.c
- $(CC) compute-accuracy.c -o compute-accuracy $(CFLAGS)
-clean:
- rm -rf word2vec word2vec1 weightedWord2vec cngram2vec wiord2phrase distance word-analogy compute-accuracy distance_txt kmeans_txt
diff --git a/cngram2vec.c b/src/cngram2vec.c
similarity index 100%
rename from cngram2vec.c
rename to src/cngram2vec.c
diff --git a/compute-accuracy.c b/src/compute-accuracy.c
similarity index 100%
rename from compute-accuracy.c
rename to src/compute-accuracy.c
diff --git a/word2vecExt.c b/src/dereko2vec.c
similarity index 100%
rename from word2vecExt.c
rename to src/dereko2vec.c
diff --git a/distance.c b/src/distance.c
similarity index 100%
rename from distance.c
rename to src/distance.c
diff --git a/distance_fast.c b/src/distance_fast.c
similarity index 100%
rename from distance_fast.c
rename to src/distance_fast.c
diff --git a/distance_txt.c b/src/distance_txt.c
similarity index 100%
rename from distance_txt.c
rename to src/distance_txt.c
diff --git a/kmeans_txt.c b/src/kmeans_txt.c
similarity index 100%
rename from kmeans_txt.c
rename to src/kmeans_txt.c
diff --git a/weightedWord2vec.c b/src/weightedWord2vec.c
similarity index 100%
rename from weightedWord2vec.c
rename to src/weightedWord2vec.c
diff --git a/word-analogy.c b/src/word-analogy.c
similarity index 100%
rename from word-analogy.c
rename to src/word-analogy.c
diff --git a/word2phrase.c b/src/word2phrase.c
similarity index 100%
rename from word2phrase.c
rename to src/word2phrase.c
diff --git a/wordless2vec.c b/src/wordless2vec.c
similarity index 100%
rename from wordless2vec.c
rename to src/wordless2vec.c