cmake_minimum_required(VERSION 3.10) project(xtts_inference) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) # Options option(BUILD_SHARED_LIBS "Build shared libraries" ON) option(XTTS_BUILD_TESTS "Build tests" OFF) option(XTTS_USE_CUDA "Use CUDA acceleration" OFF) option(XTTS_USE_METAL "Use Metal acceleration (iOS/macOS)" OFF) # Find dependencies find_package(Threads REQUIRED) # GGML configuration set(GGML_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ggml" CACHE PATH "Path to GGML") if(NOT EXISTS ${GGML_DIR}) message(STATUS "GGML not found, downloading...") execute_process( COMMAND git clone https://github.com/ggerganov/ggml.git ${GGML_DIR} RESULT_VARIABLE GIT_RESULT ) if(NOT GIT_RESULT EQUAL "0") message(FATAL_ERROR "Failed to download GGML") endif() endif() # Add GGML add_subdirectory(${GGML_DIR} ggml_build) # XTTS library add_library(xtts_inference xtts_inference.cpp xtts_inference.h ) target_include_directories(xtts_inference PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${GGML_DIR}/include ) target_link_libraries(xtts_inference ggml ${CMAKE_THREAD_LIBS_INIT} ) # Platform-specific configurations if(ANDROID) target_compile_definitions(xtts_inference PRIVATE XTTS_ANDROID) target_link_libraries(xtts_inference log android) elseif(IOS) target_compile_definitions(xtts_inference PRIVATE XTTS_IOS) set_target_properties(xtts_inference PROPERTIES FRAMEWORK TRUE MACOSX_FRAMEWORK_IDENTIFIER com.genmedlabs.xtts ) endif() # CUDA support if(XTTS_USE_CUDA) find_package(CUDA REQUIRED) target_compile_definitions(xtts_inference PRIVATE GGML_USE_CUDA) target_link_libraries(xtts_inference ${CUDA_LIBRARIES}) endif() # Metal support (iOS/macOS) if(XTTS_USE_METAL) target_compile_definitions(xtts_inference PRIVATE GGML_USE_METAL) find_library(METAL_FRAMEWORK Metal REQUIRED) find_library(METALPERFORMANCE_FRAMEWORK MetalPerformanceShaders REQUIRED) target_link_libraries(xtts_inference ${METAL_FRAMEWORK} ${METALPERFORMANCE_FRAMEWORK} ) endif() # Optimization flags if(CMAKE_BUILD_TYPE STREQUAL "Release") if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") target_compile_options(xtts_inference PRIVATE -O3 -march=native -ffast-math -funroll-loops ) endif() endif() # React Native module (optional) if(BUILD_REACT_NATIVE) add_library(xtts_rn MODULE ../react-native/XTTSModule.cpp ) target_include_directories(xtts_rn PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${REACT_NATIVE_DIR}/ReactCommon/jsi ${REACT_NATIVE_DIR}/ReactCommon/turbomodule/core ) target_link_libraries(xtts_rn xtts_inference jsi turbomodule ) endif() # Installation install(TARGETS xtts_inference LIBRARY DESTINATION lib ARCHIVE DESTINATION lib RUNTIME DESTINATION bin FRAMEWORK DESTINATION Frameworks ) install(FILES xtts_inference.h DESTINATION include ) # Tests if(XTTS_BUILD_TESTS) add_executable(xtts_test test/xtts_test.cpp ) target_link_libraries(xtts_test xtts_inference) enable_testing() add_test(NAME xtts_test COMMAND xtts_test) endif() # Package configuration include(CMakePackageConfigHelpers) configure_package_config_file( "${CMAKE_CURRENT_SOURCE_DIR}/cmake/XTTSConfig.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/XTTSConfig.cmake" INSTALL_DESTINATION lib/cmake/XTTS ) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/XTTSConfig.cmake" DESTINATION lib/cmake/XTTS )