Add libflac (#212)

* Add libflac

* libflac: Try to fix libogg linking

* Disable microbench building

* Fix replacement

* libflac: Fix MinGW

* Try something else for mingw

* libflac: Try something else

Based on https://github.com/msys2/MINGW-packages/issues/5803

* libflac: Try something else

* libflac: Try to set ldflags for mingw

* libflac: Try to set LDFLAGS

* Fix lua error

* libflac: Disable stack protector on MinGW

* That's it, I'm going to hell

* fix libflac for mingw/shared

Co-authored-by: Jérôme Leclercq <lynix680@gmail.com>
pull/215/head
ruki 4 years ago committed by GitHub
parent 6cb399f20f
commit a35f7513b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 67
      packages/l/libflac/patches/1.3.3/cmake.patch
  2. 60
      packages/l/libflac/xmake.lua

@ -0,0 +1,67 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index c2d2dfc7..09428ddb 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -9,7 +9,10 @@ project(FLAC VERSION 1.3.2) # HOMEPAGE_URL "https://www.xiph.org/flac/")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
option(BUILD_CXXLIBS "Build libFLAC++" ON)
+option(BUILD_PROGRAMS "Build and install programs" ON)
option(BUILD_EXAMPLES "Build and install examples" ON)
+option(BUILD_DOCS "Build and install doxygen documents" ON)
+option(BUILD_UTILS "Build utils" OFF)
option(WITH_OGG "ogg support (default: test for libogg)" ON)
if(WITH_OGG)
@@ -84,6 +87,10 @@ include_directories("include")
include_directories("${CMAKE_CURRENT_BINARY_DIR}")
add_definitions(-DHAVE_CONFIG_H)
+if(WIN32 AND NOT BUILD_SHARED_LIBS)
+ add_definitions(-DFLAC__NO_DLL)
+endif()
+
if(MSVC)
add_definitions(
-D_CRT_SECURE_NO_WARNINGS
@@ -93,13 +100,15 @@ if(CMAKE_BUILD_TYPE STREQUAL Debug OR CMAKE_BUILD_TYPE STREQUAL RelWithDebInfo)
add_definitions(-DFLAC__OVERFLOW_DETECT)
endif()
-add_subdirectory("doc")
add_subdirectory("src")
-add_subdirectory("microbench")
+if(BUILD_DOCS)
+ add_subdirectory("doc")
+endif()
if(BUILD_EXAMPLES)
add_subdirectory("examples")
endif()
if(BUILD_TESTING)
+ add_subdirectory("microbench")
add_subdirectory("test")
endif()
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index ba7a439e..5bb020f1 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -9,10 +9,14 @@ add_subdirectory("libFLAC")
if(BUILD_CXXLIBS)
add_subdirectory("libFLAC++")
endif()
-add_subdirectory("share")
-add_subdirectory("flac")
-add_subdirectory("metaflac")
-add_subdirectory("utils")
+if(BUILD_PROGRAMS)
+ add_subdirectory("flac")
+ add_subdirectory("metaflac")
+endif()
+if(BUILD_UTILS)
+ add_subdirectory("share")
+ add_subdirectory("utils")
+endif()
if(WITH_XMMS)
add_subdirectory("plugin_common")

@ -0,0 +1,60 @@
package("libflac")
set_homepage("https://xiph.org/flac")
set_description("Free Lossless Audio Codec")
set_license("BSD")
set_urls("https://github.com/xiph/flac/archive/$(version).tar.gz",
"https://github.com/xiph/flac.git")
add_versions("1.3.3", "668cdeab898a7dd43cf84739f7e1f3ed6b35ece2ef9968a5c7079fe9adfe1689")
add_patches("1.3.3", path.join(os.scriptdir(), "patches", "1.3.3", "cmake.patch"), "49baa40ab70d63e74cfc3f0cc2f13824545a618ceaeffdd51d3333d90b37fd32")
add_deps("cmake", "libogg")
if is_plat("linux") then
add_syslinks("m")
end
on_load("windows", "mingw", function (package)
if not package:config("shared") then
package:add("defines", "FLAC__NO_DLL")
end
end)
on_install("windows", "linux", "macosx", "iphoneos", "mingw", "android", function (package)
local configs = {}
table.insert(configs, "-DBUILD_CXXLIBS=OFF")
table.insert(configs, "-DBUILD_DOCS=OFF")
table.insert(configs, "-DBUILD_PROGRAMS=OFF")
table.insert(configs, "-DBUILD_EXAMPLES=OFF")
table.insert(configs, "-DBUILD_TESTING=OFF")
table.insert(configs, "-DBUILD_UTILS=OFF")
table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
table.insert(configs, "-DCMAKE_POSITION_INDEPENDENT_CODE=ON")
-- fix, undefined reference to `__memset_chk'
-- @see https://github.com/msys2/MINGW-packages/issues/5803
if package:config("shared") and package:is_plat("mingw") then
io.replace("CMakeLists.txt", "add_definitions(-DHAVE_CONFIG_H)", "add_definitions(-DHAVE_CONFIG_H -D_FORTIFY_SOURCE=0)", {plain = true})
end
-- we pass libogg as packagedeps instead of findOgg.cmake (it does not work)
local libogg = package:dep("libogg"):fetch()
if libogg then
local links = table.concat(table.wrap(libogg.links), " ")
io.replace("CMakeLists.txt", "find_package(OGG REQUIRED)", "", {plain = true})
io.replace("src/libFLAC/CMakeLists.txt",
[[
if(TARGET Ogg::ogg)
target_link_libraries(FLAC PUBLIC Ogg::ogg)
endif()]], "target_link_libraries(FLAC PUBLIC " .. links .. ")", {plain = true})
end
import("package.tools.cmake").install(package, configs, {packagedeps = "libogg"})
end)
on_test(function (package)
assert(package:has_cfuncs("FLAC__format_sample_rate_is_valid", {includes = "FLAC/format.h"}))
end)
Loading…
Cancel
Save