@@ -12,6 +12,12 @@ set (CMAKE_C_STANDARD 17)# Using C17
12
12
set (CMAKE_C_EXTENSIONS OFF )
13
13
set (CMAKE_C_STANDARD_REQUIRED ON )
14
14
15
+ set (ADDITIONAL_C_FLAGS "" )
16
+ if (NOT WIN32 )
17
+ list (APPEND ADDITIONAL_C_FLAGS "-Wno-implicit-function-declaration" ) # so that "strdup" doesn't cause an error on GCC
18
+ list (APPEND ADDITIONAL_C_FLAGS "-Wno-int-conversion" ) # so that int can be implicitly converted to char* on GCC
19
+ endif ()
20
+
15
21
set (CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL" )# Using /MD and /MDd on MSVC
16
22
17
23
include (GNUInstallDirs )
@@ -143,7 +149,10 @@ if (${LAME_MP3X})
143
149
add_executable (mp3x ${SRC_PATH} /config.h ${COMMON_SRC} ${MPX_SRC} ${RC_SRC} )
144
150
endif (${LAME_MP3X} )
145
151
add_executable (mp3rtp ${SRC_PATH} /config.h ${COMMON_SRC} ${MP3RTP_SRC} ${RC_SRC} )
146
- add_library (lame_enc SHARED ${SRC_PATH} /config.h ${DLL_SRC} ${RC_SRC} )
152
+ # DLL is not supported on GNU/Linux
153
+ if (WIN32 )
154
+ add_library (lame_enc SHARED ${SRC_PATH} /config.h ${DLL_SRC} ${RC_SRC} )
155
+ endif (WIN32 )
147
156
add_library (mp3lame SHARED ${SRC_PATH} /config.h ${DLL_DEF} ${SRC_PATH} /libmp3lame/version.c )
148
157
add_library (mp3lame-static STATIC ${LAMELIB_SRC} ${MPGLIB_SRC} )
149
158
if (${LAME_ASM} )
@@ -168,7 +177,10 @@ if (${LAME_MP3X})
168
177
target_include_directories (mp3x PRIVATE ${SRC_INC} )
169
178
endif (${LAME_MP3X} )
170
179
target_include_directories (mp3rtp PRIVATE ${SRC_INC} )
171
- target_include_directories (lame_enc PRIVATE ${SRC_INC} )
180
+ # DLL is not supported on GNU/Linux
181
+ if (WIN32 )
182
+ target_include_directories (lame_enc PRIVATE ${SRC_INC} )
183
+ endif (WIN32 )
172
184
173
185
if (${LAME_ASM} )
174
186
target_include_directories (lame_asm PRIVATE ${ASM_INC} )
@@ -201,7 +213,10 @@ if (${LAME_MP3X})
201
213
target_compile_definitions (mp3x PUBLIC ${LAME_MACRO} )
202
214
endif (${LAME_MP3X} )
203
215
target_compile_definitions (mp3rtp PUBLIC ${LAME_MACRO} )
204
- target_compile_definitions (lame_enc PUBLIC ${LAME_MACRO} )
216
+ # DLL is not supported on GNU/Linux
217
+ if (WIN32 )
218
+ target_compile_definitions (lame_enc PUBLIC ${LAME_MACRO} )
219
+ endif (WIN32 )
205
220
target_compile_definitions (mp3lame PUBLIC ${LAME_MACRO} )
206
221
target_compile_definitions (mp3lame-static PUBLIC ${LAME_MACRO} )
207
222
@@ -210,17 +225,35 @@ if (${LAME_ASM} AND WIN32)
210
225
endif (${LAME_ASM} AND WIN32 )
211
226
212
227
# Compile Settings
213
- set_target_properties (lame mp3rtp lame_enc mp3lame mp3lame-static
228
+ set_target_properties (lame mp3rtp mp3lame mp3lame-static
214
229
PROPERTIES POSITION_INDEPENDENT_CODE ON
215
230
)
231
+ # lame_enc is only for Windows
232
+ if (WIN32 )
233
+ set_target_properties (lame_enc
234
+ PROPERTIES POSITION_INDEPENDENT_CODE ON
235
+ )
236
+ endif (WIN32 )
216
237
if (${LAME_MP3X} )
217
238
set_target_properties (mp3x
218
239
PROPERTIES POSITION_INDEPENDENT_CODE ON
219
240
)
220
241
endif (${LAME_MP3X} )
221
242
243
+ target_compile_options (lame PRIVATE ${ADDITIONAL_C_FLAGS} )
244
+ if (${LAME_MP3X} )
245
+ target_compile_options (mp3x PRIVATE ${ADDITIONAL_C_FLAGS} )
246
+ endif (${LAME_MP3X} )
247
+ target_compile_options (mp3rtp PRIVATE ${ADDITIONAL_C_FLAGS} )
248
+ # DLL is not supported on GNU/Linux
249
+ if (WIN32 )
250
+ target_compile_options (lame_enc PRIVATE ${ADDITIONAL_C_FLAGS} )
251
+ endif (WIN32 )
252
+ target_compile_options (mp3lame PRIVATE ${ADDITIONAL_C_FLAGS} )
253
+ target_compile_options (mp3lame-static PRIVATE ${ADDITIONAL_C_FLAGS} )
254
+
222
255
if (${LAME_ASM} AND MSVC )
223
- target_compile_options (lame_asm PRIVATE "-Sf" )# MSVC
256
+ target_compile_options (lame_asm PRIVATE "-Sf" ${ADDITIONAL_C_FLAGS} )# MSVC
224
257
endif (${LAME_ASM} AND MSVC )
225
258
226
259
# Link Libraries
@@ -235,13 +268,18 @@ if (WIN32)
235
268
set (WSOCK32_LIB wsock32 )# Windows
236
269
set (USER32_LIB user32 )# Windows
237
270
endif (WIN32 )
271
+ if (NOT WIN32 )
272
+ set (MATH_LIB m ) # On Linux GCC it doesn't link the math library by default
273
+ endif (NOT WIN32 )
238
274
239
- target_link_libraries (lame PRIVATE mp3lame-static ${SNDFILE_LIB} ${ADDL_LIB} )
275
+ target_link_libraries (lame PRIVATE mp3lame-static ${SNDFILE_LIB} ${ADDL_LIB} ${MATH_LIB} )
240
276
if (${LAME_MP3X} )
241
- target_link_libraries (mp3x PRIVATE mp3lame-static ${SNDFILE_LIB} ${ADDL_LIB} )
277
+ target_link_libraries (mp3x PRIVATE mp3lame-static ${SNDFILE_LIB} ${ADDL_LIB} ${MATH_LIB} )
242
278
endif (${LAME_MP3X} )
243
- target_link_libraries (mp3rtp PRIVATE mp3lame-static ${SNDFILE_LIB} ${ADDL_LIB} ${WSOCK32_LIB} )
244
- target_link_libraries (lame_enc PRIVATE mp3lame-static ${ADDL_LIB} ${USER32_LIB} )
279
+ target_link_libraries (mp3rtp PRIVATE mp3lame-static ${SNDFILE_LIB} ${ADDL_LIB} ${WSOCK32_LIB} ${MATH_LIB} )
280
+ if (WIN32 ) # Windows-only library
281
+ target_link_libraries (lame_enc PRIVATE mp3lame-static ${ADDL_LIB} ${USER32_LIB} )
282
+ endif (WIN32 )
245
283
target_link_libraries (mp3lame PRIVATE mp3lame-static )
246
284
247
285
if (${LAME_ASM} )
@@ -256,12 +294,20 @@ if (LAME_VCPKG_TOOLS_HINT)
256
294
else ()
257
295
set (TOOLS_DIR ${CMAKE_INSTALL_BINDIR} )
258
296
endif ()
259
- install (TARGETS lame mp3rtp lame_enc mp3lame mp3lame-static
297
+ install (TARGETS lame mp3rtp mp3lame mp3lame-static
260
298
EXPORT ${LAME_INSTALL_NAME} Targets
261
299
RUNTIME DESTINATION "${TOOLS_DIR} " OPTIONAL
262
300
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR} " OPTIONAL
263
301
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR} " OPTIONAL
264
302
)
303
+ if (WIN32 ) # Install DLL only on Windows
304
+ install (TARGETS lame_enc
305
+ EXPORT ${LAME_INSTALL_NAME} Targets
306
+ RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR} " OPTIONAL
307
+ LIBRARY DESTINATION "${CMAKE_INSTALL_BINDIR} " OPTIONAL
308
+ ARCHIVE DESTINATION "${CMAKE_INSTALL_BINDIR} " OPTIONAL
309
+ )
310
+ endif (WIN32 )
265
311
if (${LAME_MP3X} )
266
312
install (TARGETS mp3x
267
313
EXPORT ${LAME_INSTALL_NAME} Targets
0 commit comments