CMake support added
authorVitaliy Kirsanov <krokoziabla@yandex-team.ru>
Sun, 31 Mar 2019 20:04:45 +0000 (23:04 +0300)
committerErik de Castro Lopo <erikd@mega-nerd.com>
Sat, 4 May 2019 01:41:48 +0000 (11:41 +1000)
41 files changed:
CMakeLists.txt [new file with mode: 0644]
cmake/UseSystemExtensions.cmake [new file with mode: 0644]
doc/CMakeLists.txt [new file with mode: 0644]
doc/html/CMakeLists.txt [new file with mode: 0644]
doc/html/images/CMakeLists.txt [new file with mode: 0644]
examples/CMakeLists.txt [new file with mode: 0644]
examples/c/CMakeLists.txt [new file with mode: 0644]
examples/c/decode/file/CMakeLists.txt [new file with mode: 0644]
examples/c/encode/file/CMakeLists.txt [new file with mode: 0644]
examples/cpp/CMakeLists.txt [new file with mode: 0644]
examples/cpp/decode/file/CMakeLists.txt [new file with mode: 0644]
examples/cpp/encode/file/CMakeLists.txt [new file with mode: 0644]
flac-config.cmake.in [new file with mode: 0644]
microbench/CMakeLists.txt [new file with mode: 0644]
microbench/util.c
src/CMakeLists.txt [new file with mode: 0644]
src/flac/CMakeLists.txt [new file with mode: 0644]
src/libFLAC++/CMakeLists.txt [new file with mode: 0644]
src/libFLAC/CMakeLists.txt [new file with mode: 0644]
src/libFLAC/ia32/CMakeLists.txt [new file with mode: 0644]
src/metaflac/CMakeLists.txt [new file with mode: 0644]
src/plugin_common/CMakeLists.txt [new file with mode: 0644]
src/plugin_xmms/CMakeLists.txt [new file with mode: 0644]
src/share/CMakeLists.txt [new file with mode: 0644]
src/share/getopt/CMakeLists.txt [new file with mode: 0644]
src/share/grabbag/CMakeLists.txt [new file with mode: 0644]
src/share/replaygain_analysis/CMakeLists.txt [new file with mode: 0644]
src/share/replaygain_synthesis/CMakeLists.txt [new file with mode: 0644]
src/share/utf8/CMakeLists.txt [new file with mode: 0644]
src/share/win_utf8_io/CMakeLists.txt [new file with mode: 0644]
src/test_grabbag/CMakeLists.txt [new file with mode: 0644]
src/test_grabbag/cuesheet/CMakeLists.txt [new file with mode: 0644]
src/test_grabbag/picture/CMakeLists.txt [new file with mode: 0644]
src/test_libFLAC++/CMakeLists.txt [new file with mode: 0644]
src/test_libFLAC/CMakeLists.txt [new file with mode: 0644]
src/test_libs_common/CMakeLists.txt [new file with mode: 0644]
src/test_seeking/CMakeLists.txt [new file with mode: 0644]
src/test_streams/CMakeLists.txt [new file with mode: 0644]
src/utils/CMakeLists.txt [new file with mode: 0644]
src/utils/flacdiff/CMakeLists.txt [new file with mode: 0644]
src/utils/flactimer/CMakeLists.txt [new file with mode: 0644]

diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644 (file)
index 0000000..a4870fe
--- /dev/null
@@ -0,0 +1,123 @@
+cmake_minimum_required(VERSION 3.12)
+
+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)
+
+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_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wcast-align -Wshadow -Wwrite-strings -Wctor-dtor-privacy -Wnon-virtual-dtor -Wreorder -Wsign-promo -Wundef")
+
+    if(CMAKE_BULD_TYPE STREQUAL Release)
+        set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 -funroll-loops")
+    endif()
+
+    option(ENABLE_SSP "Enable GNU GCC stack smash protection" OFF)
+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" HAVE_X86INTRIN_H)
+
+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_definitions(
+    PACKAGE_VERSION="${PROJECT_VERSION}"
+    $<$<BOOL:${HAVE_BYTESWAP_H}>:HAVE_BYTESWAP_H>
+    $<$<BOOL:${HAVE_INTTYPES_H}>:HAVE_INTTYPES_H>
+    $<$<BOOL:${HAVE_STDINT_H}>:HAVE_STDINT_H>
+    $<$<BOOL:${MSVC}>:_CRT_SECURE_NO_WARNINGS>
+    CPU_IS_BIG_ENDIAN=$<BOOL:${CPU_IS_BIG_ENDIAN}>
+    CPU_IS_LITTLE_ENDIAN=$<NOT:$<BOOL:${CPU_IS_BIG_ENDIAN}>>
+    FLAC__HAS_X86INTRIN=$<BOOL:${HAVE_X86INTRIN_H}>
+    HAVE_BSWAP16=$<BOOL:${HAVE_BSWAP16}>
+    HAVE_BSWAP32=$<BOOL:${HAVE_BSWAP32}>)
+
+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>)
+
+if(HAVE_WEFFCXX_FLAG)
+    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Weffc++")
+endif()
+if(HAVE_DECL_AFTER_STMT_FLAG)
+    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wdeclaration-after-statement")
+endif()
+
+if(CMAKE_SYSTEM_PROCESSOR STREQUAL "i686" AND HAVE_STACKREALIGN_FLAG)
+    add_compile_options(-mstackrealign)
+endif()
+
+include_directories("include")
+
+add_subdirectory("doc")
+add_subdirectory("src")
+add_subdirectory("microbench")
+if(BUILD_EXAMPLES)
+    add_subdirectory("examples")
+endif()
+
+if(WIN32)
+    set(EXEEXT .exe)
+endif()
+set(top_srcdir "${CMAKE_CURRENT_SOURCE_DIR}")
+set(top_builddir "${CMAKE_CURRENT_BINARY_DIR}")
+configure_file(test/common.sh.in test/common.sh @ONLY)
+
+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"
+    DESTINATION "${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}/cmake")
+
+file(GLOB FLAC_HEADERS "include/FLAC/*.h")
+file(GLOB FLACXX_HEADERS "include/FLAC++/*.h")
+install(FILES ${FLAC_HEADERS} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/FLAC")
+install(FILES ${FLACXX_HEADERS} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/FLAC++")
+install(FILES "man/flac.1" "man/metaflac.1" DESTINATION "${CMAKE_INSTALL_MANDIR}")
diff --git a/cmake/UseSystemExtensions.cmake b/cmake/UseSystemExtensions.cmake
new file mode 100644 (file)
index 0000000..4a33fd4
--- /dev/null
@@ -0,0 +1,81 @@
+cmake_minimum_required(VERSION 3.12)
+
+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_compile_definitions(
+    _ALL_SOURCE
+    _DARWIN_C_SOURCE
+    _GNU_SOURCE
+    _POSIX_PTHREAD_SEMANTICS
+    __STDC_WANT_IEC_60559_ATTRIBS_EXT__
+    __STDC_WANT_IEC_60559_BFP_EXT__
+    __STDC_WANT_IEC_60559_DFP_EXT__
+    __STDC_WANT_IEC_60559_FUNCS_EXT__
+    __STDC_WANT_IEC_60559_TYPES_EXT__
+    __STDC_WANT_LIB_EXT2__
+    __STDC_WANT_MATH_SPEC_FUNCS__
+    _TANDEM_SOURCE
+    $<$<AND:$<BOOL:${DODEFINE_FORTIFY_SOURCE}>,$<OR:$<CONFIG:Release>,$<CONFIG:RelWithDebInfo>>>:_FORTIFY_SOURCE=2>
+    $<$<BOOL:${DODEFINE_XOPEN_SOURCE}>:_XOPEN_SOURCE=500>
+    $<$<BOOL:${DODEFINE_EXTENTIONS}>:__EXTENSIONS__>)
diff --git a/doc/CMakeLists.txt b/doc/CMakeLists.txt
new file mode 100644 (file)
index 0000000..a4e38ef
--- /dev/null
@@ -0,0 +1,23 @@
+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")
diff --git a/doc/html/CMakeLists.txt b/doc/html/CMakeLists.txt
new file mode 100644 (file)
index 0000000..6ac1e11
--- /dev/null
@@ -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")
diff --git a/doc/html/images/CMakeLists.txt b/doc/html/images/CMakeLists.txt
new file mode 100644 (file)
index 0000000..922d305
--- /dev/null
@@ -0,0 +1,4 @@
+install(FILES
+    logo.svg
+    logo130.gif
+DESTINATION "${CMAKE_INSTALL_DOCDIR}/html/images")
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
new file mode 100644 (file)
index 0000000..96298fd
--- /dev/null
@@ -0,0 +1,4 @@
+add_subdirectory("c")
+if(BUILD_CXXLIBS)
+    add_subdirectory("cpp")
+endif()
diff --git a/examples/c/CMakeLists.txt b/examples/c/CMakeLists.txt
new file mode 100644 (file)
index 0000000..4115341
--- /dev/null
@@ -0,0 +1,2 @@
+add_subdirectory("decode/file")
+add_subdirectory("encode/file")
diff --git a/examples/c/decode/file/CMakeLists.txt b/examples/c/decode/file/CMakeLists.txt
new file mode 100644 (file)
index 0000000..60dc18e
--- /dev/null
@@ -0,0 +1,2 @@
+add_executable(decode_file main.c)
+target_link_libraries(decode_file FLAC-static)
diff --git a/examples/c/encode/file/CMakeLists.txt b/examples/c/encode/file/CMakeLists.txt
new file mode 100644 (file)
index 0000000..c9c8e80
--- /dev/null
@@ -0,0 +1,2 @@
+add_executable(encode_file main.c)
+target_link_libraries(encode_file FLAC-static)
diff --git a/examples/cpp/CMakeLists.txt b/examples/cpp/CMakeLists.txt
new file mode 100644 (file)
index 0000000..4115341
--- /dev/null
@@ -0,0 +1,2 @@
+add_subdirectory("decode/file")
+add_subdirectory("encode/file")
diff --git a/examples/cpp/decode/file/CMakeLists.txt b/examples/cpp/decode/file/CMakeLists.txt
new file mode 100644 (file)
index 0000000..0cea828
--- /dev/null
@@ -0,0 +1,2 @@
+add_executable(decode_file_cxx main.cpp)
+target_link_libraries(decode_file_cxx FLACXX-static)
diff --git a/examples/cpp/encode/file/CMakeLists.txt b/examples/cpp/encode/file/CMakeLists.txt
new file mode 100644 (file)
index 0000000..b4526d7
--- /dev/null
@@ -0,0 +1,2 @@
+add_executable(encode_file_cxx main.cpp)
+target_link_libraries(encode_file_cxx FLACXX-static)
diff --git a/flac-config.cmake.in b/flac-config.cmake.in
new file mode 100644 (file)
index 0000000..89c6e7d
--- /dev/null
@@ -0,0 +1,3 @@
+@PACKAGE_INIT@
+
+include("${CMAKE_CURRENT_LIST_DIR}/targets.cmake")
diff --git a/microbench/CMakeLists.txt b/microbench/CMakeLists.txt
new file mode 100644 (file)
index 0000000..6404205
--- /dev/null
@@ -0,0 +1,17 @@
+if(MSVC)
+    return()
+endif()
+
+set(CMAKE_REQUIRED_LIBRARIES rt)
+check_function_exists(clock_gettime HAVE_CLOCK_GETTIME)
+
+add_compile_definitions(
+    $<$<BOOL:${HAVE_CLOCK_GETTIME}>:HAVE_CLOCK_GETTIME>
+    $<$<BOOL:${APPLE}>:FLAC__SYS_DARWIN>)
+
+add_executable(benchmark_residual benchmark_residual.c util.c)
+target_include_directories(benchmark_residual PRIVATE
+    "$<TARGET_PROPERTY:FLAC-static,SOURCE_DIR>/include")
+target_link_libraries(benchmark_residual
+    FLAC-static
+    $<$<BOOL:${HAVE_CLOCK_GETTIME}>:rt>)
index e8389ed..66003d7 100644 (file)
@@ -29,7 +29,9 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include <config.h>
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
 
 #include <stdlib.h>
 #include "util.h"
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
new file mode 100644 (file)
index 0000000..7de7a7f
--- /dev/null
@@ -0,0 +1,43 @@
+cmake_minimum_required(VERSION 3.12)
+
+option(ENABLE_64_BIT_WORDS "Set FLAC__BYTES_PER_WORD to 8 (4 is the default)" OFF)
+option(WITH_OGG "ogg support (default: test for libogg)" ON)
+option(WITH_XMMS "Build XMMS plugin" OFF)
+
+if(WITH_OGG)
+    find_package(OGG REQUIRED)
+endif()
+
+check_include_file("iconv.h" HAVE_ICONV_H)
+
+add_compile_definitions(
+    ENABLE_64_BIT_WORDS=$<BOOL:${ENABLE_64_BIT_WORDS}>
+    FLAC__HAS_OGG=$<BOOL:${OGG_FOUND}>
+    WORDS_BIGENDIAN=$<BOOL:${CPU_IS_BIG_ENDIAN}>
+    $<$<BOOL:${HAVE_ICONV_H}>:HAVE_ICONV>
+    $<$<BOOL:${HAVE_SYS_PARAM_H}>:HAVE_SYS_PARAM_H>)
+
+add_subdirectory("libFLAC")
+if(BUILD_CXXLIBS)
+    add_subdirectory("libFLAC++")
+endif()
+add_subdirectory("flac")
+add_subdirectory("metaflac")
+add_subdirectory("share")
+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()
diff --git a/src/flac/CMakeLists.txt b/src/flac/CMakeLists.txt
new file mode 100644 (file)
index 0000000..3fb2e2f
--- /dev/null
@@ -0,0 +1,27 @@
+cmake_minimum_required(VERSION 3.12)
+
+check_include_file("sys/ioctl.h" HAVE_SYS_IOCTL_H)
+check_include_file("termios.h" HAVE_TERMIOS_H)
+
+add_compile_definitions(
+    $<$<BOOL:${HAVE_SYS_IOCTL_H}>:HAVE_SYS_IOCTL_H>
+    $<$<BOOL:${HAVE_TERMIOS_H}>:HAVE_TERMIOS_H>)
+
+add_executable(flac
+    analyze.c
+    decode.c
+    encode.c
+    foreign_metadata.c
+    main.c
+    local_string_utils.c
+    utils.c
+    vorbiscomment.c)
+target_link_libraries(flac
+    FLAC-static
+    getopt
+    grabbag
+    replaygain_synthesis
+    utf8)
+
+install(TARGETS flac EXPORT targets
+    RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
diff --git a/src/libFLAC++/CMakeLists.txt b/src/libFLAC++/CMakeLists.txt
new file mode 100644 (file)
index 0000000..8303142
--- /dev/null
@@ -0,0 +1,48 @@
+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_compile_definitions($<$<BOOL:${HAVE_CXX_VARARRAYS}>:HAVE_CXX_VARARRAYS>)
+
+set(SOURCES
+    metadata.cpp
+    stream_decoder.cpp
+    stream_encoder.cpp)
+
+add_library(FLACXX-static STATIC ${SOURCES})
+target_compile_definitions(FLACXX-static PUBLIC FLAC__NO_DLL)
+target_include_directories(FLACXX-static INTERFACE
+    "$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>"
+    "$<INSTALL_INTERFACE:${CMAKE_INSTALL_PREFIX}/include>")
+target_link_libraries(FLACXX-static PUBLIC FLAC-static)
+
+add_library(FLACXX SHARED ${SOURCES})
+target_compile_definitions(FLACXX PRIVATE FLACPP_API_EXPORTS FLAC__USE_VISIBILITY_ATTR)
+target_include_directories(FLACXX INTERFACE
+    "$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>"
+    "$<INSTALL_INTERFACE:${CMAKE_INSTALL_PREFIX}/include>")
+target_link_libraries(FLACXX PRIVATE FLAC)
+set_target_properties(FLACXX PROPERTIES CXX_VISIBILITY_PRESET hidden)
+
+install(TARGETS FLACXX FLACXX-static 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")
diff --git a/src/libFLAC/CMakeLists.txt b/src/libFLAC/CMakeLists.txt
new file mode 100644 (file)
index 0000000..1ea9383
--- /dev/null
@@ -0,0 +1,124 @@
+cmake_minimum_required(VERSION 3.12)
+
+if(CMAKE_SYSTEM_PROCESSOR MATCHES "[xX]86(_64)?|(AMD|amd)64|i[346]86")
+    option(WITH_AVX "Enable AVX, AVX2 optimizations" ON)
+    option(WITH_SSE "Enable AVX, AVX2 optimizations" ON)
+endif()
+
+check_c_compiler_flag(-msse2 HAVE_MSSE2_FLAG)
+if(HAVE_MSSE2_FLAG AND WITH_SSE)
+    add_compile_options(-msse2)
+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)
+
+add_compile_definitions(
+    $<$<BOOL:${MSVC}>:_USE_MATH_DEFINES>
+    FLAC__USE_AVX=$<BOOL:${WITH_AVX}>
+    HAVE_LROUND=$<BOOL:${HAVE_LROUND}>
+    $<$<BOOL:${HAVE_CPUID_H}>:HAVE_CPUID_H>
+    $<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:FLAC__OVERFLOW_DETECT>)
+
+if(CMAKE_SYSTEM_PROCESSOR MATCHES "[xX]86_64|(AMD|amd)64")
+    if(CMAKE_SIZEOF_VOID_P EQUAL 4)
+        set(IA32 TRUE)
+    endif()
+    add_compile_definitions(
+        FLAC__CPU_X86_64
+        FLAC__ALIGN_MALLOC_DATA)
+elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "([xX]|i[346])86")
+    set(IA32 TRUE)
+    add_compile_definitions(
+        FLAC__CPU_IA32
+        FLAC__ALIGN_MALLOC_DATA)
+endif()
+
+include(CheckLanguage)
+check_language(ASM_NASM)
+if(CMAKE_ASM_NASM_COMPILER)
+    enable_language(ASM_NASM)
+    add_compile_definitions(FLAC__HAS_NASM)
+endif()
+
+if(NOT WITH_ASM)
+    add_compile_definitions(FLAC__NO_ASM)
+endif()
+
+if(WITH_ASM AND IA32 AND CMAKE_ASM_NASM_COMPILER)
+    add_subdirectory(ia32)
+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)
+
+set(SOURCES
+    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>
+    $<$<BOOL:${WIN32}>:windows_unicode_filenames.c>)
+
+include_directories("include")
+
+add_library(FLAC-static STATIC ${SOURCES})
+target_compile_definitions(FLAC-static PUBLIC FLAC__NO_DLL)
+target_include_directories(FLAC-static INTERFACE
+    "$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>"
+    "$<INSTALL_INTERFACE:${CMAKE_INSTALL_PREFIX}/include>")
+target_link_libraries(FLAC-static PUBLIC
+    $<TARGET_NAME_IF_EXISTS:Ogg::Ogg>
+    $<TARGET_NAME_IF_EXISTS:FLAC-asm>
+    $<$<BOOL:${HAVE_LROUND}>:m>)
+
+add_library(FLAC SHARED ${SOURCES})
+target_compile_definitions(FLAC PRIVATE FLAC_API_EXPORTS FLAC__USE_VISIBILITY_ATTR)
+target_include_directories(FLAC INTERFACE
+    "$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>"
+    "$<INSTALL_INTERFACE:${CMAKE_INSTALL_PREFIX}/include>")
+target_link_libraries(FLAC PRIVATE
+    $<TARGET_NAME_IF_EXISTS:FLAC-asm>
+    $<$<BOOL:${HAVE_LROUND}>:m>)
+set_target_properties(FLAC PROPERTIES C_VISIBILITY_PRESET hidden)
+
+install(TARGETS FLAC FLAC-static 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")
diff --git a/src/libFLAC/ia32/CMakeLists.txt b/src/libFLAC/ia32/CMakeLists.txt
new file mode 100644 (file)
index 0000000..9435706
--- /dev/null
@@ -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 STATIC
+    cpu_asm.nasm
+    fixed_asm.nasm
+    lpc_asm.nasm)
diff --git a/src/metaflac/CMakeLists.txt b/src/metaflac/CMakeLists.txt
new file mode 100644 (file)
index 0000000..8f99d64
--- /dev/null
@@ -0,0 +1,15 @@
+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-static grabbag getopt utf8)
+
+install(TARGETS metaflac EXPORT targets
+    RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
diff --git a/src/plugin_common/CMakeLists.txt b/src/plugin_common/CMakeLists.txt
new file mode 100644 (file)
index 0000000..b5c72c9
--- /dev/null
@@ -0,0 +1,5 @@
+add_library(plugin_common STATIC
+    charset.c
+    dither.c
+    replaygain.c
+    tags.c)
diff --git a/src/plugin_xmms/CMakeLists.txt b/src/plugin_xmms/CMakeLists.txt
new file mode 100644 (file)
index 0000000..3c4b716
--- /dev/null
@@ -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)
diff --git a/src/share/CMakeLists.txt b/src/share/CMakeLists.txt
new file mode 100644 (file)
index 0000000..b3c5a71
--- /dev/null
@@ -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")
diff --git a/src/share/getopt/CMakeLists.txt b/src/share/getopt/CMakeLists.txt
new file mode 100644 (file)
index 0000000..a247336
--- /dev/null
@@ -0,0 +1,12 @@
+cmake_minimum_required(VERSION 3.12)
+
+check_include_file("libintl.h" HAVE_LIBINTL_H)
+check_include_file("string.h" HAVE_STRING_H)
+
+add_compile_definitions(
+    $<$<BOOL:${HAVE_LIBINTL_H}>:HAVE_LIBINTL_H>
+    $<$<BOOL:${HAVE_STRING_H}>:HAVE_STRING_H>)
+
+add_library(getopt STATIC
+    getopt.c
+    getopt1.c)
diff --git a/src/share/grabbag/CMakeLists.txt b/src/share/grabbag/CMakeLists.txt
new file mode 100644 (file)
index 0000000..6d405d0
--- /dev/null
@@ -0,0 +1,12 @@
+add_library(grabbag STATIC
+    alloc.c
+    cuesheet.c
+    file.c
+    picture.c
+    replaygain.c
+    seektable.c
+    snprintf.c)
+target_link_libraries(grabbag
+    FLAC-static
+    replaygain_analysis
+    $<TARGET_NAME_IF_EXISTS:win_utf8_io>)
diff --git a/src/share/replaygain_analysis/CMakeLists.txt b/src/share/replaygain_analysis/CMakeLists.txt
new file mode 100644 (file)
index 0000000..4362b90
--- /dev/null
@@ -0,0 +1,2 @@
+add_library(replaygain_analysis STATIC
+    replaygain_analysis.c)
diff --git a/src/share/replaygain_synthesis/CMakeLists.txt b/src/share/replaygain_synthesis/CMakeLists.txt
new file mode 100644 (file)
index 0000000..0736f4f
--- /dev/null
@@ -0,0 +1,2 @@
+add_library(replaygain_synthesis STATIC
+    replaygain_synthesis.c)
diff --git a/src/share/utf8/CMakeLists.txt b/src/share/utf8/CMakeLists.txt
new file mode 100644 (file)
index 0000000..e0e32ac
--- /dev/null
@@ -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 $<$<BOOL:${HAVE_ICONV_LIB}>:iconv>)
diff --git a/src/share/win_utf8_io/CMakeLists.txt b/src/share/win_utf8_io/CMakeLists.txt
new file mode 100644 (file)
index 0000000..797e728
--- /dev/null
@@ -0,0 +1 @@
+add_library(win_utf8_io STATIC win_utf8_io.c)
diff --git a/src/test_grabbag/CMakeLists.txt b/src/test_grabbag/CMakeLists.txt
new file mode 100644 (file)
index 0000000..56abe81
--- /dev/null
@@ -0,0 +1,2 @@
+add_subdirectory(cuesheet)
+add_subdirectory(picture)
diff --git a/src/test_grabbag/cuesheet/CMakeLists.txt b/src/test_grabbag/cuesheet/CMakeLists.txt
new file mode 100644 (file)
index 0000000..35c1987
--- /dev/null
@@ -0,0 +1,2 @@
+add_executable(test_cuesheet main.c)
+target_link_libraries(test_cuesheet FLAC-static grabbag)
diff --git a/src/test_grabbag/picture/CMakeLists.txt b/src/test_grabbag/picture/CMakeLists.txt
new file mode 100644 (file)
index 0000000..0ae6644
--- /dev/null
@@ -0,0 +1,2 @@
+add_executable(test_picture main.c)
+target_link_libraries(test_picture FLAC-static grabbag)
diff --git a/src/test_libFLAC++/CMakeLists.txt b/src/test_libFLAC++/CMakeLists.txt
new file mode 100644 (file)
index 0000000..a517fae
--- /dev/null
@@ -0,0 +1,10 @@
+add_executable(test_libFLAC++
+    decoders.cpp
+    encoders.cpp
+    main.cpp
+    metadata.cpp
+    metadata_manip.cpp
+    metadata_object.cpp)
+target_link_libraries(test_libFLAC++ FLACXX-static test_libs_common grabbag)
+
+add_test(NAME FLACXX COMMAND test_libFLAC++)
diff --git a/src/test_libFLAC/CMakeLists.txt b/src/test_libFLAC/CMakeLists.txt
new file mode 100644 (file)
index 0000000..9a4a475
--- /dev/null
@@ -0,0 +1,20 @@
+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_compile_definitions(test_libFLAC PRIVATE
+    $<$<BOOL:${ENABLE_64_BIT_WORDS}>:ENABLE_64_BIT_WORDS>)
+target_include_directories(test_libFLAC PRIVATE "$<TARGET_PROPERTY:FLAC-static,SOURCE_DIR>/include")
+target_link_libraries(test_libFLAC FLAC-static grabbag test_libs_common)
+
+add_test(NAME FLAC COMMAND test_libFLAC)
diff --git a/src/test_libs_common/CMakeLists.txt b/src/test_libs_common/CMakeLists.txt
new file mode 100644 (file)
index 0000000..806f353
--- /dev/null
@@ -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-static)
diff --git a/src/test_seeking/CMakeLists.txt b/src/test_seeking/CMakeLists.txt
new file mode 100644 (file)
index 0000000..1c2a2f4
--- /dev/null
@@ -0,0 +1,2 @@
+add_executable(test_seeking main.c)
+target_link_libraries(test_seeking FLAC-static)
diff --git a/src/test_streams/CMakeLists.txt b/src/test_streams/CMakeLists.txt
new file mode 100644 (file)
index 0000000..13e3023
--- /dev/null
@@ -0,0 +1,2 @@
+add_executable(test_streams main.c)
+target_link_libraries(test_streams FLAC-static grabbag)
diff --git a/src/utils/CMakeLists.txt b/src/utils/CMakeLists.txt
new file mode 100644 (file)
index 0000000..cd7b060
--- /dev/null
@@ -0,0 +1,6 @@
+if(BUILD_CXXLIBS)
+    add_subdirectory(flacdiff)
+    if(WIN32)
+        add_subdirectory(flactimer)
+    endif()
+endif()
diff --git a/src/utils/flacdiff/CMakeLists.txt b/src/utils/flacdiff/CMakeLists.txt
new file mode 100644 (file)
index 0000000..d64383f
--- /dev/null
@@ -0,0 +1,4 @@
+add_executable(flacdiff main.cpp)
+target_link_libraries(flacdiff 
+    FLACXX-static
+    $<TARGET_NAME_IF_EXISTS:win_utf8_io>)
\ No newline at end of file
diff --git a/src/utils/flactimer/CMakeLists.txt b/src/utils/flactimer/CMakeLists.txt
new file mode 100644 (file)
index 0000000..d40de89
--- /dev/null
@@ -0,0 +1,2 @@
+add_executable(flactimer main.cpp)
+target_link_libraries(flactimer FLACXX-static)