### CMakeLists.txt Example Source: https://github.com/divideconcept/fluidlite/blob/master/example/CMakeLists.txt This is an example CMakeLists.txt file demonstrating how to find and link against the FluidLite library. ```cmake cmake_minimum_required(VERSION 3.1) project(fluidlite-test LANGUAGES C) #1. To find an installed fluidlite with pkg-config: #find_package(PkgConfig REQUIRED) #pkg_check_modules(fluidlite REQUIRED fluidlite) #2. To find an installed fluidlite with cmake only: #find_package(fluidlite REQUIRED) #3. using a subdirectory (for instance, a git submodule): add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/FluidLite) include(${CMAKE_CURRENT_SOURCE_DIR}/FluidLite/aliases.cmake) add_executable(${PROJECT_NAME} src/main.c ) if(UNIX AND NOT APPLE) find_library(MATH_LIB m) endif() # if you include 'aliases.cmake' or after find_package(fluidlite), # you get two targets defined, that you may link directly here: # 1. 'fluidlite::fluidlite-static' is the static library # 2. 'fluidlite::fluidlite' is the shared dynamic library target_link_libraries(${PROJECT_NAME} PRIVATE fluidlite::fluidlite-static ${MATH_LIB} ) ``` -------------------------------- ### Install Package Configuration Files Source: https://github.com/divideconcept/fluidlite/blob/master/CMakeLists.txt Installs the generated package configuration files. ```cmake install( FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake" "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake" DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} ) ``` -------------------------------- ### Install Static Library Targets Source: https://github.com/divideconcept/fluidlite/blob/master/CMakeLists.txt Installs the static library targets if FLUIDLITE_BUILD_STATIC is enabled. ```cmake if(FLUIDLITE_BUILD_STATIC) install(TARGETS ${PROJECT_NAME}-static EXPORT ${PROJECT_NAME}-static-targets RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ) install(EXPORT ${PROJECT_NAME}-static-targets FILE ${PROJECT_NAME}-static-targets.cmake NAMESPACE ${PROJECT_NAME}:: DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} ) endif() ``` -------------------------------- ### Example Usage Source: https://github.com/divideconcept/fluidlite/blob/master/README.md This C code demonstrates how to use FluidLite to synthesize audio, load a soundfont, play a note, and write the output to a PCM file. ```c #include #include #include "fluidlite.h" #define SAMPLE_RATE 44100 #define SAMPLE_SIZE sizeof(float) #define NUM_FRAMES SAMPLE_RATE #define NUM_CHANNELS 2 #define NUM_SAMPLES (NUM_FRAMES * NUM_CHANNELS) int main() { fluid_settings_t* settings = new_fluid_settings(); fluid_synth_t* synth = new_fluid_synth(settings); fluid_synth_sfload(synth, "soundfont.sf2", 1); float* buffer = calloc(SAMPLE_SIZE, NUM_SAMPLES); FILE* file = fopen("float32output.pcm", "wb"); fluid_synth_noteon(synth, 0, 60, 127); fluid_synth_write_float(synth, NUM_FRAMES, buffer, 0, NUM_CHANNELS, buffer, 1, NUM_CHANNELS); fwrite(buffer, SAMPLE_SIZE, NUM_SAMPLES, file); fluid_synth_noteoff(synth, 0, 60); fluid_synth_write_float(synth, NUM_FRAMES, buffer, 0, NUM_CHANNELS, buffer, 1, NUM_CHANNELS); fwrite(buffer, SAMPLE_SIZE, NUM_SAMPLES, file); fclose(file); free(buffer); delete_fluid_synth(synth); delete_fluid_settings(settings); } ``` -------------------------------- ### Install Shared Library Targets Source: https://github.com/divideconcept/fluidlite/blob/master/CMakeLists.txt Installs the shared library targets if FLUIDLITE_BUILD_SHARED is enabled. ```cmake if(FLUIDLITE_BUILD_SHARED) install(TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME}-shared-targets RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ) install(EXPORT ${PROJECT_NAME}-shared-targets FILE ${PROJECT_NAME}-shared-targets.cmake NAMESPACE ${PROJECT_NAME}:: DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} ) endif() ``` -------------------------------- ### Linking FluidLite Source: https://github.com/divideconcept/fluidlite/blob/master/README.md Example of how to link the FluidLite static library in a CMake project. ```cmake target_link_libraries(${PROJECT_NAME} PRIVATE fluidlite::fluidlite-static ${MATH_LIB} ) ``` -------------------------------- ### Project Initialization Source: https://github.com/divideconcept/fluidlite/blob/master/CMakeLists.txt Initializes the CMake project with a minimum version, project name, languages, and version. ```cmake cmake_minimum_required(VERSION 3.1...3.10) project(fluidlite LANGUAGES C VERSION 1.2.2 ) ``` -------------------------------- ### Dependency Initialization Source: https://github.com/divideconcept/fluidlite/blob/master/CMakeLists.txt Initializes variables for additional libraries and package configuration. ```cmake # Dependencies: set(ADDITIONAL_LIBS) set(PC_LIBS) set(PC_REQUIRES) ``` -------------------------------- ### Header and Source File Lists Source: https://github.com/divideconcept/fluidlite/blob/master/CMakeLists.txt Lists of header and source files used in the project. ```cmake list(APPEND HEADERS include/fluidlite.h ) configure_file(src/version.cmake ${PROJECT_BINARY_DIR}/fluidlite/version.h @ONLY) list(APPEND SCOPED_HEADERS include/fluidlite/types.h include/fluidlite/settings.h include/fluidlite/synth.h include/fluidlite/sfont.h include/fluidlite/ramsfont.h include/fluidlite/log.h include/fluidlite/misc.h include/fluidlite/mod.h include/fluidlite/gen.h include/fluidlite/voice.h ${PROJECT_BINARY_DIR}/fluidlite/version.h ) list(APPEND SOURCES src/fluid_init.c src/fluid_chan.c src/fluid_chorus.c src/fluid_conv.c src/fluid_defsfont.c src/fluid_dsp_float.c src/fluid_gen.c src/fluid_hash.c src/fluid_list.c src/fluid_mod.c src/fluid_ramsfont.c src/fluid_rev.c src/fluid_settings.c src/fluid_synth.c src/fluid_sys.c src/fluid_tuning.c src/fluid_voice.c ) ``` -------------------------------- ### Interface Library for Options Source: https://github.com/divideconcept/fluidlite/blob/master/CMakeLists.txt Creates an INTERFACE library to collect private build options. ```cmake # The interface library collects all PRIVATE build options for the static and dynamic targets add_library(${PROJECT_NAME}-options INTERFACE) if(WIN32) target_compile_definitions(${PROJECT_NAME}-options INTERFACE _CRT_SECURE_NO_WARNINGS) endif() target_include_directories(${PROJECT_NAME}-options INTERFACE ${PROJECT_BINARY_DIR}) target_include_directories(${PROJECT_NAME}-options INTERFACE ${PROJECT_SOURCE_DIR}/src) target_include_directories(${PROJECT_NAME}-options INTERFACE ${PROJECT_SOURCE_DIR}/include) ``` -------------------------------- ### Build Options Source: https://github.com/divideconcept/fluidlite/blob/master/CMakeLists.txt Defines build options for features like SF3, STB_VORBIS, float samples, and position-independent code. ```cmake option(ENABLE_SF3 "Enable SF3 files (ogg/vorbis compressed samples)" FALSE) option(STB_VORBIS "Use stb_vorbis library instead of libogg/libvorbis" FALSE) option(WITH_FLOAT "Use 32 bit float type samples (instead of 64 bit double type)" TRUE) option(CMAKE_POSITION_INDEPENDENT_CODE "Use PIC for building all sources" TRUE) ``` -------------------------------- ### SF3 Support Configuration Source: https://github.com/divideconcept/fluidlite/blob/master/CMakeLists.txt Configures the SF3 support based on ENABLE_SF3 and STB_VORBIS options. ```cmake if (ENABLE_SF3) if (STB_VORBIS) set(FLUIDLITE_SF3_SUPPORT "SF3_STB_VORBIS") else() set(FLUIDLITE_SF3_SUPPORT "SF3_XIPH_VORBIS") endif() else() set(FLUIDLITE_SF3_SUPPORT "SF3_DISABLED") endif() configure_file(src/fluid_config.cmake ${PROJECT_BINARY_DIR}/fluid_config.h @ONLY) ``` -------------------------------- ### Math Library Finding Source: https://github.com/divideconcept/fluidlite/blob/master/CMakeLists.txt Finds the math library 'm' on UNIX systems (excluding macOS) and adds it to the build if found. ```cmake if (UNIX AND NOT APPLE) find_library(M_LIBRARY m) message(STATUS "Math library: ${M_LIBRARY}") if(M_LIBRARY) list(APPEND ADDITIONAL_LIBS ${M_LIBRARY}) list(APPEND PC_LIBS -lm) endif() endif() ``` -------------------------------- ### Package Configuration File Generation Source: https://github.com/divideconcept/fluidlite/blob/master/CMakeLists.txt Generates the package configuration files for the project. ```cmake include(CMakePackageConfigHelpers) write_basic_package_version_file( ${PROJECT_NAME}-config-version.cmake VERSION ${PROJECT_VERSION} COMPATIBILITY AnyNewerVersion ) configure_package_config_file( ${PROJECT_NAME}-config.cmake.in ${PROJECT_NAME}-config.cmake INSTALL_DESTINATION ${CMAKE_CURRENT_BINARY_DIR} ) ``` -------------------------------- ### stb_vorbis Dependency Handling Source: https://github.com/divideconcept/fluidlite/blob/master/CMakeLists.txt Handles the stb_vorbis dependency when ENABLE_SF3 and STB_VORBIS are both defined, marking the build as vendored. ```cmake if (ENABLE_SF3 AND STB_VORBIS) message(STATUS "Using vendored stb_vorbis") set(FLUIDLITE_VENDORED TRUE) list(APPEND SOURCES stb/stb_vorbis.c) target_include_directories(${PROJECT_NAME}-options INTERFACE ${PROJECT_SOURCE_DIR}/stb) endif() ``` -------------------------------- ### Static Library Target Configuration Source: https://github.com/divideconcept/fluidlite/blob/master/CMakeLists.txt Configures and adds a static library target for FluidLite, respecting build options and setting properties like output name and include directories. ```cmake option(FLUIDLITE_BUILD_STATIC "Build static library" ${FLUIDLITE_STATIC_ENABLED_BY_DEFAULT}) if(FLUIDLITE_BUILD_STATIC) add_library(${PROJECT_NAME}-static STATIC ${SOURCES}) set_target_properties(${PROJECT_NAME}-static PROPERTIES C_STANDARD 90) set_target_properties(${PROJECT_NAME}-static PROPERTIES C_EXTENSIONS TRUE) target_compile_definitions(${PROJECT_NAME}-static PUBLIC FLUIDLITE_STATIC) target_link_libraries(${PROJECT_NAME}-static PRIVATE $) target_link_libraries(${PROJECT_NAME}-static PUBLIC ${ADDITIONAL_LIBS}) if(MSVC OR (WATCOM AND (WIN32 OR OS2))) set_target_properties(${PROJECT_NAME}-static PROPERTIES OUTPUT_NAME ${PROJECT_NAME}-static) else() set_target_properties(${PROJECT_NAME}-static PROPERTIES OUTPUT_NAME ${PROJECT_NAME}) endif() target_include_directories(${PROJECT_NAME}-static PUBLIC "$") endif() ``` -------------------------------- ### Fatal Error on No Library Build Source: https://github.com/divideconcept/fluidlite/blob/master/CMakeLists.txt Checks if neither dynamic nor static library build is selected and throws a fatal error if so. ```cmake if((NOT FLUIDLITE_BUILD_SHARED) AND (NOT FLUIDLITE_BUILD_STATIC)) message(FATAL_ERROR "Neither dynamic nor static library build is selected.") endif() ``` -------------------------------- ### Shared Library Target Configuration Source: https://github.com/divideconcept/fluidlite/blob/master/CMakeLists.txt Configures the build for a shared library if FLUIDLITE_BUILD_SHARED is enabled. ```cmake option(FLUIDLITE_BUILD_SHARED "Build shared library" ${FLUIDLITE_SHARED_ENABLED_BY_DEFAULT}) if(FLUIDLITE_BUILD_SHARED) add_library(${PROJECT_NAME} SHARED ${SOURCES}) set_target_properties(${PROJECT_NAME} PROPERTIES C_STANDARD 90) set_target_properties(${PROJECT_NAME} PROPERTIES C_EXTENSIONS TRUE) target_compile_definitions(${PROJECT_NAME} PRIVATE FLUIDLITE_DLL_EXPORTS) target_link_libraries(${PROJECT_NAME} PRIVATE $) target_link_libraries(${PROJECT_NAME} PRIVATE ${ADDITIONAL_LIBS}) set_target_properties(${PROJECT_NAME} PROPERTIES VERSION ${PROJECT_VERSION}) set_target_properties(${PROJECT_NAME} PROPERTIES SOVERSION ${PROJECT_VERSION_MAJOR}) if(NOT WIN32) set_target_properties(${PROJECT_NAME} PROPERTIES C_VISIBILITY_PRESET "hidden") endif() target_include_directories(${PROJECT_NAME} PUBLIC "$" "$" ) endif() ``` -------------------------------- ### Vorbis Dependency Handling Source: https://github.com/divideconcept/fluidlite/blob/master/CMakeLists.txt Handles the Vorbis dependency, either by finding the system library or using a vendored version if ENABLE_SF3 is set and STB_VORBIS is not defined. ```cmake if (ENABLE_SF3 AND NOT STB_VORBIS) find_package(Vorbis QUIET) if (NOT TARGET Vorbis::vorbisfile) message(WARNING "Using vendored libogg/libvorbis") set(FLUIDLITE_VENDORED TRUE) list(APPEND SOURCES libogg-1.3.2/src/bitwise.c libogg-1.3.2/src/framing.c libvorbis-1.3.5/lib/vorbisenc.c libvorbis-1.3.5/lib/info.c libvorbis-1.3.5/lib/analysis.c libvorbis-1.3.5/lib/bitrate.c libvorbis-1.3.5/lib/block.c libvorbis-1.3.5/lib/codebook.c libvorbis-1.3.5/lib/envelope.c libvorbis-1.3.5/lib/floor0.c libvorbis-1.3.5/lib/floor1.c libvorbis-1.3.5/lib/lookup.c libvorbis-1.3.5/lib/lpc.c libvorbis-1.3.5/lib/lsp.c libvorbis-1.3.5/lib/mapping0.c libvorbis-1.3.5/lib/mdct.c libvorbis-1.3.5/lib/psy.c libvorbis-1.3.5/lib/registry.c libvorbis-1.3.5/lib/res0.c libvorbis-1.3.5/lib/sharedbook.c libvorbis-1.3.5/lib/smallft.c libvorbis-1.3.5/lib/vorbisfile.c libvorbis-1.3.5/lib/window.c libvorbis-1.3.5/lib/synthesis.c ) target_include_directories(${PROJECT_NAME}-options INTERFACE ${PROJECT_SOURCE_DIR}/libogg-1.3.2/include ${PROJECT_SOURCE_DIR}/libvorbis-1.3.5/include ${PROJECT_SOURCE_DIR}/libvorbis-1.3.5/lib ) else() message(STATUS "Using system libvorbis") list(APPEND ADDITIONAL_LIBS Vorbis::vorbisfile) list(APPEND PC_REQUIRES vorbisfile) endif() endif() ``` -------------------------------- ### Module Path Configuration Source: https://github.com/divideconcept/fluidlite/blob/master/CMakeLists.txt Appends a directory to the CMAKE_MODULE_PATH for finding CMake modules. ```cmake include(GNUInstallDirs) list (APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") ``` -------------------------------- ### Debug Build Configuration Source: https://github.com/divideconcept/fluidlite/blob/master/CMakeLists.txt Sets the DEBUG variable to TRUE if the CMAKE_BUILD_TYPE is 'debug'. ```cmake string(TOLOWER "${CMAKE_BUILD_TYPE}" LOWERCASE_BUILD_TYPE) if("${LOWERCASE_BUILD_TYPE}" STREQUAL "debug") set(DEBUG TRUE) endif() ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.