-
Notifications
You must be signed in to change notification settings - Fork 5
/
CMakeLists.txt
225 lines (193 loc) · 8.84 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
project(jive5ab CXX ASM)
cmake_minimum_required (VERSION 2.6.0)
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
include(CheckCXXCompilerFlag)
include(TargetArch)
# we sure need those
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
# Debug/Release builds. Set a default build type if none given
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
if(NOT CMAKE_BUILD_TYPE STREQUAL "Release")
set(PROJECT_VERSION_BUILD "-dev")
else()
set(PROJECT_VERSION_BUILD "")
endif()
set(PROJECT_VERSION_MAJOR 3)
set(PROJECT_VERSION_MINOR 1)
set(PROJECT_VERSION_PATCH 0)
set(PROJECT_VERSION_REVISION 0)
set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}${PROJECT_VERSION_BUILD}")
SET(CMAKE_SKIP_RPATH TRUE)
# get the target architecture
target_architecture(TARGET_ARCH)
# Prepare the BUILDINFO string
execute_process(
COMMAND bash "-c" "echo \"`hostname` : `date '+%d-%b-%Y : %Hh%Mm%Ss'`\""
OUTPUT_VARIABLE BUILDINFO
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND bash "-c" "date '+%d-%b-%Y %Hh%Mm%Ss'"
OUTPUT_VARIABLE DATE
OUTPUT_STRIP_TRAILING_WHITESPACE
)
#option(BUILD_SHARED_LIBS "Build shared library(ies)" ON)
# Set policy to allow "ON" to appear in an if() statement
cmake_policy(SET CMP0012 NEW)
# Set policy to require CMakeLists.txt in every source directory
cmake_policy(SET CMP0014 NEW)
# https://cmake.org/cmake/help/latest/policy/CMP0022.html#policy:CMP0022
#cmake_policy(SET CMP0022 OLD)
# https://cmake.org/cmake/help/latest/policy/CMP0074.html
if(POLICY CMP0074)
cmake_policy(SET CMP0074 NEW)
endif(POLICY CMP0074)
# MACOS_RPATH
if(POLICY CMP0042)
cmake_policy(SET CMP0042 NEW)
endif(POLICY CMP0042)
# RPATH handling - for 3rd party dependencies we want to retain
# the link path in the RPATH thank you very much
#set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
# control the c++ standard to force the compilert to use
# default to 'ansi' (which is an alias for "-std=c++98")
set(CXXSTANDARD "-ansi")
option(C++11 "Force compilation using C++11 standard" OFF)
if(${C++11})
set(CXXSTANDARD "-std=c++11")
endif()
# We (that is "I") like to turn up warnings & errors to insanity level
set(INSANITY_FLAGS -pthread -Wall -W -Werror -Wextra -pedantic -Wcast-qual -Wwrite-strings -Wredundant-decls -Wfloat-equal -Wshadow)
set(INSANITY_DEFS _REENTRANT _POSIX_PTHREAD_SEMANTICS __STDC_FORMAT_MACROS _FILE_OFFSET_BITS=64)
# We cannot compile with those options (below) (_POSIX_C_SOURCE && _XOPEN_SOURCE)
# because then we loose IP_ADD_MEMBERSHIP, struct ip_mreq for multicast
# support; POSIX does not define those.
# Also, on MacOSX then mountpoint.cc triggers inclusion of a header which
# claims to have no definitions for u_long (and some other types) such that
# another internal struct has an incomplete definition.
#set(INSANITY_DEFS _REENTRANT _POSIX_PTHREAD_SEMANTICS __STDC_FORMAT_MACROS _FILE_OFFSET_BITS=64 _POSIX_C_SOURCE=200809L _XOPEN_SOURCE=700)
# It's nice that people suggest using "modern stuff(tm)" like YOU SHOULD USE add_compile_definitions()
# and shite like target properties. But if you need to use a cmake that doesn't have that you're pretty much
# stuffed are you? FFS.
#add_compile_options(-ansi -Wall -W -Werror -Wextra -pedantic -Wcast-qual -Wwrite-strings -Wredundant-decls -Wfloat-equal -Wshadow)
#add_compile_definitions(_REENTRANT _POSIX_PTHREAD_SEMANTICS __STDC_FORMAT_MACROS _FILE_OFFSET_BITS=64)
# we want to have options for:
# FILA specific option
option(FILA10G "Limit recording of UDP packets to support only FiLa10G-Mark5B output" OFF)
if(${FILA10G})
set(FILA "-FiLa10G")
list(APPEND INSANITY_DEFS FILA=1)
#add_compile_definitions(FILA=1)
endif()
# DEBUG
# handled through "-DCMAKE_BUILD_TYPE=Debug"
# SSE=20,41
# do autodetection
if(NOT DEFINED SSE)
execute_process(
COMMAND sh "-c" "if [ -f /proc/cpuinfo ]; then if [ -n \"`grep sse4_1 /proc/cpuinfo`\" ]; then echo \"41\"; else echo \"20\"; fi; else echo \"0\"; fi;"
OUTPUT_VARIABLE SSE
OUTPUT_STRIP_TRAILING_WHITESPACE
)
endif(NOT DEFINED SSE)
# For the assembler
# Debian Wheezy has cmake 2.9 (WTF 8-/)
# which does NOT have string concat, append FFS
#string(APPEND CMAKE_ASM_FLAGS " -DSSE=${SSE}")
set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -DSSE=${SSE}")
# These should be handled by cmake/Find{SSAPI,ETRANSFER}.cmake
# NOSSAPI, SSAPIROOT/WDAPIVER
# use -DSSAPI_ROOT=/path/to/ssapi [-DWDAPIVER=XXX]
find_package(SSAPI REQUIRED)
# ETRANSFER
# Use -DETRANSFER_ROOT=/path/to/etransfer-github-clone
find_package(Etransfer)
# ETRANSFER, if enabled, may force c++11 standard so
# only now it's safe to append the c++ standard to the flags
list(APPEND INSANITY_FLAGS ${CXXSTANDARD})
#string(APPEND CMAKE_C_FLAGS " -Wbad-function-cast -Wstrict-prototypes")
#string(APPEND CMAKE_CXX_FLAGS " -Wno-long-long -Wno-unused-function")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wbad-function-cast -Wstrict-prototypes")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-long-long -Wno-unused-function")
# OpenBSD system headers redeclare the same stuff many times ...
if(${CMAKE_SYSTEM_NAME} STREQUAL "OpenBSD")
#string(APPEND CMAKE_C_FLAGS " -Wno-redundant-decls")
#string(APPEND CMAKE_CXX_FLAGS " -Wno-redundant-decls")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-redundant-decls")
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -Wno-redundant-decls")
endif()
# In order to make really sure that _GNU_SOURCE is *un*defined
# (we don't want no gnu-isms in our code), we must literally
# put this sequence on the compiler command line:
# -D_GNU_SOURCE -U_GNU_SOURCE
# Unfortunately, under Linux, doing this breaks everything.
# Defining _POSIX_C_SOURCE/_XOPEN_SOURCE helps but then
# *other* stuff breaks (see above, loss of IP multicast). Sigh.
# But on e.g. MacOSX it's fine to do so so we do - avoiding GNU-isms
# wherever possible.
if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
set(UNDEF_GNU_SOURCE "-D_GNU_SOURCE -U_GNU_SOURCE")
endif(NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
set(CMAKE_C_FLAGS_RELEASE "-O2 ${UNDEF_GNU_SOURCE}")
set(CMAKE_CXX_FLAGS_RELEASE "-O2 ${UNDEF_GNU_SOURCE}")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -g ${UNDEF_GNU_SOURCE}")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g ${UNDEF_GNU_SOURCE}")
set(CMAKE_C_FLAGS_DEBUG "-O0 -g -DGDBDEBUG=1 ${UNDEF_GNU_SOURCE}")
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g -DGDBDEBUG=1 ${UNDEF_GNU_SOURCE}")
# forcing 32/64 bit build
# experienced jive5ab builders will use B2B=32 or B2B=64
# but we cannot honour that the same way with cmake.
# So let's error out and inform users that things have changed.
if(DEFINED B2B)
message(FATAL_ERROR "Passing B2B=[32|64] as option is not supported anymore. Use:
CFLAGS=-m32 CXXFLAGS=-m32 cmake [options] /path/to/here
to force a 32-bit build")
endif()
# do this:
# $>CFLAGS=-m32 CXXFLAGS=-m32 [/path/to/]cmake [options] /path/to/jive5ab
# to enable 32-bit builds
# NOTE: cmake doesn't honour ASFLAGS (nor CMAKE_ASM_FLAGS) so running
# CFLAGS=-m32 CXXFLAGS=-m32 (AS|CMAKE_ASM_)FLAGS=-m32 cmake [options] /path/to/here
# doesn't work. Thanks guys!
if(${CMAKE_SIZEOF_VOID_P} EQUAL 4)
set(B2B "32")
#add_compile_definitions(B2B=32)
list(APPEND INSANITY_DEFS B2B=32)
#string(APPEND CMAKE_ASM_FLAGS " -m32")
set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -m32")
elseif(${CMAKE_SIZEOF_VOID_P} EQUAL 8)
set(B2B "64")
#add_compile_definitions(B2B=64)
list(APPEND INSANITY_DEFS B2B=64)
#string(APPEND CMAKE_ASM_FLAGS " -m64")
set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -m64")
else()
message(FATAL_ERROR "Your machine does not have 32- or 64-bit pointers, it's ${CMAKE_SIZEOF_VOID_P}!")
endif()
add_subdirectory(libudt5ab)
add_subdirectory(src)
add_subdirectory(scripts)
# CPack / Debian package generator stuff
set(CPACK_GENERATOR "DEB")
set(CPACK_PACKAGE_VENDOR "Joint Institute for VLBI - ERIC")
set(CPACK_DEBIAN_PACKAGE_DEBUG)
# the project version is NOT taken over (as advertised)
set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
set(CPACK_DEBIAN_PACKAGE_VERSION ${PROJECT_VERSION})
set(CPACK_DEBIAN_PACKAGE_DESCRIPTION "JIVE's Mark5A/B/C/6, FlexBuff control s/w")
set(CPACK_DEBIAN_PACKAGE_SECTION "contrib")
set(CPACK_DEBIAN_FILE_NAME "DEB-DEFAULT")
# Following trick found in
# https://www.guyrutenberg.com/2012/07/19/auto-detect-dependencies-when-building-debs-using-cmake/
# to have CPack generate the "Depends:" section automatically
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "verkouter@jive.eu") #required
set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/debian/postinst;${CMAKE_CURRENT_SOURCE_DIR}/cmake/debian/preinst;"
)
set(CPACK_DEBIAN_PACKAGE_BUILDS_DEPENDS "debhelper (>> 5.0.0), g++")
include(CPack)
message("Configuration: ${PROJECT_VERSION} ${CMAKE_BUILD_TYPE} WDAPI=${WDAPIVER} SSE=${SSE} FILA=${FILA}")