Move RSA key loading and decryption functions to wsutil
[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         rsa.c
58         sober128.c
59         strnatcmp.c
60         str_util.c
61         strtoi.c
62         report_message.c
63         tempfile.c
64         time_util.c
65         type_util.c
66         unicode-utils.c
67         ws_mempbrk.c
68         wsgcrypt.c
69         wsjsmn.c
70 )
71
72 set(WSUTIL_FILES ${WSUTIL_COMMON_FILES})
73 if(WIN32)
74         list(APPEND WSUTIL_FILES
75                 file_util.c
76                 inet_ntop.c
77                 inet_pton.c
78                 win32-utils.c
79         )
80 ENDIF(WIN32)
81
82
83 if(HAVE_OS_X_FRAMEWORKS)
84         list(APPEND WSUTIL_FILES cfutils.c)
85 endif()
86
87 #
88 # XXX - we're assuming MSVC doesn't require a flag to enable SSE 4.2
89 # support, and that, if the compiler supports a flag for SSE 4.2
90 # support, the intrinsics are supported iff we can include the
91 # <nmmintrin.h> flag.
92 #
93 # We only check for the GCC-style -msse4.2 flag and the Sun C
94 # -xarch=sse4_2 flag.
95 #
96 if(CMAKE_C_COMPILER_ID MATCHES "MSVC")
97         set(COMPILER_CAN_HANDLE_SSE4_2 TRUE)
98         set(SSE4_2_FLAG "")
99 else()
100         message(STATUS "Checking for c-compiler flag: -msse4.2")
101         check_c_compiler_flag(-msse4.2 COMPILER_CAN_HANDLE_SSE4_2)
102         if(COMPILER_CAN_HANDLE_SSE4_2)
103                 set(SSE4_2_FLAG "-msse4.2")
104         else()
105                 message(STATUS "Checking for c-compiler flag: -xarch=sse4_2")
106                 check_c_compiler_flag(-xarch=sse4_2 COMPILER_CAN_HANDLE_SSE4_2)
107                 if(COMPILER_CAN_HANDLE_SSE4_2)
108                         set(SSE4_2_FLAG "-xarch=sse4_2")
109                 endif()
110         endif()
111 endif()
112 if(COMPILER_CAN_HANDLE_SSE4_2)
113         #
114         # Make sure we have the necessary headers for the SSE4.2 intrinsics
115         # and that we can use them.
116         #
117         # First, check whether we have emmintrin.h and can use it
118         # *without* the SSE 4.2 flag.
119         #
120         check_include_file("emmintrin.h" EMMINTRIN_H_WORKS)
121
122         #
123         # OK, if that works, see whether we have nmmintrin.h and
124         # can use it *with* the SSE 4.2 flag.
125         #
126         if(EMMINTRIN_H_WORKS)
127                 #
128                 # Does this add the SSE4.2 flags to the beginning of
129                 # CFLAGS?
130                 #
131                 # Note that if there's a mix of "enable SSE 4.2" and
132                 # "disable SSE 4.2" flags, this may not indicate that
133                 # we can use the header.  That's not a bug, that's a
134                 # feature; the other flags may have been forced by
135                 # the build process, e.g. in Gentoo Linux, and we want
136                 # to check this with whatever flags will actually be
137                 # used when building (see bug 10792).
138                 #
139                 cmake_push_check_state()
140                 set(CMAKE_REQUIRED_FLAGS "${SSE4_2_FLAG}")
141                 check_include_file("nmmintrin.h" HAVE_SSE4_2)
142                 cmake_pop_check_state()
143         endif()
144 endif()
145 if(HAVE_SSE4_2)
146         list(APPEND WSUTIL_FILES ws_mempbrk_sse42.c)
147 endif()
148
149 if(NOT HAVE_GETOPT_LONG)
150         list(APPEND WSUTIL_FILES getopt_long.c)
151 endif()
152
153 if(NOT HAVE_INET_ATON)
154         list(APPEND WSUTIL_FILES inet_aton.c)
155 endif()
156
157 if(NOT HAVE_POPCOUNT)
158         list(APPEND WSUTIL_FILES popcount.c)
159 endif()
160
161 if(NOT HAVE_STRPTIME)
162         list(APPEND WSUTIL_FILES strptime.c)
163 endif()
164
165 if(APPLE)
166         #
167         # We assume that APPLE means macOS so that we have the macOS
168         # frameworks.
169         #
170         FIND_LIBRARY (APPLE_CORE_FOUNDATION_LIBRARY CoreFoundation)
171 endif()
172
173 set(wsutil_LIBS
174         ${CMAKE_DL_LIBS}
175         ${APPLE_CORE_FOUNDATION_LIBRARY}
176         ${GMODULE2_LIBRARIES}
177         ${GLIB2_LIBRARIES}
178         ${GCRYPT_LIBRARIES}
179         ${ZLIB_LIBRARIES}
180         ${WIN_WSOCK32_LIBRARY}
181         ${GNUTLS_LIBRARIES}
182 )
183 IF(WIN32)
184         set(wsutil_LIBS ${wsutil_LIBS} "iphlpapi.lib" "ws2_32.lib")
185 ENDIF(WIN32)
186
187 set(CLEAN_FILES
188         ${WSUTIL_FILES}
189 )
190
191 set_source_files_properties(
192         ${CLEAN_FILES}
193         PROPERTIES
194         COMPILE_FLAGS "${WERROR_COMMON_FLAGS}"
195 )
196 if (HAVE_SSE4_2)
197         # TODO with CMake 2.8.12, we could use COMPILE_OPTIONS and just append
198         # instead of this COMPILE_FLAGS duplication...
199         set_source_files_properties(
200                 ws_mempbrk_sse42.c
201                 PROPERTIES
202                 COMPILE_FLAGS "${WERROR_COMMON_FLAGS} ${SSE4_2_FLAG}"
203         )
204 endif()
205
206 add_library(wsutil ${LINK_MODE_LIB}
207         ${WSUTIL_FILES}
208         ${CMAKE_BINARY_DIR}/image/libwsutil.rc
209 )
210
211 set(FULL_SO_VERSION "0.0.0")
212
213 set_target_properties(wsutil PROPERTIES
214         PREFIX "lib"
215         COMPILE_DEFINITIONS "WS_BUILD_DLL"
216         COMPILE_OPTIONS "${WS_WARNINGS_C_FLAGS}"
217         LINK_FLAGS "${WS_LINK_FLAGS}"
218         VERSION ${FULL_SO_VERSION} SOVERSION 0
219         FOLDER "DLLs")
220
221 if(ENABLE_APPLICATION_BUNDLE)
222         set_target_properties(wsutil PROPERTIES
223                 LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/run/Wireshark.app/Contents/Frameworks
224         )
225 endif()
226
227 ABICHECK(libwsutil)
228
229 add_custom_command(OUTPUT libwsutil.abi.tar.gz
230         COMMAND ${CMAKE_COMMAND} -E remove_directory ${ABICHECK_TMPDIR}
231         COMMAND ${CMAKE_COMMAND} -E make_directory ${ABICHECK_TMPDIR}
232         COMMAND ${ABI_COPY_COMMAND} ../config.h ${ABICHECK_TMPDIR}/ ${ABI_COPY_FLAGS}
233         COMMAND ${ABI_COPY_COMMAND} ${ABICHECK_HEADERS} ${ABICHECK_TMPDIR}/ ${ABI_COPY_FLAGS}
234         COMMAND ${ABICHECK_COMMAND}
235         COMMAND cp ${CMAKE_CURRENT_BINARY_DIR}/abi_dumps/libwsutil/libwsutil_* ${CMAKE_CURRENT_BINARY_DIR}/libwsutil.abi.tar.gz
236         COMMAND rm -rf ${ABICHECK_TMPDIR} ${CMAKE_CURRENT_BINARY_DIR}/abi_dumps
237         DEPENDS ${HEADERS} wsutil)
238
239 target_link_libraries(wsutil ${wsutil_LIBS})
240
241 if(NOT ${ENABLE_STATIC})
242         install(TARGETS wsutil
243                 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
244                 RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}
245                 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
246         )
247 endif()
248
249 # Export build-time datadir (note: the macro "DATAFILE_DIR" is defined in
250 # config.h and points to the install-time data directory, hence the different
251 # name).
252 set_property(SOURCE filesystem.c APPEND PROPERTY
253         COMPILE_DEFINITIONS BUILD_TIME_DATAFILE_DIR="${DATAFILE_DIR}"
254 )
255
256 CHECKAPI(
257         NAME
258           wsutil
259         SWITCHES
260           -g termoutput -build
261         SOURCES
262           ${WSUTIL_COMMON_FILES}
263 )
264
265 set_source_files_properties(jsmn.c PROPERTIES COMPILE_DEFINITIONS "JSMN_STRICT")
266
267 #
268 # Editor modelines  -  http://www.wireshark.org/tools/modelines.html
269 #
270 # Local variables:
271 # c-basic-offset: 8
272 # tab-width: 8
273 # indent-tabs-mode: t
274 # End:
275 #
276 # vi: set shiftwidth=8 tabstop=8 noexpandtab:
277 # :indentSize=8:tabSize=8:noTabs=false:
278 #