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