forked from sortmerna/sortmerna
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
187 lines (159 loc) · 7.04 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#===============================================================================
# FILE: CMakeLists.txt
# Created: Jun 06, 2017
#
# Top level CMake file for sortmerna
#===============================================================================
cmake_minimum_required(VERSION 3.5)
project(sortmerna CXX C)
set(CMAKE_CXX_STANDARD 14)
set(EXTERNAL_DEPS ${CMAKE_SOURCE_DIR}/3rdparty)
#include(ExternalProject)
message("CMAKE_CXX_COMPILER_ID = ${CMAKE_CXX_COMPILER_ID}") # 'GNU' on Ubuntu
message("CMAKE_CONFIGURATION_TYPES = ${CMAKE_CONFIGURATION_TYPES}")
message("CMAKE_HOST_SYSTEM_NAME = ${CMAKE_HOST_SYSTEM_NAME}")
message("CMAKE_HOST_SYSTEM_VERSION = ${CMAKE_HOST_SYSTEM_VERSION}")
message("CMAKE_HOST_SYSTEM = ${CMAKE_HOST_SYSTEM}")
message("PROJECT_BINARY_DIR = ${PROJECT_BINARY_DIR}")
message("CMAKE_BINARY_DIR = ${CMAKE_BINARY_DIR}")
message("CMAKE_CURRENT_BINARY_DIR = ${CMAKE_CURRENT_BINARY_DIR}")
message("RUNTIME_OUTPUT_DIRECTORY_RELEASE = ${RUNTIME_OUTPUT_DIRECTORY_RELEASE}")
# append sortmerna custom modules to cmake modules
#list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake/modules/")
option(SRC_ZLIB "Download Zlib sources" OFF)
option(SRC_ROCKSDB "Download RocksDB sources" OFF)
option(SRC_RAPIDJSON "Download Rapidjson sources" OFF)
option(SET_ROCKSDB "Add RocksDB headers and lib to the build (if RocksDB was built from sources)" OFF)
option(SET_ZLIB "Add Zlib headers and lib to the build (if Zlib was built from sources)" OFF)
option(WITH_TESTS "Select whether to build tests" ON)
if("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" AND "${EXTRA_CXX_FLAGS_RELEASE}" STRGREATER "")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${EXTRA_CXX_FLAGS_RELEASE}")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${EXTRA_C_FLAGS_RELEASE}")
endif()
endif()
message("CMAKE_CXX_FLAGS_RELEASE: ${CMAKE_CXX_FLAGS_RELEASE}")
message("EXTRA_CXX_FLAGS_RELEASE: ${EXTRA_CXX_FLAGS_RELEASE}")
## download zlib
if(SRC_ZLIB AND NOT EXISTS ${EXTERNAL_DEPS}/zlib)
execute_process(COMMAND git clone --depth 1 https://github.com/madler/zlib
WORKING_DIRECTORY ${EXTERNAL_DEPS}
)
endif()
## Download RocksDB
if(SRC_ROCKSDB AND NOT EXISTS ${EXTERNAL_DEPS}/rocksdb)
execute_process(COMMAND git clone --depth 1 https://github.com/facebook/rocksdb
WORKING_DIRECTORY ${EXTERNAL_DEPS}
)
endif()
## Download Rapidjson
if(SRC_RAPIDJSON AND NOT EXISTS ${EXTERNAL_DEPS}/rapidjson)
execute_process(COMMAND git clone --depth 1 https://github.com/Tencent/rapidjson
WORKING_DIRECTORY ${EXTERNAL_DEPS}
)
endif()
# download dirent. Only dirent.h used from this project - no need to build
if(WIN32 AND NOT EXISTS ${EXTERNAL_DEPS}/dirent)
execute_process(COMMAND git clone --depth 1 https://github.com/tronkko/dirent
WORKING_DIRECTORY ${EXTERNAL_DEPS}
)
endif()
## Download concurrentqueue
if(NOT EXISTS ${EXTERNAL_DEPS}/concurrentqueue)
execute_process(COMMAND git clone --depth 1 https://github.com/cameron314/concurrentqueue
WORKING_DIRECTORY ${EXTERNAL_DEPS}
)
endif()
## mman for Windows TODO: not used any longer. Remove.
#if(WIN32 AND NOT EXISTS ${EXTERNAL_DEPS}/mman-win32)
## download archive. The archive contains directory "mman-win32".
# file(DOWNLOAD
# https://storage.googleapis.com/google-code-archive-source/v2/code.google.com/mman-win32/source-archive.zip
# ${EXTERNAL_DEPS}/mman.zip
# )
## extract mman-win32 archive.
# execute_process(COMMAND ${CMAKE_COMMAND} -E tar -xf mman.zip
# WORKING_DIRECTORY ${EXTERNAL_DEPS}
# )
## remove mman-win32 archive
# file(REMOVE ${EXTERNAL_DEPS}/mman.zip)
## move source file. NOTE: modify mman.c to include 'sys/mman.h' instead of 'mman.h'
# file(RENAME ${EXTERNAL_DEPS}/mman-win32/trunk/mman.c ${EXTERNAL_DEPS}/mman-win32/mman.c)
## move header file.
# file(MAKE_DIRECTORY ${EXTERNAL_DEPS}/mman-win32/sys)
# file(RENAME ${EXTERNAL_DEPS}/mman-win32/trunk/mman.h ${EXTERNAL_DEPS}/mman-win32/sys/mman.h)
## remove unused directories
# file(REMOVE_RECURSE
# ${EXTERNAL_DEPS}/mman-win32/.svn
# ${EXTERNAL_DEPS}/mman-win32/branches
# ${EXTERNAL_DEPS}/mman-win32/tags
# ${EXTERNAL_DEPS}/mman-win32/trunk
# ${EXTERNAL_DEPS}/mman-win32/wiki
# )
#endif(WIN32 AND NOT EXISTS ${EXTERNAL_DEPS}/mman-win32)
## build cmph
add_subdirectory(${EXTERNAL_DEPS}/cmph)
## build alp
add_subdirectory(${EXTERNAL_DEPS}/alp)
## build winapi
if(WIN32)
add_subdirectory(${CMAKE_SOURCE_DIR}/src/winapi)
endif()
## build indexdb
add_subdirectory(${CMAKE_SOURCE_DIR}/src/indexdb)
## build sortmerna
add_subdirectory(${CMAKE_SOURCE_DIR}/src/sortmerna)
## 3rd party libraries
if(SET_ROCKSDB)
## cache entries for RocksDB
set(ROCKSDB_INCLUDE_DIR ${EXTERNAL_DEPS}/rocksdb/include CACHE PATH "Rocksdb Include directory" FORCE)
set(ROCKSDB_LIB_DEBUG ${EXTERNAL_DEPS}/rocksdb/build/Debug CACHE PATH "Rocksdb Debug Lib directory" FORCE)
set(ROCKSDB_LIB_RELEASE ${EXTERNAL_DEPS}/rocksdb/build/Release CACHE PATH "Rocksdb Release Lib directory" FORCE)
message("ROCKSDB_INCLUDE_DIR = ${ROCKSDB_INCLUDE_DIR}")
message("CMAKE_BUILD_TYPE = ${CMAKE_BUILD_TYPE}")
## library
add_library(rocksdb STATIC IMPORTED GLOBAL)
set_target_properties(rocksdb PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${ROCKSDB_INCLUDE_DIR})
if(WIN32)
set_target_properties(rocksdb PROPERTIES IMPORTED_LOCATION_DEBUG ${ROCKSDB_LIB_DEBUG}/rocksdb.lib)
set_target_properties(rocksdb PROPERTIES IMPORTED_LOCATION_RELEASE ${ROCKSDB_LIB_RELEASE}/rocksdb.lib)
else()
set_target_properties(rocksdb PROPERTIES IMPORTED_LOCATION_DEBUG ${ROCKSDB_LIB_DEBUG}/librocksdb.a)
set_target_properties(rocksdb PROPERTIES IMPORTED_LOCATION_RELEASE ${ROCKSDB_LIB_RELEASE}/librocksdb.a)
endif()
endif()
if(SET_ZLIB)
## zlib cache entries
set(ZLIB_LIB_DEBUG ${EXTERNAL_DEPS}/zlib/build/Debug CACHE PATH "Zlib library directory")
set(ZLIB_LIB_RELEASE ${EXTERNAL_DEPS}/zlib/build/Release CACHE PATH "Zlib library directory")
## library
add_library(z STATIC IMPORTED GLOBAL)
set_target_properties(z PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${EXTERNAL_DEPS}/zlib/dist/include)
set_target_properties(z PROPERTIES IMPORTED_LOCATION_DEBUG ${ZLIB_LIB_DEBUG}/zlibstaticd.lib)
set_target_properties(z PROPERTIES IMPORTED_LOCATION_RELEASE ${ZLIB_LIB_RELEASE}/zlibstatic.lib)
endif()
if (WITH_TESTS)
ADD_SUBDIRECTORY (tests/sortmerna)
endif ()
#find_package(zlib REQUIRED)
#option(WITH_MD_LIBRARY "build with MD" ON)
#if(WIN32 AND MSVC)
# if(WITH_MD_LIBRARY)
# set(RUNTIME_LIBRARY "MD")
# else()
# set(RUNTIME_LIBRARY "MT")
# endif()
#endif()
#ExternalProject_Add(zlib
# DOWNLOAD_COMMAND C:/a03_libs/git-2.12.2-x64/bin/git clone --depth 1 https://github.com/madler/zlib
# UPDATE_COMMAND C:/a03_libs/git-2.12.2-x64/bin/git pull
# DOWNLOAD_DIR ${EXTERNAL_DEPS_ROOT} # seems DOWNLOAD_DIR only works with DOWNLOAD_COMMAND. Ignored with GIT_REPOSITORY
# GIT_REPOSITORY https://github.com/madler/zlib
# GIT_SHALLOW 1
# CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${EXTERNAL_DEPS_ROOT}
#)
#include_directories(${EXTERNAL_DEPS_ROOT}/include)
#link_directories(${EXTERNAL_DEPS_ROOT}/lib)
#add_executable(FirstTest main.cpp)
#add_dependencies(FirstTest googletest)
#target_link_libraries(FirstTest gtest gtest_main pthread)