-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
340 lines (290 loc) · 12.9 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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
cmake_minimum_required(VERSION 3.0)
project(AliStat)
set(CPACK_PACKAGE_VERSION "1.15")
###############################################################################
## file globbing ##############################################################
###############################################################################
file(GLOB_RECURSE sources src/*.cpp src/*.h)
###############################################################################
## target definitions #########################################################
###############################################################################
add_executable(alistat ${sources})
target_compile_options(alistat PUBLIC -std=c++1y -Wall -Wfloat-conversion)
# this lets me include files relative to the root source directory with a <> pair
target_include_directories(alistat PUBLIC src)
##################################################################
# Detect target platforms
##################################################################
if (WIN32)
message("Target OS : Windows")
# build as static binary to run on most machines
if (ALISTAT_FLAGS MATCHES "static")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static")
endif()
SET(CMAKE_FIND_LIBRARY_SUFFIXES .lib .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
elseif (APPLE)
message("Target OS : Mac OS X")
if(OSX_NATIVE_ARCHITECTURE STREQUAL "arm64")
add_definitions("--target=arm64-apple-macos10.5")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --target=arm64-apple-macos12.0.1")
else()
# to be compatible back to Mac OS X 10.7
if (ALISTAT_FLAGS MATCHES "oldmac")
add_definitions("-mmacosx-version-min=10.5")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -mmacosx-version-min=10.5")
else()
add_definitions("--target=x86_64-apple-macos10.7")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --target=x86_64-apple-macos10.7")
endif()
endif()
SET(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
elseif (UNIX)
message("Target OS : Unix")
# build as static binary to run on most machines
if (NOT ALISTAT_FLAGS MATCHES "static")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -rdynamic")
else()
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static")
endif()
else()
# Note that IQ-TREE has NOT been tested on other platforms
message("Target OS : Unknown and untested yet")
endif()
##################################################################
# Setup compiler, currently supported GCC, CLANG, MSVC, and ICC
##################################################################
set(GCC "FALSE") # GNU compiler
set(CLANG "FALSE") # Clang compiler
set(ICC "FALSE") # Intel compiler
set(VCC "FALSE") # MS Visual C Compiler, note that it is different from MSVC variable
set(CLANG_UNDER_VS "FALSE") #Clang compiler, used from inside Visual Studio
# using C++11 standard
# disable AVX for NEON
if (__ARM_NEON)
set(ALISTAT_FLAGS "${ALISTAT_FLAGS} novx")
elseif (CMAKE_CXX_COMPILER MATCHES "VISUAL STUDIO")
set(CLANG_UNDER_VS "TRUE")
#it won't recognize the -std=c++11 parameter.
#Todo: don't hard-code this; figure out some way it can be passed in (though ideally, not the whole shebang).
include_directories("C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\Llvm\\lib\\clang\\10.0.0\\include")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
endif()
if (CMAKE_COMPILER_IS_GNUCXX)
message("Compiler : GNU Compiler (gcc)")
set(GCC "TRUE")
# set(COMBINED_FLAGS "-Wall -Wno-unused-function -Wno-sign-compare -pedantic -D_GNU_SOURCE -fms-extensions -Wno-deprecated")
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -g -ffunction-sections -fdata-sections")
set(CMAKE_C_FLAGS_RELEASE "-O2 -g -ffunction-sections -fdata-sections")
if (APPLE)
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} -Wl,-dead_strip")
else()
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} -Wl,--gc-sections")
endif()
# require at least gcc ${GCC_MIN_VERSION}
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS GCC_MIN_VERSION)
message(FATAL_ERROR "GCC version must be at least ${GCC_MIN_VERSION}!")
endif()
if (WIN32)
# disable AVX on Windows due to memory alignment
set(ALISTAT_FLAGS "${ALISTAT_FLAGS} novx")
message("WARNING: AVX is disabled on Windows as GCC does not properly suport memory alignment")
endif()
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
message("Compiler : Clang")
set(CLANG "TRUE")
# set(COMBINED_FLAGS "-Wall -Wno-unused-function -Wno-sign-compare -pedantic -D_GNU_SOURCE -Wno-nested-anon-types")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -ffunction-sections -fdata-sections")
set(CMAKE_C_FLAGS_RELEASE "-O3 -ffunction-sections -fdata-sections")
if (APPLE)
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} -Wl,-dead_strip")
else()
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} -Wl,--gc-sections")
endif()
# use libc++ per default in MacOS
if (APPLE)
SET(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libc++")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
endif()
#remove -rdynamic for Clang under Linux
if (UNIX AND ALISTAT_FLAGS MATCHES "static")
SET(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS)
endif()
elseif (CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
set(VCC "TRUE")
message("Compiler : MS Visual C++ Compiler")
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Intel")
message("Compiler : Intel C++ Compiler (icc)")
set(ICC "TRUE")
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Qstd=c99")
else()
message("Compiler : Unknown and untested yet")
endif()
message("Compiler version: ${CMAKE_CXX_COMPILER_VERSION}")
set(EXE_SUFFIX "")
if (MSVC)
# MS Visual Studio environment
message("Exporting MS Visual Studio projects...")
if (CLANG_UNDER_VS)
#see https://clang.llvm.org/docs/UsersManual.html#clang-cl
#note .GX is how you say -fexceptions
add_definitions(/D_UWIN)
set(CMAKE_C_FLAGS_RELEASE "/O2 /GX")
set(CMAKE_C_FLAGS_DEBUG "/D_UWIN /GX")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /I${EIGEN3_INCLUDE_DIR}")
else()
add_definitions(/MP) # enable multi-processor compilation
endif()
if (CMAKE_BUILD_TYPE STREQUAL "Release")
add_definitions(/Ot /Oi)
if (VCC)
add_definitions(/O2)
elseif (ICC)
add_definitions(/O3)
endif()
endif()
endif()
# enable link time optimization
if (ALISTAT_FLAGS MATCHES "lto")
#if (CLANG)
# set(COMBINED_FLAGS "${COMBINED_FLAGS} -flto=thin")
#else()
set(COMBINED_FLAGS "${COMBINED_FLAGS} -flto")
#endif()
endif()
##################################################################
# Setup compiler flags
##################################################################
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COMBINED_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMBINED_FLAGS}")
set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS} -fno-inline-functions -fno-inline-functions-called-once -fno-optimize-sibling-calls -fno-default-inline -fno-inline -O2 -fno-omit-frame-pointer -g")
set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS} -fno-inline-functions -fno-inline-functions-called-once -fno-optimize-sibling-calls -O2 -fno-omit-frame-pointer -g")
if(CLANG AND ALISTAT_FLAGS MATCHES "static")
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pthread -Wl,--allow-multiple-definition")
endif()
if (ALISTAT_FLAGS MATCHES "libcxx")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
endif()
if (CMAKE_BUILD_TYPE STREQUAL "Release")
message("C flags : ${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_RELEASE}")
message("CXX flags : ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELEASE}")
endif()
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
message("C flags : ${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_DEBUG}")
message("CXX flags : ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_DEBUG}")
endif()
if (CMAKE_BUILD_TYPE STREQUAL "Profile")
message("C flags : ${CMAKE_C_FLAGS_PROFILE} ")
message("CXX flags : ${CMAKE_CXX_FLAGS_PROFILE} ")
endif()
message("LINKER flags : ${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_EXE_LINKER_FLAGS_RELEASE}")
if (GCC)
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g -fno-inline-functions -fno-inline-functions-called-once -fno-default-inline -fno-inline")
set(CMAKE_C_FLAGS_DEBUG "-O0 -g -fno-inline-functions -fno-inline-functions-called-once -fno-default-inline -fno-inline")
set(CMAKE_CXX_FLAGS_MEM "-g -O1")
set(CMAKE_C_FLAGS_MEM "-g -O1")
elseif (CLANG AND NOT CLANG_UNDER_VS)
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g -fno-inline-functions -fno-inline")
set(CMAKE_C_FLAGS_DEBUG "-O0 -g -fno-inline-functions -fno-inline")
set(CMAKE_CXX_FLAGS_MEM "-g -O1")
set(CMAKE_C_FLAGS_MEM "-g -O1")
endif()
##################################################################
# setup linking flags
##################################################################
# link special lib for WIN32
if (WIN32)
set(PLATFORM_LIB "ws2_32")
else()
set(PLATFORM_LIB "m")
endif()
if (ALISTAT_FLAGS MATCHES "libcxx")
set(STD_LIB "c++abi")
endif()
set(THREAD_LIB "")
if (NOT ALISTAT_FLAGS MATCHES "single")
if (MSVC)
if (BINARY32)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /LIBPATH:${PROJECT_SOURCE_DIR}/lib32")
set(THREAD_LIB "pthreadVC2")
else()
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /LIBPATH:${PROJECT_SOURCE_DIR}/lib")
set(THREAD_LIB "pthreadVC2")
endif()
elseif(CLANG AND WIN32)
if (BINARY32)
target_link_libraries(alistat ${PROJECT_SOURCE_DIR}/lib32/libiomp5md.dll)
else()
target_link_libraries(alistat ${PROJECT_SOURCE_DIR}/lib/libiomp5md.dll)
endif()
# set(THREAD_LIB "ompstatic")
endif()
if (CLANG AND BINARY32)
set (ATOMIC_LIB "atomic")
endif()
endif()
# basic linking libraries
target_link_libraries(alistat PUBLIC ${PLATFORM_LIB} ${STD_LIB} ${THREAD_LIB} ${ATOMIC_LIB})
##############################################################
# add the install targets
##############################################################
install (TARGETS alistat DESTINATION bin)
install (FILES "${PROJECT_SOURCE_DIR}/test.fas" DESTINATION examples)
install (FILES "${PROJECT_SOURCE_DIR}/M_Ento.fas" DESTINATION examples)
install (FILES "${PROJECT_SOURCE_DIR}/M_Ento.partition" DESTINATION examples)
install (FILES "${PROJECT_SOURCE_DIR}/AliStat_manual.pdf" DESTINATION .)
if (WIN32)
install (FILES "${BINARY_DIR}/alistat${EXE_SUFFIX}-click.exe" DESTINATION bin)
if (NOT ALISTAT_FLAGS MATCHES "single" AND MSVC)
if (BINARY32)
install(FILES "${PROJECT_SOURCE_DIR}/lib32/pthreadVC2.dll" DESTINATION bin)
install(FILES "${PROJECT_SOURCE_DIR}/lib32/libiomp5md.dll" DESTINATION bin)
else()
install(FILES "${PROJECT_SOURCE_DIR}/lib/pthreadVC2.dll" DESTINATION bin)
install(FILES "${PROJECT_SOURCE_DIR}/lib/libiomp5md.dll" DESTINATION bin)
endif()
# install(FILES "${PROJECT_SOURCE_DIR}/lib/pthreadGC2.dll" DESTINATION bin)
# install(FILES "${PROJECT_SOURCE_DIR}/lib/pthreadGC2_64.dll" DESTINATION bin)
endif()
if (NOT ALISTAT_FLAGS MATCHES "single" AND CLANG)
if (BINARY32)
install(FILES "${PROJECT_SOURCE_DIR}/lib32/libiomp5md.dll" DESTINATION bin)
else()
install(FILES "${PROJECT_SOURCE_DIR}/lib/libiomp5md.dll" DESTINATION bin)
endif()
endif()
endif()
###############################################################################
## packaging ##################################################################
###############################################################################
include (InstallRequiredSystemLibraries)
set (CPACK_RESOURCE_FILE_LICENSE
"${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
if(WIN32 OR APPLE)
set(CPACK_GENERATOR "ZIP")
set(CPACK_SOURCE_GENERATOR "ZIP")
else()
set(CPACK_GENERATOR "TGZ")
set(CPACK_SOURCE_GENERATOR "TGZ")
endif()
set (SYSTEM_NAME "${CMAKE_SYSTEM_NAME}")
if (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
if (ALISTAT_FLAGS MATCHES "oldmac")
set (SYSTEM_NAME "MacOS10.5")
else()
set (SYSTEM_NAME "MacOSX")
endif()
endif()
if (BINARY32)
set (SYSTEM_NAME "${SYSTEM_NAME}32")
endif()
if (ALISTAT_FLAGS MATCHES "KNL")
set (SYSTEM_NAME "${SYSTEM_NAME}KNL")
endif()
set(CPACK_PACKAGE_FILE_NAME
"${CMAKE_PROJECT_NAME}${EXE_SUFFIX}-${CPACK_PACKAGE_VERSION}-${SYSTEM_NAME}")
if (NOT APPLE)
set(CPACK_STRIP_FILES TRUE)
endif()
include(CPack)