Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: Feat/windows support #31

Draft
wants to merge 21 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@ ignore
.cache/
src/test/
archlinux-dist/

# vs specific files
.vs/
out/
vcpkg_installed/
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,6 @@
[submodule "libs/cppcodec"]
path = libs/cppcodec
url = https://github.com/tplgy/cppcodec.git
[submodule "windows/libs/postgres"]
path = windows/libs/postgres
url = https://github.com/postgres/postgres.git
296 changes: 180 additions & 116 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,25 @@ project(Musicat
LANGUAGES CXX
DESCRIPTION "Discord Music Bot written in C++")


# CMAKE_BUILD_TYPE : Debug, Release, RelWithDebInfo and MinSizeRel

option(MUSICAT_WITH_CORO "Configure Musicat with C++20 coroutines" OFF)
option(MUSICAT_DEBUG_SYMBOL "Build Musicat with debug symbol" ON)
option(COMPILE_GNUPLOT "Download and compile gnuplot" OFF)
option(MUSICAT_NO_SERVER "Disable Musicat server" OFF)

set(MUSICAT_CXX_STANDARD 17)
set(DPP_INSTALL OFF)
set(DPP_USE_EXTERNAL_JSON ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic")

if (MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Wall /W4")

# disable server on windows
set(MUSICAT_NO_SERVER ON)
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic")
endif()

set(WITH_COMPILE_GNUPLOT 0)

Expand All @@ -36,92 +47,114 @@ file(GLOB_RECURSE MUSICAT_SOURCE_FILES
file(GLOB_RECURSE ELIZA_SOURCE_FILES
${CMAKE_CURRENT_SOURCE_DIR}/libs/ELIZA/src/eliza.cpp)

list(APPEND MUSICAT_HEADER_FILES
"include/nlohmann/json.hpp")

if (MUSICAT_NO_SERVER)
message("-- INFO: Musicat uWebSockets server disabled")
add_compile_definitions(MUSICAT_NO_SERVER)
else()
list(APPEND MUSICAT_HEADER_FILES
"libs/uWebSockets/uSockets/src/libusockets.h"
"libs/uWebSockets/uSockets/src/quic.h")
endif()

list(APPEND MUSICAT_SOURCE_FILES
"libs/yt-search.h/src/yt-search/encode.cpp"
"libs/yt-search.h/src/yt-search/yt-playlist.cpp"
"libs/yt-search.h/src/yt-search/yt-search.cpp"
"libs/yt-search.h/src/yt-search/yt-track-info.cpp"
"libs/nekos-bestpp/src/nekos-best++.cpp")

# Create an executable
add_executable(Shasha
# include files
${MUSICAT_HEADER_FILES}
include/nlohmann/json.hpp
libs/uWebSockets/uSockets/src/libusockets.h
libs/uWebSockets/uSockets/src/quic.h
# ${ELIZA_HEADER_FILES}
# !TODO: include/uWebSockets/files

# impl files
${MUSICAT_SOURCE_FILES}
libs/yt-search.h/src/yt-search/encode.cpp
libs/yt-search.h/src/yt-search/yt-playlist.cpp
libs/yt-search.h/src/yt-search/yt-search.cpp
libs/yt-search.h/src/yt-search/yt-track-info.cpp
libs/nekos-bestpp/src/nekos-best++.cpp
${ELIZA_SOURCE_FILES}
src/main.cpp)

set(USOCKETS_OBJECT_FILES
${CMAKE_CURRENT_SOURCE_DIR}/libs/uWebSockets/uSockets/bsd.o
${CMAKE_CURRENT_SOURCE_DIR}/libs/uWebSockets/uSockets/context.o
${CMAKE_CURRENT_SOURCE_DIR}/libs/uWebSockets/uSockets/epoll_kqueue.o
${CMAKE_CURRENT_SOURCE_DIR}/libs/uWebSockets/uSockets/gcd.o
${CMAKE_CURRENT_SOURCE_DIR}/libs/uWebSockets/uSockets/libuv.o
${CMAKE_CURRENT_SOURCE_DIR}/libs/uWebSockets/uSockets/loop.o
${CMAKE_CURRENT_SOURCE_DIR}/libs/uWebSockets/uSockets/openssl.o
${CMAKE_CURRENT_SOURCE_DIR}/libs/uWebSockets/uSockets/quic.o
${CMAKE_CURRENT_SOURCE_DIR}/libs/uWebSockets/uSockets/sni_tree.o
${CMAKE_CURRENT_SOURCE_DIR}/libs/uWebSockets/uSockets/socket.o
${CMAKE_CURRENT_SOURCE_DIR}/libs/uWebSockets/uSockets/udp.o)

file(GLOB_RECURSE USOCKETS_SOURCE_FILES
${CMAKE_CURRENT_SOURCE_DIR}/libs/uWebSockets/uSockets/src/*.c)

file(GLOB_RECURSE UWEBSOCKETS_HEADER_FILES
${CMAKE_CURRENT_SOURCE_DIR}/libs/uWebSockets/src/*.h)

add_custom_target(uWebSockets
DEPENDS ${USOCKETS_OBJECT_FILES})

add_custom_command(OUTPUT ${USOCKETS_OBJECT_FILES}
COMMAND WITH_OPENSSL=1 WITH_ZLIB=1 make
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/libs/uWebSockets/uSockets
DEPENDS ${USOCKETS_SOURCE_FILES} ${UWEBSOCKETS_HEADER_FILES})

add_custom_target(deps
DEPENDS ShashaDeps)

add_custom_command(OUTPUT ShashaDeps
COMMAND COMPILE_GNUPLOT=${WITH_COMPILE_GNUPLOT} GNUPLOT_VERSION=${GNUPLOT_VERSION} make
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/libs)

add_dependencies(Shasha deps uWebSockets)

add_custom_target(archlinux-dist-folder
COMMAND mkdir -p archlinux-dist
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})

add_custom_target(archlinux-dist

COMMAND cp build/Shasha
build/libs/DPP/library/libdpp.so*
libs/curlpp/build/libcurlpp.so*
libs/icu/usr/local/lib/lib*
src/yt-dlp/ytdlp.py
archlinux-dist

COMMAND cp -r libs/yt-dlp
src/yt-dlp/utils
archlinux-dist

WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS archlinux-dist-folder Shasha)

if (COMPILE_GNUPLOT)
add_custom_target(archlinux-dist-cp-gnuplot
if (NOT MSVC)
# uWebSockets
if (NOT MUSICAT_NO_SERVER)
set(USOCKETS_OBJECT_FILES
${CMAKE_CURRENT_SOURCE_DIR}/libs/uWebSockets/uSockets/bsd.o
${CMAKE_CURRENT_SOURCE_DIR}/libs/uWebSockets/uSockets/context.o
${CMAKE_CURRENT_SOURCE_DIR}/libs/uWebSockets/uSockets/epoll_kqueue.o
${CMAKE_CURRENT_SOURCE_DIR}/libs/uWebSockets/uSockets/gcd.o
${CMAKE_CURRENT_SOURCE_DIR}/libs/uWebSockets/uSockets/libuv.o
${CMAKE_CURRENT_SOURCE_DIR}/libs/uWebSockets/uSockets/loop.o
${CMAKE_CURRENT_SOURCE_DIR}/libs/uWebSockets/uSockets/openssl.o
${CMAKE_CURRENT_SOURCE_DIR}/libs/uWebSockets/uSockets/quic.o
${CMAKE_CURRENT_SOURCE_DIR}/libs/uWebSockets/uSockets/sni_tree.o
${CMAKE_CURRENT_SOURCE_DIR}/libs/uWebSockets/uSockets/socket.o
${CMAKE_CURRENT_SOURCE_DIR}/libs/uWebSockets/uSockets/udp.o)

file(GLOB_RECURSE USOCKETS_SOURCE_FILES
${CMAKE_CURRENT_SOURCE_DIR}/libs/uWebSockets/uSockets/src/*.c)

file(GLOB_RECURSE UWEBSOCKETS_HEADER_FILES
${CMAKE_CURRENT_SOURCE_DIR}/libs/uWebSockets/src/*.h)

add_custom_target(uWebSockets
DEPENDS ${USOCKETS_OBJECT_FILES})

add_custom_command(OUTPUT ${USOCKETS_OBJECT_FILES}
COMMAND WITH_OPENSSL=1 WITH_ZLIB=1 make
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/libs/uWebSockets/uSockets
DEPENDS ${USOCKETS_SOURCE_FILES} ${UWEBSOCKETS_HEADER_FILES})

add_dependencies(Shasha uWebSockets)
endif()

# other deps specified in libs/Makefile
add_custom_command(OUTPUT ShashaDeps
COMMAND COMPILE_GNUPLOT=${WITH_COMPILE_GNUPLOT} GNUPLOT_VERSION=${GNUPLOT_VERSION} make
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/libs)

add_custom_target(deps
DEPENDS ShashaDeps)
add_dependencies(Shasha deps)

add_custom_target(archlinux-dist-folder
COMMAND mkdir -p archlinux-dist
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})

add_custom_target(archlinux-dist

COMMAND cp build/Shasha
build/libs/DPP/library/libdpp.so*
build/libs/curlpp/libcurlpp.so*
libs/icu/usr/local/lib/lib*
src/yt-dlp/ytdlp.py
archlinux-dist

COMMAND cp libs/gnuplot-${GNUPLOT_VERSION}/build/bin/gnuplot
COMMAND cp -r libs/yt-dlp
src/yt-dlp/utils
archlinux-dist

WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS archlinux-dist-folder Shasha)

add_dependencies(archlinux-dist archlinux-dist-cp-gnuplot)
if (COMPILE_GNUPLOT)
add_custom_target(archlinux-dist-cp-gnuplot

COMMAND cp libs/gnuplot-${GNUPLOT_VERSION}/build/bin/gnuplot
archlinux-dist

WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS archlinux-dist-folder Shasha)

add_dependencies(archlinux-dist archlinux-dist-cp-gnuplot)
endif()
else()
# MSVC deps
set(CURL_LIBRARY "${CMAKE_CURRENT_SOURCE_DIR}/windows/libs/curl-8.7.1_7-win64-mingw/bin/libcurl-x64.lib")
set(CURL_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/windows/libs/curl-8.7.1_7-win64-mingw/include/")
endif()

if (MUSICAT_WITH_CORO)
Expand All @@ -133,56 +166,87 @@ if (MUSICAT_WITH_CORO)
set(MUSICAT_CXX_STANDARD 20)
endif()

if (MUSICAT_DEBUG_SYMBOL)
if (CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
message("-- INFO: Will build Musicat with debug symbol")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")
# set(CMAKE_BUILD_TYPE "Debug")

if (MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Debug")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")
endif()
endif()

# Linking libraries
target_link_libraries(Shasha
dpp
# oggz
# ogg
pq
curlpp
curl
cppcodec
icui18n
icuuc
icudata
icuio
${USOCKETS_OBJECT_FILES}
ssl
crypto
z
pthread
# Add any other libs you want to use here
)
list(APPEND MUSICAT_INC_DIRS
"include"
"libs/DPP/include"
"libs/yt-search.h/include"
"libs/nekos-bestpp/include"
"libs/icu/usr/local/include"
"libs/curlpp/include"
"libs/jwt-cpp/include"
"libs/ELIZA/src")

if (MSVC)
# vcpkg cmake confs, PLANNED TO BE UNUSED
# set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH};${CMAKE_CURRENT_SOURCE_DIR}/vcpkg_installed/x64-windows)
# set(FIND_PATH_HINTS "${CMAKE_CURRENT_SOURCE_DIR}/vcpkg_installed/x64-windows/include")

# uwebsockets
# find_path(UWEBSOCKETS_INCLUDE_DIRS "uwebsockets/App.h"
# HINTS ${FIND_PATH_HINTS}
# )
# target_include_directories(Shasha PRIVATE ${UWEBSOCKETS_INCLUDE_DIRS})

# curlpp
# find_package(unofficial-curlpp CONFIG REQUIRED)
# target_link_libraries(Shasha PRIVATE unofficial::curlpp::curlpp)

# libpq
# find_package(PostgreSQL REQUIRED)
# target_link_libraries(Shasha PRIVATE PostgreSQL::PostgreSQL)

# manual installation (non-vcpkg)
list(APPEND MUSICAT_INC_DIRS ${CURL_INCLUDE_DIR})
else()
list(APPEND MUSICAT_INC_DIRS
# uWebSockets
"libs"
"libs/uWebSockets/uSockets/src"
"/usr/include/postgresql")

list(APPEND MUSICAT_LN_DIRS
"libs/icu/usr/local/lib")

list(APPEND MUSICAT_LN_LIBS
"dpp"
"pq"
"curlpp"
"curl"
"cppcodec"
"icui18n"
"icuuc"
"icudata"
"icuio"
${USOCKETS_OBJECT_FILES}
"ssl"
"crypto"
"z"
"pthread"
)
endif()

# Specify includes
target_include_directories(Shasha PRIVATE
include
# uWebSockets
libs
libs/DPP/include
libs/yt-search.h/include
libs/nekos-bestpp/include
libs/uWebSockets/uSockets/src
libs/icu/usr/local/include
libs/curlpp/include
# libs/liboggz/include
libs/jwt-cpp/include
/usr/include/postgresql
libs/ELIZA/src
# Remember to add the include directories of any other libraries too
)
${MUSICAT_INC_DIRS})

target_link_directories(Shasha PRIVATE
libs/curlpp/build
libs/icu/usr/local/lib
# libs/liboggz/build/lib
)
if (MUSICAT_LN_DIRS)
target_link_directories(Shasha PRIVATE
${MUSICAT_LN_DIRS})
endif()

if (MUSICAT_LN_LIBS)
target_link_libraries(Shasha
${MUSICAT_LN_LIBS})
endif()

# Set C++ version
set_target_properties(Shasha PROPERTIES
Expand All @@ -191,10 +255,10 @@ set_target_properties(Shasha PROPERTIES
EXPORT_COMPILE_COMMANDS ON
)

# Add DPP as dependency
# Add submodule cmake dependency
add_subdirectory(libs/DPP)
add_subdirectory(libs/cppcodec)
# You can also add any other libs you want to use
add_subdirectory(libs/curlpp)

message(WARNING "If you like this bot or wanna suggest smt, say hi in https://discord.gg/ADGcaHnRFs <3")

Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ WORKDIR /home/musicat
COPY --chown=musicat:musicat --from=build \
/app/build/Shasha \
/app/build/libs/DPP/library/libdpp.so* \
/app/libs/curlpp/build/libcurlpp.so* \
/app/build/libs/curlpp/libcurlpp.so* \
/app/libs/icu/usr/local/lib/lib* \
/app/src/yt-dlp/ytdlp.py \
/home/musicat/
Expand Down
7 changes: 6 additions & 1 deletion include/musicat/child.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
#ifndef MUSICAT_CHILD_H
#define MUSICAT_CHILD_H

#include <semaphore.h>
#include <string>

#ifdef WIN32
#include <windows.h>
#else
#include <semaphore.h>
#endif

#define CMD_BUFSIZE BUFSIZ

namespace musicat
Expand Down
Loading