Felix Weinrank | 71be071 | 2015-08-26 13:52:37 +0200 | [diff] [blame] | 1 | # |
| 2 | # Copyright (C) 2015-2015 Oleg Alexeenkov |
Felix Weinrank | 2718a59 | 2019-07-30 11:44:35 +0200 | [diff] [blame] | 3 | # Copyright (C) 2015-2019 Felix Weinrank |
Felix Weinrank | 71be071 | 2015-08-26 13:52:37 +0200 | [diff] [blame] | 4 | # |
| 5 | # All rights reserved. |
| 6 | # |
| 7 | # Redistribution and use in source and binary forms, with or without |
| 8 | # modification, are permitted provided that the following conditions |
| 9 | # are met: |
| 10 | # 1. Redistributions of source code must retain the above copyright |
| 11 | # notice, this list of conditions and the following disclaimer. |
| 12 | # 2. Redistributions in binary form must reproduce the above copyright |
| 13 | # notice, this list of conditions and the following disclaimer in the |
| 14 | # documentation and/or other materials provided with the distribution. |
| 15 | # 3. Neither the name of the project nor the names of its contributors |
| 16 | # may be used to endorse or promote products derived from this software |
| 17 | # without specific prior written permission. |
| 18 | # |
| 19 | # THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND |
| 20 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 21 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 22 | # ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE |
| 23 | # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 24 | # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 25 | # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 26 | # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 27 | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 28 | # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 29 | # SUCH DAMAGE. |
| 30 | # |
| 31 | |
Felix Weinrank | 1482700 | 2019-08-06 16:14:48 +0200 | [diff] [blame] | 32 | project(usrsctplib C) |
Felix Weinrank | a0ccbee | 2017-11-16 15:06:23 +0100 | [diff] [blame] | 33 | cmake_minimum_required(VERSION 3.0) |
Felix Weinrank | 69bbc20 | 2016-03-16 11:29:09 +0100 | [diff] [blame] | 34 | |
| 35 | # Debug build type as default |
| 36 | if (NOT CMAKE_BUILD_TYPE) |
Felix Weinrank | 9d18096 | 2017-11-07 15:46:54 +0100 | [diff] [blame] | 37 | message(STATUS "No build type selected, using DEBUG") |
| 38 | set(CMAKE_BUILD_TYPE "DEBUG") |
Felix Weinrank | 6c32195 | 2017-07-12 01:06:33 +0200 | [diff] [blame] | 39 | endif () |
| 40 | |
| 41 | include(CheckStructHasMember) |
Felix Weinrank | 5b9ee52 | 2017-07-14 15:45:16 +0200 | [diff] [blame] | 42 | include(CheckIncludeFile) |
| 43 | include(CheckIncludeFiles) |
Felix Weinrank | 396ed2a | 2017-11-15 14:17:00 +0100 | [diff] [blame] | 44 | include(CheckCCompilerFlag) |
Felix Weinrank | 6c32195 | 2017-07-12 01:06:33 +0200 | [diff] [blame] | 45 | |
| 46 | ################################################# |
| 47 | # CHECK OPTIONS |
| 48 | ################################################# |
| 49 | |
Felix Weinrank | 396ed2a | 2017-11-15 14:17:00 +0100 | [diff] [blame] | 50 | option(sctp_invariants "Add runtime checks" 0) |
| 51 | if (sctp_invariants) |
Felix Weinrank | 9d18096 | 2017-11-07 15:46:54 +0100 | [diff] [blame] | 52 | add_definitions(-DINVARIANTS) |
Felix Weinrank | 6c32195 | 2017-07-12 01:06:33 +0200 | [diff] [blame] | 53 | endif () |
| 54 | |
Felix Weinrank | 396ed2a | 2017-11-15 14:17:00 +0100 | [diff] [blame] | 55 | option(sctp_debug "Provide debug information" 1) |
| 56 | if (sctp_debug) |
Felix Weinrank | 9d18096 | 2017-11-07 15:46:54 +0100 | [diff] [blame] | 57 | add_definitions(-DSCTP_DEBUG) |
Felix Weinrank | 6c32195 | 2017-07-12 01:06:33 +0200 | [diff] [blame] | 58 | endif () |
| 59 | |
Felix Weinrank | 396ed2a | 2017-11-15 14:17:00 +0100 | [diff] [blame] | 60 | option(sctp_inet "Support IPv4" 1) |
| 61 | if (sctp_inet) |
Felix Weinrank | 9d18096 | 2017-11-07 15:46:54 +0100 | [diff] [blame] | 62 | add_definitions(-DINET) |
Felix Weinrank | 6c32195 | 2017-07-12 01:06:33 +0200 | [diff] [blame] | 63 | endif () |
| 64 | |
Felix Weinrank | 396ed2a | 2017-11-15 14:17:00 +0100 | [diff] [blame] | 65 | option(sctp_inet6 "Support IPv6" 1) |
Felix Weinrank | 2230605 | 2017-11-15 14:33:14 +0100 | [diff] [blame] | 66 | if (sctp_inet6) |
Felix Weinrank | 9d18096 | 2017-11-07 15:46:54 +0100 | [diff] [blame] | 67 | add_definitions(-DINET6) |
Felix Weinrank | 6c32195 | 2017-07-12 01:06:33 +0200 | [diff] [blame] | 68 | endif () |
| 69 | |
Michael Tuexen | daaaf94 | 2018-05-21 18:19:52 +0200 | [diff] [blame] | 70 | option(sctp_werror "Treat warning as error" 1) |
Felix Weinrank | 6c32195 | 2017-07-12 01:06:33 +0200 | [diff] [blame] | 71 | |
Felix Weinrank | 396ed2a | 2017-11-15 14:17:00 +0100 | [diff] [blame] | 72 | option(sctp_link_programs_static "Link example programs static" 0) |
Felix Weinrank | 6c32195 | 2017-07-12 01:06:33 +0200 | [diff] [blame] | 73 | |
Felix Weinrank | 396ed2a | 2017-11-15 14:17:00 +0100 | [diff] [blame] | 74 | option(sctp_build_programs "Build example programs" 1) |
Felix Weinrank | 6c32195 | 2017-07-12 01:06:33 +0200 | [diff] [blame] | 75 | |
Felix Weinrank | 396ed2a | 2017-11-15 14:17:00 +0100 | [diff] [blame] | 76 | option(sctp_sanitizer_address "Compile with address sanitizer" 0) |
Felix Weinrank | 3f31a25 | 2017-07-18 09:47:59 +0200 | [diff] [blame] | 77 | |
Felix Weinrank | 396ed2a | 2017-11-15 14:17:00 +0100 | [diff] [blame] | 78 | option(sctp_sanitizer_memory "Compile with memory sanitizer" 0) |
Felix Weinrank | 3f31a25 | 2017-07-18 09:47:59 +0200 | [diff] [blame] | 79 | |
Felix Weinrank | 04d617c | 2019-08-25 17:56:12 +0200 | [diff] [blame] | 80 | option(sctp_build_fuzzer "Compile in clang fuzzing mode" 0) |
Felix Weinrank | 04d617c | 2019-08-25 17:56:12 +0200 | [diff] [blame] | 81 | |
Felix Weinrank | 396ed2a | 2017-11-15 14:17:00 +0100 | [diff] [blame] | 82 | if (sctp_sanitizer_address AND sctp_sanitizer_memory) |
Felix Weinrank | 9d18096 | 2017-11-07 15:46:54 +0100 | [diff] [blame] | 83 | message(FATAL_ERROR "Can not compile with both sanitizer options") |
Felix Weinrank | 3f31a25 | 2017-07-18 09:47:59 +0200 | [diff] [blame] | 84 | endif () |
| 85 | |
Felix Weinrank | cbe162f | 2018-07-26 18:22:13 +0200 | [diff] [blame] | 86 | if (sctp_link_programs_static OR WIN32) |
Felix Weinrank | 396ed2a | 2017-11-15 14:17:00 +0100 | [diff] [blame] | 87 | set(programs_link_library "usrsctp-static") |
Felix Weinrank | 6c32195 | 2017-07-12 01:06:33 +0200 | [diff] [blame] | 88 | else () |
Felix Weinrank | 396ed2a | 2017-11-15 14:17:00 +0100 | [diff] [blame] | 89 | set(programs_link_library "usrsctp") |
Felix Weinrank | 6c32195 | 2017-07-12 01:06:33 +0200 | [diff] [blame] | 90 | endif () |
| 91 | |
| 92 | |
| 93 | ################################################# |
Felix Weinrank | 5b9ee52 | 2017-07-14 15:45:16 +0200 | [diff] [blame] | 94 | # CHECK FOR TYPES AND FUNCTIONS |
| 95 | ################################################# |
| 96 | |
Felix Weinrank | 396ed2a | 2017-11-15 14:17:00 +0100 | [diff] [blame] | 97 | check_include_files("sys/queue.h" have_sys_queue_h) |
| 98 | if (have_sys_queue_h) |
Felix Weinrank | 9d18096 | 2017-11-07 15:46:54 +0100 | [diff] [blame] | 99 | add_definitions(-DHAVE_SYS_QUEUE_H) |
Felix Weinrank | 5b9ee52 | 2017-07-14 15:45:16 +0200 | [diff] [blame] | 100 | endif () |
| 101 | |
Felix Weinrank | 396ed2a | 2017-11-15 14:17:00 +0100 | [diff] [blame] | 102 | check_include_files("sys/socket.h;linux/if_addr.h" have_linux_if_addr_h) |
| 103 | if (have_linux_if_addr_h) |
Felix Weinrank | 9d18096 | 2017-11-07 15:46:54 +0100 | [diff] [blame] | 104 | add_definitions(-DHAVE_LINUX_IF_ADDR_H) |
Felix Weinrank | 5b9ee52 | 2017-07-14 15:45:16 +0200 | [diff] [blame] | 105 | endif () |
| 106 | |
Felix Weinrank | 396ed2a | 2017-11-15 14:17:00 +0100 | [diff] [blame] | 107 | check_include_files("sys/socket.h;linux/rtnetlink.h" have_linux_rtnetlink_h) |
| 108 | if (have_linux_rtnetlink_h) |
Felix Weinrank | 9d18096 | 2017-11-07 15:46:54 +0100 | [diff] [blame] | 109 | add_definitions(-DHAVE_LINUX_RTNETLINK_H) |
Felix Weinrank | 5b9ee52 | 2017-07-14 15:45:16 +0200 | [diff] [blame] | 110 | endif () |
| 111 | |
Felix Weinrank | 396ed2a | 2017-11-15 14:17:00 +0100 | [diff] [blame] | 112 | check_include_files("sys/types.h;netinet/in.h;netinet/ip.h;netinet/ip_icmp.h" have_netinet_ip_icmp_h) |
| 113 | if (have_netinet_ip_icmp_h) |
Felix Weinrank | 9d18096 | 2017-11-07 15:46:54 +0100 | [diff] [blame] | 114 | add_definitions(-DHAVE_NETINET_IP_ICMP_H) |
Felix Weinrank | 5b9ee52 | 2017-07-14 15:45:16 +0200 | [diff] [blame] | 115 | endif () |
| 116 | |
Felix Weinrank | 396ed2a | 2017-11-15 14:17:00 +0100 | [diff] [blame] | 117 | check_include_files("stdatomic.h" have_stdatomic_h) |
| 118 | if (have_stdatomic_h) |
Felix Weinrank | 9d18096 | 2017-11-07 15:46:54 +0100 | [diff] [blame] | 119 | add_definitions(-DHAVE_STDATOMIC_H) |
Felix Weinrank | 5b9ee52 | 2017-07-14 15:45:16 +0200 | [diff] [blame] | 120 | endif () |
| 121 | |
| 122 | |
| 123 | ################################################# |
Felix Weinrank | 6c32195 | 2017-07-12 01:06:33 +0200 | [diff] [blame] | 124 | # CHECK STRUCT MEMBERS |
| 125 | ################################################# |
| 126 | |
Paul-Louis Ageneau | 17983b0 | 2020-01-22 14:10:27 +0000 | [diff] [blame] | 127 | set(CMAKE_REQUIRED_INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/usrsctplib") |
Felix Weinrank | 396ed2a | 2017-11-15 14:17:00 +0100 | [diff] [blame] | 128 | |
| 129 | check_include_file(usrsctp.h have_usrsctp_h) |
| 130 | if (NOT have_usrsctp_h) |
Felix Weinrank | 9d18096 | 2017-11-07 15:46:54 +0100 | [diff] [blame] | 131 | message(FATAL_ERROR "usrsctp.h not found") |
Felix Weinrank | 5b9ee52 | 2017-07-14 15:45:16 +0200 | [diff] [blame] | 132 | endif () |
Felix Weinrank | f9f5222 | 2017-07-13 01:09:34 +0200 | [diff] [blame] | 133 | |
Felix Weinrank | 396ed2a | 2017-11-15 14:17:00 +0100 | [diff] [blame] | 134 | check_struct_has_member("struct sockaddr" "sa_len" "sys/types.h;sys/socket.h" have_sa_len) |
| 135 | if (have_sa_len) |
| 136 | message(STATUS "have_sa_len") |
Felix Weinrank | 9d18096 | 2017-11-07 15:46:54 +0100 | [diff] [blame] | 137 | add_definitions(-DHAVE_SA_LEN) |
Felix Weinrank | 6c32195 | 2017-07-12 01:06:33 +0200 | [diff] [blame] | 138 | endif () |
| 139 | |
Felix Weinrank | 396ed2a | 2017-11-15 14:17:00 +0100 | [diff] [blame] | 140 | check_struct_has_member("struct sockaddr_in" "sin_len" "sys/types.h;netinet/in.h" have_sin_len) |
| 141 | if (have_sin_len) |
| 142 | message(STATUS "have_sin_len") |
Felix Weinrank | 9d18096 | 2017-11-07 15:46:54 +0100 | [diff] [blame] | 143 | add_definitions(-DHAVE_SIN_LEN) |
Felix Weinrank | 6c32195 | 2017-07-12 01:06:33 +0200 | [diff] [blame] | 144 | endif () |
| 145 | |
Felix Weinrank | 396ed2a | 2017-11-15 14:17:00 +0100 | [diff] [blame] | 146 | check_struct_has_member("struct sockaddr_in6" "sin6_len" "sys/types.h;netinet/in.h" have_sin6_len) |
| 147 | if (have_sin6_len) |
| 148 | message(STATUS "have_sin6_len") |
Felix Weinrank | 9d18096 | 2017-11-07 15:46:54 +0100 | [diff] [blame] | 149 | add_definitions(-DHAVE_SIN6_LEN) |
Felix Weinrank | 6c32195 | 2017-07-12 01:06:33 +0200 | [diff] [blame] | 150 | endif () |
| 151 | |
Felix Weinrank | 396ed2a | 2017-11-15 14:17:00 +0100 | [diff] [blame] | 152 | check_struct_has_member("struct sockaddr_conn" "sconn_len" "usrsctp.h" have_sconn_len) |
| 153 | if (have_sconn_len) |
Felix Weinrank | 9d18096 | 2017-11-07 15:46:54 +0100 | [diff] [blame] | 154 | message(STATUS "HAVE_SCONN_LEN") |
| 155 | add_definitions(-DHAVE_SCONN_LEN) |
Felix Weinrank | 6c32195 | 2017-07-12 01:06:33 +0200 | [diff] [blame] | 156 | endif () |
| 157 | |
| 158 | |
| 159 | ################################################# |
| 160 | # COMPILER SETTINGS |
| 161 | ################################################# |
| 162 | |
Yury Yaroshevich | ef8a35a | 2019-10-10 15:00:14 +0300 | [diff] [blame] | 163 | # Determine if compiler is Visual Studio compiler or Clang in MSVC compatible mode |
| 164 | if (CMAKE_C_COMPILER_ID MATCHES "MSVC" OR CMAKE_C_SIMULATE_ID MATCHES "MSVC") |
| 165 | set(C_COMPILER_IS_MSVC_LIKE TRUE) |
| 166 | endif() |
| 167 | |
| 168 | # SETTINGS FOR VISUAL STUDIO COMPILER |
| 169 | if (C_COMPILER_IS_MSVC_LIKE) |
| 170 | if (CMAKE_C_FLAGS MATCHES "/W[0-4]") |
| 171 | string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") |
| 172 | else () |
| 173 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4") |
| 174 | endif () |
| 175 | |
| 176 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4100") # 'identifier' : unreferenced formal parameter |
| 177 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4127") # conditional expression is constant |
| 178 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4200") # nonstandard extension used : zero-sized array in struct/union |
| 179 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4214") # bit field types other than int |
| 180 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4706") # assignment within conditional expression |
| 181 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4245") # 'conversion' : conversion from 'type1' to 'type2', signed/unsigned mismatch |
| 182 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4389") # 'operator' : signed/unsigned mismatch |
| 183 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4702") # unreachable code |
| 184 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4701") # Potentially uninitialized local variable 'name' used |
| 185 | |
| 186 | # ToDo |
| 187 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4244") # 'conversion' conversion from 'type1' to 'type2', possible loss of data |
| 188 | |
| 189 | if (sctp_werror) |
| 190 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /WX") |
| 191 | |
| 192 | if (CMAKE_C_COMPILER_ID MATCHES "Clang") |
| 193 | # temporary disable exta clang warnings preventing compilation |
| 194 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /clang:-Wno-unused-function") |
| 195 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /clang:-Wno-missing-field-initializers") |
| 196 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /clang:-Wno-sign-compare") |
| 197 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /clang:-Wno-format") |
| 198 | endif() |
| 199 | endif () |
Felix Weinrank | 6c32195 | 2017-07-12 01:06:33 +0200 | [diff] [blame] | 200 | # SETTINGS FOR UNIX COMPILER |
Yury Yaroshevich | ef8a35a | 2019-10-10 15:00:14 +0300 | [diff] [blame] | 201 | elseif (CMAKE_C_COMPILER_ID MATCHES "Clang" OR CMAKE_C_COMPILER_ID MATCHES "AppleClang" OR CMAKE_C_COMPILER_ID MATCHES "GNU") |
Felix Weinrank | 1482700 | 2019-08-06 16:14:48 +0200 | [diff] [blame] | 202 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -pedantic -Wall -Wextra") |
Felix Weinrank | 3f31a25 | 2017-07-18 09:47:59 +0200 | [diff] [blame] | 203 | |
Felix Weinrank | 396ed2a | 2017-11-15 14:17:00 +0100 | [diff] [blame] | 204 | check_c_compiler_flag(-Wfloat-equal has_wfloat_equal) |
| 205 | if (has_wfloat_equal) |
Felix Weinrank | 1482700 | 2019-08-06 16:14:48 +0200 | [diff] [blame] | 206 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wfloat-equal") |
Felix Weinrank | 396ed2a | 2017-11-15 14:17:00 +0100 | [diff] [blame] | 207 | endif () |
| 208 | |
| 209 | check_c_compiler_flag(-Wshadow has_wshadow) |
| 210 | if (has_wshadow) |
Felix Weinrank | 1482700 | 2019-08-06 16:14:48 +0200 | [diff] [blame] | 211 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wshadow") |
Felix Weinrank | 396ed2a | 2017-11-15 14:17:00 +0100 | [diff] [blame] | 212 | endif () |
| 213 | |
| 214 | check_c_compiler_flag(-Wpointer-arith has_wpointer_aritih) |
| 215 | if (has_wpointer_aritih) |
Felix Weinrank | 1482700 | 2019-08-06 16:14:48 +0200 | [diff] [blame] | 216 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wpointer-arith") |
Felix Weinrank | 396ed2a | 2017-11-15 14:17:00 +0100 | [diff] [blame] | 217 | endif () |
| 218 | |
| 219 | check_c_compiler_flag(-Wunreachable-code has_wunreachable_code) |
| 220 | if (has_wunreachable_code) |
Felix Weinrank | 1482700 | 2019-08-06 16:14:48 +0200 | [diff] [blame] | 221 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wunreachable-code") |
Felix Weinrank | 396ed2a | 2017-11-15 14:17:00 +0100 | [diff] [blame] | 222 | endif () |
| 223 | |
| 224 | check_c_compiler_flag(-Winit-self has_winit_self) |
| 225 | if (has_winit_self) |
Felix Weinrank | 1482700 | 2019-08-06 16:14:48 +0200 | [diff] [blame] | 226 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Winit-self") |
Felix Weinrank | 396ed2a | 2017-11-15 14:17:00 +0100 | [diff] [blame] | 227 | endif () |
| 228 | |
Felix Weinrank | 41fbcc1 | 2017-11-15 14:48:32 +0100 | [diff] [blame] | 229 | check_c_compiler_flag(-Wno-unused-function has_wno_unused_function) |
| 230 | if (has_wno_unused_function) |
Felix Weinrank | 1482700 | 2019-08-06 16:14:48 +0200 | [diff] [blame] | 231 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-function") |
Felix Weinrank | 41fbcc1 | 2017-11-15 14:48:32 +0100 | [diff] [blame] | 232 | endif () |
| 233 | |
| 234 | check_c_compiler_flag(-Wno-unused-parameter has_wno_unused_parameter) |
| 235 | if (has_wno_unused_parameter) |
Felix Weinrank | 1482700 | 2019-08-06 16:14:48 +0200 | [diff] [blame] | 236 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-parameter") |
Felix Weinrank | 41fbcc1 | 2017-11-15 14:48:32 +0100 | [diff] [blame] | 237 | endif () |
| 238 | |
Felix Weinrank | 9755866 | 2017-11-15 14:52:15 +0100 | [diff] [blame] | 239 | check_c_compiler_flag(-Wno-unreachable-code has_wno_unreachable_code) |
| 240 | if (has_wno_unreachable_code) |
Felix Weinrank | 1482700 | 2019-08-06 16:14:48 +0200 | [diff] [blame] | 241 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unreachable-code") |
Felix Weinrank | 9755866 | 2017-11-15 14:52:15 +0100 | [diff] [blame] | 242 | endif () |
| 243 | |
Felix Weinrank | a0a5a65 | 2018-03-23 20:09:51 +0100 | [diff] [blame] | 244 | check_c_compiler_flag(-Wstrict-prototypes has_wstrict_prototypes) |
| 245 | if (has_wstrict_prototypes) |
Felix Weinrank | 1482700 | 2019-08-06 16:14:48 +0200 | [diff] [blame] | 246 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wstrict-prototypes") |
Felix Weinrank | a0a5a65 | 2018-03-23 20:09:51 +0100 | [diff] [blame] | 247 | endif () |
| 248 | |
Felix Weinrank | 396ed2a | 2017-11-15 14:17:00 +0100 | [diff] [blame] | 249 | if (sctp_werror) |
Felix Weinrank | 1482700 | 2019-08-06 16:14:48 +0200 | [diff] [blame] | 250 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror") |
Felix Weinrank | 9d18096 | 2017-11-07 15:46:54 +0100 | [diff] [blame] | 251 | endif () |
Felix Weinrank | 3f31a25 | 2017-07-18 09:47:59 +0200 | [diff] [blame] | 252 | |
Felix Weinrank | 396ed2a | 2017-11-15 14:17:00 +0100 | [diff] [blame] | 253 | if (sctp_sanitizer_address) |
Felix Weinrank | 248221f | 2019-09-26 16:53:56 +0200 | [diff] [blame] | 254 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address,undefined,signed-integer-overflow -fno-omit-frame-pointer -fno-sanitize-recover=all -fsanitize-address-use-after-scope ") |
Felix Weinrank | 9d18096 | 2017-11-07 15:46:54 +0100 | [diff] [blame] | 255 | endif () |
Felix Weinrank | 3f31a25 | 2017-07-18 09:47:59 +0200 | [diff] [blame] | 256 | |
Felix Weinrank | 396ed2a | 2017-11-15 14:17:00 +0100 | [diff] [blame] | 257 | if (sctp_sanitizer_memory) |
Felix Weinrank | 248221f | 2019-09-26 16:53:56 +0200 | [diff] [blame] | 258 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=memory -fno-omit-frame-pointer -fsanitize-memory-track-origins -fPIE") |
Felix Weinrank | 9d18096 | 2017-11-07 15:46:54 +0100 | [diff] [blame] | 259 | endif () |
Felix Weinrank | 04d617c | 2019-08-25 17:56:12 +0200 | [diff] [blame] | 260 | |
Felix Weinrank | 248221f | 2019-09-26 16:53:56 +0200 | [diff] [blame] | 261 | if (sctp_build_fuzzer) |
Felix Weinrank | 7b87cd4 | 2020-03-18 00:38:11 +0100 | [diff] [blame] | 262 | set(CMAKE_BUILD_TYPE "DEBUG") |
Felix Weinrank | 248221f | 2019-09-26 16:53:56 +0200 | [diff] [blame] | 263 | add_definitions(-DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION) |
Felix Weinrank | 7b87cd4 | 2020-03-18 00:38:11 +0100 | [diff] [blame] | 264 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O1 -fsanitize=fuzzer-no-link") |
Felix Weinrank | 04d617c | 2019-08-25 17:56:12 +0200 | [diff] [blame] | 265 | endif () |
Felix Weinrank | 6c32195 | 2017-07-12 01:06:33 +0200 | [diff] [blame] | 266 | endif () |
| 267 | |
Felix Weinrank | 3c3962c | 2018-08-02 14:00:47 +0200 | [diff] [blame] | 268 | message(STATUS "Compiler flags (CMAKE_C_FLAGS): ${CMAKE_C_FLAGS}") |
| 269 | |
Felix Weinrank | 6c32195 | 2017-07-12 01:06:33 +0200 | [diff] [blame] | 270 | |
| 271 | ################################################# |
| 272 | # INCLUDE SUBDIRS |
| 273 | ################################################# |
Felix Weinrank | 69bbc20 | 2016-03-16 11:29:09 +0100 | [diff] [blame] | 274 | |
Felix Weinrank | 9acfd0f | 2015-08-26 13:01:12 +0200 | [diff] [blame] | 275 | add_subdirectory(usrsctplib) |
Felix Weinrank | 6c32195 | 2017-07-12 01:06:33 +0200 | [diff] [blame] | 276 | |
Felix Weinrank | 396ed2a | 2017-11-15 14:17:00 +0100 | [diff] [blame] | 277 | if (sctp_build_programs) |
Felix Weinrank | 9d18096 | 2017-11-07 15:46:54 +0100 | [diff] [blame] | 278 | add_subdirectory(programs) |
Felix Weinrank | 6c32195 | 2017-07-12 01:06:33 +0200 | [diff] [blame] | 279 | endif () |
Felix Weinrank | 04d617c | 2019-08-25 17:56:12 +0200 | [diff] [blame] | 280 | |
| 281 | if (sctp_build_fuzzer) |
| 282 | add_subdirectory(fuzzer) |
| 283 | endif () |