Always set the COMPILE_FLAGS property, so we can always fetch it.
[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 if(WIN32)
25         set(WSUTIL_PLATFORM_FILES
26                 file_util.c
27                 inet_ntop.c
28                 inet_pton.c
29         )
30 ENDIF(WIN32)
31
32 set(WSUTIL_FILES
33         adler32.c
34         aes.c
35         airpdcap_wep.c
36         base64.c
37         bitswap.c
38         buffer.c
39         cfutils.c
40         clopts_common.c
41         cmdarg_err.c
42         copyright_info.c
43         crash_info.c
44         crc10.c
45         crc16.c
46         crc16-plain.c
47         crc32.c
48         crc6.c
49         crc7.c
50         crc8.c
51         crc11.c
52         des.c
53         eax.c
54         filesystem.c
55         g711.c
56         md4.c
57         md5.c
58         mpeg-audio.c
59         nstime.c
60         os_version_info.c
61         plugins.c
62         privileges.c
63         sha1.c
64         sober128.c
65         strnatcmp.c
66         str_util.c
67         rc4.c
68         report_err.c
69         tempfile.c
70         time_util.c
71         type_util.c
72         u3.c
73         unicode-utils.c
74         ws_mempbrk.c
75         ws_version_info.c
76         ${WSUTIL_PLATFORM_FILES}
77 )
78
79 #
80 # XXX - we're assuming MSVC supports the SSE 4.2 intrinsics and
81 # that other C compilers support them iff they support the
82 # -msse4.2 flag.
83 #
84 # Perhaps we should check whether we can compile something
85 # that uses them, instead, and do something else to figure
86 # out what compiler flag, if any, we need to pass to the
87 # compiler to compile code that uses them.
88 #
89 if(CMAKE_C_COMPILER_ID MATCHES "MSVC")
90         set(HAVE_SSE4_2 TRUE)
91         set(SSE4_2_FLAG "")
92 else()
93         message(STATUS "Checking for c-compiler flag: -msse4.2")
94         check_c_compiler_flag(-msse4.2 HAVE_SSE4_2)
95         if(HAVE_SSE4_2)
96                 set(SSE4_2_FLAG "-msse4.2")
97         endif()
98 endif()
99 if(HAVE_SSE4_2)
100         #
101         # Make sure we have the necessary header for the SSE4.2 intrinsics
102         # and that we can use it.
103         #
104
105         #
106         # Does this add the SSE4.2 flags to the beginning of CFLAGS?
107         #
108         cmake_push_check_state()
109         set(CMAKE_REQUIRED_FLAGS "${SSE4_2_FLAG}")
110         check_include_file("nmmintrin.h" CAN_USE_SSE4_2)
111         cmake_pop_check_state()
112         if(NOT CAN_USE_SSE4_2)
113                 #
114                 # OK, it's not working for some reason, perhaps because
115                 # ${SSE4_2_FLAG} above didn't enable SSE 4.2 support.
116                 #
117                 set(HAVE_SSE4_2 FALSE)
118         endif()
119 endif()
120 if(HAVE_SSE4_2)
121         set(WSUTIL_FILES ${WSUTIL_FILES} ws_mempbrk_sse42.c)
122 endif()
123
124 if(NOT HAVE_GETOPT_LONG)
125         set(WSUTIL_FILES ${WSUTIL_FILES} wsgetopt.c)
126 endif()
127
128 if(NOT HAVE_INET_ATON)
129         set(WSUTIL_FILES ${WSUTIL_FILES} inet_aton.c)
130 endif()
131
132 if(NOT HAVE_POPCOUNT)
133         set(WSUTIL_FILES ${WSUTIL_FILES} popcount.c)
134 endif()
135
136 if(NOT HAVE_STRPTIME)
137         set(WSUTIL_FILES ${WSUTIL_FILES} strptime.c)
138 endif()
139
140 if(APPLE)
141         #
142         # We assume that APPLE means OS X so that we have the OS X
143         # frameworks.
144         #
145         FIND_LIBRARY (APPLE_CORE_FOUNDATION_LIBRARY CoreFoundation)
146 endif()
147
148 set(wsutil_LIBS
149         ${APPLE_CORE_FOUNDATION_LIBRARY}
150         ${GMODULE2_LIBRARIES}
151         ${GLIB2_LIBRARIES}
152         ${GCRYPT_LIBRARIES}
153         ${WIN_WSOCK32_LIBRARY}
154 )
155 IF(WIN32)
156         set(wsutil_LIBS ${wsutil_LIBS} "ws2_32.lib")
157 ENDIF(WIN32)
158
159 set(CLEAN_FILES
160         ${WSUTIL_FILES}
161 )
162
163 if (WERROR)
164         set_source_files_properties(
165                 ${CLEAN_FILES}
166                 PROPERTIES
167                 COMPILE_FLAGS -Werror
168         )
169 else()
170         #
171         # Set the property to an empty string, so that if we try
172         # to get it below, it succeeds.
173         #
174         set_source_files_properties(
175                 ${CLEAN_FILES}
176                 PROPERTIES
177                 COMPILE_FLAGS ""
178         )
179 endif()
180 if (HAVE_SSE4_2)
181         get_source_file_property(
182                 WS_MEMPBRK_SSE42_COMPILE_FLAGS
183                 ws_mempbrk_sse42.c
184                 COMPILE_FLAGS
185         )
186         set_source_files_properties(
187                 ws_mempbrk_sse42.c
188                 PROPERTIES
189                 COMPILE_FLAGS "${WS_MEMPBRK_SSE42_COMPILE_FLAGS} ${SSE4_2_FLAG}"
190         )
191 endif()
192
193 add_library(wsutil ${LINK_MODE_LIB}
194         ${WSUTIL_FILES}
195         ${CMAKE_BINARY_DIR}/image/libwsutil.rc
196 )
197
198 add_dependencies(wsutil gitversion)
199
200 set(FULL_SO_VERSION "0.0.0")
201
202 set_target_properties(wsutil PROPERTIES
203         PREFIX "lib"
204         COMPILE_DEFINITIONS "WS_BUILD_DLL"
205         LINK_FLAGS "${WS_LINK_FLAGS}"
206         VERSION ${FULL_SO_VERSION} SOVERSION 0
207         FOLDER "Libs")
208
209 if(ENABLE_APPLICATION_BUNDLE)
210         set_target_properties(wsutil PROPERTIES
211                 LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/run/Wireshark.app/Contents/Frameworks
212         )
213 endif()
214
215 ABICHECK(libwsutil)
216
217 add_custom_command(OUTPUT libwsutil.abi.tar.gz
218         COMMAND cp ../config.h ${ABICHECK_TMPDIR}/
219         COMMAND ${ABICHECK_COMMAND}
220         COMMAND cp ${CMAKE_CURRENT_BINARY_DIR}/abi_dumps/libwsutil/libwsutil_* ${CMAKE_CURRENT_BINARY_DIR}/libwsutil.abi.tar.gz
221         COMMAND rm -rf ${ABICHECK_TMPDIR}/* ${CMAKE_CURRENT_BINARY_DIR}/abi_dumps
222         DEPENDS ${HEADERS} wsutil)
223
224 target_link_libraries(wsutil ${wsutil_LIBS})
225
226 if(NOT ${ENABLE_STATIC})
227         install(TARGETS wsutil
228                 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
229                 RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}
230                 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
231         )
232 endif()
233
234 add_definitions( -DTOP_SRCDIR=\"${CMAKE_SOURCE_DIR}\" )
235
236 #
237 # Editor modelines  -  http://www.wireshark.org/tools/modelines.html
238 #
239 # Local variables:
240 # c-basic-offset: 8
241 # tab-width: 8
242 # indent-tabs-mode: t
243 # End:
244 #
245 # vi: set shiftwidth=8 tabstop=8 noexpandtab:
246 # :indentSize=8:tabSize=8:noTabs=false:
247 #