Building with CMake
1. Toolchain
Before compiling, you will need to install cmake
on your system. To be sure that cmake
is installed, you can type the following command:
$ cmake --version
cmake version 3.20.4
2. Create a CMake project
In an empty directory, create the following files and directories:
- your_project/
|-- libs/
|-- src/
|-- main.cpp
|-- CMakeLists.txt
In the libs/
directory, clone D++ with: git clone https://github.com/brainboxdotcc/DPP.git
3. Configure CMake
Here is an example CMake configuration, adapt it according to your needs:
# minimum CMake version required
cmake_minimum_required(VERSION 3.15)
# Project name, version and description
project(discord-bot VERSION 1.0 DESCRIPTION "A discord bot")
# Add DPP as dependency
add_subdirectory(libs/DPP)
add_subdirectory(libs/spdlog) # if you need a logger. Don't forget to clone sources
# in the `libs/` directory
# Create an executable
add_executable(${PROJECT_NAME}
src/main.cpp
# your others files...
)
# Linking libraries
target_link_libraries(${PROJECT_NAME}
dpp
spdlog # Like before, if you need spdlog
)
# Specify includes
target_include_directories(${PROJECT_NAME} PRIVATE
libs/DPP/include
libs/spdlog/include # Like before, if you need spdlog
)
# Set C++ version
set_target_properties(${PROJECT_NAME} PROPERTIES
CXX_STANDARD 17 # or 20 if you want something more recent
CXX_STANDARD_REQUIRED ON
)
Your project directory should look like this:
- your_project/
|-- libs/
|-- DPP
|-- spdlog # again, only if you need it
|-- src/
|-- main.cpp
|-- CMakeLists.txt
Have fun!