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

docs: added more info to the buildcmake page. Merged cmake.md with #820. #872

Merged
merged 5 commits into from
Sep 21, 2023
Merged
Changes from 4 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
79 changes: 46 additions & 33 deletions docpages/make_a_bot/cmake.md
Original file line number Diff line number Diff line change
@@ -1,74 +1,87 @@
\page buildcmake Building a Discord Bot using CMake/UNIX
\page buildcmake Building a Discord Bot Using CMake (UNIX)

## 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
Before compiling, you will need to install `cmake` on your system. To be sure that `cmake` is installed, you can type the following command:

```bash
$ cmake --version
cmake version 3.22.1
```

## 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`
```puml
Jaskowicz1 marked this conversation as resolved.
Show resolved Hide resolved
- your_project/
|-- build/
|-- libs/
|-- src/
|-- main.cpp
|-- CMakeLists.txt
```

Now, you'll want to clone D++ in the `libs/` directory. You can clone D++ with: `git clone https://github.com/brainboxdotcc/DPP.git`.

Once that's done, your project directory should look like this:

```puml
- your_project/
|-- build/
|-- libs/
|-- DPP/
|-- src/
|-- main.cpp
|-- CMakeLists.txt
```

## 3. Configure CMake

Here is an example CMake configuration, adapt it according to your needs:
You'll need to modify the `CMakeLists.txt` to tell CMake what it's looking for, and other information.

~~~~~~~~~~~~~~{.cmake}
Here is an example CMake configuration, you can adapt it according to your needs:

~~~~~~~~~~~~~~cmake
# 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")
project(discord-bot VERSION 1.0 DESCRIPTION "A Discord bot")

# Add DPP as dependency
add_subdirectory(libs/DPP)
Jaskowicz1 marked this conversation as resolved.
Show resolved Hide resolved
# You can also add any other libs you want to use

# Create an executable
add_executable(${PROJECT_NAME}
src/main.cpp
# your other files...
src/main.cpp
# your other files...
)

# Linking libraries
target_link_libraries(${PROJECT_NAME}
dpp
# Add any other libs you want to use here
dpp
# Add any other libs you want to use here
)

# Specify includes
target_include_directories(${PROJECT_NAME} PRIVATE
libs/DPP/include
# Remember to add the include directories of any other libraries too
libs/DPP/include
# Remember to add the include directories of any other libraries too
)

# Set C++ version
set_target_properties(${PROJECT_NAME} PROPERTIES
CXX_STANDARD 17
CXX_STANDARD_REQUIRED ON
CXX_STANDARD 17
CXX_STANDARD_REQUIRED ON
)
~~~~~~~~~~~~~~

Your project directory should look like this:
## 4. Build the bot.

- your_project/
|-- libs/
|-- DPP
|-- src/
|-- main.cpp
|-- CMakeLists.txt
Now that we have our CMakeLists.txt setup and the D++ library downloaded, we can go ahead and get CMake ready to build (As long as you've added code to your `main.cpp` file inside `src/`!). You'll want to go inside the `build/` directory and do `cmake ..`. Once that's completed, you'll want to head back to your up-most folder (where all the folders are for your bot).

Now, you can do `cmake --build build/ -j4` (replace -j4 with however many threads you want to use) and let your bot build!

**Have fun!**
Once that's complete, you can head into `build/` and run your bot by doing `./discord-bot`!

**Have fun!**