462 lines
20 KiB
CMake
462 lines
20 KiB
CMake
cmake_minimum_required(VERSION 3.22)
|
|
project(looper VERSION 1.0.0 LANGUAGES C CXX)
|
|
option(SHARED_LIB "Enables building as a shared library." OFF)
|
|
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Emscripten")
|
|
set(EMSCRIPTEN ON)
|
|
message("Building for WASM.")
|
|
endif()
|
|
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)
|
|
set(SDL_MIXER_X_STATIC ON CACHE BOOL "")
|
|
set(SDL_MIXER_X_SHARED OFF CACHE BOOL "")
|
|
set(DOWNLOAD_AUDIO_CODECS_DEPENDENCY OFF CACHE BOOL "")
|
|
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)
|
|
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)
|
|
if (DEFINED EMSCRIPTEN)
|
|
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(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 --shell-file=${CMAKE_CURRENT_SOURCE_DIR}/web/shell.html --js-library=${CMAKE_CURRENT_SOURCE_DIR}/web/api.js -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 -sASYNCIFY_IMPORTS=read_file,read_storage,write_storage,remove_storage,find_keys")
|
|
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}")
|
|
else()
|
|
set(BUILD_STATIC OFF CACHE BOOL "")
|
|
endif()
|
|
option(BUILD_SDL "Enables built-in SDL" OFF)
|
|
option(BUILD_SDL_IMAGE "Enables built-in SDL_image" ${BUILD_SDL})
|
|
if(DEFINED ANDROID_NDK)
|
|
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)
|
|
endif()
|
|
if (BUILD_SDL)
|
|
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)
|
|
endif()
|
|
if (BUILD_SDL_IMAGE)
|
|
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)
|
|
endif()
|
|
find_package(PkgConfig)
|
|
#add_subdirectory(subprojects/jsoncpp)
|
|
|
|
include(GNUInstallDirs)
|
|
add_subdirectory(subprojects/SDL-Mixer-X)
|
|
add_subdirectory(subprojects/vgmstream)
|
|
if (DEFINED EMSCRIPTEN)
|
|
set(EXTRA_LIBS )
|
|
else()
|
|
set(EXTRA_LIBS libvgmstream_shared)
|
|
endif()
|
|
if(SDL_MIXER_X_STATIC)
|
|
set(SDL_MIXER_X_TARGET SDL2_mixer_ext_Static)
|
|
else()
|
|
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)
|
|
execute_process(COMMAND ./version.sh OUTPUT_VARIABLE TAG WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
|
|
message("" ${TAG})
|
|
else()
|
|
set(TAG "unknown")
|
|
endif()
|
|
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
|
set(DEBUG ON)
|
|
endif()
|
|
|
|
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
|
|
include(log)
|
|
#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)
|
|
add_subdirectory(subprojects/fmt)
|
|
macro(target_pkgconfig)
|
|
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()
|
|
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)
|
|
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()
|
|
find_package(Protobuf REQUIRED)
|
|
find_package(gRPC CONFIG REQUIRED)
|
|
|
|
set(_PROTOBUF_LIBPROTOBUF ${Protobuf_LIBRARY_RELEASE})
|
|
set(_REFLECTION gRPC::grpc++_reflection)
|
|
set(_GRPC_GRPCPP gRPC::grpc++)
|
|
find_program(_GRPC_CPP_PLUGIN_EXE grpc_cpp_plugin)
|
|
find_program(_PROTOBUF_PROTOC protoc)
|
|
function(grpc_proto)
|
|
cmake_parse_arguments(GRPC_PROTO "" "TARGET"
|
|
"SOURCES" ${ARGV})
|
|
foreach (GRPC_PROTO_SOURCE ${GRPC_PROTO_SOURCES})
|
|
set(GRPC_PROTO_SRCS)
|
|
set(GRPC_PROTO_HDRS)
|
|
set(GRPC_GRPC_SRCS)
|
|
set(GRPC_GRPC_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)
|
|
list(APPEND GRPC_GRPC_SRCS ${src_out}/${src_stem}.grpc.pb.cc)
|
|
list(APPEND GRPC_GRPC_HDRS ${src_out}/${src_stem}.grpc.pb.h)
|
|
make_directory(${src_out})
|
|
add_custom_command(
|
|
OUTPUT ${GRPC_PROTO_SRCS} ${GRPC_PROTO_HDRS} ${GRPC_GRPC_SRCS} ${GRPC_GRPC_HDRS}
|
|
COMMAND ${_PROTOBUF_PROTOC}
|
|
ARGS --grpc_out "${src_out}"
|
|
--cpp_out "${src_out}"
|
|
-I "${src_path}"
|
|
--plugin=protoc-gen-grpc="${_GRPC_CPP_PLUGIN_EXE}"
|
|
"${GRPC_PROTO_SOURCE}"
|
|
DEPENDS "${GRPC_PROTO_SOURCE}"
|
|
)
|
|
target_sources(${GRPC_PROTO_TARGET} PRIVATE ${GRPC_PROTO_SRCS} ${GRPC_GRPC_SRCS})
|
|
target_include_directories(${GRPC_PROTO_TARGET} PRIVATE ${src_out})
|
|
endforeach()
|
|
target_include_directories(${GRPC_PROTO_TARGET} PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
|
|
target_link_libraries(${GRPC_PROTO_TARGET} PUBLIC ${_REFLECTION} ${_GRPC_GRPCPP} ${_PROTOBUF_LIBPROTOBUF})
|
|
endfunction()
|
|
prefix_all(LIBRARY_SOURCES
|
|
${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
|
|
)
|
|
add_library(liblooper STATIC ${LIBRARY_SOURCES})
|
|
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})
|
|
target_link_libraries(liblooper PUBLIC grpc++)
|
|
target_include_directories(liblooper PUBLIC)
|
|
set(JSONCPP_TARGET PkgConfig::jsoncpp)
|
|
set(SOUNDTOUCH_TARGET PkgConfig::SoundTouch)
|
|
function(set_to_value_of_condition var)
|
|
if (${ARGN})
|
|
set(${var} ON PARENT_SCOPE)
|
|
else()
|
|
set(${var} OFF PARENT_SCOPE)
|
|
endif()
|
|
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})
|
|
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)
|
|
add_subdirectory(subprojects/jsoncpp)
|
|
set(JSONCPP_TARGET jsoncpp_static)
|
|
endif()
|
|
if(BUILD_SOUNDTOUCH)
|
|
add_subdirectory(subprojects/soundtouch)
|
|
set(SOUNDTOUCH_TARGET SoundTouch)
|
|
endif()
|
|
if(USE_LIBINTL_LITE)
|
|
add_subdirectory(subprojects/libintl-lite)
|
|
set(LIBINTL_LIBRARY intl CACHE INTERNAL "")
|
|
set(LIBINTL_INCDIRS "subprojects/libintl-lite" CACHE INTERNAL "")
|
|
else()
|
|
find_package(Intl REQUIRED)
|
|
set(LIBINTL_LIBRARY Intl::Intl CACHE INTERNAL "")
|
|
set(LIBINTL_INCDIRS ${Intl_INCLUDE_DIRS} CACHE INTERNAL "")
|
|
endif()
|
|
if (DEFINED ANDROID_NDK)
|
|
add_subdirectory(subprojects/oboe)
|
|
target_link_libraries(liblooper PUBLIC oboe)
|
|
endif()
|
|
find_package(absl CONFIG REQUIRED)
|
|
target_link_libraries(liblooper PUBLIC ${Protobuf_LIBRARY_RELEASE} fmt::fmt)
|
|
target_include_directories(liblooper PUBLIC ${LIBINTL_INCDIRS})
|
|
target_link_libraries(liblooper PUBLIC ${LIBINTL_LIBRARY})
|
|
if(DEFINED EMSCRIPTEN)
|
|
target_link_libraries(liblooper PUBLIC ${SDL_MIXER_X_TARGET} ${SOUNDTOUCH_TARGET} libvgmstream ${JSONCPP_TARGET})
|
|
target_compile_options(liblooper PUBLIC "-sUSE_SDL=2")
|
|
else()
|
|
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})
|
|
endif()
|
|
if (${ENABLE_DBUS})
|
|
target_link_libraries(liblooper PUBLIC SDBusCpp::sdbus-c++)
|
|
target_compile_definitions(liblooper PUBLIC DBUS_ENABLED)
|
|
endif()
|
|
macro(add_ui_backend)
|
|
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()
|
|
macro(ui_backend_subdir)
|
|
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()
|
|
endmacro()
|
|
macro(add_playback_backend)
|
|
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)
|
|
endmacro()
|
|
macro(playback_backend_subdir)
|
|
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()
|
|
endmacro()
|
|
set(ENABLED_UIS )
|
|
set(ENABLED_PLAYBACK_BACKENDS )
|
|
ui_backend_subdir(NAME "IMGUI" READABLE_NAME "Dear ImGui" SUBDIR backends/ui/imgui)
|
|
if (NOT (DEFINED EMSCRIPTEN OR DEFINED ANDROID_NDK))
|
|
ui_backend_subdir(NAME "GTK" READABLE_NAME "GTK4" SUBDIR backends/ui/gtk)
|
|
endif()
|
|
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})
|
|
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)
|
|
if(DEFINED EMSCRIPTEN)
|
|
set(CMAKE_EXECUTABLE_SUFFIX ".html")
|
|
endif()
|
|
|
|
set(TARGET_NAME looper)
|
|
if(DEFINED EMSCRIPTEN)
|
|
set(TARGET_NAME index)
|
|
endif()
|
|
function(copy_to_bindir src dst)
|
|
add_custom_command(TARGET ${TARGET_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/${src}" "$<TARGET_FILE_DIR:${TARGET_NAME}>/${dst}")
|
|
endfunction()
|
|
if (DEFINED ANDROID_NDK OR SHARED_LIB)
|
|
add_library(${TARGET_NAME} SHARED ${SOURCES})
|
|
else()
|
|
add_executable(${TARGET_NAME} ${SOURCES})
|
|
endif()
|
|
add_dependencies(${TARGET_NAME} looper_assets ${UI_BACKENDS})
|
|
|
|
if(DEFINED EMSCRIPTEN)
|
|
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()
|
|
find_program(ASCLI_EXE NAMES "appstreamcli" NO_CACHE)
|
|
if(${ASCLI_EXE} STREQUAL "ASCLIEXE-NOTFOUND")
|
|
message("Cannot verify Appstream Metadata.")
|
|
else()
|
|
add_test(NAME "verify appstream metadata" COMMAND ${ASCLI_EXE} validate --no-net --pedantic "assets/com.complecwaft.Looper.metainfo.xml")
|
|
endif()
|
|
target_link_libraries(${TARGET_NAME} PUBLIC liblooper ${UI_BACKENDS} ${PLAYBACK_BACKENDS})
|
|
install(TARGETS ${TARGET_NAME} ${EXTRA_LIBS})
|
|
if (${BUILD_SDL2})
|
|
install(EXPORT SDL2-static SDL2main)
|
|
endif()
|
|
if (NOT DEFINED EMSCRIPTEN)
|
|
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")
|
|
endif()
|
|
|
|
if (SHARED_LIB)
|
|
target_compile_definitions(${TARGET_NAME} PRIVATE "LIBRARY_MODE")
|
|
endif()
|