-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
173 lines (109 loc) · 4.13 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
project(analysis)
cmake_minimum_required (VERSION 3.0)
# extra cmake modules
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
#########################################
# project global c/c++ compiler settings
#########################################
# common to both c & c++ flags
set(MY_ALL_FLAGS "-Wall -O3 -march=native")
# c++ only
set(MY_CXX_FLAGS "-std=c++14")
# c only
set(MY_C_FLAGS "-std=c11")
# is future namespace wizardy allowed?
# YES: set(MY_CXX_FLAGS "-Wc++1z-extensions")
############################################
# compiler specific project wide defintions
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# TODO for clang these are clang specific
# set(MY_CXX_FLAGS "-Rpass=.*") # have clang show optimizations
# set(MY_CXX_FLAGS "-fsanitize=address") doesn't work with apple 3.6 compiler!
set(MY_ALL_FLAGS "${MY_ALL_FLAGS} -funroll-loops -fvectorize -fslp-vectorize")
endif()
######################################################################
# we use think different threading backends on Darwin derived systems
# also we probe what cpu features we can exploit...
set(CPU_FEATURES)
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
#######################################################
# OS X/XNU specific configuration - should work for iOS
message(STATUS "Will compile for Blocks/GCD and other Apple sweetness...")
set(HAVE_DISPATCH 1)
set(MY_CXX_FLAGS "${MY_CXX_FLAGS} -stdlib=libc++")
set(CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS} "-stdlib=libc++")
exec_program("sysctl -n machdep.cpu.features" OUTPUT_VARIABLE CPU_FEATURES)
else()
###############################
# Use openmp on non OSX Systems
find_package(OpenMP REQUIRED)
if (OPENMP_FOUND)
message(STATUS "OpenMP is configured")
set(HAVE_OPENMP 1)
set(MY_ALL_FLAGS "${MY_ALL_FLAGS} -fopenmp")
set(MY_C_FLAGS "${MY_C_FLAGS} ${OpenMP_C_FLAGS}")
set(MY_CXX_FLAGS "${MY_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
# linker needs openmp library
set(CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS})
# find Threads package
find_package(Threads REQUIRED)
# pthreads?
if (CMAKE_USE_PTHREADS_INIT)
set(MY_CXX_FLAGS "${MY_CXX_FLAGS} -pthread")
endif()
# linker needs thread library
set(CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_THREAD_LIBS_INIT})
# inspect CPUINFO
file(READ "/proc/cpuinfo" _cpuinfo)
string(REGEX REPLACE ".*flags[ \t]*:[ \t]+([a-zA-Z0-9_ ]+).*" "\\1" CPU_FEATURES "${_cpuinfo}")
endif()
endif()
##############################
# Now set the CXX and C FLAGS
set(CMAKE_CXX_FLAGS "${MY_CXX_FLAGS} ${MY_ALL_FLAGS}")
set(CMAKE_C_FLAGS "${MY_C_FLAGS} ${MY_ALL_FLAGS}")
# let's see
message(${CMAKE_CXX_FLAGS})
message(${CMAKE_C_FLAGS})
# normalise CPU features before searching
string(TOUPPER ${CPU_FEATURES} CPU_FEATURES)
# these can now be searched and further optimizations applied
# of course this is only relevant to host compilation
message(${CPU_FEATURES})
# ...
#######################
# now the actual build
#######################
include_directories(.)
# boost
find_package(Boost REQUIRED COMPONENTS program_options)
include_directories (${Boost_INCLUDE_DIR})
# eigen
find_package(Eigen3 REQUIRED)
include_directories(${EIGEN3_INCLUDE_DIR})
#####################
# command line tools
# deprecated monolith
#add_executable (feature_space feature_space.cpp)
#target_link_libraries(feature_space ${Boost_LIBRARIES})
# get samples into sparse cooc matrix
add_executable (samples2cooc samples2cooc.cpp)
# logl from cooc
add_executable (cooc2logl cooc2logl.cpp)
target_link_libraries(cooc2logl ${Boost_LIBRARIES})
# logl filter
add_executable (loglfilter loglfilter.cpp)
target_link_libraries(loglfilter ${Boost_LIBRARIES})
# cosine scores
add_executable (AB_cosine AB_cosine.cpp)
target_link_libraries(AB_cosine ${Boost_LIBRARIES})
# feature space inspector
add_executable (show_features show_features.cpp)
# matrix inspector
add_executable (showmat showmat.cpp)
# matrix dump
add_executable (dumpmat dumpmat.cpp)
# test io
add_executable (testio testio.cpp)
# matrix convert to matrix market
add_executable (mat2mtx mat2mtx.cpp)