looper/CMakeLists.txt

492 lines
21 KiB
Text
Raw Normal View History

2024-04-25 11:23:38 -07:00
cmake_minimum_required(VERSION 3.22)
project(looper VERSION 1.0.0 LANGUAGES C CXX)
2024-05-02 14:52:11 -07:00
option(SHARED_LIB "Enables building as a shared library." OFF)
2024-04-24 09:59:51 -07:00
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Emscripten")
2024-09-28 10:31:06 -07:00
set(EMSCRIPTEN ON)
message("Building for WASM.")
2024-04-24 09:59:51 -07:00
endif()
2024-09-28 10:31:06 -07:00
option(TESTS "Enables unit testing" OFF)
find_package(Threads)
2024-08-08 13:12:37 -07:00
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
include(SanitizerBuildTypes)
sanitizer_build_types(ASAN AddressSanitizer LSAN LeakSanitizer MSAN MemorySanitizer TSAN ThreadSanitizer UBSAN UndefinedBehaviorSanitizer)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
2024-03-26 18:39:02 -07:00
set(SDL_MIXER_X_STATIC ON CACHE BOOL "")
set(SDL_MIXER_X_SHARED OFF CACHE BOOL "")
2024-04-09 10:15:05 -07:00
set(DOWNLOAD_AUDIO_CODECS_DEPENDENCY OFF CACHE BOOL "")
2024-03-26 18:39:02 -07:00
set(AUDIO_CODECS_BUILD_LOCAL_SDL2 OFF CACHE BOOL "" FORCE)
set(MIXERX_LGPL ON CACHE BOOL "" FORCE)
set(USE_MIDI ON CACHE BOOL "" FORCE)
set(USE_MIDI_NATIVE_ALT OFF CACHE BOOL "" FORCE)
set(USE_MIDI_NATIVE OFF CACHE BOOL "" FORCE)
set(USE_MIDI_TIMIDITY OFF CACHE BOOL "" FORCE)
set(USE_MIDI_FLUIDLITE OFF CACHE BOOL "" FORCE)
set(USE_MIDI_OPNMIDI OFF CACHE BOOL "" FORCE)
set(USE_MIDI_ADLMIDI OFF CACHE BOOL "" FORCE)
set(USE_MIDI_FLUIDSYNTH ON CACHE BOOL "" FORCE)
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(BUILD_FB2K OFF CACHE BOOL "" FORCE)
set(BUILD_CLI OFF CACHE BOOL "" FORCE)
set(BUILD_WINAMP OFF CACHE BOOL "" FORCE)
set(BUILD_XMPLAY OFF CACHE BOOL "" FORCE)
set(BUILD_AUDACIOUS OFF CACHE BOOL "" FORCE)
set(BUILD_V123 OFF CACHE BOOL "" FORCE)
2024-04-24 09:59:51 -07:00
set(JSONCPP_WITH_TESTS OFF CACHE BOOL "" FORCE)
set(BUILD_STATIC_LIBS ON CACHE BOOL "" FORCE)
set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE)
set(JSONCPP_WITH_PKGCONFIG_SUPPORT OFF CACHE BOOL "" FORCE)
set(JSONCPP_WITH_CMAKE_PACKAGE OFF CACHE BOOL "" FORCE)
option(ENABLE_DBUS "Enables DBus support" ON)
option(USE_PORTALS "Enables libportal" ON)
2024-09-28 11:19:41 -07:00
option(BUILD_LIBFMT "Builds libfmt" OFF)
2024-04-24 09:59:51 -07:00
if (DEFINED EMSCRIPTEN)
2024-09-28 10:31:06 -07:00
option(FOR_WASMER "Enables support for wasmer" OFF)
set(BUILD_STATIC ON CACHE BOOL "" FORCE)
set(ENABLE_DBUS OFF CACHE BOOL "" FORCE)
set(DOWNLOAD_AUDIO_CODECS_DEPENDENCY ON CACHE BOOL "" FORCE)
set(SDL_MIXER_X_SHARED OFF CACHE BOOL "" FORCE)
set(SDL_MIXER_X_STATIC ON CACHE BOOL "" FORCE)
set(USE_OGG_VORBIS_STB ON CACHE BOOL "" FORCE)
set(USE_OPUS OFF CACHE BOOL "" FORCE)
set(USE_MODPLUG OFF CACHE BOOL "" FORCE)
set(USE_GME OFF CACHE BOOL "" FORCE)
set(USE_WAVPACK OFF CACHE BOOL "" FORCE)
set(USE_XMP OFF CACHE BOOL "" FORCE)
set(USE_MIDI_EDMIDI OFF CACHE BOOL "" FORCE)
set(USE_PORTALS OFF CACHE BOOL "" FORCE)
set(USE_SYSTEM_SDL2 ON CACHE BOOL "" FORCE)
set(USE_MPEG OFF CACHE BOOL "" FORCE)
set(USE_CELT OFF CACHE BOOL "" FORCE)
set(USE_ATRAC9 OFF CACHE BOOL "" FORCE)
set(USE_SPEEX OFF CACHE BOOL "" FORCE)
set(BUILD_PROTOC OFF CACHE BOOL "" FORCE)
# set(BUILD_LIBUPB OFF CACHE BOOL "" FORCE)
set(USE_G719 OFF CACHE BOOL "" FORCE)
set(EXTRA_FLAGS "-sUSE_VORBIS -sUSE_MPG123=1 -sUSE_ZLIB -sUSE_OGG=1 -sUSE_MODPLUG=1 -sUSE_SDL=2 -sUSE_SDL_IMAGE=2 -sNO_DISABLE_EXCEPTION_CATCHING")
set(DEBUG_INFO ${CMAKE_BUILD_TYPE} STREQUAL Debug OR ${CMAKE_BUILD_TYPE} STREQUAL RelWithDebInfo)
set(RELASE_OPTS ${CMAKE_BUILD_TYPE} STREQUAL Release OR ${CMAKE_BUILD_TYPE} STREQUAL RelWithDebInfo)
set(PROFILE_ENABLED ${CMAKE_BUILD_TYPE} STREQUAL RelWithDebInfo)
set(EXTRA_LINKER_FLAGS "-sALLOW_MEMORY_GROWTH=1 -sEXPORTED_RUNTIME_METHODS=UTF8ToString,stringToUTF8,lengthBytesUTF8 -sEXPORTED_FUNCTIONS=_malloc,_main,_memset,_write_log,_write_logln")
if (NOT FOR_WASMER)
set(EXTRA_LINKER_FLAGS "${EXTRA_LINKER_FLAGS} -sASYNCIFY_IMPORTS=read_file,read_storage,write_storage,remove_storage,find_keys")
set(EXTRA_FLAGS "${EXTRA_FLAGS} --shell-file=${CMAKE_CURRENT_SOURCE_DIR}/web/shell.html --js-library=${CMAKE_CURRENT_SOURCE_DIR}/web/api.js")
endif()
set(OPENMP OFF CACHE BOOL "" FORCE)
set(SOUNDSTRETCH OFF CACHE BOOL "" FORCE)
set(SOUNDTOUCH_DLL OFF CACHE BOOL "" FORCE)
if(DEBUG_INFO)
option(STACK_OVERFLOW_CHECK "Enables extra stack overflow checks" OFF)
if(${STACK_OVERFLOW_CHECK})
set(EXTRA_LINKER_FLAGS "${EXTRA_LINKER_FLAGS} -sSTACK_OVERFLOW_CHECK=2")
endif()
set(EXTRA_FLAGS "${EXTRA_FLAGS} -g -gsource-map")
set(EXTRA_LINKER_FLAGS "${EXTRA_LINKER_FLAGS} --emit-symbol-map -sASSERTIONS=1")
endif()
if(RELEASE_OPTS)
set(EXTRA_FLAGS "${EXTRA_FLAGS} -flto")
set(EXTRA_LINKER_FLAGS "${EXTRA_LINKER_FLAGS} --closure 1")
endif()
if(PROFILE_ENABLED)
set(EXTRA_LINKER_FLAGS "${EXTRA_LINKER_FLAGS} --profiling --profiling-funcs")
endif()
set(CMAKE_FIND_ROOT_PATH "${CMAKE_CURRENT_SOURCE_DIR}/web/cmake" ${CMAKE_FIND_ROOT_PATH})
set(SDL2_DIR ${CMAKE_CURRENT_SOURCE_DIR}/web/cmake)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_FLAGS}")
set(EXTRA_LINKER_FLAGS "${EXTRA_LINKER_FLAGS} ${EXTRA_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${EXTRA_LINKER_FLAGS}")
2024-04-24 09:59:51 -07:00
else()
2024-09-28 10:31:06 -07:00
set(BUILD_STATIC OFF CACHE BOOL "")
2024-04-24 09:59:51 -07:00
endif()
2024-04-25 11:23:38 -07:00
option(BUILD_SDL "Enables built-in SDL" OFF)
option(BUILD_SDL_IMAGE "Enables built-in SDL_image" ${BUILD_SDL})
if(DEFINED ANDROID_NDK)
2024-09-28 10:31:06 -07:00
set(USE_SYSTEM_SDL2 ON CACHE BOOL "" FORCE)
set(AUDIOCODECS_BUILD_TIMIDITYSDL OFF CACHE BOOL "" FORCE)
set(AUDIOCODECS_BUILD_OPUS OFF CACHE BOOL "" FORCE)
set(USE_OGG_VORBIS_STB ON CACHE BOOL "" FORCE)
set(AUDIOCODECS_BUILD_WAVPACK OFF CACHE BOOL "" FORCE)
set(USE_WAVPACK OFF CACHE BOOL "" FORCE)
set(USE_MODPLUG OFF CACHE BOOL "" FORCE)
set(USE_XMP OFF CACHE BOOL "" FORCE)
set(USE_GME OFF CACHE BOOL "" FORCE)
set(USE_MIDI_EDMIDI OFF CACHE BOOL "" FORCE)
set(USE_OPUS OFF CACHE BOOL "" FORCE)
set(USE_MPEG OFF CACHE BOOL "" FORCE)
set(USE_CELT OFF CACHE BOOL "" FORCE)
set(USE_ATRAC9 OFF CACHE BOOL "" FORCE)
set(USE_SPEEX OFF CACHE BOOL "" FORCE)
set(USE_G719 OFF CACHE BOOL "" FORCE)
set(USE_VORBIS OFF CACHE BOOL "" FORCE)
2024-04-25 11:23:38 -07:00
endif()
if (BUILD_SDL)
2024-09-28 10:31:06 -07:00
set(SDL_SHARED OFF CACHE BOOL "" FORCE)
set(SDL_STATIC ON CACHE BOOL "" FORCE)
set(SDL_TEST OFF CACHE BOOL "" FORCE)
set(USE_SYSTEM_SDL2 ON CACHE BOOL "" FORCE)
set(SDL_MIXER_X_STATIC ON CACHE BOOL "" FORCE)
add_subdirectory(${CMAKE_SOURCE_DIR}/subprojects/SDL)
install(TARGETS SDL2-static SDL2main EXPORT SDL_EXPORTS)
install(EXPORT SDL_EXPORTS DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
export(TARGETS SDL2-static sdl-build-options SDL2main FILE ${CMAKE_CURRENT_BINARY_DIR}/SDL2Config.cmake NAMESPACE SDL2)
set(SDL2_DIR ${CMAKE_CURRENT_SOURCE_DIR}/cmake/built_sdl)
2024-04-25 11:23:38 -07:00
endif()
if (BUILD_SDL_IMAGE)
2024-09-28 10:31:06 -07:00
set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE)
set(SDL2IMAGE_SAMPLES OFF CACHE BOOL "" FORCE)
set(SDL2IMAGE_TESTS OFF CACHE BOOL "" FORCE)
add_subdirectory(${CMAKE_SOURCE_DIR}/subprojects/SDL_image)
set(SDL2_image_DIR ${CMAKE_CURRENT_SOURCE_DIR}/cmake/built_sdl_image)
2024-04-25 11:23:38 -07:00
endif()
find_package(PkgConfig)
2024-04-10 13:57:18 -07:00
#add_subdirectory(subprojects/jsoncpp)
2024-04-24 09:59:51 -07:00
2024-04-09 10:15:05 -07:00
include(GNUInstallDirs)
add_subdirectory(subprojects/SDL-Mixer-X)
add_subdirectory(subprojects/vgmstream)
2024-04-24 09:59:51 -07:00
if (DEFINED EMSCRIPTEN)
2024-09-28 10:31:06 -07:00
set(EXTRA_LIBS )
2024-04-24 09:59:51 -07:00
else()
2024-09-28 10:31:06 -07:00
set(EXTRA_LIBS libvgmstream_shared)
2024-04-24 09:59:51 -07:00
endif()
if(SDL_MIXER_X_STATIC)
2024-09-28 10:31:06 -07:00
set(SDL_MIXER_X_TARGET SDL2_mixer_ext_Static)
else()
2024-09-28 10:31:06 -07:00
set(SDL_MIXER_X_TARGET SDL2_mixer_ext)
set(EXTRA_LIBS ${EXTRA_LIBS} ${SDL_MIXER_X_TARGET})
endif()
add_custom_target(looper_assets COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/assets/update_assets.py WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
find_package(Git)
if (Git_FOUND)
2024-09-28 10:31:06 -07:00
execute_process(COMMAND ./version.sh OUTPUT_VARIABLE TAG WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
message("" ${TAG})
else()
2024-09-28 10:31:06 -07:00
set(TAG "unknown")
endif()
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
2024-09-28 10:31:06 -07:00
set(DEBUG ON)
endif()
2024-04-24 09:59:51 -07:00
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
include(log)
2024-03-26 18:39:02 -07:00
#execute_process(COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/meson2cmake_cfg.py ${CMAKE_CURRENT_SOURCE_DIR}/config.meson.h.in ${CMAKE_CURRENT_SOURCE_DIR}/config.cmake.h.in)
set(DEBUG_MODE_VALUE ${DEBUG})
configure_file(config.cmake.h.in config.h)
2024-09-28 11:19:41 -07:00
if (BUILD_FMT)
add_subdirectory(subprojects/fmt)
else()
find_package(fmt)
endif()
macro(target_pkgconfig)
2024-09-28 10:31:06 -07:00
push_fnstack("target_pkgconfig")
cmake_parse_arguments(PARSED_ARGS "OPTIONAL;PRIVATE;PUBLIC;INTERFACE" "PREFIX" "TARGETS;LIBRARIES" ${ARGN})
if (NOT ${PARSED_ARGS_PREFIX})
warning(MESSAGE "No prefix specified for reading thie PKGConfig variable to. Attempting to guess it from the library specification...")
if (NOT ${PARSED_ARGS_LIBRARIES})
fatal(MESSAGE "... But it turns out no library specification was specified. Giving up.")
else()
set(PARSED_ARGS_PREFIX ${PARSED_ARGS_LIBRARIES})
endif()
else()
if(NOT ${PARSED_ARGS_NAME})
warning(MESSAGE "No library name was specified. Assuming it is the same as the prefix.")
set(PARSED_ARGS_LIBSPEC ${PARSED_ARGS_LIBRARIES})
endif()
endif()
pkg_check_modules(${PARSED_ARGS_PREFIX} IMPORTED_TARGET ${PARSED_ARGS_LIBRARIES})
set(PARSED_ARGS_PUBLICITY PRIVATE)
if(${PARSED_ARGS_PRIVATE})
set(PARSED_ARGS_PUBLICITY PRIVATE)
elseif(${PARSED_ARGS_PUBLIC})
set(PARSED_ARGS_PUBLICITY PUBLIC)
elseif(${PARSED_ARGS_INTERFACE})
set(PARSED_ARGS_PUBLICITY INTERFACE)
endif()
foreach(TARGET IN ITEMS ${PARSED_ARGS_TARGETS})
target_link_libraries(${TARGET} ${PARSED_ARGS_PUBLICITY} PkgConfig::${PARSED_ARGS_PREFIX})
endforeach()
pop_fnstack()
endmacro()
2024-04-10 18:00:19 -07:00
set(INC ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} subprojects/vgmstream/src subprojects/vgmstream/src/base)
set(UI_BACKENDS "")
list(POP_FRONT UI_BACKENDS)
macro(prefix_all)
2024-09-28 10:31:06 -07:00
set(ARGS ${ARGV})
list(POP_FRONT ARGS OUT_VAR PREFIX)
set(${OUT_VAR} )
foreach(ARG IN ITEMS ${ARGS})
list(APPEND ${OUT_VAR} ${PREFIX}${ARG})
endforeach()
endmacro()
2024-08-08 13:12:37 -07:00
2024-09-28 10:31:06 -07:00
if(BUILD_PROTOBUF)
set(_PROTOBUF_LIBPROTOBUF protobuf::libprotobuf)
else()
set(_PROTOBUF_LIBPROTOBUF protobuf::libprotobuf)
endif()
2024-08-08 13:12:37 -07:00
find_program(_PROTOBUF_PROTOC protoc)
function(grpc_proto)
2024-09-28 10:31:06 -07:00
cmake_parse_arguments(GRPC_PROTO "" "TARGET"
"SOURCES" ${ARGV})
foreach (GRPC_PROTO_SOURCE ${GRPC_PROTO_SOURCES})
set(GRPC_PROTO_SRCS)
set(GRPC_PROTO_HDRS)
get_filename_component(src_stem "${GRPC_PROTO_SOURCE}" NAME_WE)
get_filename_component(src_path "${GRPC_PROTO_SOURCE}" DIRECTORY)
cmake_path(RELATIVE_PATH src_path BASE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} OUTPUT_VARIABLE src_rel_path)
set(src_out ${CMAKE_CURRENT_BINARY_DIR}/${src_rel_path})
message("Output directory: ${src_out}")
list(APPEND GRPC_PROTO_SRCS ${src_out}/${src_stem}.pb.cc)
list(APPEND GRPC_PROTO_HDRS ${src_out}/${src_stem}.pb.h)
make_directory(${src_out})
2024-09-28 10:48:35 -07:00
execute_process(COMMAND ${_PROTOBUF_PROTOC} --cpp_out "${src_out}" -I "${src_path}" "${GRPC_PROTO_SOURCE}")
2024-09-28 10:31:06 -07:00
target_sources(${GRPC_PROTO_TARGET} PRIVATE ${GRPC_PROTO_SRCS})
target_include_directories(${GRPC_PROTO_TARGET} PRIVATE ${src_out})
endforeach()
target_include_directories(${GRPC_PROTO_TARGET} PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
if (BUILD_PROTOBUF)
target_include_directories(${GRPC_PROTO_TARGET} PUBLIC ${CMAKE_SOURCE_DIR}/subprojects/protobuf/src ${CMAKE_SOURCE_DIR}/subprojects/protobuf/third_party/abseil-cpp)
endif()
target_link_libraries(${GRPC_PROTO_TARGET} PUBLIC ${_PROTOBUF_LIBPROTOBUF})
2024-08-08 13:12:37 -07:00
endfunction()
prefix_all(LIBRARY_SOURCES
2024-09-28 10:31:06 -07:00
${CMAKE_CURRENT_SOURCE_DIR}/
backend.cpp
options.cpp
playback.cpp
util.cpp
log.cpp
dbus.cpp
file_backend.cpp
playback_backend.cpp
translation.cpp
playback_process.cpp
base85.cpp
)
add_library(liblooper STATIC ${LIBRARY_SOURCES})
2024-09-28 10:31:06 -07:00
if(FOR_WASMER)
target_compile_definitions(liblooper PUBLIC FOR_WASMER)
endif()
2024-08-08 13:12:37 -07:00
grpc_proto(TARGET liblooper SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/ipc/internal.proto ${CMAKE_CURRENT_SOURCE_DIR}/ipc/common.proto)
target_include_directories(liblooper PUBLIC ${INC})
2024-08-08 13:12:37 -07:00
target_include_directories(liblooper PUBLIC)
2024-04-25 11:23:38 -07:00
set(JSONCPP_TARGET PkgConfig::jsoncpp)
set(SOUNDTOUCH_TARGET PkgConfig::SoundTouch)
function(set_to_value_of_condition var)
2024-09-28 10:31:06 -07:00
if (${ARGN})
set(${var} ON PARENT_SCOPE)
else()
set(${var} OFF PARENT_SCOPE)
endif()
2024-04-25 11:23:38 -07:00
endfunction()
set_to_value_of_condition(BUILD_THIRDPARTY DEFINED EMSCRIPTEN OR DEFINED ANDROID_NDK)
find_package(Intl)
set_to_value_of_condition(_USE_LIBINTL_LITE NOT Intl_FOUND)
option(BUILD_JSONCPP "Builds JsonCpp instead of using the system package." ${BUILD_THIRDPARTY})
option(BUILD_SOUNDTOUCH "Builds SoundTouch instead of using the system package" ${BUILD_THIRDPARTY})
2024-09-28 10:31:06 -07:00
option(BUILD_PROTOBUF "Builds protobuf instead of using the system package" ${BUILD_THIRDPARTY})
2024-04-25 11:23:38 -07:00
option(USE_LIBINTL_LITE "Set to ON to build and use libintl-lite" ${_USE_LIBINTL_LITE})
set(LIBINTL_LIBRARY)
set(LIBINTL_INCDIRS)
if(BUILD_JSONCPP)
2024-09-28 10:31:06 -07:00
add_subdirectory(subprojects/jsoncpp)
set(JSONCPP_TARGET jsoncpp_static)
2024-04-25 11:23:38 -07:00
endif()
if(BUILD_SOUNDTOUCH)
2024-09-28 10:31:06 -07:00
set(SOUNDSTRETCH OFF CACHE BOOL "" FORCE)
set(INTEGER_SAMPLES OFF CACHE BOOL "")
add_subdirectory(subprojects/soundtouch)
set(SOUNDTOUCH_TARGET SoundTouch)
endif()
if(BUILD_PROTOBUF)
add_subdirectory(subprojects/protobuf)
else()
find_package(protobuf REQUIRED)
find_package(absl CONFIG REQUIRED)
2024-04-25 11:23:38 -07:00
endif()
if(USE_LIBINTL_LITE)
2024-09-28 10:31:06 -07:00
add_subdirectory(subprojects/libintl-lite)
set(LIBINTL_LIBRARY intl CACHE INTERNAL "")
set(LIBINTL_INCDIRS "subprojects/libintl-lite" CACHE INTERNAL "")
2024-04-25 11:23:38 -07:00
else()
2024-09-28 10:31:06 -07:00
find_package(Intl REQUIRED)
set(LIBINTL_LIBRARY Intl::Intl CACHE INTERNAL "")
set(LIBINTL_INCDIRS ${Intl_INCLUDE_DIRS} CACHE INTERNAL "")
2024-04-25 11:23:38 -07:00
endif()
if (DEFINED ANDROID_NDK)
2024-09-28 10:31:06 -07:00
add_subdirectory(subprojects/oboe)
target_link_libraries(liblooper PUBLIC oboe)
endif()
2024-08-08 13:12:37 -07:00
target_link_libraries(liblooper PUBLIC ${Protobuf_LIBRARY_RELEASE} fmt::fmt)
2024-04-25 11:23:38 -07:00
target_include_directories(liblooper PUBLIC ${LIBINTL_INCDIRS})
target_link_libraries(liblooper PUBLIC ${LIBINTL_LIBRARY})
2024-04-24 09:59:51 -07:00
if(DEFINED EMSCRIPTEN)
2024-09-28 10:31:06 -07:00
target_link_libraries(liblooper PUBLIC ${SDL_MIXER_X_TARGET} ${SOUNDTOUCH_TARGET} libvgmstream ${JSONCPP_TARGET})
target_compile_options(liblooper PUBLIC "-sUSE_SDL=2")
2024-04-24 09:59:51 -07:00
else()
2024-09-28 10:31:06 -07:00
if(NOT BUILD_SOUNDTOUCH)
pkg_check_modules(SoundTouch IMPORTED_TARGET soundtouch)
endif()
if (NOT BUILD_JSONCPP)
pkg_check_modules(jsoncpp IMPORTED_TARGET jsoncpp)
endif()
if (NOT BUILD_SDL)
find_package(SDL2 REQUIRED)
endif()
if (ENABLE_DBUS)
find_package(sdbus-c++)
if(NOT ${sdbus-c++_FOUND})
set(ENABLE_DBUS OFF)
message("Warning: Dbus support not found - Not enabling DBus")
endif()
endif()
set(SDL2_TARGET SDL2::SDL2)
if (TARGET SDL2-static)
set(SDL2_TARGET SDL2-static)
endif()
target_link_libraries(liblooper PUBLIC ${SDL2_TARGET} SDL2main ${SDL_MIXER_X_TARGET} ${SOUNDTOUCH_TARGET} libvgmstream libvgmstream_shared ${JSONCPP_TARGET})
2024-04-24 09:59:51 -07:00
endif()
if (${ENABLE_DBUS})
2024-09-28 10:31:06 -07:00
target_link_libraries(liblooper PUBLIC SDBusCpp::sdbus-c++)
target_compile_definitions(liblooper PUBLIC DBUS_ENABLED)
2024-04-24 09:59:51 -07:00
endif()
macro(add_ui_backend)
2024-09-28 10:31:06 -07:00
set(ARGS ${ARGV})
list(POP_FRONT ARGS target)
add_library(${target} STATIC ${ARGS})
message("Enabling UI backend '" ${target} "'...")
list(APPEND UI_BACKENDS ${target})
set(UI_BACKENDS ${UI_BACKENDS} PARENT_SCOPE)
add_dependencies(${target} looper_assets)
target_include_directories(${target} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${INC})
target_link_libraries(${target} PRIVATE liblooper)
if(${USE_PORTALS})
target_pkgconfig(TARGETS ${target} PRIVATE PREFIX libPortal LIBRARIES libportal)
if (NOT ${libPortal_FOUND} EQUAL "1")
set(USE_PORTALS OFF)
else()
info("Enabling libportal support...")
target_compile_definitions(imgui_ui PRIVATE "PORTALS")
endif()
endif()
endmacro()
2024-04-24 09:59:51 -07:00
macro(ui_backend_subdir)
2024-09-28 10:31:06 -07:00
cmake_parse_arguments(UI_OPTS "" "SUBDIR;NAME;READABLE_NAME" "" ${ARGN} )
message("Backend ${UI_OPTS_READABLE_NAME} defined...")
set(UI_DISABLE_OPT DISABLE_${UI_OPTS_NAME}_UI)
option(${UI_DISABLE_OPT} "Disables the ${UI_OPTS_READABLE_NAME} UI" OFF)
if (NOT ${${UI_DISABLE_OPT}})
cmake_path(GET UI_OPTS_SUBDIR STEM UI_OPTS_DIRNAME)
set(BASE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/${UI_OPTS_SUBDIR})
add_subdirectory(${UI_OPTS_SUBDIR})
list(APPEND ENABLED_UIS "${UI_OPTS_DIRNAME}")
message("Enabled backend ${UI_OPTS_READABLE_NAME}.")
else()
message("Disabled backend ${UI_OPTS_READABLE_NAME}")
endif()
2024-04-24 09:59:51 -07:00
endmacro()
2024-08-08 13:12:37 -07:00
macro(add_playback_backend)
2024-09-28 10:31:06 -07:00
set(ARGS ${ARGV})
list(POP_FRONT ARGS target)
add_library(${target} STATIC ${ARGS})
message("Enabling playback backend '" ${target} "'...")
list(APPEND PLAYBACK_BACKENDS ${target})
set(PLAYBACK_BACKENDS ${PLAYBACK_BACKENDS} PARENT_SCOPE)
add_dependencies(${target} looper_assets)
target_include_directories(${target} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${INC})
target_link_libraries(${target} PRIVATE liblooper)
2024-08-08 13:12:37 -07:00
endmacro()
macro(playback_backend_subdir)
2024-09-28 10:31:06 -07:00
cmake_parse_arguments(PLAYBACK_OPTS "" "SUBDIR;NAME;READABLE_NAME" "" ${ARGN} )
message("Backend ${PLAYBACK_OPTS_READABLE_NAME} defined...")
set(PLAYBACK_DISABLE_OPT DISABLE_${PLAYBACK_OPTS_NAME}_PLAYBACK_BACKEND)
option(${PLAYBACK_DISABLE_OPT} "Disables the ${PLAYBACK_OPTS_READABLE_NAME} playback backend" OFF)
if (NOT ${${PLAYBACK_DISABLE_OPT}})
cmake_path(GET PLAYBACK_OPTS_SUBDIR STEM PLAYBACK_OPTS_DIRNAME)
set(BASE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/${PLAYBACK_OPTS_SUBDIR})
add_subdirectory(${PLAYBACK_OPTS_SUBDIR})
list(APPEND ENABLED_PLAYBACK_BACKENDS "${PLAYBACK_OPTS_DIRNAME}")
message("Enabled backend ${PLAYBACK_OPTS_READABLE_NAME}.")
else()
message("Disabled backend ${PLAYBACK_OPTS_READABLE_NAME}")
endif()
2024-08-08 13:12:37 -07:00
endmacro()
set(ENABLED_UIS )
2024-08-08 13:12:37 -07:00
set(ENABLED_PLAYBACK_BACKENDS )
2024-04-24 09:59:51 -07:00
ui_backend_subdir(NAME "IMGUI" READABLE_NAME "Dear ImGui" SUBDIR backends/ui/imgui)
2024-04-25 11:23:38 -07:00
if (NOT (DEFINED EMSCRIPTEN OR DEFINED ANDROID_NDK))
2024-09-28 10:31:06 -07:00
ui_backend_subdir(NAME "GTK" READABLE_NAME "GTK4" SUBDIR backends/ui/gtk)
endif()
2024-08-08 13:12:37 -07:00
playback_backend_subdir(NAME "VGMSTREAM" READABLE_NAME "VgmStream" SUBDIR backends/playback/vgmstream)
playback_backend_subdir(NAME "SDL_MIXER_X" READABLE_NAME "SDL Mixer X" SUBDIR backends/playback/sdl_mixer_x)
playback_backend_subdir(NAME "ZSM" READABLE_NAME "ZSM" SUBDIR backends/playback/zsm)
execute_process(COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/gen_ui_backend_inc.py ${CMAKE_CURRENT_BINARY_DIR} --ui ${ENABLED_UIS} --playback ${ENABLED_PLAYBACK_BACKENDS})
2024-05-01 09:07:08 -07:00
prefix_all(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/ main.cpp daemon_backend.cpp proxy_backend.cpp)
list(APPEND SOURCES ${CMAKE_CURRENT_BINARY_DIR}/backend_glue.cpp)
2024-04-24 09:59:51 -07:00
if(DEFINED EMSCRIPTEN)
2024-09-28 10:31:06 -07:00
set(CMAKE_EXECUTABLE_SUFFIX ".html")
2024-04-24 09:59:51 -07:00
endif()
set(TARGET_NAME looper)
if(DEFINED EMSCRIPTEN)
2024-09-28 10:31:06 -07:00
set(TARGET_NAME index)
2024-04-24 09:59:51 -07:00
endif()
function(copy_to_bindir src dst)
2024-09-28 10:31:06 -07:00
add_custom_command(TARGET ${TARGET_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/${src}" "$<TARGET_FILE_DIR:${TARGET_NAME}>/${dst}")
2024-04-24 09:59:51 -07:00
endfunction()
2024-05-02 14:52:11 -07:00
if (DEFINED ANDROID_NDK OR SHARED_LIB)
2024-09-28 10:31:06 -07:00
add_library(${TARGET_NAME} SHARED ${SOURCES})
2024-04-25 11:23:38 -07:00
else()
2024-09-28 10:31:06 -07:00
add_executable(${TARGET_NAME} ${SOURCES})
2024-04-25 11:23:38 -07:00
endif()
2024-04-24 09:59:51 -07:00
add_dependencies(${TARGET_NAME} looper_assets ${UI_BACKENDS})
if(DEFINED EMSCRIPTEN)
2024-09-28 10:31:06 -07:00
copy_to_bindir(assets/icon.svg icon.svg)
copy_to_bindir(assets/icon.png icon.png)
copy_to_bindir(web/shell.js shell.js)
copy_to_bindir(web/style.css style.css)
copy_to_bindir(web/serviceWorker.js serviceWorker.js)
copy_to_bindir(web/manifest.json manifest.json)
copy_to_bindir(assets/ForkAwesome/fonts/forkawesome-webfont.ttf forkawesome-webfont.ttf)
copy_to_bindir(assets/ForkAwesome/css/fork-awesome.min.css fork-awesome.min.css)
copy_to_bindir(assets/ForkAwesome/css/fork-awesome.min.css.map fork-awesome.min.css.map)
endif()
2024-08-08 13:12:37 -07:00
target_link_libraries(${TARGET_NAME} PUBLIC liblooper ${UI_BACKENDS} ${PLAYBACK_BACKENDS})
2024-04-24 09:59:51 -07:00
install(TARGETS ${TARGET_NAME} ${EXTRA_LIBS})
2024-08-08 13:12:37 -07:00
if (${BUILD_SDL2})
2024-09-28 10:31:06 -07:00
install(EXPORT SDL2-static SDL2main)
2024-04-25 11:23:38 -07:00
endif()
2024-04-24 09:59:51 -07:00
if (NOT DEFINED EMSCRIPTEN)
2024-09-28 10:31:06 -07:00
install(FILES assets/icon.svg DESTINATION ${CMAKE_INSTALL_DATADIR}/icons/hicolor/scalable/apps/)
install(FILES assets/com.complecwaft.Looper.desktop DESTINATION ${CMAKE_INSTALL_DATADIR}/applications)
install(FILES assets/com.complecwaft.Looper.metainfo.xml DESTINATION ${CMAKE_INSTALL_DATADIR}/metainfo)
install(DIRECTORY assets/translations/ TYPE LOCALE PATTERN "*" EXCLUDE PATTERN "looper.pot")
2024-04-24 09:59:51 -07:00
endif()
2024-05-02 14:52:11 -07:00
if (SHARED_LIB)
2024-09-28 10:31:06 -07:00
target_compile_definitions(${TARGET_NAME} PRIVATE "LIBRARY_MODE")
2024-08-08 13:12:37 -07:00
endif()
2024-09-28 10:31:06 -07:00
if(TESTS)
include(GoogleTest)
include(CTest)
set(INSTALL_GTEST OFF CACHE BOOL "" FORCE)
add_subdirectory(subprojects/googletest)
add_executable(looper_tests tests.cpp ${CMAKE_CURRENT_BINARY_DIR}/backend_glue.cpp)
add_dependencies(looper_tests looper_assets)
target_link_libraries(looper_tests PRIVATE ${PLAYBACK_BACKENDS} ${UI_BACKENDS})
set(TESTS "FileBackend.Seeking" "FileBackend.Reading" "FileBackend.ReadingSeeking" "PlaybackBackend.Looping")
foreach (test ${TESTS})
get_filename_component(test_cat ${test} NAME_WE)
get_filename_component(test_name ${test} EXT)
string(SUBSTRING ${test_name} 1 -1 test_name)
add_test(NAME ${test_name} COMMAND ${CMAKE_CURRENT_BINARY_DIR}/looper_tests --gtest_filter=${test} PROPERTY LABELS ${test_cat})
endforeach()
target_include_directories(liblooper SYSTEM PUBLIC subprojects/googletest/googletest/include)
target_link_libraries(looper_tests PRIVATE liblooper)
target_link_libraries(liblooper PUBLIC gtest_main)
target_compile_definitions(liblooper PUBLIC TESTS)
2024-09-28 10:48:35 -07:00
endif()