zdoom-macos-deps/patch/flac-fix-cmake.diff

1118 lines
31 KiB
Diff
Raw Normal View History

--- /dev/null
+++ a/CMakeLists.txt
@@ -0,0 +1,130 @@
+cmake_minimum_required(VERSION 3.1)
+
+if(NOT (CMAKE_BUILD_TYPE OR CMAKE_CONFIGURATION_TYPES OR DEFINED ENV{CFLAGS} OR DEFINED ENV{CXXFLAGS}))
+ set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build, options are: None Debug Release RelWithDebInfo")
+endif()
+
+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_EXAMPLES "Build and install examples" ON)
+option(WITH_OGG "ogg support (default: test for libogg)" ON)
+
+if(WITH_OGG)
+ find_package(OGG REQUIRED)
+endif()
+
+if(CMAKE_C_COMPILER_ID MATCHES "GNU|Clang")
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wstrict-prototypes -Wmissing-prototypes -Waggregate-return -Wcast-align -Wnested-externs -Wshadow -Wundef -Wmissing-declarations -Winline")
+ set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O3 -funroll-loops")
+
+ option(ENABLE_SSP "Enable GNU GCC stack smash protection" OFF)
+endif()
+if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wcast-align -Wshadow -Wwrite-strings -Wctor-dtor-privacy -Wnon-virtual-dtor -Wreorder -Wsign-promo -Wundef")
+endif()
+if(CMAKE_C_COMPILER_ID MATCHES "GNU")
+ set(CMAKE_EXE_LINKER_FLAGS -no-pie)
+endif()
+
+include(CMakePackageConfigHelpers)
+include(CPack)
+include(CTest)
+include(CheckCCompilerFlag)
+include(CheckCXXCompilerFlag)
+include(CheckSymbolExists)
+include(CheckFunctionExists)
+include(CheckIncludeFile)
+include(CheckCSourceCompiles)
+include(CheckCXXSourceCompiles)
+include(GNUInstallDirs)
+include(UseSystemExtensions)
+include(TestBigEndian)
+
+check_include_file("byteswap.h" HAVE_BYTESWAP_H)
+check_include_file("inttypes.h" HAVE_INTTYPES_H)
+check_include_file("stdint.h" HAVE_STDINT_H)
+check_include_file("x86intrin.h" FLAC__HAS_X86INTRIN)
+
+check_function_exists(fseeko HAVE_FSEEKO)
+
+check_c_source_compiles("int main() { return __builtin_bswap16 (0) ; }" HAVE_BSWAP16)
+check_c_source_compiles("int main() { return __builtin_bswap32 (0) ; }" HAVE_BSWAP32)
+
+test_big_endian(CPU_IS_BIG_ENDIAN)
+
+check_c_compiler_flag(-Werror HAVE_WERROR_FLAG)
+check_c_compiler_flag(-Wdeclaration-after-statement HAVE_DECL_AFTER_STMT_FLAG)
+check_c_compiler_flag("-fstack-protector --param ssp-buffer-size=4" HAVE_SSP_FLAG)
+check_c_compiler_flag(-mstackrealign HAVE_STACKREALIGN_FLAG)
+check_cxx_compiler_flag(-Weffc++ HAVE_WEFFCXX_FLAG)
+
+if(HAVE_WERROR_FLAG)
+ option(ENABLE_WERROR "Enable -Werror in all Makefiles" OFF)
+endif()
+
+add_compile_options(
+ $<$<BOOL:${MSVC}>:/wd4267>
+ $<$<BOOL:${MSVC}>:/wd4996>
+ $<$<BOOL:${ENABLE_WERROR}>:-Werror>
+ $<$<AND:$<BOOL:${HAVE_SSP_FLAG}>,$<BOOL:${ENABLE_SSP}>>:-fstack-protector>
+ $<$<AND:$<BOOL:${HAVE_SSP_FLAG}>,$<BOOL:${ENABLE_SSP}>>:--param>
+ $<$<AND:$<BOOL:${HAVE_SSP_FLAG}>,$<BOOL:${ENABLE_SSP}>>:ssp-buffer-size=4>
+ $<$<AND:$<COMPILE_LANGUAGE:CXX>,$<BOOL:${HAVE_WEFFCXX_FLAG}>>:-Weffc++>
+ $<$<AND:$<COMPILE_LANGUAGE:C>,$<BOOL:${HAVE_DECL_AFTER_STMT_FLAG}>>:-Wdeclaration-after-statement>)
+
+if(CMAKE_SYSTEM_PROCESSOR STREQUAL "i686" AND HAVE_STACKREALIGN_FLAG)
+ add_compile_options(-mstackrealign)
+endif()
+
+include_directories("include")
+
+include_directories("${CMAKE_CURRENT_BINARY_DIR}")
+add_definitions(-DHAVE_CONFIG_H)
+
+if(MSVC)
+ add_definitions(
+ -D_CRT_SECURE_NO_WARNINGS
+ -D_USE_MATH_DEFINES)
+endif()
+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_EXAMPLES)
+ add_subdirectory("examples")
+endif()
+if(BUILD_TESTING)
+ add_subdirectory("test")
+endif()
+
+configure_file(config.cmake.h.in config.h)
+
+install(
+ EXPORT targets
+ DESTINATION "${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}/cmake"
+ NAMESPACE FLAC::)
+
+configure_package_config_file(
+ flac-config.cmake.in flac-config.cmake
+ INSTALL_DESTINATION "${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}/cmake")
+write_basic_package_version_file(
+ flac-config-version.cmake COMPATIBILITY AnyNewerVersion)
+
+install(
+ FILES
+ "${CMAKE_CURRENT_BINARY_DIR}/flac-config.cmake"
+ "${CMAKE_CURRENT_BINARY_DIR}/flac-config-version.cmake"
+ "cmake/FindOGG.cmake"
+ DESTINATION "${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}/cmake")
+
+file(GLOB FLAC_HEADERS "include/FLAC/*.h")
+file(GLOB FLAC++_HEADERS "include/FLAC++/*.h")
+install(FILES ${FLAC_HEADERS} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/FLAC")
+install(FILES ${FLAC++_HEADERS} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/FLAC++")
+install(FILES "man/flac.1" "man/metaflac.1" DESTINATION "${CMAKE_INSTALL_MANDIR}")
--- /dev/null
+++ a/doc/CMakeLists.txt
@@ -0,0 +1,24 @@
+cmake_minimum_required(VERSION 3.1)
+find_package(Doxygen)
+
+if (NOT DOXYGEN_FOUND)
+ return()
+endif()
+
+option(BUILD_DOXYGEN "Enable API documentation building via Doxygen" ON)
+
+if (NOT BUILD_DOXYGEN)
+ return()
+endif()
+
+set(DOXYGEN_HTML_FOOTER doxygen.footer.html)
+set(DOXYGEN_GENERATE_TAGFILE FLAC.tag)
+
+doxygen_add_docs(FLAC-doxygen
+ "${PROJECT_SOURCE_DIR}/include/FLAC"
+ "${PROJECT_SOURCE_DIR}/include/FLAC++")
+
+add_subdirectory(html)
+
+install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/html/"
+ DESTINATION "${CMAKE_INSTALL_DOCDIR}/html/api")
--- /dev/null
+++ a/doc/html/CMakeLists.txt
@@ -0,0 +1,22 @@
+add_subdirectory(images)
+
+install(FILES
+ changelog.html
+ developers.html
+ documentation.html
+ documentation_bugs.html
+ documentation_example_code.html
+ documentation_format_overview.html
+ documentation_tools.html
+ documentation_tools_flac.html
+ documentation_tools_metaflac.html
+ faq.html
+ favicon.ico
+ features.html
+ flac.css
+ format.html
+ id.html
+ index.html
+ license.html
+ ogg_mapping.html
+DESTINATION "${CMAKE_INSTALL_DOCDIR}/html")
--- /dev/null
+++ a/doc/html/images/CMakeLists.txt
@@ -0,0 +1,4 @@
+install(FILES
+ logo.svg
+ logo130.gif
+DESTINATION "${CMAKE_INSTALL_DOCDIR}/html/images")
--- /dev/null
+++ a/examples/c/CMakeLists.txt
@@ -0,0 +1,2 @@
+add_subdirectory("decode/file")
+add_subdirectory("encode/file")
--- /dev/null
+++ a/examples/c/decode/file/CMakeLists.txt
@@ -0,0 +1,2 @@
+add_executable(decode_file main.c)
+target_link_libraries(decode_file FLAC)
--- /dev/null
+++ a/examples/c/encode/file/CMakeLists.txt
@@ -0,0 +1,2 @@
+add_executable(encode_file main.c)
+target_link_libraries(encode_file FLAC)
--- /dev/null
+++ a/examples/CMakeLists.txt
@@ -0,0 +1,4 @@
+add_subdirectory("c")
+if(BUILD_CXXLIBS)
+ add_subdirectory("cpp")
+endif()
--- /dev/null
+++ a/examples/cpp/CMakeLists.txt
@@ -0,0 +1,2 @@
+add_subdirectory("decode/file")
+add_subdirectory("encode/file")
--- /dev/null
+++ a/examples/cpp/decode/file/CMakeLists.txt
@@ -0,0 +1,2 @@
+add_executable(decode_file_cxx main.cpp)
+target_link_libraries(decode_file_cxx FLAC++)
--- /dev/null
+++ a/examples/cpp/encode/file/CMakeLists.txt
@@ -0,0 +1,2 @@
+add_executable(encode_file_cxx main.cpp)
+target_link_libraries(encode_file_cxx FLAC++)
--- /dev/null
+++ a/microbench/CMakeLists.txt
@@ -0,0 +1,17 @@
+if(MSVC)
+ return()
+endif()
+
+set(CMAKE_REQUIRED_LIBRARIES rt)
+check_function_exists(clock_gettime HAVE_CLOCK_GETTIME)
+
+if(APPLE)
+ add_definitions(-DFLAC__SYS_DARWIN)
+endif()
+
+add_executable(benchmark_residual benchmark_residual.c util.c)
+target_include_directories(benchmark_residual PRIVATE
+ "$<TARGET_PROPERTY:FLAC,SOURCE_DIR>/include")
+target_link_libraries(benchmark_residual
+ FLAC
+ $<$<BOOL:${HAVE_CLOCK_GETTIME}>:rt>)
--- /dev/null
+++ a/src/CMakeLists.txt
@@ -0,0 +1,31 @@
+cmake_minimum_required(VERSION 3.0)
+
+option(ENABLE_64_BIT_WORDS "Set FLAC__BYTES_PER_WORD to 8 (4 is the default)" OFF)
+option(WITH_XMMS "Build XMMS plugin" OFF)
+
+check_include_file("iconv.h" HAVE_ICONV)
+
+add_subdirectory("libFLAC")
+if(BUILD_CXXLIBS)
+ add_subdirectory("libFLAC++")
+endif()
+add_subdirectory("share")
+add_subdirectory("flac")
+add_subdirectory("metaflac")
+add_subdirectory("utils")
+
+if(WITH_XMMS)
+ add_subdirectory("plugin_common")
+ add_subdirectory("plugin_xmms")
+endif()
+
+if(BUILD_TESTING)
+ add_subdirectory("test_libs_common")
+ add_subdirectory("test_libFLAC")
+ if(BUILD_CXXLIBS)
+ add_subdirectory("test_libFLAC++")
+ endif()
+ add_subdirectory("test_grabbag")
+ add_subdirectory("test_seeking")
+ add_subdirectory("test_streams")
+endif()
--- /dev/null
+++ a/src/flac/CMakeLists.txt
@@ -0,0 +1,24 @@
+check_include_file("sys/ioctl.h" HAVE_SYS_IOCTL_H)
+check_include_file("termios.h" HAVE_TERMIOS_H)
+
+add_executable(flacapp
+ analyze.c
+ decode.c
+ encode.c
+ foreign_metadata.c
+ main.c
+ local_string_utils.c
+ utils.c
+ vorbiscomment.c)
+set_property(TARGET flacapp PROPERTY RUNTIME_OUTPUT_NAME flac)
+target_link_libraries(flacapp
+ FLAC
+ getopt
+ replaygain_synthesis
+ utf8)
+if(TARGET win_utf8_io)
+ target_link_libraries(flacapp win_utf8_io)
+endif()
+
+install(TARGETS flacapp EXPORT targets
+ RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
--- /dev/null
+++ a/src/libFLAC/CMakeLists.txt
@@ -0,0 +1,121 @@
+cmake_minimum_required(VERSION 3.0)
+
+if(CMAKE_SYSTEM_PROCESSOR MATCHES "[xX]86(_64)?|(AMD|amd)64|i[346]86")
+ option(WITH_AVX "Enable AVX, AVX2 optimizations" ON)
+endif()
+
+option(WITH_ASM "Use any assembly optimization routines" ON)
+
+check_include_file("cpuid.h" HAVE_CPUID_H)
+check_include_file("sys/param.h" HAVE_SYS_PARAM_H)
+
+set(CMAKE_REQUIRED_LIBRARIES m)
+check_function_exists(lround HAVE_LROUND)
+
+if(CMAKE_SYSTEM_PROCESSOR MATCHES "[xX]86_64|(AMD|amd)64")
+ if(CMAKE_SIZEOF_VOID_P EQUAL 4)
+ set(IA32 TRUE)
+ endif()
+ add_definitions(-DFLAC__CPU_X86_64 -DFLAC__ALIGN_MALLOC_DATA)
+elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "([xX]|i[346])86")
+ set(IA32 TRUE)
+ add_definitions(-DFLAC__CPU_IA32 -DFLAC__ALIGN_MALLOC_DATA)
+endif()
+
+include(CheckLanguage)
+check_language(ASM_NASM)
+if(CMAKE_ASM_NASM_COMPILER)
+ enable_language(ASM_NASM)
+ add_definitions(-DFLAC__HAS_NASM)
+endif()
+
+if(NOT WITH_ASM)
+ add_definitions(-DFLAC__NO_ASM)
+endif()
+
+if(IA32)
+ if(WITH_ASM AND CMAKE_ASM_NASM_COMPILER)
+ add_subdirectory(ia32)
+ endif()
+
+ option(WITH_SSE "Enable SSE2 optimizations" ON)
+ check_c_compiler_flag(-msse2 HAVE_MSSE2_FLAG)
+ if(WITH_SSE)
+ add_compile_options(
+ $<$<BOOL:${HAVE_MSSE2_FLAG}>:-msse2>
+ $<$<BOOL:${MSVC}>:/arch:SSE2>)
+ endif()
+endif()
+
+
+set(prefix "${CMAKE_INSTALL_PREFIX}")
+set(exec_prefix "${CMAKE_INSTALL_PREFIX}")
+set(libdir "${CMAKE_INSTALL_FULL_LIBDIR}")
+set(includedir "${CMAKE_INSTALL_FULL_INCLUDEDIR}")
+configure_file(flac.pc.in flac.pc @ONLY)
+
+include_directories("include")
+
+add_library(FLAC
+ bitmath.c
+ bitreader.c
+ bitwriter.c
+ cpu.c
+ crc.c
+ fixed.c
+ fixed_intrin_sse2.c
+ fixed_intrin_ssse3.c
+ float.c
+ format.c
+ lpc.c
+ lpc_intrin_sse.c
+ lpc_intrin_sse2.c
+ lpc_intrin_sse41.c
+ lpc_intrin_avx2.c
+ lpc_intrin_vsx.c
+ md5.c
+ memory.c
+ metadata_iterators.c
+ metadata_object.c
+ stream_decoder.c
+ stream_encoder.c
+ stream_encoder_intrin_sse2.c
+ stream_encoder_intrin_ssse3.c
+ stream_encoder_intrin_avx2.c
+ stream_encoder_framing.c
+ window.c
+ $<$<BOOL:${OGG_FOUND}>:ogg_decoder_aspect.c>
+ $<$<BOOL:${OGG_FOUND}>:ogg_encoder_aspect.c>
+ $<$<BOOL:${OGG_FOUND}>:ogg_helper.c>
+ $<$<BOOL:${OGG_FOUND}>:ogg_mapping.c>)
+if(TARGET FLAC-asm)
+ target_sources(FLAC PRIVATE $<TARGET_OBJECTS:FLAC-asm>)
+endif()
+if(WIN32)
+ target_sources(FLAC PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/windows_unicode_filenames.c>)
+endif()
+
+target_compile_definitions(FLAC
+ PRIVATE $<$<BOOL:${BUILD_SHARED_LIBS}>:FLAC_API_EXPORTS>
+ PRIVATE $<$<BOOL:${BUILD_SHARED_LIBS}>:FLAC__USE_VISIBILITY_ATTR>
+ PUBLIC $<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:FLAC__NO_DLL>)
+target_include_directories(FLAC INTERFACE
+ "$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>"
+ "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")
+target_link_libraries(FLAC PRIVATE $<$<BOOL:${HAVE_LROUND}>:m>)
+if(TARGET Ogg::ogg)
+ target_link_libraries(FLAC PUBLIC Ogg::ogg)
+endif()
+if(BUILD_SHARED_LIBS)
+ set_target_properties(FLAC PROPERTIES
+ C_VISIBILITY_PRESET hidden
+ VERSION 8.3.0
+ SOVERSION 8)
+endif()
+
+install(TARGETS FLAC EXPORT targets
+ ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}/"
+ LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}/"
+ RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}/")
+install(FILES "${CMAKE_CURRENT_BINARY_DIR}/flac.pc"
+ DESTINATION "${CMAKE_INSTALL_DATADIR}/pkgconfig")
--- /dev/null
+++ a/src/libFLAC/ia32/CMakeLists.txt
@@ -0,0 +1,18 @@
+cmake_minimum_required(VERSION 3.12)
+
+include_directories("${CMAKE_CURRENT_SOURCE_DIR}")
+
+if(APPLE)
+ add_compile_options(-dOBJ_FORMAT_macho)
+elseif(WIN32)
+ #add_compile_options(-d OBJ_FORMAT_win32)
+ # FIXME the command above doesn't seem to work on Windows
+ set(CMAKE_ASM_NASM_FLAGS -dOBJ_FORMAT_win32)
+else()
+ add_compile_options(-dOBJ_FORMAT_elf)
+endif()
+
+add_library(FLAC-asm OBJECT
+ cpu_asm.nasm
+ fixed_asm.nasm
+ lpc_asm.nasm)
--- /dev/null
+++ a/src/libFLAC++/CMakeLists.txt
@@ -0,0 +1,45 @@
+set(prefix "${CMAKE_INSTALL_PREFIX}")
+set(exec_prefix "${CMAKE_INSTALL_PREFIX}")
+set(libdir "${CMAKE_INSTALL_FULL_LIBDIR}")
+set(includedir "${CMAKE_INSTALL_FULL_INCLUDEDIR}")
+configure_file(flac++.pc.in flac++.pc @ONLY)
+
+check_cxx_source_compiles("
+ #ifdef __STDC_NO_VLA__
+ syntax error;
+ #else
+ int fvla (int m, int * c)
+ {
+ int D[m];
+ return D[0] == c[0];
+ }
+
+ int main(int, char * []) { return 0; }
+ #endif"
+ HAVE_CXX_VARARRAYS)
+
+add_library(FLAC++
+ metadata.cpp
+ stream_decoder.cpp
+ stream_encoder.cpp)
+target_compile_definitions(FLAC++
+ PRIVATE $<$<BOOL:${BUILD_SHARED_LIBS}>:FLACPP_API_EXPORTS>
+ PRIVATE $<$<BOOL:${BUILD_SHARED_LIBS}>:FLAC__USE_VISIBILITY_ATTR>
+ PUBLIC $<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:FLAC__NO_DLL>)
+target_include_directories(FLAC++ INTERFACE
+ "$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>"
+ "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")
+target_link_libraries(FLAC++ PUBLIC FLAC)
+if(BUILD_SHARED_LIBS)
+ set_target_properties(FLAC++ PROPERTIES
+ CXX_VISIBILITY_PRESET hidden
+ VERSION 6.3.0
+ SOVERSION 6)
+endif()
+
+install(TARGETS FLAC++ EXPORT targets
+ ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}/"
+ LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}/"
+ RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}/")
+install(FILES "${CMAKE_CURRENT_BINARY_DIR}/flac++.pc"
+ DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig")
--- /dev/null
+++ a/src/metaflac/CMakeLists.txt
@@ -0,0 +1,18 @@
+add_executable(metaflac
+ main.c
+ operations.c
+ operations_shorthand_cuesheet.c
+ operations_shorthand_picture.c
+ operations_shorthand_seektable.c
+ operations_shorthand_streaminfo.c
+ operations_shorthand_vorbiscomment.c
+ options.c
+ usage.c
+ utils.c)
+target_link_libraries(metaflac FLAC getopt utf8)
+if(TARGET win_utf8_io)
+ target_link_libraries(metaflac win_utf8_io)
+endif()
+
+install(TARGETS metaflac EXPORT targets
+ RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
--- /dev/null
+++ a/src/plugin_common/CMakeLists.txt
@@ -0,0 +1,5 @@
+add_library(plugin_common STATIC
+ charset.c
+ dither.c
+ replaygain.c
+ tags.c)
--- /dev/null
+++ a/src/plugin_xmms/CMakeLists.txt
@@ -0,0 +1,8 @@
+add_library(xmms-flac STATIC
+ charset.c
+ configure.c
+ fileinfo.c
+ http.c
+ plugin.c
+ tag.c)
+target_link_libraries(xmms-flac plugin_common)
--- /dev/null
+++ a/src/share/CMakeLists.txt
@@ -0,0 +1,8 @@
+add_subdirectory("replaygain_analysis")
+add_subdirectory("replaygain_synthesis")
+add_subdirectory("getopt")
+add_subdirectory("utf8")
+if(WIN32)
+ add_subdirectory("win_utf8_io")
+endif()
+add_subdirectory("grabbag")
--- /dev/null
+++ a/src/share/getopt/CMakeLists.txt
@@ -0,0 +1,11 @@
+check_include_file("string.h" HAVE_STRING_H)
+
+find_package(Intl)
+
+add_library(getopt STATIC getopt.c getopt1.c)
+
+if(Intl_FOUND)
+ target_include_directories(getopt PRIVATE ${Intl_INCLUDE_DIRS})
+ target_link_libraries(getopt PUBLIC ${Intl_LIBRARIES})
+ target_compile_definitions(getopt PRIVATE HAVE_LIBINTL_H)
+endif()
--- /dev/null
+++ a/src/share/grabbag/CMakeLists.txt
@@ -0,0 +1,14 @@
+add_library(grabbag STATIC
+ alloc.c
+ cuesheet.c
+ file.c
+ picture.c
+ replaygain.c
+ seektable.c
+ snprintf.c)
+target_link_libraries(grabbag PUBLIC
+ FLAC
+ replaygain_analysis)
+if(TARGET win_utf8_io)
+ target_link_libraries(grabbag PUBLIC win_utf8_io)
+endif()
--- /dev/null
+++ a/src/share/replaygain_analysis/CMakeLists.txt
@@ -0,0 +1,2 @@
+add_library(replaygain_analysis STATIC
+ replaygain_analysis.c)
--- /dev/null
+++ a/src/share/replaygain_synthesis/CMakeLists.txt
@@ -0,0 +1,2 @@
+add_library(replaygain_synthesis STATIC
+ replaygain_synthesis.c)
--- /dev/null
+++ a/src/share/utf8/CMakeLists.txt
@@ -0,0 +1,9 @@
+set(CMAKE_REQUIRED_LIBRARIES iconv)
+check_symbol_exists(iconv "iconv.h" HAVE_ICONV_LIB)
+
+add_library(utf8 STATIC
+ charset.c
+ iconvert.c
+ utf8.c)
+
+target_link_libraries(utf8 PUBLIC grabbag $<$<BOOL:${HAVE_ICONV_LIB}>:iconv>)
--- /dev/null
+++ a/src/share/win_utf8_io/CMakeLists.txt
@@ -0,0 +1 @@
+add_library(win_utf8_io STATIC win_utf8_io.c)
--- /dev/null
+++ a/src/test_grabbag/CMakeLists.txt
@@ -0,0 +1,2 @@
+add_subdirectory(cuesheet)
+add_subdirectory(picture)
--- /dev/null
+++ a/src/test_grabbag/cuesheet/CMakeLists.txt
@@ -0,0 +1,2 @@
+add_executable(test_cuesheet main.c)
+target_link_libraries(test_cuesheet FLAC grabbag)
--- /dev/null
+++ a/src/test_grabbag/picture/CMakeLists.txt
@@ -0,0 +1,2 @@
+add_executable(test_picture main.c)
+target_link_libraries(test_picture FLAC grabbag)
--- /dev/null
+++ a/src/test_libFLAC/CMakeLists.txt
@@ -0,0 +1,23 @@
+add_executable(test_libFLAC
+ bitreader.c
+ bitwriter.c
+ crc.c
+ decoders.c
+ encoders.c
+ endswap.c
+ format.c
+ main.c
+ metadata.c
+ metadata_manip.c
+ metadata_object.c
+ md5.c
+ "$<TARGET_PROPERTY:FLAC,SOURCE_DIR>/bitreader.c"
+ "$<TARGET_PROPERTY:FLAC,SOURCE_DIR>/bitwriter.c"
+ "$<TARGET_PROPERTY:FLAC,SOURCE_DIR>/crc.c"
+ "$<TARGET_PROPERTY:FLAC,SOURCE_DIR>/md5.c")
+
+target_compile_definitions(test_libFLAC PRIVATE
+ $<$<BOOL:${ENABLE_64_BIT_WORDS}>:ENABLE_64_BIT_WORDS>)
+target_include_directories(test_libFLAC PRIVATE
+ "$<TARGET_PROPERTY:FLAC,SOURCE_DIR>/include")
+target_link_libraries(test_libFLAC FLAC grabbag test_libs_common)
--- /dev/null
+++ a/src/test_libFLAC++/CMakeLists.txt
@@ -0,0 +1,8 @@
+add_executable(test_libFLAC++
+ decoders.cpp
+ encoders.cpp
+ main.cpp
+ metadata.cpp
+ metadata_manip.cpp
+ metadata_object.cpp)
+target_link_libraries(test_libFLAC++ FLAC++ test_libs_common grabbag)
--- /dev/null
+++ a/src/test_libs_common/CMakeLists.txt
@@ -0,0 +1,4 @@
+add_library(test_libs_common STATIC
+ file_utils_flac.c
+ metadata_utils.c)
+target_link_libraries(test_libs_common PUBLIC FLAC)
--- /dev/null
+++ a/src/test_seeking/CMakeLists.txt
@@ -0,0 +1,2 @@
+add_executable(test_seeking main.c)
+target_link_libraries(test_seeking FLAC)
--- /dev/null
+++ a/src/test_streams/CMakeLists.txt
@@ -0,0 +1,2 @@
+add_executable(test_streams main.c)
+target_link_libraries(test_streams FLAC grabbag)
--- /dev/null
+++ a/src/utils/CMakeLists.txt
@@ -0,0 +1,6 @@
+if(BUILD_CXXLIBS)
+ add_subdirectory(flacdiff)
+ if(WIN32)
+ add_subdirectory(flactimer)
+ endif()
+endif()
--- /dev/null
+++ a/src/utils/flacdiff/CMakeLists.txt
@@ -0,0 +1,5 @@
+add_executable(flacdiff main.cpp)
+target_link_libraries(flacdiff FLAC++)
+if(TARGET win_utf8_io)
+ target_link_libraries(flacdiff win_utf8_io)
+endif()
--- /dev/null
+++ a/src/utils/flactimer/CMakeLists.txt
@@ -0,0 +1,2 @@
+add_executable(flactimer main.cpp)
+target_link_libraries(flactimer FLAC++)
--- /dev/null
+++ a/test/CMakeLists.txt
@@ -0,0 +1,49 @@
+if(NOT UNIX)
+ return()
+endif()
+
+if(WIN32)
+ set(EXEEXT .exe)
+endif()
+set(top_srcdir "${PROJECT_SOURCE_DIR}")
+set(top_builddir "${PROJECT_BINARY_DIR}")
+configure_file(common.sh.in common.sh @ONLY)
+
+set(ALL_TESTS libFLAC grabbag flac metaflac replaygain seeking streams compression)
+
+add_test(NAME libFLAC
+ COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/test_libFLAC.sh"
+ WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
+if(BUILD_CXXLIBS)
+ add_test(NAME libFLAC++
+ COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/test_libFLAC++.sh"
+ WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
+ list(APPEND ALL_TESTS libFLAC++)
+endif()
+file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/cuesheets")
+add_test(NAME grabbag
+ COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/test_grabbag.sh"
+ WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
+add_test(NAME flac
+ COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/test_flac.sh"
+ WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
+file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/metaflac-test-files")
+add_test(NAME metaflac
+ COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/test_metaflac.sh"
+ WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
+add_test(NAME replaygain
+ COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/test_replaygain.sh"
+ WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
+add_test(NAME seeking
+ COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/test_seeking.sh"
+ WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
+add_test(NAME streams
+ COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/test_streams.sh"
+ WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
+# increase this if standard 1500 seconds are not enough
+# set_tests_properties(streams PROPERTIES TIMEOUT 1500)
+add_test(NAME compression
+ COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/test_compression.sh"
+ WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
+
+set_property(TEST ${ALL_TESTS} APPEND PROPERTY ENVIRONMENT ECHO_C=\\c)
--- /dev/null
+++ a/cmake/FindOGG.cmake
@@ -0,0 +1,26 @@
+find_package(PkgConfig)
+pkg_check_modules(_OGG QUIET ogg)
+
+find_path(OGG_INCLUDE_DIR
+ NAMES "ogg/ogg.h"
+ PATHS ${_OGG_INCLUDE_DIRS})
+
+find_library(OGG_LIBRARY
+ NAMES ogg libogg
+ HINTS ${_OGG_LIBRARY_DIRS})
+
+mark_as_advanced(
+ OGG_INCLUDE_DIR
+ OGG_LIBRARY)
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(OGG
+ REQUIRED_VARS OGG_INCLUDE_DIR OGG_LIBRARY
+ VERSION_VAR _OGG_VERSION)
+
+if(OGG_FOUND AND NOT TARGET Ogg::ogg)
+ add_library(Ogg::ogg UNKNOWN IMPORTED)
+ set_target_properties(Ogg::ogg PROPERTIES
+ INTERFACE_INCLUDE_DIRECTORIES "${OGG_INCLUDE_DIR}"
+ IMPORTED_LOCATION "${OGG_LIBRARY}")
+endif()
--- /dev/null
+++ /cmake/UseSystemExtensions.cmake
@@ -0,0 +1,73 @@
+include(CheckCSourceCompiles)
+
+check_c_source_compiles("
+ int main()
+ {
+ #ifndef _FORTIFY_SOURCE
+ return 0;
+ #else
+ this_is_an_error;
+ #endif
+ }"
+ DODEFINE_FORTIFY_SOURCE)
+check_c_source_compiles("
+ #include <wchar.h>
+ mbstate_t x;
+ int main() { return 0; }"
+ HAVE_MBSTATE)
+if(NOT HAVE_MBSTATE)
+ check_c_source_compiles("
+ #define _XOPEN_SOURCE 500
+ #include <wchar.h>
+ mbstate_t x;
+ int main() { return 0; }"
+ DODEFINE_XOPEN_SOURCE)
+endif()
+check_c_source_compiles("
+ #define __EXTENSIONS__ 1
+ #include <stdio.h>
+ #ifdef HAVE_SYS_TYPES_H
+ # include <sys/types.h>
+ #endif
+ #ifdef HAVE_SYS_STAT_H
+ # include <sys/stat.h>
+ #endif
+ #ifdef STDC_HEADERS
+ # include <stdlib.h>
+ # include <stddef.h>
+ #else
+ # ifdef HAVE_STDLIB_H
+ # include <stdlib.h>
+ # endif
+ #endif
+ #ifdef HAVE_STRING_H
+ # if !defined STDC_HEADERS && defined HAVE_MEMORY_H
+ # include <memory.h>
+ # endif
+ # include <string.h>
+ #endif
+ #ifdef HAVE_STRINGS_H
+ # include <strings.h>
+ #endif
+ #ifdef HAVE_INTTYPES_H
+ # include <inttypes.h>
+ #endif
+ #ifdef HAVE_STDINT_H
+ # include <stdint.h>
+ #endif
+ #ifdef HAVE_UNISTD_H
+ # include <unistd.h>
+ #endif
+ int main() { return 0; }"
+ DODEFINE_EXTENSIONS)
+
+add_definitions(
+ -D_DARWIN_C_SOURCE
+ -D_POSIX_PTHREAD_SEMANTICS
+ -D__STDC_WANT_IEC_60559_BFP_EXT__
+ -D__STDC_WANT_IEC_60559_DFP_EXT__
+ -D__STDC_WANT_IEC_60559_FUNCS_EXT__
+ -D__STDC_WANT_IEC_60559_TYPES_EXT__
+ -D__STDC_WANT_LIB_EXT2__
+ -D__STDC_WANT_MATH_SPEC_FUNCS__
+ -D_TANDEM_SOURCE)
--- /dev/null
+++ a/config.cmake.h.in
@@ -0,0 +1,234 @@
+/* config.h.in. Generated from configure.ac by autoheader. */
+
+/* Define if building universal (internal helper macro) */
+#cmakedefine AC_APPLE_UNIVERSAL_BUILD
+
+/* Target processor is big endian. */
+#cmakedefine01 CPU_IS_BIG_ENDIAN
+
+/* Target processor is little endian. */
+#cmakedefine01 CPU_IS_LITTLE_ENDIAN
+
+/* Set FLAC__BYTES_PER_WORD to 8 (4 is the default) */
+#cmakedefine01 ENABLE_64_BIT_WORDS
+
+/* define to align allocated memory on 32-byte boundaries */
+#cmakedefine FLAC__ALIGN_MALLOC_DATA
+
+/* define if you have docbook-to-man or docbook2man */
+#cmakedefine FLAC__HAS_DOCBOOK_TO_MAN
+
+/* define if you are compiling for x86 and have the NASM assembler */
+#cmakedefine FLAC__HAS_NASM
+
+/* define if you have the ogg library */
+#cmakedefine01 OGG_FOUND
+#define FLAC__HAS_OGG OGG_FOUND
+
+/* define if compiler has __attribute__((target("cpu=power8"))) support */
+#cmakedefine FLAC__HAS_TARGET_POWER8
+
+/* define if compiler has __attribute__((target("cpu=power9"))) support */
+#cmakedefine FLAC__HAS_TARGET_POWER9
+
+/* Set to 1 if <x86intrin.h> is available. */
+#cmakedefine01 FLAC__HAS_X86INTRIN
+
+/* define if building for Darwin / MacOS X */
+#cmakedefine FLAC__SYS_DARWIN
+
+/* define if building for Linux */
+#cmakedefine FLAC__SYS_LINUX
+
+/* define to enable use of Altivec instructions */
+#cmakedefine FLAC__USE_ALTIVEC
+
+/* define to enable use of AVX instructions */
+#cmakedefine01 WITH_AVX
+#define FLAC__USE_AVX WITH_AVX
+
+/* define to enable use of VSX instructions */
+#cmakedefine FLAC__USE_VSX
+
+/* Compiler has the __builtin_bswap16 intrinsic */
+#cmakedefine01 HAVE_BSWAP16
+
+/* Compiler has the __builtin_bswap32 intrinsic */
+#cmakedefine01 HAVE_BSWAP32
+
+/* Define to 1 if you have the <byteswap.h> header file. */
+#cmakedefine HAVE_BYTESWAP_H
+
+/* define if you have clock_gettime */
+#cmakedefine HAVE_CLOCK_GETTIME
+
+/* Define to 1 if you have the <cpuid.h> header file. */
+#cmakedefine HAVE_CPUID_H
+
+/* Define to 1 if C++ supports variable-length arrays. */
+#cmakedefine HAVE_CXX_VARARRAYS
+
+/* Define to 1 if C supports variable-length arrays. */
+#cmakedefine HAVE_C_VARARRAYS
+
+/* Define to 1 if fseeko (and presumably ftello) exists and is declared. */
+#cmakedefine HAVE_FSEEKO
+
+/* Define to 1 if you have the `getopt_long' function. */
+#cmakedefine HAVE_GETOPT_LONG
+
+/* Define if you have the iconv() function and it works. */
+#cmakedefine HAVE_ICONV
+
+/* Define to 1 if you have the <inttypes.h> header file. */
+#cmakedefine01 HAVE_INTTYPES_H
+
+/* Define if you have <langinfo.h> and nl_langinfo(CODESET). */
+#cmakedefine HAVE_LANGINFO_CODESET
+
+/* lround support */
+#cmakedefine01 HAVE_LROUND
+
+/* Define to 1 if you have the <memory.h> header file. */
+#cmakedefine HAVE_MEMORY_H
+
+/* Define to 1 if the system has the type `socklen_t'. */
+#cmakedefine HAVE_SOCKLEN_T
+
+/* Define to 1 if you have the <stdint.h> header file. */
+#cmakedefine01 HAVE_STDINT_H
+
+/* Define to 1 if you have the <stdlib.h> header file. */
+#cmakedefine HAVE_STDLIB_H
+
+/* Define to 1 if you have the <string.h> header file. */
+#cmakedefine HAVE_STRING_H
+
+/* Define to 1 if you have the <sys/ioctl.h> header file. */
+#cmakedefine HAVE_SYS_IOCTL_H
+
+/* Define to 1 if you have the <sys/param.h> header file. */
+#cmakedefine HAVE_SYS_PARAM_H
+
+/* Define to 1 if you have the <sys/stat.h> header file. */
+#cmakedefine HAVE_SYS_STAT_H
+
+/* Define to 1 if you have the <sys/types.h> header file. */
+#cmakedefine HAVE_SYS_TYPES_H
+
+/* Define to 1 if you have the <termios.h> header file. */
+#cmakedefine HAVE_TERMIOS_H
+
+/* Define to 1 if typeof works with your compiler. */
+#cmakedefine HAVE_TYPEOF
+
+/* Define to 1 if you have the <unistd.h> header file. */
+#cmakedefine HAVE_UNISTD_H
+
+/* Define to 1 if you have the <x86intrin.h> header file. */
+#cmakedefine HAVE_X86INTRIN_H
+
+/* Define as const if the declaration of iconv() needs const. */
+#cmakedefine ICONV_CONST
+
+/* Define if debugging is disabled */
+#cmakedefine NDEBUG
+
+/* Name of package */
+#cmakedefine PACKAGE
+
+/* Define to the address where bug reports for this package should be sent. */
+#cmakedefine PACKAGE_BUGREPORT
+
+/* Define to the full name of this package. */
+#cmakedefine PACKAGE_NAME
+
+/* Define to the full name and version of this package. */
+#cmakedefine PACKAGE_STRING
+
+/* Define to the one symbol short name of this package. */
+#cmakedefine PACKAGE_TARNAME
+
+/* Define to the home page for this package. */
+#cmakedefine PACKAGE_URL
+
+/* Define to the version of this package. */
+#define PACKAGE_VERSION "@PROJECT_VERSION@"
+
+/* The size of `off_t', as computed by sizeof. */
+#cmakedefine SIZEOF_OFF_T
+
+/* The size of `void*', as computed by sizeof. */
+#cmakedefine SIZEOF_VOIDP
+
+/* Define to 1 if you have the ANSI C header files. */
+#cmakedefine STDC_HEADERS
+
+/* Enable extensions on AIX 3, Interix. */
+#ifndef _ALL_SOURCE
+#define _ALL_SOURCE
+#endif
+
+/* Enable GNU extensions on systems that have them. */
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+
+#ifndef _FORTIFY_SOURCE
+#cmakedefine DODEFINE_FORTIFY_SOURCE 2
+#define _FORTIFY_SOURCE DODEFINE_FORTIFY_SOURCE
+#endif
+
+#ifndef _XOPEN_SOURCE
+#cmakedefine DODEFINE_XOPEN_SOURCE 500
+#define _XOPEN_SOURCE DODEFINE_XOPEN_SOURCE
+#endif
+
+/* Enable threading extensions on Solaris. */
+#ifndef _POSIX_PTHREAD_SEMANTICS
+#cmakedefine _POSIX_PTHREAD_SEMANTICS
+#endif
+/* Enable extensions on HP NonStop. */
+#ifndef _TANDEM_SOURCE
+#cmakedefine _TANDEM_SOURCE
+#endif
+/* Enable general extensions on Solaris. */
+#ifndef __EXTENSIONS__
+#cmakedefine DODEFINE_EXTENSIONS
+#define __EXTENSIONS__ DODEFINE_EXTENSIONS
+#endif
+
+
+/* Target processor is big endian. */
+#define WORDS_BIGENDIAN CPU_IS_BIG_ENDIAN
+
+/* Enable large inode numbers on Mac OS X 10.5. */
+#ifndef _DARWIN_USE_64_BIT_INODE
+# define _DARWIN_USE_64_BIT_INODE 1
+#endif
+
+/* Number of bits in a file offset, on hosts where this is settable. */
+#ifndef _FILE_OFFSET_BITS
+# define _FILE_OFFSET_BITS 64
+#endif
+
+/* Define to 1 to make fseeko visible on some hosts (e.g. glibc 2.2). */
+#ifndef _LARGEFILE_SOURCE
+# define _LARGEFILE_SOURCE
+#endif
+
+/* Define for large files, on AIX-style hosts. */
+#cmakedefine _LARGE_FILES
+
+/* Define to 1 if on MINIX. */
+#cmakedefine _MINIX
+
+/* Define to 2 if the system does not provide POSIX.1 features except with
+ this defined. */
+#cmakedefine _POSIX_1_SOURCE
+
+/* Define to 1 if you need to in order for `stat' and other things to work. */
+#cmakedefine _POSIX_SOURCE
+
+/* Define to __typeof__ if your compiler spells it that way. */
+#cmakedefine typeof
--- /dev/null
+++ a/flac-config.cmake.in
@@ -0,0 +1,18 @@
+@PACKAGE_INIT@
+
+if(@OGG_FOUND@)
+ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")
+ include(CMakeFindDependencyMacro)
+ find_dependency(OGG)
+endif()
+
+include("${CMAKE_CURRENT_LIST_DIR}/targets.cmake")
+
+if(TARGET FLAC::FLAC)
+ set(FLAC_FLAC_FOUND 1)
+endif()
+if(TARGET FLAC::FLAC++)
+ set(FLAC_FLAC++_FOUND 1)
+endif()
+
+check_required_components(FLAC)