From 6199eca4e4997b8589b4e9d84175fc6de7c15afb Mon Sep 17 00:00:00 2001 From: Jaskowicz1 Date: Wed, 20 Sep 2023 12:26:17 +0100 Subject: [PATCH 1/5] docs: added more info to cmake.md --- docpages/make_a_bot/cmake.md | 74 +++++++++++++++++++++--------------- 1 file changed, 43 insertions(+), 31 deletions(-) diff --git a/docpages/make_a_bot/cmake.md b/docpages/make_a_bot/cmake.md index 127fd44824..cb07fc9eb1 100644 --- a/docpages/make_a_bot/cmake.md +++ b/docpages/make_a_bot/cmake.md @@ -1,35 +1,49 @@ -\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 +- 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: -~~~~~~~~~~~~~~{.cmake} +~~~~~~~~~~~~~~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) @@ -37,38 +51,36 @@ add_subdirectory(libs/DPP) # 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. + +Now that we have all our CMake config setup and the D++ library downloaded, we can go ahead and get CMake ready to build. 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). - - your_project/ - |-- libs/ - |-- DPP - |-- src/ - |-- main.cpp - |-- CMakeLists.txt +Now, you can do `cmake --build build/ -j4` (replace -j4 with however many threads you want to use) and let your bot build! +Once that's complete, you can head into `build/` and run your bot by doing `./discord-bot`! **Have fun!** From d329f4e402744200332d443218c5a96e66653cba Mon Sep 17 00:00:00 2001 From: Jaskowicz1 Date: Wed, 20 Sep 2023 12:43:32 +0100 Subject: [PATCH 2/5] docs: altered wording, removed an extra end-line. Merged changes with #820. Co-authored-by: Jakub 'Eremiell' Marek --- docpages/make_a_bot/cmake.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docpages/make_a_bot/cmake.md b/docpages/make_a_bot/cmake.md index cb07fc9eb1..aecadede02 100644 --- a/docpages/make_a_bot/cmake.md +++ b/docpages/make_a_bot/cmake.md @@ -76,11 +76,10 @@ set_target_properties(${PROJECT_NAME} PROPERTIES ## 4. Build the bot. -Now that we have all our CMake config setup and the D++ library downloaded, we can go ahead and get CMake ready to build. 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 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! Once that's complete, you can head into `build/` and run your bot by doing `./discord-bot`! **Have fun!** - From 347d762aa414097683081a2b1890ede6fcd67c62 Mon Sep 17 00:00:00 2001 From: Jaskowicz1 Date: Wed, 20 Sep 2023 12:48:58 +0100 Subject: [PATCH 3/5] docs: reworded section 3 in cmake.md --- docpages/make_a_bot/cmake.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docpages/make_a_bot/cmake.md b/docpages/make_a_bot/cmake.md index aecadede02..0acda52168 100644 --- a/docpages/make_a_bot/cmake.md +++ b/docpages/make_a_bot/cmake.md @@ -37,7 +37,9 @@ Once that's done, your project directory should look like this: ## 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. + +Here is an example CMake configuration, you can adapt it according to your needs: ~~~~~~~~~~~~~~cmake # minimum CMake version required From 3e6abb0a17509d616d4afb9a2799f1085bb28353 Mon Sep 17 00:00:00 2001 From: Jaskowicz1 Date: Wed, 20 Sep 2023 12:50:04 +0100 Subject: [PATCH 4/5] docs: added missing punctuation. --- docpages/make_a_bot/cmake.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docpages/make_a_bot/cmake.md b/docpages/make_a_bot/cmake.md index 0acda52168..3f00e463c7 100644 --- a/docpages/make_a_bot/cmake.md +++ b/docpages/make_a_bot/cmake.md @@ -37,7 +37,7 @@ Once that's done, your project directory should look like this: ## 3. Configure CMake -You'll need to modify the `CMakeLists.txt` to tell CMake what it's looking for and other information. +You'll need to modify the `CMakeLists.txt` to tell CMake what it's looking for, and other information. Here is an example CMake configuration, you can adapt it according to your needs: From abca9314e27d3a07bee4b3a0ab2eac841dc2cc64 Mon Sep 17 00:00:00 2001 From: Jaskowicz1 Date: Thu, 21 Sep 2023 16:40:23 +0100 Subject: [PATCH 5/5] docs: added improvements to buildcmake as suggested. --- docpages/make_a_bot/cmake.md | 122 +++++++++++++++++++++++------------ 1 file changed, 82 insertions(+), 40 deletions(-) diff --git a/docpages/make_a_bot/cmake.md b/docpages/make_a_bot/cmake.md index 3f00e463c7..ca215d66a2 100644 --- a/docpages/make_a_bot/cmake.md +++ b/docpages/make_a_bot/cmake.md @@ -1,39 +1,69 @@ \page buildcmake Building a Discord Bot Using CMake (UNIX) +\warning **This tutorial will assume that you have already installed DPP.** If you haven't, please head over to \ref install-linux-deb "this page", or any install page that matches your OS. If you want to use source, then continue your journey over at \ref buildlinux "this page" for a full explanation into using CMake with source. + ## 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: +Before continuing, 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 ``` +If your CMake version is not as shown above then don't worry! You can still follow along, even if you're ahead or behind! + ## 2. Create a CMake project In an empty directory, create the following files and directories: -```puml -- 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 -``` +\dot +digraph "Example Directory" { + graph [ranksep=1]; + node [colorscheme="blues9", fontname="helvetica"]; + + "Your Directory" [style=filled, color=1, shape=rect] + + subgraph cluster_0 { + style=filled; + color=lightgrey; + node [style=filled, color=2, shape=rect] + build; + cmake; + src; + "CMakeLists.txt"; + label = "The main area for your bot's files."; + } + + subgraph cluster_1 { + style=filled; + color=lightgrey; + node [style=filled, color=3, shape=rect] + "FindDPP.cmake"; + label = "This file is to tell CMake where DPP is."; + } + + subgraph cluster_2 { + style=filled; + color=lightgrey; + node [style=filled, color=3, shape=rect] + "main.cpp"; + "main.h"; + "more code..."; + label = "This is where your bot's code will go."; + } + + "Your Directory" -> build; + "Your Directory" -> src; + "Your Directory" -> cmake; + "Your Directory" -> "CMakeLists.txt"; + + cmake -> "FindDPP.cmake"; + + src -> "main.cpp"; + src -> "main.h"; + src -> "more code..."; +} +\enddot ## 3. Configure CMake @@ -42,31 +72,29 @@ You'll need to modify the `CMakeLists.txt` to tell CMake what it's looking for, 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) +# Minimum CMake version required, we'll just use the latest version. +cmake_minimum_required(VERSION 3.22) # 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) -# You can also add any other libs you want to use +list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) # Create an executable add_executable(${PROJECT_NAME} src/main.cpp - # your other files... ) -# Linking libraries -target_link_libraries(${PROJECT_NAME} - dpp - # Add any other libs you want to use here +# Find our pre-installed DPP package (using FindDPP.cmake). +find_package(DPP REQUIRED) + +# Link the pre-installed DPP package. +target_link_libraries(${PROJECT_NAME} + ${DPP_LIBRARIES} ) -# Specify includes +# Include the DPP directories. target_include_directories(${PROJECT_NAME} PRIVATE - libs/DPP/include - # Remember to add the include directories of any other libraries too + ${DPP_INCLUDE_DIR} ) # Set C++ version @@ -76,12 +104,26 @@ set_target_properties(${PROJECT_NAME} PROPERTIES ) ~~~~~~~~~~~~~~ +We'll also need to populate our `FindDPP.cmake` file, inside the `cmake` directory! + +Here's what you should use: + +~~~~~~~~~~~~~~cmake +find_path(DPP_INCLUDE_DIR NAMES dpp/dpp.h HINTS ${DPP_ROOT_DIR}) + +find_library(DPP_LIBRARIES NAMES dpp "libdpp.a" HINTS ${DPP_ROOT_DIR}) + +include(FindPackageHandleStandardArgs) + +find_package_handle_standard_args(DPP DEFAULT_MSG DPP_LIBRARIES DPP_INCLUDE_DIR) +~~~~~~~~~~~~~~ + ## 4. Build the bot. -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 that we have our all our cmake stuff setup and we've got our code in place, we can initalise CMake. You'll want to go inside the `build/` directory and do `cmake ..`. -Now, you can do `cmake --build build/ -j4` (replace -j4 with however many threads you want to use) and let your bot build! +Once that's completed, you'll want to head back to your up-most folder (where all the folders are for your bot) and run `cmake --build build/ -j4` (replace -j4 with however many threads you want to use). This will start compiling your bot and creating the executable. -Once that's complete, you can head into `build/` and run your bot by doing `./discord-bot`! +After that has finished, you can head into `build/` and run your bot by doing `./discord-bot`! If everything went well, you should see your bot come online! **Have fun!**