Skip to content

Commit 5d21527

Browse files
committed
Rewrote c++20 module support
1 parent 403a0ce commit 5d21527

File tree

352 files changed

+2373
-2122
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

352 files changed

+2373
-2122
lines changed

CMakeLists.txt

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ else() # Use c++14 by default on all other compilers
8181
set(TGUI_DEFAULT_CXX_STANDARD "14")
8282
endif()
8383

84-
tgui_set_option(TGUI_CXX_STANDARD ${TGUI_DEFAULT_CXX_STANDARD} STRING "C++ standard version to build TGUI with. Possible values: 14, 17, 20 or 23. Projects using TGUI must use a c++ version equal or higher to this")
84+
set(TGUI_CXX_STANDARD_docstring "C++ standard version to build TGUI with. Possible values: 14, 17, 20 or 23. Projects using TGUI must use a c++ version equal or higher to this")
85+
tgui_set_option(TGUI_CXX_STANDARD ${TGUI_DEFAULT_CXX_STANDARD} STRING ${TGUI_CXX_STANDARD_docstring})
8586

8687
# At least c++14 has to be used
8788
if(TGUI_CXX_STANDARD LESS "14")
@@ -160,14 +161,20 @@ string(TOUPPER "${TGUI_BACKEND}" TGUI_BACKEND_UPPERCASE)
160161
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.28)
161162
# We currently don't create the option as it is still too experimental,
162163
# it can still be used if the user manually specifies the option though.
163-
#option(TGUI_BUILD_AS_CXX_MODULE "ON to build TGUI as a c++20 module instead of using header files" OFF)
164-
#mark_as_advanced(TGUI_BUILD_AS_CXX_MODULE)
165-
if(TGUI_BUILD_AS_CXX_MODULE)
164+
if (DEFINED TGUI_BUILD_AS_CXX_MODULE)
165+
message(WARNING "Warning: TGUI_BUILD_AS_CXX_MODULE was renamed to TGUI_BUILD_CXX20_MODULE")
166+
option(TGUI_BUILD_CXX20_MODULE "ON to build TGUI as a c++20 module that can be used as alternative to using header files" ${TGUI_BUILD_AS_CXX_MODULE})
167+
else()
168+
option(TGUI_BUILD_CXX20_MODULE "ON to build TGUI as a c++20 module that can be used as alternative to using header files" OFF)
169+
endif()
170+
mark_as_advanced(TGUI_BUILD_CXX20_MODULE)
171+
if(TGUI_BUILD_CXX20_MODULE)
166172
if(TGUI_CXX_STANDARD LESS 20)
167-
message(FATAL_ERROR "TGUI_BUILD_AS_CXX_MODULE can only be turned on if TGUI_CXX_STANDARD is set to at least 20")
173+
message(WARNING "Warning: TGUI_CXX_STANDARD has been changed because the value was too low to use TGUI_BUILD_CXX20_MODULE")
174+
set(TGUI_CXX_STANDARD 20 CACHE STRING ${TGUI_CXX_STANDARD_docstring} FORCE)
168175
endif()
169176
if(TGUI_OS_WINDOWS AND TGUI_SHARED_LIBS)
170-
message(FATAL_ERROR "On Windows, BUILD_SHARED_LIBS must be OFF if TGUI_BUILD_AS_CXX_MODULE is ON")
177+
message(FATAL_ERROR "On Windows, BUILD_SHARED_LIBS must be OFF if TGUI_BUILD_CXX20_MODULE is ON")
171178
endif()
172179
endif()
173180
endif()
@@ -353,10 +360,6 @@ endif()
353360
if(NOT TGUI_OS_ANDROID)
354361
option(TGUI_BUILD_EXAMPLES "TRUE to build the TGUI examples, FALSE to ignore them" FALSE)
355362
if(TGUI_BUILD_EXAMPLES)
356-
if(TGUI_BUILD_AS_CXX_MODULE)
357-
message(FATAL_ERROR "Examples don't support c++20 modules. Turn off either TGUI_BUILD_AS_CXX_MODULE or TGUI_BUILD_EXAMPLES.")
358-
endif()
359-
360363
add_subdirectory(examples)
361364
endif()
362365
endif()

cmake/Macros.cmake

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ function(tgui_set_global_compile_flags target)
8585
endif()
8686
endif()
8787

88-
if (NOT TGUI_BUILD_AS_CXX_MODULE)
88+
if (NOT TGUI_BUILD_CXX20_MODULE)
8989
# We turn GNU extensions off to make sure that our code doesn't rely on them.
9090
# This isn't done when building TGUI as a module though. At least when using Clang 18, doing so required that the set_target_properties
9191
# function is also called on the user's target to avoid the "GNU extensions was enabled in PCH file but is currently disabled" error.
@@ -176,21 +176,3 @@ function(copy_dlls_to_exe post_build_destination install_destination target)
176176
endforeach()
177177
endif()
178178
endfunction()
179-
180-
# Bundles a set of source files into a c++20 module
181-
function(tgui_create_module_from_sources source_file_list module_name)
182-
file(READ "TGUI-Module.cppm.in" file_contents)
183-
string(APPEND file_contents "\nexport module ${module_name};\n")
184-
string(APPEND file_contents "\nexport import tgui;\n")
185-
if(${ARGC} GREATER 2)
186-
foreach(extra_module_to_export ${ARGN})
187-
string(APPEND file_contents "export import ${extra_module_to_export};\n")
188-
endforeach()
189-
endif()
190-
string(APPEND file_contents "\n")
191-
foreach(source_file ${source_file_list})
192-
string(APPEND file_contents "#include \"${CMAKE_CURRENT_SOURCE_DIR}/${source_file}\"\n")
193-
endforeach()
194-
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/module_${module_name}.cppm" "${file_contents}")
195-
set(module_source "${CMAKE_CURRENT_BINARY_DIR}/module_${module_name}.cppm" PARENT_SCOPE)
196-
endfunction()

doc/doxyfile.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ MACRO_EXPANSION = YES
7070
EXPAND_ONLY_PREDEF = YES
7171
PREDEFINED = TGUI_DEPRECATED(x)= \
7272
TGUI_COMPILED_WITH_CPP_VER=23 \
73-
TGUI_BUILD_AS_CXX_MODULE=0 \
73+
TGUI_BUILD_CXX20_MODULE=0 \
7474
TGUI_HAS_WINDOW_BACKEND_SFML=1 \
7575
TGUI_HAS_WINDOW_BACKEND_SDL=1 \
7676
TGUI_HAS_WINDOW_BACKEND_GLFW=1 \

examples/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ macro(tgui_add_example target)
4545
target_link_libraries(${target} PRIVATE tgui tgui-gui-app-interface)
4646
tgui_set_global_compile_flags(${target})
4747
tgui_set_stdlib(${target})
48+
49+
if (TGUI_BUILD_CXX20_MODULE)
50+
target_compile_definitions(${target} PRIVATE TGUI_BUILD_CXX20_MODULE)
51+
endif()
52+
if (DEFINED TGUI_USE_SDL3)
53+
target_compile_definitions(${target} PRIVATE TGUI_USE_SDL3)
54+
endif()
4855
endmacro()
4956

5057
# Build the examples

examples/main-GLFW_GLES2.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,21 @@
2222
//
2323
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2424

25-
#include <TGUI/TGUI.hpp>
26-
#include <TGUI/Backend/GLFW-GLES2.hpp>
27-
28-
// Optional: include OpenGL ES functions via TGUI (which you can call AFTER creating the Gui object)
29-
// This will include a built-in GLAD header that defines all functions that exist in GLES 3.2 (and OpenGL 4.6)
30-
//#include <TGUI/Backend/Renderer/OpenGL.hpp>
31-
3225
#define GLFW_INCLUDE_NONE // Don't let GLFW include an OpenGL extention loader
3326
#include <GLFW/glfw3.h>
3427

28+
#if TGUI_BUILD_CXX20_MODULE
29+
import tgui;
30+
import tgui.backend.glfw_gles2;
31+
#else
32+
#include <TGUI/TGUI.hpp>
33+
#include <TGUI/Backend/GLFW-GLES2.hpp>
34+
35+
// Optional: include OpenGL ES functions via TGUI (which you can call AFTER creating the Gui object)
36+
// This will include a built-in GLAD header that defines all functions that exist in GLES 3.2 (and OpenGL 4.6)
37+
//#include <TGUI/Backend/Renderer/OpenGL.hpp>
38+
#endif
39+
3540
bool runExample(tgui::BackendGui& gui);
3641

3742
// We don't put this code in main() to make sure that all TGUI resources are destroyed before destroying GLFW

examples/main-GLFW_OPENGL3.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,21 @@
2222
//
2323
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2424

25-
#include <TGUI/TGUI.hpp>
26-
#include <TGUI/Backend/GLFW-OpenGL3.hpp>
27-
28-
// Optional: include (modern) OpenGL functions via TGUI (which you can call AFTER creating the Gui object)
29-
// This will include a built-in GLAD header that defines all functions that exist in OpenGL 4.6 (and GLES 3.2)
30-
//#include <TGUI/Backend/Renderer/OpenGL.hpp>
31-
3225
#define GLFW_INCLUDE_NONE // Don't let GLFW include an OpenGL extention loader
3326
#include <GLFW/glfw3.h>
3427

28+
#if TGUI_BUILD_CXX20_MODULE
29+
import tgui;
30+
import tgui.backend.glfw_opengl3;
31+
#else
32+
#include <TGUI/TGUI.hpp>
33+
#include <TGUI/Backend/GLFW-OpenGL3.hpp>
34+
35+
// Optional: include (modern) OpenGL functions via TGUI (which you can call AFTER creating the Gui object)
36+
// This will include a built-in GLAD header that defines all functions that exist in OpenGL 4.6 (and GLES 3.2)
37+
//#include <TGUI/Backend/Renderer/OpenGL.hpp>
38+
#endif
39+
3540
bool runExample(tgui::BackendGui& gui);
3641

3742
// We don't put this code in main() to make sure that all TGUI resources are destroyed before destroying GLFW

examples/main-RAYLIB.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,14 @@
2222
//
2323
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2424

25-
#include <TGUI/TGUI.hpp>
26-
#include <TGUI/Backend/raylib.hpp>
25+
#if TGUI_BUILD_CXX20_MODULE
26+
#include <raylib.h>
27+
import tgui;
28+
import tgui.backend.raylib;
29+
#else
30+
#include <TGUI/TGUI.hpp>
31+
#include <TGUI/Backend/raylib.hpp>
32+
#endif
2733

2834
bool runExample(tgui::BackendGui& gui);
2935

examples/main-SDL_GLES2.cpp

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,25 @@
2222
//
2323
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2424

25-
#include <TGUI/TGUI.hpp>
26-
#include <TGUI/Backend/SDL-GLES2.hpp>
27-
28-
#if SDL_MAJOR_VERSION >= 3
29-
#include <SDL3/SDL_main.h>
30-
#include <SDL3/SDL_opengles2.h>
25+
#if TGUI_BUILD_CXX20_MODULE
26+
#include <TGUI/extlibs/IncludeSDL.hpp>
27+
#if SDL_MAJOR_VERSION >= 3
28+
#include <SDL3/SDL_main.h>
29+
#include <SDL3/SDL_opengles2.h>
30+
#else
31+
#include <SDL_opengles2.h>
32+
#endif
33+
import tgui;
34+
import tgui.backend.sdl_gles2;
3135
#else
32-
#include <SDL_opengles2.h>
36+
#include <TGUI/TGUI.hpp>
37+
#include <TGUI/Backend/SDL-GLES2.hpp>
38+
#if TGUI_USE_SDL3
39+
#include <SDL3/SDL_main.h>
40+
#include <SDL3/SDL_opengles2.h>
41+
#else
42+
#include <SDL_opengles2.h>
43+
#endif
3344
#endif
3445

3546
bool runExample(tgui::BackendGui& gui);
@@ -69,7 +80,11 @@ int main(int, char **)
6980
run_application(window);
7081

7182
// Note that all TGUI resources must be destroyed before SDL is cleaned up
83+
#if SDL_MAJOR_VERSION >= 3
84+
SDL_GL_DestroyContext(glContext);
85+
#else
7286
SDL_GL_DeleteContext(glContext);
87+
#endif
7388
SDL_DestroyWindow(window);
7489
SDL_Quit();
7590
return 0;

examples/main-SDL_GPU.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,22 @@
2222
//
2323
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2424

25-
#include <TGUI/TGUI.hpp>
26-
#include <TGUI/Backend/SDL-GPU.hpp>
2725
#include <SDL3/SDL_main.h>
2826

27+
#if TGUI_BUILD_CXX20_MODULE
28+
#include <TGUI/extlibs/IncludeSDL.hpp>
29+
#if SDL_MAJOR_VERSION >= 3
30+
#include <SDL3_ttf/SDL_ttf.h>
31+
#else
32+
#include <SDL_ttf.h>
33+
#endif
34+
import tgui;
35+
import tgui.backend.sdl_gpu;
36+
#else
37+
#include <TGUI/TGUI.hpp>
38+
#include <TGUI/Backend/SDL-GPU.hpp>
39+
#endif
40+
2941
bool runExample(tgui::BackendGui& gui);
3042

3143
// We don't put this code in main() to make sure that all TGUI resources are destroyed before destroying SDL

examples/main-SDL_OPENGL3.cpp

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,25 @@
2222
//
2323
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2424

25-
#include <TGUI/TGUI.hpp>
26-
#include <TGUI/Backend/SDL-OpenGL3.hpp>
27-
28-
#if SDL_MAJOR_VERSION >= 3
29-
#include <SDL3/SDL_main.h>
30-
#include <SDL3/SDL_opengl.h>
25+
#if TGUI_BUILD_CXX20_MODULE
26+
#include <TGUI/extlibs/IncludeSDL.hpp>
27+
#if SDL_MAJOR_VERSION >= 3
28+
#include <SDL3/SDL_main.h>
29+
#include <SDL3/SDL_opengl.h>
30+
#else
31+
#include <SDL_opengl.h>
32+
#endif
33+
import tgui;
34+
import tgui.backend.sdl_opengl3;
3135
#else
32-
#include <SDL_opengl.h>
36+
#include <TGUI/TGUI.hpp>
37+
#include <TGUI/Backend/SDL-OpenGL3.hpp>
38+
#if TGUI_USE_SDL3
39+
#include <SDL3/SDL_main.h>
40+
#include <SDL3/SDL_opengl.h>
41+
#else
42+
#include <SDL_opengl.h>
43+
#endif
3344
#endif
3445

3546
bool runExample(tgui::BackendGui& gui);
@@ -69,7 +80,11 @@ int main(int, char **)
6980
run_application(window);
7081

7182
// Note that all TGUI resources must be destroyed before SDL is cleaned up
83+
#if SDL_MAJOR_VERSION >= 3
84+
SDL_GL_DestroyContext(glContext);
85+
#else
7286
SDL_GL_DeleteContext(glContext);
87+
#endif
7388
SDL_DestroyWindow(window);
7489
SDL_Quit();
7590
return 0;

0 commit comments

Comments
 (0)