Clean up handling of enabled/disabled protocols/heuristic dissectors.
[metze/wireshark/wip.git] / wsutil / CMakeLists.txt
1 # CMakeLists.txt
2 #
3 # Wireshark - Network traffic analyzer
4 # By Gerald Combs <gerald@wireshark.org>
5 # Copyright 1998 Gerald Combs
6 #
7 # This program is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU General Public License
9 # as published by the Free Software Foundation; either version 2
10 # of the License, or (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #
21
22 include(UseABICheck)
23
24 set(WSUTIL_COMMON_FILES
25         adler32.c
26         airpdcap_wep.c
27         base32.c
28         base64.c
29         bitswap.c
30         buffer.c
31         clopts_common.c
32         cmdarg_err.c
33         copyright_info.c
34         crash_info.c
35         crc10.c
36         crc16.c
37         crc16-plain.c
38         crc32.c
39         crc6.c
40         crc7.c
41         crc8.c
42         crc11.c
43         eax.c
44         filesystem.c
45         frequency-utils.c
46         g711.c
47         glib-compat.c
48         inet_addr.c
49         interface.c
50         jsmn.c
51         mpeg-audio.c
52         nstime.c
53         cpu_info.c
54         os_version_info.c
55         plugins.c
56         privileges.c
57         sober128.c
58         strnatcmp.c
59         str_util.c
60         strtoi.c
61         report_message.c
62         tempfile.c
63         time_util.c
64         type_util.c
65         unicode-utils.c
66         ws_mempbrk.c
67         wsgcrypt.c
68         wsjsmn.c
69 )
70
71 set(WSUTIL_FILES ${WSUTIL_COMMON_FILES})
72 if(WIN32)
73         list(APPEND WSUTIL_FILES
74                 file_util.c
75                 inet_ntop.c
76                 inet_pton.c
77                 win32-utils.c
78         )
79 ENDIF(WIN32)
80
81
82 if(HAVE_OS_X_FRAMEWORKS)
83         list(APPEND WSUTIL_FILES cfutils.c)
84 endif()
85
86 #
87 # XXX - we're assuming MSVC doesn't require a flag to enable SSE 4.2
88 # support, and that, if the compiler supports a flag for SSE 4.2
89 # support, the intrinsics are supported iff we can include the
90 # <nmmintrin.h> flag.
91 #
92 # We only check for the GCC-style -msse4.2 flag and the Sun C
93 # -xarch=sse4_2 flag.
94 #
95 if(CMAKE_C_COMPILER_ID MATCHES "MSVC")
96         set(COMPILER_CAN_HANDLE_SSE4_2 TRUE)
97         set(SSE4_2_FLAG "")
98 else()
99         message(STATUS "Checking for c-compiler flag: -msse4.2")
100         check_c_compiler_flag(-msse4.2 COMPILER_CAN_HANDLE_SSE4_2)
101         if(COMPILER_CAN_HANDLE_SSE4_2)
102                 set(SSE4_2_FLAG "-msse4.2")
103         else()
104                 message(STATUS "Checking for c-compiler flag: -xarch=sse4_2")
105                 check_c_compiler_flag(-xarch=sse4_2 COMPILER_CAN_HANDLE_SSE4_2)
106                 if(COMPILER_CAN_HANDLE_SSE4_2)
107                         set(SSE4_2_FLAG "-xarch=sse4_2")
108                 endif()
109         endif()
110 endif()
111 if(COMPILER_CAN_HANDLE_SSE4_2)
112         #
113         # Make sure we have the necessary headers for the SSE4.2 intrinsics
114         # and that we can use them.
115         #
116         # First, check whether we have emmintrin.h and can use it
117         # *without* the SSE 4.2 flag.
118         #
119         check_include_file("emmintrin.h" EMMINTRIN_H_WORKS)
120
121         #
122         # OK, if that works, see whether we have nmmintrin.h and
123         # can use it *with* the SSE 4.2 flag.
124         #
125         if(EMMINTRIN_H_WORKS)
126                 #
127                 # Does this add the SSE4.2 flags to the beginning of
128                 # CFLAGS?
129                 #
130                 # Note that if there's a mix of "enable SSE 4.2" and
131                 # "disable SSE 4.2" flags, this may not indicate that
132                 # we can use the header.  That's not a bug, that's a
133                 # feature; the other flags may have been forced by
134                 # the build process, e.g. in Gentoo Linux, and we want
135                 # to check this with whatever flags will actually be
136                 # used when building (see bug 10792).
137                 #
138                 cmake_push_check_state()
139                 set(CMAKE_REQUIRED_FLAGS "${SSE4_2_FLAG}")
140                 check_include_file("nmmintrin.h" HAVE_SSE4_2)
141                 cmake_pop_check_state()
142         endif()
143 endif()
144 if(HAVE_SSE4_2)
145         list(APPEND WSUTIL_FILES ws_mempbrk_sse42.c)
146 endif()
147
148 if(NOT HAVE_GETOPT_LONG)
149         list(APPEND WSUTIL_FILES getopt_long.c)
150 endif()
151
152 if(NOT HAVE_INET_ATON)
153         list(APPEND WSUTIL_FILES inet_aton.c)
154 endif()
155
156 if(NOT HAVE_POPCOUNT)
157         list(APPEND WSUTIL_FILES popcount.c)
158 endif()
159
160 if(NOT HAVE_STRPTIME)
161         list(APPEND WSUTIL_FILES strptime.c)
162 endif()
163
164 if(APPLE)
165         #
166         # We assume that APPLE means macOS so that we have the macOS
167         # frameworks.
168         #
169         FIND_LIBRARY (APPLE_CORE_FOUNDATION_LIBRARY CoreFoundation)
170 endif()
171
172 set(wsutil_LIBS
173         ${CMAKE_DL_LIBS}
174         ${APPLE_CORE_FOUNDATION_LIBRARY}
175         ${GMODULE2_LIBRARIES}
176         ${GLIB2_LIBRARIES}
177         ${GCRYPT_LIBRARIES}
178         ${ZLIB_LIBRARIES}
179         ${WIN_WSOCK32_LIBRARY}
180 )
181 IF(WIN32)
182         set(wsutil_LIBS ${wsutil_LIBS} "iphlpapi.lib" "ws2_32.lib")
183 ENDIF(WIN32)
184
185 set(CLEAN_FILES
186         ${WSUTIL_FILES}
187 )
188
189 set_source_files_properties(
190         ${CLEAN_FILES}
191         PROPERTIES
192         COMPILE_FLAGS "${WERROR_COMMON_FLAGS}"
193 )
194 if (HAVE_SSE4_2)
195         # TODO with CMake 2.8.12, we could use COMPILE_OPTIONS and just append
196         # instead of this COMPILE_FLAGS duplication...
197         set_source_files_properties(
198                 ws_mempbrk_sse42.c
199                 PROPERTIES
200                 COMPILE_FLAGS "${WERROR_COMMON_FLAGS} ${SSE4_2_FLAG}"
201         )
202 endif()
203
204 add_library(wsutil ${LINK_MODE_LIB}
205         ${WSUTIL_FILES}
206         ${CMAKE_BINARY_DIR}/image/libwsutil.rc
207 )
208
209 set(FULL_SO_VERSION "0.0.0")
210
211 set_target_properties(wsutil PROPERTIES
212         PREFIX "lib"
213         COMPILE_DEFINITIONS "WS_BUILD_DLL"
214         COMPILE_OPTIONS "${WS_WARNINGS_C_FLAGS}"
215         LINK_FLAGS "${WS_LINK_FLAGS}"
216         VERSION ${FULL_SO_VERSION} SOVERSION 0
217         FOLDER "DLLs")
218
219 if(ENABLE_APPLICATION_BUNDLE)
220         set_target_properties(wsutil PROPERTIES
221                 LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/run/Wireshark.app/Contents/Frameworks
222         )
223 endif()
224
225 ABICHECK(libwsutil)
226
227 add_custom_command(OUTPUT libwsutil.abi.tar.gz
228         COMMAND ${CMAKE_COMMAND} -E remove_directory ${ABICHECK_TMPDIR}
229         COMMAND ${CMAKE_COMMAND} -E make_directory ${ABICHECK_TMPDIR}
230         COMMAND ${ABI_COPY_COMMAND} ../config.h ${ABICHECK_TMPDIR}/ ${ABI_COPY_FLAGS}
231         COMMAND ${ABI_COPY_COMMAND} ${ABICHECK_HEADERS} ${ABICHECK_TMPDIR}/ ${ABI_COPY_FLAGS}
232         COMMAND ${ABICHECK_COMMAND}
233         COMMAND cp ${CMAKE_CURRENT_BINARY_DIR}/abi_dumps/libwsutil/libwsutil_* ${CMAKE_CURRENT_BINARY_DIR}/libwsutil.abi.tar.gz
234         COMMAND rm -rf ${ABICHECK_TMPDIR} ${CMAKE_CURRENT_BINARY_DIR}/abi_dumps
235         DEPENDS ${HEADERS} wsutil)
236
237 target_link_libraries(wsutil ${wsutil_LIBS})
238
239 if(NOT ${ENABLE_STATIC})
240         install(TARGETS wsutil
241                 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
242                 RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}
243                 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
244         )
245 endif()
246
247 # Export build-time datadir (note: the macro "DATAFILE_DIR" is defined in
248 # config.h and points to the install-time data directory, hence the different
249 # name).
250 set_property(SOURCE filesystem.c APPEND PROPERTY
251         COMPILE_DEFINITIONS BUILD_TIME_DATAFILE_DIR="${DATAFILE_DIR}"
252 )
253
254 CHECKAPI(
255         NAME
256           wsutil
257         SWITCHES
258           -g termoutput -build
259         SOURCES
260           ${WSUTIL_COMMON_FILES}
261 )
262
263 set_source_files_properties(jsmn.c PROPERTIES COMPILE_DEFINITIONS "JSMN_STRICT")
264
265 #
266 # Editor modelines  -  http://www.wireshark.org/tools/modelines.html
267 #
268 # Local variables:
269 # c-basic-offset: 8
270 # tab-width: 8
271 # indent-tabs-mode: t
272 # End:
273 #
274 # vi: set shiftwidth=8 tabstop=8 noexpandtab:
275 # :indentSize=8:tabSize=8:noTabs=false:
276 #