Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
tostc committed Dec 31, 2020
2 parents a3b6c43 + 27984d1 commit 408a1fe
Show file tree
Hide file tree
Showing 295 changed files with 78,742 additions and 620 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
## Version 2.2.2-beta (31.12.2020)
- Added the renaming of users
- Added the moving of users
- Added the muting of users
- Added role management of users. You can now assign and remove roles of members
- Discords object fields are now atomic.
- Guild administration interface added.
- Added command to change the command prefix for a guild. Thanks to @niansa for this suggestion.
- Added version.rc file for windows.

## Version 2.2.1-alpha (06.10.2020)
- Added fix from issue #9 to build the library flawsless for the raspberry pi.

## Version 2.2.0-alpha (19.06.2020)
- Added access to the cached guilds
- Added access to the cached users
Expand Down
112 changes: 78 additions & 34 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
cmake_minimum_required(VERSION 3.3.0)
project(discordbot VERSION 2.2.1 LANGUAGES CXX)
project(discordbot VERSION 2.2.2 LANGUAGES CXX)

#----------------------------Setup any needed variable and include any needed module.----------------------------#

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

include(${CMAKE_ROOT}/Modules/ExternalProject.cmake)

set(VERSION_SUFFIX "-alpha")
set(VERSION_SUFFIX "-beta")

set(PROJECT_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
set(PROJECT_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
Expand All @@ -18,13 +23,12 @@ set(MBEDTLS_LIBRARY ${PROJECT_BINARY_DIR}/${LINK_SUB_DIR}${CMAKE_STATIC_LIBRARY_
set(MBEDX509_LIBRARY ${PROJECT_BINARY_DIR}/${LINK_SUB_DIR}${CMAKE_STATIC_LIBRARY_PREFIX}mbedx509${CMAKE_STATIC_LIBRARY_SUFFIX})
set(MBEDTLS_LIBRARIES "${MBEDCRYPTO_LIBRARY};${MBEDTLS_LIBRARY};${MBEDX509_LIBRARY}")

set(PTHREAD "")
set(ADDITIONAL_LIBS "")
set(ZLIB_LIB "")
set(ZLIB_ROOT ${PROJECT_BINARY_DIR}/zlib) # IXWebsocket doesn't deliver zlib anymore, so this is the new build path.
set(ZLIB_PROJECT_ROOT ${PROJECT_SOURCE_DIR}/externals/zlib-1.2.11)
set(LINK_DIRS "")
# "${PROJECT_BINARY_DIR}/externals/mbedtls/library/${LINK_SUB_DIR}"
# "${PROJECT_BINARY_DIR}/externals/IXWebSocket/${LINK_SUB_DIR}"
# "${PROJECT_BINARY_DIR}/externals/IXWebSocket/third_party/zlib/${LINK_SUB_DIR}"
# "${PROJECT_BINARY_DIR}/externals/opus/${LINK_SUB_DIR}")
set(ZLIB_BINARY_DIR ${PROJECT_BINARY_DIR}/externals/zlib-1.2.11)

set(libsodium_src ${PROJECT_SOURCE_DIR}/externals/libsodium)

Expand All @@ -38,61 +42,93 @@ set(ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
if(MSVC)
set(CMAKE_DEBUG_POSTFIX "d")
set(BUILD_CMD_MBED msbuild /p:OutputPath=${PROJECT_BINARY_DIR} /p:OutDir=${PROJECT_BINARY_DIR} "${PROJECT_BINARY_DIR}/externals/mbedtls/mbed TLS.sln")
set(BUILD_CMD_WEBSOCKET msbuild /p:OutputPath=${PROJECT_BINARY_DIR} /p:OutDir=${PROJECT_BINARY_DIR} "${PROJECT_BINARY_DIR}/externals/IXWebSocket/ixwebsocket.sln")
set(BUILD_CMD_WEBSOCKET msbuild /p:OutputPath=${PROJECT_BINARY_DIR} /p:OutDir=${PROJECT_BINARY_DIR} "${PROJECT_BINARY_DIR}/externals/IXWebSocket/ixwebsocket.sln")

add_definitions(-DSODIUM_STATIC=1 -DSODIUM_EXPORT=.)
add_definitions(-DSODIUM_STATIC=1 -DSODIUM_EXPORT=. -DDLL_BUILD)
endif(MSVC)

set(SKIP_INSTALL_LIBRARIES on)
set(SKIP_INSTALL_HEADERS on)
set(SKIP_INSTALL_FILES on)
set(SKIP_INSTALL_ALL on)

file(MAKE_DIRECTORY ${ZLIB_ROOT}/include)
file(MAKE_DIRECTORY ${ZLIB_ROOT}/lib)

set(TOOLCHAIN_PARAM "")
set(EXTERNAL_ENV "")
set(EXTERNAL_HOST_PARAM "")
if(CMAKE_CROSSCOMPILING)
get_filename_component(TOOLCHAIN "${CMAKE_TOOLCHAIN_FILE}"
REALPATH BASE_DIR "${PROJECT_BINARY_DIR}")

set(TOOLCHAIN_PARAM "-DCMAKE_TOOLCHAIN_FILE=${TOOLCHAIN}")
set(EXTERNAL_ENV ${CMAKE_COMMAND} -E env PATH=${ROOT_PATH}/bin:$ENV{PATH})
set(EXTERNAL_HOST_PARAM --host=${HOST_NAME})
endif()

#----------------------------Create build targets----------------------------#

add_subdirectory(${ZLIB_PROJECT_ROOT})

if(UNIX)
set(ZLIB_LIBS ${ZLIB_BINARY_DIR}/libz.a)
else(UNIX)
set(ZLIB_LIBS ${ZLIB_BINARY_DIR}/Release/zlibstatic.lib)
endif(UNIX)

add_custom_target(zlib_copy ALL
COMMAND ${CMAKE_COMMAND} -E copy ${ZLIB_LIBS} ${ZLIB_ROOT}/lib
COMMAND ${CMAKE_COMMAND} -E copy ${ZLIB_PROJECT_ROOT}/zlib.h ${ZLIB_BINARY_DIR}/zconf.h ${ZLIB_ROOT}/include
DEPENDS zlibstatic)

#Workaround for dependencies.
ExternalProject_Add(mbedtls_build
SOURCE_DIR ${mbedtls_src}
BINARY_DIR ${PROJECT_BINARY_DIR}/externals/mbedtls
CONFIGURE_COMMAND cmake ${mbedtls_src} -G ${CMAKE_GENERATOR} -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_ARCHIVE_OUTPUT_DIRECTORY=${PROJECT_ARCHIVE_OUTPUT_DIRECTORY} -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=${PROJECT_LIBRARY_OUTPUT_DIRECTORY} -DCMAKE_INSTALL_PREFIX=${PROJECT_BINARY_DIR} -DENABLE_PROGRAMS=OFF -DENABLE_TESTING=OFF -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_CONFIGURATION_TYPES=RELEASE
CONFIGURE_COMMAND ${CMAKE_COMMAND} ${mbedtls_src} -G ${CMAKE_GENERATOR} -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_ARCHIVE_OUTPUT_DIRECTORY=${PROJECT_ARCHIVE_OUTPUT_DIRECTORY} -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=${PROJECT_LIBRARY_OUTPUT_DIRECTORY} -DCMAKE_INSTALL_PREFIX=${PROJECT_BINARY_DIR} -DENABLE_PROGRAMS=OFF -DENABLE_TESTING=OFF -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_CONFIGURATION_TYPES=RELEASE ${TOOLCHAIN_PARAM}
BUILD_COMMAND ${BUILD_CMD_MBED}
INSTALL_COMMAND ""
TEST_COMMAND "")

ExternalProject_Add(IXWebSocket_build
SOURCE_DIR ${IXWebSocket_src}
BINARY_DIR ${PROJECT_BINARY_DIR}/externals/IXWebSocket
CONFIGURE_COMMAND cmake ${IXWebSocket_src} -G ${CMAKE_GENERATOR} -DUSE_TLS=ON -DUSE_MBED_TLS=ON -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_CONFIGURATION_TYPES=RELEASE -DMBEDTLS_INCLUDE_DIRS=${mbedtls_src}/include -DMBEDCRYPTO_LIBRARY=${MBEDCRYPTO_LIBRARY} -DMBEDTLS_LIBRARY=${MBEDTLS_LIBRARY} -DMBEDX509_LIBRARY=${MBEDX509_LIBRARY} -DMBEDTLS_LIBRARIES=${MBEDTLS_LIBRARIES} -DCMAKE_ARCHIVE_OUTPUT_DIRECTORY=${PROJECT_ARCHIVE_OUTPUT_DIRECTORY} -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=${PROJECT_LIBRARY_OUTPUT_DIRECTORY} -DCMAKE_INSTALL_PREFIX=${PROJECT_BINARY_DIR} -DUSE_ZLIB=OFF
CONFIGURE_COMMAND ${CMAKE_COMMAND} ${IXWebSocket_src} -G ${CMAKE_GENERATOR} -DZLIB_ROOT=${ZLIB_ROOT} -DUSE_TLS=ON -DUSE_MBED_TLS=ON -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_CONFIGURATION_TYPES=RELEASE -DMBEDTLS_INCLUDE_DIRS=${mbedtls_src}/include -DMBEDCRYPTO_LIBRARY=${MBEDCRYPTO_LIBRARY} -DMBEDTLS_LIBRARY=${MBEDTLS_LIBRARY} -DMBEDX509_LIBRARY=${MBEDX509_LIBRARY} -DMBEDTLS_LIBRARIES=${MBEDTLS_LIBRARIES} -DCMAKE_ARCHIVE_OUTPUT_DIRECTORY=${PROJECT_ARCHIVE_OUTPUT_DIRECTORY} -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=${PROJECT_LIBRARY_OUTPUT_DIRECTORY} -DCMAKE_INSTALL_PREFIX=${PROJECT_BINARY_DIR} ${TOOLCHAIN_PARAM}
BUILD_COMMAND ${BUILD_CMD_WEBSOCKET}
INSTALL_COMMAND ""
TEST_COMMAND ""
DEPENDS mbedtls_build)
DEPENDS mbedtls_build
DEPENDS zlib_copy)

# There is an issue on arm processors for opus (https://github.com/xiph/opus/issues/203)
if(CMAKE_SYSTEM_PROCESSOR MATCHES "(arm|aarch64)")
set(OPUS_DISABLE_INTRINSICS ON CACHE BOOL "")
endif()

add_subdirectory(${PROJECT_SOURCE_DIR}/externals/opus EXCLUDE_FROM_ALL)

set(SRCS "")

if(NOT WIN32)
set(PTHREAD pthread)
set(ADDITIONAL_LIBS pthread)
set(LINK_DIRS "${PROJECT_BINARY_DIR}/src/libsodium/.libs/")

if (NOT ZLIB_FOUND)
find_package(ZLIB)
endif()

if (ZLIB_FOUND)
set(ZLIB_LIB "z")
else()
set(ZLIB_LIB "${CMAKE_STATIC_LIBRARY_PREFIX}z${CMAKE_STATIC_LIBRARY_SUFFIX}")
endif()

set(ZLIB_LIB "${ZLIB_ROOT}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}z${CMAKE_STATIC_LIBRARY_SUFFIX}")

ExternalProject_Add(libsodium_build
SOURCE_DIR ${libsodium_src}
BINARY_DIR ${PROJECT_BINARY_DIR}
PATCH_COMMAND "${libsodium_src}/autogen.sh"
CONFIGURE_COMMAND "${libsodium_src}/configure" "--disable-pie" "--with-pic=\"yes\""
BUILD_COMMAND "make"
INSTALL_COMMAND cp -TR "${PROJECT_BINARY_DIR}/src/libsodium/include/" "${libsodium_src}/src/libsodium/include/"
TEST_COMMAND "")
ExternalProject_Add(libsodium_build
SOURCE_DIR ${libsodium_src}
BINARY_DIR ${PROJECT_BINARY_DIR}
PATCH_COMMAND "${libsodium_src}/autogen.sh"
CONFIGURE_COMMAND ${EXTERNAL_ENV} "${libsodium_src}/configure" "--disable-pie" --with-pic="yes" ${EXTERNAL_HOST_PARAM}
BUILD_COMMAND ${EXTERNAL_ENV} "make"
INSTALL_COMMAND cp -TR "${PROJECT_BINARY_DIR}/src/libsodium/include/" "${libsodium_src}/src/libsodium/include/"
TEST_COMMAND "")
else(NOT WIN32)
if(MSVC)
set(LINK_DIRS ${LINK_DIRS} "${PROJECT_BINARY_DIR}")
set(ZLIB_LIB "zlibstatic${CMAKE_STATIC_LIBRARY_SUFFIX}")
set(ZLIB_LIB "zlibstatic${CMAKE_STATIC_LIBRARY_SUFFIX}")
set(ADDITIONAL_LIBS "crypt32")

ExternalProject_Add(libsodium_build
SOURCE_DIR ${libsodium_src}
Expand All @@ -102,6 +138,10 @@ else(NOT WIN32)
INSTALL_COMMAND ""
TEST_COMMAND "")
endif(MSVC)

configure_file("${PROJECT_SOURCE_DIR}/version.rc.in" version.rc @ONLY)
set(SRCS "${CMAKE_CURRENT_BINARY_DIR}/version.rc")

endif(NOT WIN32)

message(${PROJECT_VERSION})
Expand All @@ -121,16 +161,20 @@ link_directories(${PROJECT_BINARY_DIR}
${LINK_DIRS})

set(SRCS
${SRCS}
"${PROJECT_SOURCE_DIR}/src/controller/DiscordClient.cpp"
"${PROJECT_SOURCE_DIR}/src/controller/VoiceSocket.cpp"
"${PROJECT_SOURCE_DIR}/src/controller/ICommand.cpp"
"${PROJECT_SOURCE_DIR}/src/controller/IController.cpp"
"${PROJECT_SOURCE_DIR}/src/controller/IMusicQueue.cpp"
"${PROJECT_SOURCE_DIR}/src/controller/JSONCmdsConfig.cpp"
"${PROJECT_SOURCE_DIR}/src/controller/GuildAdmin.cpp"
"${PROJECT_SOURCE_DIR}/src/commands/RightsCommand.cpp"
"${PROJECT_SOURCE_DIR}/src/commands/HelpCommand.cpp")
"${PROJECT_SOURCE_DIR}/src/commands/HelpCommand.cpp"
"${PROJECT_SOURCE_DIR}/src/commands/PrefixCommand.cpp")

add_library(${PROJECT_NAME} SHARED ${SRCS})

add_dependencies(${PROJECT_NAME} IXWebSocket_build)
add_dependencies(${PROJECT_NAME} libsodium_build)

Expand All @@ -149,4 +193,4 @@ install(TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME}
)

set_target_properties(${PROJECT_NAME} PROPERTIES SOVERSION ${PROJECT_VERSION}${VERSION_SUFFIX})
target_link_libraries(${PROJECT_NAME} libsodium${CMAKE_STATIC_LIBRARY_SUFFIX} ixwebsocket ${CMAKE_STATIC_LIBRARY_PREFIX}mbedtls${CMAKE_STATIC_LIBRARY_SUFFIX} ${CMAKE_STATIC_LIBRARY_PREFIX}mbedcrypto${CMAKE_STATIC_LIBRARY_SUFFIX} ${CMAKE_STATIC_LIBRARY_PREFIX}mbedx509${CMAKE_STATIC_LIBRARY_SUFFIX} ${ZLIB_LIB} opus ${PTHREAD})
target_link_libraries(${PROJECT_NAME} libsodium${CMAKE_STATIC_LIBRARY_SUFFIX} ixwebsocket ${CMAKE_STATIC_LIBRARY_PREFIX}mbedtls${CMAKE_STATIC_LIBRARY_SUFFIX} ${CMAKE_STATIC_LIBRARY_PREFIX}mbedcrypto${CMAKE_STATIC_LIBRARY_SUFFIX} ${CMAKE_STATIC_LIBRARY_PREFIX}mbedx509${CMAKE_STATIC_LIBRARY_SUFFIX} zlibstatic opus ${ADDITIONAL_LIBS})
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ First of all, thank you for your interest in this project. However, before addin
- For any kind of bugs please open an bug report first.
- For any kind of wiki things like typos or improvements open a wiki improvement.
- Before you add a feature please open a feature request.
- I've you add a feature or for bug fixes please check if your code runs. If you add any platform specific calls like WinAPI, you must notice this inside the pull request.
- If you add a feature or for bug fixes please check if your code runs. If you add any platform specific calls like WinAPI, you must notice this inside the pull request.
- Any issue should detailed as possible, so that I can understand what you mean.
17 changes: 17 additions & 0 deletions README.MD
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Read me

You are currently on the development branch of the libDiscordBot library. Keep in mind that you can encounter bugs/errors, the API isn't at this point fixed and/or the project might not build.

# libDiscordBot
libDiscordBot is an easy-to-use C++ library which helps you to create quickly a Discord bot. It's inspired by [Discord.Net](https://github.com/discord-net/Discord.Net) for C#.

Expand Down Expand Up @@ -56,6 +60,19 @@ For Windows open the *.sln file inside the build directory

3. Copy and rename the project_template directory somewhere to get starting. Follow the introduction inside the README.MD of the template.

## Crosscompiling

To crosscompile the library there are toolchain files inside the crosscompile folder.
How to use

1. Do the same steps (1 - 2) as describe above except the `cmake ../` step.
2. The current way to set the root of your compiler toolchain is currently sadly to insert the path inside the `crosscompile/TOOLCHAINFILE.cmake` file as ROOT_PATH.
4. Call cmake with the following parameters.
```
cmake ../ -DCMAKE_TOOLCHAIN_FILE=../crosscompile/TOOLCHAINFILE.cmake
```
5. You can now compile your programm.

### First bot

Please visit the [wiki page](https://github.com/tostc/libDiscordBot/wiki/Your-first-bot).
Expand Down
18 changes: 18 additions & 0 deletions crosscompile/rpi.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
SET(CMAKE_SYSTEM_NAME Linux)
SET(CMAKE_SYSTEM_VERSION 1)

unset(CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES)
unset(CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES)

set(ROOT_PATH "") # Path to the root of the tools. Tested with https://github.com/abhiTronix/raspberry-pi-cross-compilers
set(HOST_NAME "arm-linux-gnueabihf") # For Autoconf

SET(CMAKE_C_COMPILER ${ROOT_PATH}/bin/${HOST_NAME}-gcc)
SET(CMAKE_CXX_COMPILER ${ROOT_PATH}/bin/${HOST_NAME}-g++)

SET(CMAKE_FIND_ROOT_PATH ${ROOT_PATH})
set(CMAKE_BUILD_WITH_INSTALL_RPATH ON)

set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH)
Loading

0 comments on commit 408a1fe

Please sign in to comment.