Skip to content

Commit fbb4156

Browse files
Add Linux support (#2)
* Add Linux support * Assign compiler options to each target instead of setting globally * Revert "Assign compiler options to each target instead of setting globally" This reverts commit 23b0dd5. * Fixed CMake compile option flags --------- Co-authored-by: kyv001 <kyvyang@foxmail.com> Co-authored-by: 無常 <3142324836@qq.com>
1 parent a951735 commit fbb4156

File tree

3 files changed

+67
-10
lines changed

3 files changed

+67
-10
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
lame-3.100/config.h
3333
[Oo]ut/**
3434
cmake-*/**
35+
build/**
36+
install/**
3537

3638
# IDE Temp
3739
.vs/**

CMakeLists.txt

Lines changed: 56 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ set (CMAKE_C_STANDARD 17)# Using C17
1212
set (CMAKE_C_EXTENSIONS OFF)
1313
set (CMAKE_C_STANDARD_REQUIRED ON)
1414

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+
1521
set (CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")# Using /MD and /MDd on MSVC
1622

1723
include(GNUInstallDirs)
@@ -143,7 +149,10 @@ if (${LAME_MP3X})
143149
add_executable (mp3x ${SRC_PATH}/config.h ${COMMON_SRC} ${MPX_SRC} ${RC_SRC})
144150
endif (${LAME_MP3X})
145151
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)
147156
add_library (mp3lame SHARED ${SRC_PATH}/config.h ${DLL_DEF} ${SRC_PATH}/libmp3lame/version.c)
148157
add_library (mp3lame-static STATIC ${LAMELIB_SRC} ${MPGLIB_SRC})
149158
if (${LAME_ASM})
@@ -168,7 +177,10 @@ if (${LAME_MP3X})
168177
target_include_directories (mp3x PRIVATE ${SRC_INC})
169178
endif (${LAME_MP3X})
170179
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)
172184

173185
if (${LAME_ASM})
174186
target_include_directories (lame_asm PRIVATE ${ASM_INC})
@@ -201,7 +213,10 @@ if (${LAME_MP3X})
201213
target_compile_definitions (mp3x PUBLIC ${LAME_MACRO})
202214
endif (${LAME_MP3X})
203215
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)
205220
target_compile_definitions (mp3lame PUBLIC ${LAME_MACRO})
206221
target_compile_definitions (mp3lame-static PUBLIC ${LAME_MACRO})
207222

@@ -210,17 +225,35 @@ if (${LAME_ASM} AND WIN32)
210225
endif (${LAME_ASM} AND WIN32)
211226

212227
# Compile Settings
213-
set_target_properties (lame mp3rtp lame_enc mp3lame mp3lame-static
228+
set_target_properties (lame mp3rtp mp3lame mp3lame-static
214229
PROPERTIES POSITION_INDEPENDENT_CODE ON
215230
)
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)
216237
if (${LAME_MP3X})
217238
set_target_properties (mp3x
218239
PROPERTIES POSITION_INDEPENDENT_CODE ON
219240
)
220241
endif (${LAME_MP3X})
221242

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+
222255
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
224257
endif (${LAME_ASM} AND MSVC)
225258

226259
# Link Libraries
@@ -235,13 +268,18 @@ if (WIN32)
235268
set (WSOCK32_LIB wsock32)# Windows
236269
set (USER32_LIB user32)# Windows
237270
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)
238274

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})
240276
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})
242278
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)
245283
target_link_libraries (mp3lame PRIVATE mp3lame-static)
246284

247285
if (${LAME_ASM})
@@ -256,12 +294,20 @@ if (LAME_VCPKG_TOOLS_HINT)
256294
else ()
257295
set(TOOLS_DIR ${CMAKE_INSTALL_BINDIR})
258296
endif ()
259-
install (TARGETS lame mp3rtp lame_enc mp3lame mp3lame-static
297+
install (TARGETS lame mp3rtp mp3lame mp3lame-static
260298
EXPORT ${LAME_INSTALL_NAME}Targets
261299
RUNTIME DESTINATION "${TOOLS_DIR}" OPTIONAL
262300
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" OPTIONAL
263301
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" OPTIONAL
264302
)
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)
265311
if (${LAME_MP3X})
266312
install (TARGETS mp3x
267313
EXPORT ${LAME_INSTALL_NAME}Targets

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,20 @@ Use CMake to compile LAME library.
44
## Platform support
55
- Windows (MSVC)
66
- Windows (MinGW)
7+
- Linux (GCC)
78

89
## Target support
10+
### Windows
911
- lame.exe - OK (Without NASM and libsndfile)
1012
- mp3x.exe - ERROR (No GTK Lib)
1113
- mp3rtp.exe - OK (Without NASM and libsndfile)
1214
- lame_enc.dll - OK (Without NASM and libsndfile)
1315
- mp3lame.dll - OK (Without NASM and libsndfile)
1416
- mp3lame-static.lib - OK (Without NASM and libsndfile)
17+
### Linux
18+
- lame - OK (Without NASM and libsndfile)
19+
- mp3x - ERROR (No GTK Lib)
20+
- mp3rtp - OK (Without NASM and libsndfile)
21+
- lame_enc.so - NOT SUPPORTED (Windows only)
22+
- mp3lame.so - OK (Without NASM and libsndfile)
23+
- mp3lame-static.a - OK (Without NASM and libsndfile)

0 commit comments

Comments
 (0)