forked from Opendigitalradio/ka9q-fec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
324 lines (273 loc) · 8.92 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
########################################################################
# Project setup
########################################################################
cmake_minimum_required(VERSION 2.8)
project(libfec ASM C)
option(BUILD_32BIT_ON_64BIT "Build a 32-bit library on a 64-bit system" OFF)
# Select the release build type by default to get optimization flags
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
message(STATUS "Build type not specified: defaulting to release.")
endif(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} CACHE STRING "")
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/Modules)
if(NOT LIB_INSTALL_DIR)
set(LIB_INSTALL_DIR lib)
endif()
########################################################################
# Version information
########################################################################
set(VERSION_INFO_MAJOR 3)
set(VERSION_INFO_MINOR 0)
set(VERSION_INFO_PATCH 0)
if(NOT DEFINED VERSION_INFO_EXTRA)
set(VERSION_INFO_EXTRA "git")
endif()
include(Version)
if(NOT DEFINED VERSION)
#set(VERSION "\"${VERSION_INFO_MAJOR}.${VERSION_INFO_MINOR}.${VERSION_INFO_PATCH}\"")
set(VERSION "\"${VERSION_INFO}\"")
endif()
########################################################################
# Compiler specific setup
########################################################################
if(BUILD_32BIT_ON_64BIT)
set(CMAKE_SYSTEM_PROCESSOR "i386")
set(CMAKE_SIZEOF_VOID_P 4)
set(CMAKE_C_FLAGS -m32)
set(CMAKE_CXX_FLAGS -m32)
add_definitions(-m32)
endif()
if((CMAKE_SYSTEM_PROCESSOR MATCHES "i386|i686|x86|AMD64") AND (CMAKE_SIZEOF_VOID_P EQUAL 4))
set(TARGET_ARCH "x86")
elseif((CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|AMD64") AND (CMAKE_SIZEOF_VOID_P EQUAL 8))
set(TARGET_ARCH "x64")
elseif((CMAKE_SYSTEM_PROCESSOR MATCHES "i386") AND (CMAKE_SIZEOF_VOID_P EQUAL 8) AND (APPLE))
# Mac is weird like that.
set(TARGET_ARCH "x64")
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^arm*")
set(TARGET_ARCH "ARM")
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(powerpc|ppc)64le")
set(TARGET_ARCH "ppc64" "ppc64le")
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(powerpc|ppc)64")
set(TARGET_ARCH "ppc64" "ppc")
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(powerpc|ppc)")
set(TARGET_ARCH "ppc")
endif()
if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANGCC)
add_definitions(-Wall)
add_definitions(-Wno-unused)
if(TARGET_ARCH MATCHES "x64")
add_definitions(-fPIC)
add_definitions(-msse2)
elseif(TARGET_ARCH MATCHES "x86")
add_definitions(-mmmx)
add_definitions(-msse)
add_definitions(-msse2)
elseif(TARGET_ARCH MATCHES "ppc|ppc64")
add_definitions(-fno-common)
add_definitions(-faltivec)
endif()
endif()
########################################################################
# Find build dependencies
########################################################################
# libm
find_library(M_LIB m REQUIRED)
########################################################################
# config.h
########################################################################
#add_definitions(-DHAVE_CONFIG_H)
# Checks for includes
include(CheckIncludeFile)
check_include_file("getopt.h" HAVE_GETOPT_H)
check_include_file("stdio.h" HAVE_STDIO_H)
check_include_file("stdlib.h" HAVE_STDLIB_H)
check_include_file("memory.h" HAVE_MEMORY_H)
check_include_file("string.h" HAVE_STRING_H)
# Checks for functions
include(CheckFunctionExists)
check_function_exists("getopt_long" HAVE_GETOPT_LONG)
check_function_exists("memset" HAVE_MEMSET)
check_function_exists("memmove" HAVE_MEMMOVE)
########################################################################
# Setup apps
########################################################################
if(TARGET_ARCH MATCHES "x64")
list(APPEND libfec_sources
dotprod_port.c
peakval_port.c
sumsq.c
sumsq_port.c
cpu_mode_x86_64.c
##asm
#sse2bfly27-64.s
#sse2bfly29-64.s
)
elseif(TARGET_ARCH MATCHES "x86")
list(APPEND libfec_sources
viterbi27_mmx.c
viterbi27_sse.c
viterbi27_sse2.c
viterbi29_mmx.c
viterbi29_sse.c
viterbi29_sse2.c
viterbi39_sse2.c
viterbi39_sse.c
viterbi39_mmx.c
viterbi615_mmx.c
viterbi615_sse.c
viterbi615_sse2.c
dotprod_mmx.c
dotprod_sse2.c
#peakval_mmx.c
#peakval_sse.c
#peakval_sse2.c
sumsq.c
sumsq_port.c
sumsq_sse2.c
sumsq_mmx.c
cpu_mode_x86.c
#asm
cpu_features.s
dotprod_mmx_assist.s
dotprod_sse2_assist.s
mmxbfly27.s
mmxbfly29.s
peak_mmx_assist.s
peak_sse2_assist.s
peak_sse_assist.s
peakval_mmx_assist.s
peakval_sse2_assist.s
peakval_sse_assist.s
sse2bfly27.s
sse2bfly29.s
ssebfly27.s
ssebfly29.s
sumsq_mmx_assist.s
sumsq_sse2_assist.s
)
elseif(TARGET_ARCH MATCHES "ppc|ppc64")
list(APPEND libfec_sources
viterbi27_av.c
viterbi29_av.c
viterbi39_av.c
viterbi615_av.c
encode_rs_av.c
dotprod_av.c
sumsq_av.c
peakval_av.c
cpu_mode_ppc.c
)
else()
list(APPEND libfec_sources
cpu_mode_generic.c
)
endif()
list(APPEND libfec_sources
fec.c
sim.c
viterbi27.c
viterbi27_port.c
viterbi29.c
viterbi29_port.c
viterbi39.c
viterbi39_port.c
viterbi615.c
viterbi615_port.c
encode_rs_char.c
encode_rs_int.c
encode_rs_8.c
decode_rs_char.c
decode_rs_int.c
decode_rs_8.c
init_rs_char.c
init_rs_int.c
encode_rs_ccsds.c
decode_rs_ccsds.c
dotprod.c
dotprod_port.c
peakval.c
peakval_port.c
sumsq.c
sumsq_port.c
ccsds_tab.c
ccsds_tal.c
)
################################################################################
# Generate pkg-config file
################################################################################
foreach(inc ${LIBFEC_INCLUDE_DIR})
list(APPEND LIBFEC_PC_CFLAGS "-I${inc}")
endforeach()
foreach(lib ${LIBFEC_LIBRARY_DIRS})
list(APPEND LIBFEC_PC_PRIV_LIBS "-L${lib}")
endforeach()
set(LIBFEC_PC_PREFIX ${CMAKE_INSTALL_PREFIX})
set(LIBFEC_PC_EXEC_PREFIX \${prefix})
set(LIBFEC_PC_LIBDIR \${exec_prefix}/${LIB_INSTALL_DIR})
set(LIBFEC_PC_INCLUDEDIR \${prefix}/include)
set(LIBFEC_PC_VERSION ${VERSION})
set(LIBFEC_PC_LIBS "-lfec")
# Use space-delimiter in the .pc file, rather than CMake's semicolon separator
string(REPLACE ";" " " LIBFEC_PC_CFLAGS "${LIBFEC_PC_CFLAGS}")
string(REPLACE ";" " " LIBFEC_PC_LIBS "${LIBFEC_PC_LIBS}")
# Unset these to avoid hard-coded paths in a cross-environment
if(CMAKE_CROSSCOMPILING)
unset(LIBFEC_PC_CFLAGS)
unset(LIBFEC_PC_LIBS)
endif()
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/libfec.pc.in
${CMAKE_CURRENT_BINARY_DIR}/libfec.pc
@ONLY
)
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/libfec.pc
DESTINATION ${LIB_INSTALL_DIR}/pkgconfig/
)
########################################################################
# Setup libraries
########################################################################
# generate ccsds_tab.c
add_executable(gen_ccsds gen_ccsds.c init_rs_char.c)
add_custom_command(
OUTPUT ${CMAKE_BINARY_DIR}/ccsds_tab.c
COMMAND ${CMAKE_BINARY_DIR}/gen_ccsds > ccsds_tab.c
DEPENDS gen_ccsds
)
# generate ccsds_tal.c
add_executable(gen_ccsds_tal gen_ccsds_tal.c)
add_custom_command(
OUTPUT ${CMAKE_BINARY_DIR}/ccsds_tal.c
COMMAND ${CMAKE_BINARY_DIR}/gen_ccsds_tal > ccsds_tal.c
DEPENDS gen_ccsds_tal
)
# libfec
add_library(libfec_shared SHARED ${libfec_sources})
set_target_properties(libfec_shared PROPERTIES OUTPUT_NAME fec)
set_target_properties(libfec_shared PROPERTIES SOVERSION ${VERSION_INFO_MAJOR})
target_link_libraries(libfec_shared ${M_LIB})
install(TARGETS libfec_shared
DESTINATION ${LIB_INSTALL_DIR})
install(FILES "${PROJECT_SOURCE_DIR}/fec.h"
DESTINATION include)
########################################################################
# Create uninstall target
########################################################################
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY)
add_custom_target(uninstall
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
########################################################################
# Print Summary
########################################################################
message(STATUS "")
message(STATUS "##########################################################")
message(STATUS "## Building for version: ${VERSION}")
message(STATUS "## Target Architecture: ${TARGET_ARCH}")
message(STATUS "## Using install prefix: ${CMAKE_INSTALL_PREFIX}")
message(STATUS "##########################################################")
message(STATUS "")