Skip to content

Commit bda0199

Browse files
Add modules unit test
1 parent b14691c commit bda0199

39 files changed

+282
-121
lines changed

.github/workflows/test-docs-examples.yml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ permissions:
1818
jobs:
1919
test_docs_examples:
2020
name: Test build examples
21-
runs-on: ubuntu-22.04
21+
runs-on: ubuntu-24.04
2222
concurrency:
2323
group: ${{ github.workflow }}-${{ github.ref }}
2424
cancel-in-progress: true
@@ -35,17 +35,19 @@ jobs:
3535
submodules: recursive
3636

3737
- name: Install apt packages
38-
run: sudo sed -i 's/azure\.//' /etc/apt/sources.list && sudo apt-get update && sudo apt-get install -y g++-12 libopus-dev zlib1g-dev libmpg123-dev liboggz-dev cmake libfmt-dev libopusfile-dev
38+
run: sudo sed -i 's/azure\.//' /etc/apt/sources.list && sudo apt-get update && sudo apt-get install -y clang-20 libopus-dev ninja-build zlib1g-dev libmpg123-dev liboggz-dev cmake libfmt-dev libopusfile-dev
3939

4040
- name: Generate CMake
41-
run: mkdir build && cd build && cmake -DDPP_NO_VCPKG=ON -DAVX_TYPE=T_fallback -DDPP_CORO=ON -DCMAKE_BUILD_TYPE=Debug ..
41+
run: mkdir build && cd build && cmake -G Ninja -DDPP_NO_VCPKG=ON -DDPP_MODULES=ON -DAVX_TYPE=T_fallback -DDPP_CORO=ON -DCMAKE_BUILD_TYPE=Debug ..
4242
env:
43-
CXX: g++-12
43+
CXX: clang++-20
4444

4545
- name: Build Project
46-
run: cd build && make -j2 && sudo make install
46+
run: cd build && cmake --build . -j2 && sudo ninja install
47+
env:
48+
CXX: clang++-20
4749

4850
- name: Test compile examples
49-
run: cd docpages/example_code && mkdir build && cd build && cmake .. && make -j2
51+
run: cd docpages/example_code && mkdir build && cd build && cmake -G Ninja -DDPP_MODULES=ON .. && cmake --build . -j2
5052
env:
51-
CXX: g++-12
53+
CXX: clang++-20

CMakeLists.txt

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ option(DPP_USE_EXTERNAL_JSON "Use an external installation of nlohmann::json" OF
3333
option(DPP_USE_PCH "Use precompiled headers to speed up compilation" OFF)
3434
option(AVX_TYPE "Force AVX type for speeding up audio mixing" OFF)
3535
option(DPP_TEST_VCPKG "Force VCPKG build without VCPKG installed (for development use only!)" OFF)
36-
option(DPP_MODULES "Support for C++20 modules" OFF)
36+
option(DPP_MODULES "Support for C++20 modules (experimental)" OFF)
3737

3838
include(CheckCXXSymbolExists)
3939
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
@@ -161,38 +161,3 @@ if (NOT WIN32)
161161
target_link_libraries(dpp PRIVATE std::filesystem)
162162
endif()
163163

164-
if (DPP_MODULES)
165-
message("-- C++20 Modules support: ${Green}ENABLED${ColourReset}")
166-
add_library(dpp_module)
167-
168-
target_sources(dpp_module
169-
PUBLIC
170-
FILE_SET CXX_MODULES
171-
FILES "${CMAKE_CURRENT_SOURCE_DIR}/include/dpp/dpp.cppm"
172-
)
173-
174-
target_compile_features(dpp_module PUBLIC cxx_std_20)
175-
176-
target_include_directories(dpp_module PUBLIC
177-
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
178-
$<INSTALL_INTERFACE:include>
179-
)
180-
181-
target_link_libraries(dpp_module PUBLIC dpp)
182-
183-
add_library(dpp::module ALIAS dpp_module)
184-
185-
# Installation
186-
install(TARGETS dpp_module
187-
EXPORT ${PROJECT_NAME}Targets
188-
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
189-
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
190-
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
191-
FILE_SET CXX_MODULES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/dpp/include
192-
)
193-
194-
target_compile_definitions(dpp PUBLIC DPP_MODULES)
195-
else()
196-
message("-- C++20 Modules support: ${Red}DISABLED${ColourReset} (enable with -DDPP_MODULES=ON)")
197-
endif()
198-

cmake/CPackSetup.cmake

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,40 @@ set(DPP_INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}/${DPP_VERSIONED})
1111

1212
## Pack the binary output
1313
if (WIN32)
14-
install(TARGETS dpp
15-
EXPORT ${DPP_EXPORT_NAME}
16-
LIBRARY DESTINATION ${DPP_INSTALL_LIBRARY_DIR}
17-
ARCHIVE DESTINATION ${DPP_INSTALL_LIBRARY_DIR}
18-
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
19-
INCLUDES DESTINATION ${DPP_INSTALL_INCLUDE_DIR})
14+
if (DPP_MODULES)
15+
install(TARGETS dpp
16+
EXPORT ${DPP_EXPORT_NAME}
17+
LIBRARY DESTINATION ${DPP_INSTALL_LIBRARY_DIR}
18+
ARCHIVE DESTINATION ${DPP_INSTALL_LIBRARY_DIR}
19+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
20+
INCLUDES DESTINATION ${DPP_INSTALL_INCLUDE_DIR}
21+
FILE_SET CXX_MODULES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/dpp/include)
22+
else()
23+
install(TARGETS dpp
24+
EXPORT ${DPP_EXPORT_NAME}
25+
LIBRARY DESTINATION ${DPP_INSTALL_LIBRARY_DIR}
26+
ARCHIVE DESTINATION ${DPP_INSTALL_LIBRARY_DIR}
27+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
28+
INCLUDES DESTINATION ${DPP_INSTALL_INCLUDE_DIR})
29+
endif()
2030
install(DIRECTORY "${DPP_ROOT_PATH}/include/" DESTINATION "${DPP_INSTALL_INCLUDE_DIR}")
2131
else()
22-
install(TARGETS dpp
23-
EXPORT ${DPP_EXPORT_NAME}
24-
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBRARY_DIR}
25-
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBRARY_DIR}
26-
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
27-
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDE_DIR})
32+
if (DPP_MODULES)
33+
install(TARGETS dpp
34+
EXPORT ${DPP_EXPORT_NAME}
35+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBRARY_DIR}
36+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBRARY_DIR}
37+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
38+
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDE_DIR}
39+
FILE_SET CXX_MODULES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/dpp/include)
40+
else()
41+
install(TARGETS dpp
42+
EXPORT ${DPP_EXPORT_NAME}
43+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBRARY_DIR}
44+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBRARY_DIR}
45+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
46+
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDE_DIR})
47+
endif()
2848
endif()
2949

3050
## Allow for a specific version to be chosen in the `find_package` command

docpages/example_code/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ project(documentation_tests)
3333

3434
string(ASCII 27 Esc)
3535

36-
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DDPP_CORO -DPP_MODULES -std=c++20 -pthread -O0 -fPIC -rdynamic -DFMT_HEADER_ONLY -Wall -Wextra -Wpedantic -Werror -Wno-unused-parameter -Wno-deprecated-declarations")
36+
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DDPP_CORO -DDPP_MODULES -std=c++20 -pthread -O0 -fPIC -DFMT_HEADER_ONLY -Wall -Wextra -Wpedantic -Werror -Wno-unused-parameter -Wno-deprecated-declarations")
3737
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0")
3838

3939
file(GLOB example_list ./*.cpp)

docpages/example_code/attachments1.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ int main() {
66
bot.on_log(dpp::utility::cout_logger());
77

88
/* The event is fired when someone issues your commands */
9-
bot.on_slashcommand([&bot](const dpp::slashcommand_t& event) {
9+
bot.on_slashcommand([](const dpp::slashcommand_t& event) {
1010
/* Check which command they ran */
1111
if (event.command.get_command_name() == "file") {
1212
dpp::message msg(event.command.channel_id, "Hey there, I've got a new file!");

docpages/example_code/attachments3.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ int main() {
66
bot.on_log(dpp::utility::cout_logger());
77

88
/* The event is fired when someone issues your commands */
9-
bot.on_slashcommand([&bot](const dpp::slashcommand_t& event) {
9+
bot.on_slashcommand([](const dpp::slashcommand_t& event) {
1010
/* Check which command they ran */
1111
if (event.command.get_command_name() == "file") {
1212
/* Create a message. */

docpages/example_code/autocomplete.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ int main()
2323
});
2424

2525
/* The interaction create event is fired when someone issues your commands */
26-
bot.on_slashcommand([&bot](const dpp::slashcommand_t & event) {
26+
bot.on_slashcommand([](const dpp::slashcommand_t & event) {
2727

2828
/* Check which command they ran */
2929
if (event.command.get_command_name() == "blep") {

docpages/example_code/cache_messages.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ int main() {
2323
});
2424

2525
/* The event is fired when someone issues your commands */
26-
bot.on_slashcommand([&bot, &message_cache](const dpp::slashcommand_t& event) {
26+
bot.on_slashcommand([&message_cache](const dpp::slashcommand_t& event) {
2727
/* Check which command they ran */
2828
if (event.command.get_command_name() == "get") {
2929

docpages/example_code/components.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ int main() {
77
bot.on_log(dpp::utility::cout_logger());
88

99
/* The event is fired when someone issues your commands */
10-
bot.on_slashcommand([&bot](const dpp::slashcommand_t& event) {
10+
bot.on_slashcommand([](const dpp::slashcommand_t& event) {
1111
/* Check which command they ran */
1212
if (event.command.get_command_name() == "button") {
1313
/* Create a message */
@@ -33,7 +33,7 @@ int main() {
3333
/* When a user clicks your button, the on_button_click event will fire,
3434
* containing the custom_id you defined in your button.
3535
*/
36-
bot.on_button_click([&bot](const dpp::button_click_t& event) {
36+
bot.on_button_click([](const dpp::button_click_t& event) {
3737
/* Button clicks are still interactions, and must be replied to in some form to
3838
* prevent the "this interaction has failed" message from Discord to the user.
3939
*/

docpages/example_code/components2.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ int main() {
66
bot.on_log(dpp::utility::cout_logger());
77

88
/* The event is fired when someone issues your commands */
9-
bot.on_slashcommand([&bot](const dpp::slashcommand_t& event) {
9+
bot.on_slashcommand([](const dpp::slashcommand_t& event) {
1010
/* Check which command they ran */
1111
if (event.command.get_command_name() == "math") {
1212

@@ -40,7 +40,7 @@ int main() {
4040
}
4141
});
4242

43-
bot.on_button_click([&bot](const dpp::button_click_t & event) {
43+
bot.on_button_click([](const dpp::button_click_t & event) {
4444
if (event.custom_id == "10") {
4545
event.reply(dpp::message("You got it right!").set_flags(dpp::m_ephemeral));
4646
} else {

0 commit comments

Comments
 (0)