#!/usr/bin/cmake cmake_minimum_required (VERSION 3.18) # ------------------------------------------------------------------------------------------------- project( FLAC VERSION 1.4.2 DESCRIPTION "A popular and very versatile, lossless audio codec" ) include("../../BuildSystem/cmake/cplusplus.cmake") # FLAC also includes optional support for the OGG audio container, which we # enabled, so this library is a dependency as well if(NOT (TARGET OGG)) add_subdirectory(${PROJECT_SOURCE_DIR}/../ogg ${CMAKE_BINARY_DIR}/ogg) endif() # ------------------------------------------------------------------------------------------------- if(NOT EXISTS ${PROJECT_SOURCE_DIR}/downloads/flac-1.4.2.tar.xz) message(STATUS "Downloading FLAC sources") file( DOWNLOAD https://ftp.osuosl.org/pub/xiph/releases/flac/flac-1.4.2.tar.xz ${PROJECT_SOURCE_DIR}/downloads/flac-1.4.2.tar.xz SHOW_PROGRESS EXPECTED_HASH SHA256=e322d58a1f48d23d9dd38f432672865f6f79e73a6f9cc5a5f57fcaa83eb5a8e4 STATUS DOWNLOAD_STATUS ) if(NOT DOWNLOAD_STATUS EQUAL 0) file(REMOVE ${PROJECT_SOURCE_DIR}/downloads/flac-1.4.2.tar.xz) message(FATAL_ERROR "Download failed, stopping build (error ${DOWNLOAD_STATUS})") endif() endif() # ------------------------------------------------------------------------------------------------- if(NOT EXISTS ${PROJECT_SOURCE_DIR}/build) message(STATUS "Extracting FLAC sources") file( ARCHIVE_EXTRACT INPUT ${PROJECT_SOURCE_DIR}/downloads/flac-1.4.2.tar.xz DESTINATION ${CMAKE_BINARY_DIR}/extract ) file( RENAME ${CMAKE_BINARY_DIR}/extract/flac-1.4.2 ${PROJECT_SOURCE_DIR}/build ) endif() file( COPY "${PROJECT_SOURCE_DIR}/config.h" DESTINATION "${PROJECT_SOURCE_DIR}/build/include/" ) # ------------------------------------------------------------------------------------------------- set( sourceFiles "build/src/libFLAC/lpc_intrin_fma.c" "build/src/libFLAC/bitmath.c" "build/src/libFLAC/bitreader.c" "build/src/libFLAC/bitwriter.c" "build/src/libFLAC/cpu.c" "build/src/libFLAC/crc.c" #"build/src/libFLAC/deduplication/lpc_compute_autocorrelation_intrin.c" #"build/src/libFLAC/deduplication/lpc_compute_autocorrelation_intrin_neon.c" #"build/src/libFLAC/deduplication/lpc_compute_autocorrelation_intrin_sse2.c" #"build/src/libFLAC/deduplication/lpc_compute_autocorrelation_intrin_vsx.c" "build/src/libFLAC/fixed.c" "build/src/libFLAC/fixed_intrin_sse2.c" "build/src/libFLAC/fixed_intrin_ssse3.c" "build/src/libFLAC/float.c" "build/src/libFLAC/format.c" "build/src/libFLAC/lpc.c" "build/src/libFLAC/lpc_intrin_avx2.c" "build/src/libFLAC/lpc_intrin_neon.c" "build/src/libFLAC/lpc_intrin_sse2.c" "build/src/libFLAC/lpc_intrin_sse41.c" "build/src/libFLAC/lpc_intrin_vsx.c" "build/src/libFLAC/md5.c" "build/src/libFLAC/memory.c" "build/src/libFLAC/metadata_iterators.c" "build/src/libFLAC/metadata_object.c" "build/src/libFLAC/ogg_decoder_aspect.c" "build/src/libFLAC/ogg_encoder_aspect.c" "build/src/libFLAC/ogg_helper.c" "build/src/libFLAC/ogg_mapping.c" "build/src/libFLAC/stream_decoder.c" "build/src/libFLAC/stream_encoder.c" "build/src/libFLAC/stream_encoder_framing.c" "build/src/libFLAC/stream_encoder_intrin_avx2.c" "build/src/libFLAC/stream_encoder_intrin_sse2.c" "build/src/libFLAC/stream_encoder_intrin_ssse3.c" "build/src/libFLAC/window.c" # Not sure if I need this. Could it be that the entire 'flac' directory # is just the command-line encoder/decoder w/zero overlap with libFLAC? "build/src/flac/analyze.c" "build/src/flac/decode.c" "build/src/flac/encode.c" "build/src/flac/foreign_metadata.c" #"build/src/flac/iffscan.c" "build/src/flac/local_string_utils.c" #"build/src/flac/main.c" "build/src/flac/utils.c" "build/src/flac/vorbiscomment.c" #"build/src/share/getopt/getopt.c" #"build/src/share/getopt/getopt1.c" "build/src/share/grabbag/alloc.c" "build/src/share/grabbag/cuesheet.c" "build/src/share/grabbag/file.c" "build/src/share/grabbag/picture.c" "build/src/share/grabbag/replaygain.c" "build/src/share/grabbag/seektable.c" "build/src/share/grabbag/snprintf.c" "build/src/share/replaygain_analysis/replaygain_analysis.c" "build/src/share/replaygain_synthesis/replaygain_synthesis.c" "build/src/share/utf8/charset.c" #"build/src/share/utf8/charset_test.c" "build/src/share/utf8/iconvert.c" #"build/src/share/utf8/makemap.c" "build/src/share/utf8/utf8.c" ) set( windowsSourceFiles "build/src/share/win_utf8_io/win_utf8_io.c" ) file( GLOB_RECURSE headerFiles CONFIGURE_DEPENDS "build/include/*.h" ) # ------------------------------------------------------------------------------------------------- add_library(FLAC STATIC) add_library(FLAC::Static ALIAS FLAC) target_compile_definitions( FLAC PRIVATE HAVE_CONFIG_H PUBLIC FLAC__NO_DLL=1 ) target_include_directories( FLAC PUBLIC "build/include/" PRIVATE "build/src/libFLAC/include/" ) target_sources( FLAC PUBLIC ${headerFiles} PRIVATE ${sourceFiles} ) if(WIN32) target_sources( FLAC PRIVATE ${windowsSourceFiles} ) endif() target_link_libraries( FLAC PUBLIC OGG::Static ) #set_target_properties(FLAC PROPERTIES PREFIX "") set_target_properties(FLAC PROPERTIES OUTPUT_NAME "flac") # ------------------------------------------------------------------------------------------------- #install( # DIRECTORY build/include/ # DESTINATION ${PROJECT_SOURCE_DIR}/Include #) install( TARGETS FLAC ARCHIVE DESTINATION ${PROJECT_SOURCE_DIR}/bin/${NUCLEX_COMPILER_TAG} ) # ------------------------------------------------------------------------------------------------- file( WRITE "${PROJECT_SOURCE_DIR}/FLACConfig.cmake" "#!/usr/bin/cmake # Configuration to include FLAC in a CMake-based project. If you want to # reference FLAC as an externally compiled static library, do this: # # set(FLAC_DIR \"../ThirdParty/flac\") # find_package(FLAC REQUIRED CONFIG) # # target_link_libraries( # MyAwesomeProject # PRIVATE GTest::Static # PRIVATE GTest::Main # ) # # Alternatively, if you want to build FLAC together with your project, # use the normal CMakeLists.txt with CMake's add_subdirectory() command: # # add_subdirectory( # \"\${PROJECT_SOURCE_DIR}/../ThirdParty/flac\" # \"\${CMAKE_BINARY_DIR}/flac\" # ) # # target_link_libraries( # MyAwesomeProject # PRIVATE FLAC # PRIVATE FLACMain # ) # # ------------------------------------------------------------------------------------------------- if(NOT DEFINED NUCLEX_COMPILER_TAG) message( FATAL_ERROR \"NUCLEX_COMPILER_TAG not defined! Include cplusplus.cmake before importing this package \\ in order to generate a tag identifying the platform/compiler/architecture/variant!\" ) endif() # ------------------------------------------------------------------------------------------------- if(NOT EXISTS \"\${CMAKE_CURRENT_LIST_DIR}/bin/\${NUCLEX_COMPILER_TAG}\") # TODO: Warn and link release build when compiling in debug mode # TODO: Warn and link build for older compiler version if found message( FATAL_ERROR \"Directory '\${CMAKE_CURRENT_LIST_DIR}/bin/\${NUCLEX_COMPILER_TAG}' not found. \\ Please either build and install this project before importing it via \\ find_package() or use this project's main CMakeFiles.txt via add_subdirectory()!\" ) endif() # ------------------------------------------------------------------------------------------------- add_library(FLAC::Static STATIC IMPORTED) add_library(FLAC::Main STATIC IMPORTED) # This may cause warnings on recent GCC versions (10.0.0+?) with LTO because GCC detects # that the headers used during build (residing in build/) are not the same used when # linking the library (copies resising in Include/). # # CMake doesn't run the install step during build, so the only way to get the headers # in place before building would be by copying them rather than installing them. set_target_properties( FLAC::Static PROPERTIES INTERFACE_INCLUDE_DIRECTORIES \"\${CMAKE_CURRENT_LIST_DIR}/Include\" IMPORTED_LINK_INTERFACE_LANGUAGES \"CXX\" ) set_target_properties( FLAC::Main PROPERTIES INTERFACE_INCLUDE_DIRECTORIES \"\${CMAKE_CURRENT_LIST_DIR}/Include\" IMPORTED_LINK_INTERFACE_LANGUAGES \"CXX\" ) if(WIN32) set_target_properties( FLAC::Static PROPERTIES IMPORTED_LOCATION \"\${CMAKE_CURRENT_LIST_DIR}/bin/\${NUCLEX_COMPILER_TAG}/flac.lib\" ) else() set_target_properties( FLAC::Static PROPERTIES IMPORTED_LOCATION \"\${CMAKE_CURRENT_LIST_DIR}/bin/\${NUCLEX_COMPILER_TAG}/libflac.a\" ) endif() message(STATUS \"Imported FLAC targets with binaries in '\${CMAKE_CURRENT_LIST_DIR}'\")" ) # -------------------------------------------------------------------------------------------------