2023-07-16 11:38:17 -06:00
#
# CMake script for building the SDL tests
#
2023-10-10 12:36:58 -06:00
2023-08-02 08:03:32 -06:00
list ( APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/../cmake" )
include ( CheckIncludeFile )
2023-10-10 12:36:58 -06:00
include ( CheckStructHasMember )
2023-08-02 08:03:32 -06:00
include ( CMakePushCheckState )
include ( sdlcompilers )
2023-10-10 12:36:58 -06:00
2022-11-30 15:40:34 -07:00
if ( SDL_TESTS_LINK_SHARED )
2023-02-16 15:30:20 -07:00
set ( sdl_name_component SDL3-shared )
2022-01-03 10:41:21 -07:00
else ( )
2022-11-30 15:40:34 -07:00
set ( sdl_name_component SDL3-static )
2022-01-03 10:41:21 -07:00
endif ( )
2023-02-27 20:20:30 -07:00
set ( HAVE_TESTS_LINK_SHARED "${SDL_TESTS_LINK_SHARED}" PARENT_SCOPE )
2023-03-21 11:16:45 -06:00
2021-10-31 18:11:09 -06:00
# CMake incorrectly detects opengl32.lib being present on MSVC ARM64
2023-07-16 11:38:17 -06:00
if ( NOT ( MSVC AND SDL_CPU_ARM64 ) )
2022-06-14 21:36:28 -06:00
# Prefer GLVND, if present
set ( OpenGL_GL_PREFERENCE GLVND )
2021-10-31 18:11:09 -06:00
find_package ( OpenGL )
endif ( )
2021-03-04 08:28:10 -07:00
2023-04-19 08:28:39 -06:00
if ( WINDOWS_STORE )
cmake_minimum_required ( VERSION 3.19 )
# CMP0112: Target file component generator expressions do not add target dependencies.
cmake_policy ( SET CMP0112 NEW )
endif ( )
2022-11-30 15:40:34 -07:00
set ( SDL_TEST_EXECUTABLES )
2023-02-27 20:20:30 -07:00
add_library ( sdltests_utils OBJECT
2022-11-30 15:40:34 -07:00
t e s t u t i l s . c
)
2023-02-27 20:20:30 -07:00
target_link_libraries ( sdltests_utils PRIVATE SDL3::Headers )
2022-11-30 15:40:34 -07:00
file ( GLOB RESOURCE_FILES *.bmp *.wav *.hex moose.dat utf8.txt )
2023-11-28 10:49:01 -07:00
if ( CMAKE_RUNTIME_OUTPUT_DIRECTORY )
set ( test_bin_dir "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}" )
if ( NOT IS_ABSOLUTE "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}" )
set ( test_bin_dir "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_RUNTIME_OUTPUT_DIRECTORY}" )
endif ( )
else ( )
set ( test_bin_dir "${CMAKE_CURRENT_BINARY_DIR}" )
endif ( )
if ( NOT CMAKE_VERSION VERSION_LESS 3.20 )
get_property ( is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG )
set ( test_bin_dir "${test_bin_dir}$<$<BOOL:${is_multi_config}>:/$<CONFIG>>" )
endif ( )
2023-02-24 21:06:44 -07:00
set ( RESOURCE_FILE_NAMES )
2023-11-28 10:49:01 -07:00
set ( RESOURCE_FILES_BINDIR )
foreach ( resource_file IN LISTS RESOURCE_FILES )
get_filename_component ( res_file_name ${ resource_file } NAME )
2023-02-24 21:06:44 -07:00
list ( APPEND RESOURCE_FILE_NAMES "${res_file_name}" )
2023-11-28 10:49:01 -07:00
set ( resource_file_bindir "${test_bin_dir}/${res_file_name}" )
add_custom_command ( OUTPUT "${resource_file_bindir}"
C O M M A N D " $ { C M A K E _ C O M M A N D } " - E c o p y " $ { r e s o u r c e _ f i l e } " " $ { r e s o u r c e _ f i l e _ b i n d i r } "
D E P E N D S " $ { r e s o u r c e _ f i l e } "
)
list ( APPEND RESOURCE_FILES_BINDIR "${resource_file_bindir}" )
2023-02-24 21:06:44 -07:00
endforeach ( )
2023-11-28 10:49:01 -07:00
add_custom_target ( copy-sdl-test-resources
D E P E N D S " $ { R E S O U R C E _ F I L E S _ B I N D I R } "
)
2022-11-30 15:40:34 -07:00
2023-03-17 12:23:56 -06:00
define_property ( TARGET PROPERTY SDL_NONINTERACTIVE BRIEF_DOCS "If true, target is a non-interactive test executable." FULL_DOCS "If true, target is a noninteractive test executable." )
define_property ( TARGET PROPERTY SDL_NONINTERACTIVE_ARGUMENTS BRIEF_DOCS "Argument(s) to run executable in non-interactive mode." FULL_DOCS "Argument(s) to run executable in non-interactive mode." )
define_property ( TARGET PROPERTY SDL_NONINTERACTIVE_TIMEOUT BRIEF_DOCS "Timeout for noninteractive executable." FULL_DOCS "Timeout for noninteractive executable." )
2023-04-19 08:28:39 -06:00
if ( WINDOWS_STORE )
add_library ( sdl_test_main_uwp OBJECT main.cpp )
target_link_libraries ( sdl_test_main_uwp PRIVATE SDL3::Headers )
target_compile_options ( sdl_test_main_uwp PRIVATE "/ZW" )
main: Added _optional_ callback entry points.
This lets apps optionally have a handful of callbacks for their entry points instead of a single main function. If used, the actual main/SDL_main/whatever entry point will be implemented in the single-header library SDL_main.h and the app will implement four separate functions:
First:
int SDL_AppInit(int argc, char **argv);
This will be called once before anything else. argc/argv work like they always do. If this returns 0, the app runs. If it returns < 0, the app calls SDL_AppQuit and terminates with an exit code that reports an error to the platform. If it returns > 0, the app calls SDL_AppQuit and terminates with an exit code that reports success to the platform. This function should not go into an infinite mainloop; it should do any one-time startup it requires and then return.
Then:
int SDL_AppIterate(void);
This is called over and over, possibly at the refresh rate of the display or some other metric that the platform dictates. This is where the heart of your app runs. It should return as quickly as reasonably possible, but it's not a "run one memcpy and that's all the time you have" sort of thing. The app should do any game updates, and render a frame of video. If it returns < 0, SDL will call SDL_AppQuit and terminate the process with an exit code that reports an error to the platform. If it returns > 0, the app calls SDL_AppQuit and terminates with an exit code that reports success to the platform. If it returns 0, then SDL_AppIterate will be called again at some regular frequency. The platform may choose to run this more or less (perhaps less in the background, etc), or it might just call this function in a loop as fast as possible. You do not check the event queue in this function (SDL_AppEvent exists for that).
Next:
int SDL_AppEvent(const SDL_Event *event);
This will be called once for each event pushed into the SDL queue. This may be called from any thread, and possibly in parallel to SDL_AppIterate. The fields in event do not need to be free'd (as you would normally need to do for SDL_EVENT_DROP_FILE, etc), and your app should not call SDL_PollEvent, SDL_PumpEvent, etc, as SDL will manage this for you. Return values are the same as from SDL_AppIterate(), so you can terminate in response to SDL_EVENT_QUIT, etc.
Finally:
void SDL_AppQuit(void);
This is called once before terminating the app--assuming the app isn't being forcibly killed or crashed--as a last chance to clean up. After this returns, SDL will call SDL_Quit so the app doesn't have to (but it's safe for the app to call it, too). Process termination proceeds as if the app returned normally from main(), so atexit handles will run, if your platform supports that.
The app does not implement SDL_main if using this. To turn this on, define SDL_MAIN_USE_CALLBACKS before including SDL_main.h. Defines like SDL_MAIN_HANDLED and SDL_MAIN_NOIMPL are also respected for callbacks, if the app wants to do some sort of magic main implementation thing.
In theory, on most platforms these can be implemented in the app itself, but this saves some #ifdefs in the app and lets everyone struggle less against some platforms, and might be more efficient in the long run, too.
On some platforms, it's possible this is the only reasonable way to go, but we haven't actually hit one that 100% requires it yet (but we will, if we want to write a RetroArch backend, for example).
Using the callback entry points works on every platform, because on platforms that don't require them, we can fake them with a simple loop in an internal implementation of the usual SDL_main.
The primary way we expect people to write SDL apps is with SDL_main, and this is not intended to replace it. If the app chooses to use this, it just removes some platform-specific details they might have to otherwise manage, and maybe removes a barrier to entry on some future platform.
Fixes #6785.
Reference PR #8247.
2023-11-01 16:40:41 -06:00
add_library ( sdl_test_main_callbacks_uwp OBJECT main.cpp )
target_link_libraries ( sdl_test_main_callbacks_uwp PRIVATE SDL3::Headers )
target_compile_options ( sdl_test_main_callbacks_uwp PRIVATE "/ZW" )
target_compile_definitions ( sdl_test_main_callbacks_uwp PRIVATE "SDL_MAIN_USE_CALLBACKS" )
2023-04-19 08:28:39 -06:00
set_source_files_properties ( ${ RESOURCE_FILES } PROPERTIES VS_DEPLOYENT_LOCATION "Assets" )
endif ( )
2022-11-30 15:40:34 -07:00
macro ( add_sdl_test_executable TARGET )
main: Added _optional_ callback entry points.
This lets apps optionally have a handful of callbacks for their entry points instead of a single main function. If used, the actual main/SDL_main/whatever entry point will be implemented in the single-header library SDL_main.h and the app will implement four separate functions:
First:
int SDL_AppInit(int argc, char **argv);
This will be called once before anything else. argc/argv work like they always do. If this returns 0, the app runs. If it returns < 0, the app calls SDL_AppQuit and terminates with an exit code that reports an error to the platform. If it returns > 0, the app calls SDL_AppQuit and terminates with an exit code that reports success to the platform. This function should not go into an infinite mainloop; it should do any one-time startup it requires and then return.
Then:
int SDL_AppIterate(void);
This is called over and over, possibly at the refresh rate of the display or some other metric that the platform dictates. This is where the heart of your app runs. It should return as quickly as reasonably possible, but it's not a "run one memcpy and that's all the time you have" sort of thing. The app should do any game updates, and render a frame of video. If it returns < 0, SDL will call SDL_AppQuit and terminate the process with an exit code that reports an error to the platform. If it returns > 0, the app calls SDL_AppQuit and terminates with an exit code that reports success to the platform. If it returns 0, then SDL_AppIterate will be called again at some regular frequency. The platform may choose to run this more or less (perhaps less in the background, etc), or it might just call this function in a loop as fast as possible. You do not check the event queue in this function (SDL_AppEvent exists for that).
Next:
int SDL_AppEvent(const SDL_Event *event);
This will be called once for each event pushed into the SDL queue. This may be called from any thread, and possibly in parallel to SDL_AppIterate. The fields in event do not need to be free'd (as you would normally need to do for SDL_EVENT_DROP_FILE, etc), and your app should not call SDL_PollEvent, SDL_PumpEvent, etc, as SDL will manage this for you. Return values are the same as from SDL_AppIterate(), so you can terminate in response to SDL_EVENT_QUIT, etc.
Finally:
void SDL_AppQuit(void);
This is called once before terminating the app--assuming the app isn't being forcibly killed or crashed--as a last chance to clean up. After this returns, SDL will call SDL_Quit so the app doesn't have to (but it's safe for the app to call it, too). Process termination proceeds as if the app returned normally from main(), so atexit handles will run, if your platform supports that.
The app does not implement SDL_main if using this. To turn this on, define SDL_MAIN_USE_CALLBACKS before including SDL_main.h. Defines like SDL_MAIN_HANDLED and SDL_MAIN_NOIMPL are also respected for callbacks, if the app wants to do some sort of magic main implementation thing.
In theory, on most platforms these can be implemented in the app itself, but this saves some #ifdefs in the app and lets everyone struggle less against some platforms, and might be more efficient in the long run, too.
On some platforms, it's possible this is the only reasonable way to go, but we haven't actually hit one that 100% requires it yet (but we will, if we want to write a RetroArch backend, for example).
Using the callback entry points works on every platform, because on platforms that don't require them, we can fake them with a simple loop in an internal implementation of the usual SDL_main.
The primary way we expect people to write SDL apps is with SDL_main, and this is not intended to replace it. If the app chooses to use this, it just removes some platform-specific details they might have to otherwise manage, and maybe removes a barrier to entry on some future platform.
Fixes #6785.
Reference PR #8247.
2023-11-01 16:40:41 -06:00
cmake_parse_arguments ( AST "BUILD_DEPENDENT;NONINTERACTIVE;NEEDS_RESOURCES;TESTUTILS;NO_C90;MAIN_CALLBACKS" "" "NONINTERACTIVE_TIMEOUT;NONINTERACTIVE_ARGS;SOURCES" ${ ARGN } )
2023-03-17 12:23:56 -06:00
if ( AST_UNPARSED_ARGUMENTS )
message ( FATAL_ERROR "Unknown argument(s): ${AST_UNPARSED_ARGUMENTS}" )
endif ( )
if ( NOT AST_SOURCES )
message ( FATAL_ERROR "add_sdl_test_executable needs at least one source" )
endif ( )
2023-02-27 20:20:30 -07:00
if ( AST_TESTUTILS )
list ( APPEND AST_SOURCES $< TARGET_OBJECTS:sdltests_utils > )
endif ( )
2023-04-19 08:28:39 -06:00
set ( EXTRA_SOURCES "" )
if ( WINDOWS_STORE )
set ( uwp_bindir "${CMAKE_CURRENT_BINARY_DIR}/${TARGET}.dir" )
if ( NOT IS_DIRECTORY "${uwp_bindir}" )
execute_process ( COMMAND "${CMAKE_COMMAND}" -E make_directory "${uwp_bindir}" )
endif ( )
string ( REGEX REPLACE "[_]" "" SAFE_TARGET "${TARGET}" )
file ( GENERATE OUTPUT "${uwp_bindir}/${TARGET}.appxmanifest"
I N P U T " $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / u w p / P a c k a g e . a p p x m a n i f e s t . i n "
T A R G E T " $ { T A R G E T } "
)
set_property ( SOURCE "${uwp_bindir}/${TARGET}.appxmanifest" PROPERTY VS_DEPLOYMENT_CONTENT 1 )
main: Added _optional_ callback entry points.
This lets apps optionally have a handful of callbacks for their entry points instead of a single main function. If used, the actual main/SDL_main/whatever entry point will be implemented in the single-header library SDL_main.h and the app will implement four separate functions:
First:
int SDL_AppInit(int argc, char **argv);
This will be called once before anything else. argc/argv work like they always do. If this returns 0, the app runs. If it returns < 0, the app calls SDL_AppQuit and terminates with an exit code that reports an error to the platform. If it returns > 0, the app calls SDL_AppQuit and terminates with an exit code that reports success to the platform. This function should not go into an infinite mainloop; it should do any one-time startup it requires and then return.
Then:
int SDL_AppIterate(void);
This is called over and over, possibly at the refresh rate of the display or some other metric that the platform dictates. This is where the heart of your app runs. It should return as quickly as reasonably possible, but it's not a "run one memcpy and that's all the time you have" sort of thing. The app should do any game updates, and render a frame of video. If it returns < 0, SDL will call SDL_AppQuit and terminate the process with an exit code that reports an error to the platform. If it returns > 0, the app calls SDL_AppQuit and terminates with an exit code that reports success to the platform. If it returns 0, then SDL_AppIterate will be called again at some regular frequency. The platform may choose to run this more or less (perhaps less in the background, etc), or it might just call this function in a loop as fast as possible. You do not check the event queue in this function (SDL_AppEvent exists for that).
Next:
int SDL_AppEvent(const SDL_Event *event);
This will be called once for each event pushed into the SDL queue. This may be called from any thread, and possibly in parallel to SDL_AppIterate. The fields in event do not need to be free'd (as you would normally need to do for SDL_EVENT_DROP_FILE, etc), and your app should not call SDL_PollEvent, SDL_PumpEvent, etc, as SDL will manage this for you. Return values are the same as from SDL_AppIterate(), so you can terminate in response to SDL_EVENT_QUIT, etc.
Finally:
void SDL_AppQuit(void);
This is called once before terminating the app--assuming the app isn't being forcibly killed or crashed--as a last chance to clean up. After this returns, SDL will call SDL_Quit so the app doesn't have to (but it's safe for the app to call it, too). Process termination proceeds as if the app returned normally from main(), so atexit handles will run, if your platform supports that.
The app does not implement SDL_main if using this. To turn this on, define SDL_MAIN_USE_CALLBACKS before including SDL_main.h. Defines like SDL_MAIN_HANDLED and SDL_MAIN_NOIMPL are also respected for callbacks, if the app wants to do some sort of magic main implementation thing.
In theory, on most platforms these can be implemented in the app itself, but this saves some #ifdefs in the app and lets everyone struggle less against some platforms, and might be more efficient in the long run, too.
On some platforms, it's possible this is the only reasonable way to go, but we haven't actually hit one that 100% requires it yet (but we will, if we want to write a RetroArch backend, for example).
Using the callback entry points works on every platform, because on platforms that don't require them, we can fake them with a simple loop in an internal implementation of the usual SDL_main.
The primary way we expect people to write SDL apps is with SDL_main, and this is not intended to replace it. If the app chooses to use this, it just removes some platform-specific details they might have to otherwise manage, and maybe removes a barrier to entry on some future platform.
Fixes #6785.
Reference PR #8247.
2023-11-01 16:40:41 -06:00
if ( AST_MAIN_CALLBACKS )
list ( APPEND EXTRA_SOURCES "$<TARGET_OBJECTS:sdl_test_main_callbacks_uwp>" )
else ( )
list ( APPEND EXTRA_SOURCES "$<TARGET_OBJECTS:sdl_test_main_uwp>" )
endif ( )
2023-04-19 08:28:39 -06:00
list ( APPEND EXTRA_SOURCES
" $ { u w p _ b i n d i r } / $ { T A R G E T } . a p p x m a n i f e s t "
" u w p / l o g o - 5 0 x 5 0 . p n g "
" u w p / s q u a r e - 4 4 x 4 4 . p n g "
" u w p / s q u a r e - 1 5 0 x 1 5 0 . p n g "
" u w p / s p l a s h - 6 2 0 x 3 0 0 . p n g "
)
endif ( )
2022-11-30 15:40:34 -07:00
if ( AST_NEEDS_RESOURCES )
2023-04-19 08:28:39 -06:00
list ( APPEND EXTRA_SOURCES ${ RESOURCE_FILES } )
2022-11-30 15:40:34 -07:00
endif ( )
2023-03-27 16:38:07 -06:00
if ( ANDROID )
2023-04-19 08:28:39 -06:00
add_library ( ${ TARGET } SHARED ${ AST_SOURCES } ${ EXTRA_SOURCES } )
2023-03-27 16:38:07 -06:00
else ( )
2023-04-19 08:28:39 -06:00
add_executable ( ${ TARGET } ${ AST_SOURCES } ${ EXTRA_SOURCES } )
2023-03-27 16:38:07 -06:00
endif ( )
2023-02-27 20:20:30 -07:00
SDL_AddCommonCompilerFlags ( ${ TARGET } )
2022-12-12 15:27:42 -07:00
target_link_libraries ( ${ TARGET } PRIVATE SDL3::SDL3_test SDL3:: ${ sdl_name_component } )
2023-05-24 17:15:12 -06:00
if ( NOT AST_NO_C90 AND NOT SDL_CMAKE_PLATFORM MATCHES "^(n3ds|ps2|psp)$" )
set_property ( TARGET ${ TARGET } PROPERTY C_STANDARD 90 )
set_property ( TARGET ${ TARGET } PROPERTY C_EXTENSIONS FALSE )
endif ( )
2022-11-30 15:40:34 -07:00
list ( APPEND SDL_TEST_EXECUTABLES ${ TARGET } )
if ( AST_NONINTERACTIVE )
2023-03-17 12:23:56 -06:00
set_property ( TARGET ${ TARGET } PROPERTY SDL_NONINTERACTIVE 1 )
endif ( )
if ( AST_NONINTERACTIVE_ARGS )
set_property ( TARGET ${ TARGET } PROPERTY SDL_NONINTERACTIVE_ARGUMENTS "${AST_NONINTERACTIVE_ARGS}" )
endif ( )
if ( AST_NONINTERACTIVE_TIMEOUT )
set_property ( TARGET ${ TARGET } PROPERTY SDL_NONINTERACTIVE_TIMEOUT "${AST_NONINTERACTIVE_TIMEOUT}" )
2022-11-30 15:40:34 -07:00
endif ( )
if ( AST_NEEDS_RESOURCES )
if ( PSP OR PS2 )
add_custom_command ( TARGET ${ TARGET } POST_BUILD
C O M M A N D $ { C M A K E _ C O M M A N D } A R G S - E m a k e _ d i r e c t o r y $ < T A R G E T _ F I L E _ D I R : $ { T A R G E T } > / s d l - $ { T A R G E T }
C O M M A N D $ { C M A K E _ C O M M A N D } A R G S - E c o p y _ i f _ d i f f e r e n t $ { R E S O U R C E _ F I L E S } $ < T A R G E T _ F I L E _ D I R : $ { T A R G E T } > / s d l - $ { T A R G E T } )
2023-04-19 08:28:39 -06:00
elseif ( WINDOWS_STORE )
# MSVC does build the dependent targets (or POST_BUILD commands) when building an application
# after starting to debug. By copying the resources in a custom target, the files can be copied afterwards.
# FIXME: find out proper way to add assets to UWP package
cmake_minimum_required ( VERSION 3.19 )
add_custom_target ( zzz-resources-copy- ${ TARGET }
C O M M A N D $ { C M A K E _ C O M M A N D } - E m a k e _ d i r e c t o r y " $ < T A R G E T _ F I L E _ D I R : $ { T A R G E T } > / A p p X "
C O M M A N D $ { C M A K E _ C O M M A N D } - E c o p y _ i f _ d i f f e r e n t $ { R E S O U R C E _ F I L E S } " $ < T A R G E T _ F I L E _ D I R : $ { T A R G E T } > / A p p X "
)
add_dependencies ( ${ TARGET } zzz-resources-copy- ${ TARGET } )
2022-11-30 15:40:34 -07:00
else ( )
2023-11-28 10:49:01 -07:00
add_dependencies ( ${ TARGET } copy-sdl-test-resources )
2022-11-30 15:40:34 -07:00
endif ( )
if ( APPLE )
# Make sure resource files get installed into macOS/iOS .app bundles.
set_target_properties ( ${ TARGET } PROPERTIES RESOURCE "${RESOURCE_FILES}" )
endif ( )
2023-06-03 07:22:39 -06:00
if ( EMSCRIPTEN )
foreach ( res IN LISTS RESOURCE_FILES )
get_filename_component ( res_name "${res}" NAME )
target_link_options ( ${ TARGET } PRIVATE "SHELL:--embed-file ${res}@${res_name}" )
endforeach ( )
endif ( )
2023-02-24 21:06:44 -07:00
set_property ( TARGET ${ TARGET } APPEND PROPERTY ADDITIONAL_CLEAN_FILES "$<TARGET_FILE_DIR:${TARGET}>/$<JOIN:${RESOURCE_FILE_NAMES},$<SEMICOLON>$<TARGET_FILE_DIR:${TARGET}>/>" )
2022-11-30 15:40:34 -07:00
endif ( )
2023-07-16 11:38:17 -06:00
if ( AST_BUILD_DEPENDENT )
2023-02-27 20:20:30 -07:00
target_include_directories ( ${ TARGET } BEFORE PRIVATE $< TARGET_PROPERTY:SDL3::${sdl_name_component},INCLUDE_DIRECTORIES > )
2023-07-16 11:38:17 -06:00
target_include_directories ( ${ TARGET } BEFORE PRIVATE ${ SDL3_SOURCE_DIR } /src )
endif ( )
2022-11-30 15:40:34 -07:00
if ( WINDOWS )
# CET support was added in VS 16.7
if ( MSVC_VERSION GREATER 1926 AND CMAKE_GENERATOR_PLATFORM MATCHES "Win32|x64" )
set_property ( TARGET ${ TARGET } APPEND_STRING PROPERTY LINK_FLAGS " -CETCOMPAT" )
endif ( )
elseif ( PSP )
target_link_libraries ( ${ TARGET } PRIVATE GL )
endif ( )
2023-04-19 08:28:39 -06:00
if ( WINDOWS_STORE )
target_compile_definitions ( ${ TARGET } PRIVATE "SDL_MAIN_NOIMPL" )
set_property ( TARGET ${ TARGET } PROPERTY WIN32_EXECUTABLE TRUE )
set_property ( TARGET ${ TARGET } PROPERTY RUNTIME_OUTPUT_DIRECTORY "${uwp_bindir}" )
target_link_options ( ${ TARGET } PRIVATE
- n o d e f a u l t l i b : v c c o r l i b $ < $ < C O N F I G : D e b u g > : d >
- n o d e f a u l t l i b : m s v c r t $ < $ < C O N F I G : D e b u g > : d >
v c c o r l i b $ < $ < C O N F I G : D e b u g > : d > . l i b
m s v c r t $ < $ < C O N F I G : D e b u g > : d > . l i b
)
endif ( )
2022-11-30 15:40:34 -07:00
2023-06-03 07:22:39 -06:00
if ( EMSCRIPTEN )
set_property ( TARGET ${ TARGET } PROPERTY SUFFIX ".html" )
endif ( )
2022-11-30 15:40:34 -07:00
if ( OPENGL_FOUND )
target_compile_definitions ( ${ TARGET } PRIVATE HAVE_OPENGL )
endif ( )
2023-01-07 08:15:28 -07:00
2023-02-27 20:20:30 -07:00
# FIXME: only add "${SDL3_BINARY_DIR}/include-config-$<LOWER_CASE:$<CONFIG>>" + include paths of external dependencies
2023-07-16 11:38:17 -06:00
target_include_directories ( ${ TARGET } PRIVATE "$<TARGET_PROPERTY:SDL3::${sdl_name_component},INCLUDE_DIRECTORIES>" )
2022-11-30 15:40:34 -07:00
endmacro ( )
2022-11-26 02:41:46 -07:00
check_include_file ( signal.h HAVE_SIGNAL_H )
2022-11-30 15:40:34 -07:00
if ( HAVE_SIGNAL_H )
2022-11-26 02:41:46 -07:00
add_definitions ( -DHAVE_SIGNAL_H )
endif ( )
check_include_file ( libudev.h HAVE_LIBUDEV_H )
2022-11-30 15:40:34 -07:00
if ( HAVE_LIBUDEV_H )
2022-11-26 02:41:46 -07:00
add_definitions ( -DHAVE_LIBUDEV_H )
2021-03-04 08:28:10 -07:00
endif ( )
2023-10-12 15:08:46 -06:00
set ( FFmpeg_FIND_COMPONENTS AVCODEC AVFORMAT AVUTIL SWSCALE )
2023-08-02 08:03:32 -06:00
include ( "${CMAKE_CURRENT_LIST_DIR}/../cmake/FindFFmpeg.cmake" )
2023-10-10 12:36:58 -06:00
if ( FFmpeg_FOUND )
cmake_push_check_state ( )
list ( APPEND CMAKE_REQUIRED_INCLUDES "${FFmpeg_AVUTIL_INCLUDE_DIRS}" )
2024-03-02 11:05:38 -07:00
list ( APPEND CMAKE_REQUIRED_INCLUDES "${SDL3_SOURCE_DIR}/src/video/khronos" )
2023-10-10 12:36:58 -06:00
check_struct_has_member ( "AVFrame" "ch_layout" "libavutil/frame.h" LIBAVUTIL_AVFRAME_HAS_CH_LAYOUT )
2024-03-02 11:05:38 -07:00
check_struct_has_member ( "AVVulkanFramesContext" "format" "libavutil/hwcontext_vulkan.h" LIBAVUTIL_AVFULKANFRAMESCONTEXT_HAS_FORMAT )
2023-10-10 12:36:58 -06:00
cmake_pop_check_state ( )
endif ( )
2024-03-08 17:26:19 -07:00
if ( FFmpeg_FOUND AND LIBAVUTIL_AVFRAME_HAS_CH_LAYOUT )
2024-03-02 11:05:38 -07:00
add_sdl_test_executable ( testffmpeg NO_C90 SOURCES testffmpeg.c testffmpeg_vulkan.c ${ icon_bmp_header } )
2024-03-08 17:26:19 -07:00
if ( LIBAVUTIL_AVFULKANFRAMESCONTEXT_HAS_FORMAT )
target_compile_definitions ( testffmpeg PRIVATE FFMPEG_VULKAN_SUPPORT )
endif ( )
2023-10-09 18:55:06 -06:00
if ( APPLE )
2024-02-06 14:54:05 -07:00
target_link_options ( testffmpeg PRIVATE "-Wl,-framework,CoreVideo" )
2023-10-09 18:55:06 -06:00
endif ( )
2024-02-27 04:28:06 -07:00
if ( TARGET OpenGL::EGL )
2023-10-10 12:36:58 -06:00
message ( DEBUG "Enabling EGL support in testffmpeg" )
2024-02-27 04:28:06 -07:00
target_link_libraries ( testffmpeg PRIVATE OpenGL::EGL )
2023-10-09 13:27:56 -06:00
target_compile_definitions ( testffmpeg PRIVATE HAVE_EGL )
endif ( )
2024-03-02 11:05:38 -07:00
target_include_directories ( testffmpeg BEFORE PRIVATE ${ SDL3_SOURCE_DIR } /src/video/khronos )
2023-10-09 22:02:27 -06:00
target_link_libraries ( testffmpeg PRIVATE ${ FFMPEG_LIBRARIES } )
2023-10-07 03:01:35 -06:00
else ( )
2023-10-10 04:58:57 -06:00
message ( STATUS "Can't find ffmpeg 5.1.3 or newer, skipping testffmpeg" )
2023-10-07 03:01:35 -06:00
endif ( )
2023-03-17 12:23:56 -06:00
add_sdl_test_executable ( checkkeys SOURCES checkkeys.c )
add_sdl_test_executable ( checkkeysthreads SOURCES checkkeysthreads.c )
main: Added _optional_ callback entry points.
This lets apps optionally have a handful of callbacks for their entry points instead of a single main function. If used, the actual main/SDL_main/whatever entry point will be implemented in the single-header library SDL_main.h and the app will implement four separate functions:
First:
int SDL_AppInit(int argc, char **argv);
This will be called once before anything else. argc/argv work like they always do. If this returns 0, the app runs. If it returns < 0, the app calls SDL_AppQuit and terminates with an exit code that reports an error to the platform. If it returns > 0, the app calls SDL_AppQuit and terminates with an exit code that reports success to the platform. This function should not go into an infinite mainloop; it should do any one-time startup it requires and then return.
Then:
int SDL_AppIterate(void);
This is called over and over, possibly at the refresh rate of the display or some other metric that the platform dictates. This is where the heart of your app runs. It should return as quickly as reasonably possible, but it's not a "run one memcpy and that's all the time you have" sort of thing. The app should do any game updates, and render a frame of video. If it returns < 0, SDL will call SDL_AppQuit and terminate the process with an exit code that reports an error to the platform. If it returns > 0, the app calls SDL_AppQuit and terminates with an exit code that reports success to the platform. If it returns 0, then SDL_AppIterate will be called again at some regular frequency. The platform may choose to run this more or less (perhaps less in the background, etc), or it might just call this function in a loop as fast as possible. You do not check the event queue in this function (SDL_AppEvent exists for that).
Next:
int SDL_AppEvent(const SDL_Event *event);
This will be called once for each event pushed into the SDL queue. This may be called from any thread, and possibly in parallel to SDL_AppIterate. The fields in event do not need to be free'd (as you would normally need to do for SDL_EVENT_DROP_FILE, etc), and your app should not call SDL_PollEvent, SDL_PumpEvent, etc, as SDL will manage this for you. Return values are the same as from SDL_AppIterate(), so you can terminate in response to SDL_EVENT_QUIT, etc.
Finally:
void SDL_AppQuit(void);
This is called once before terminating the app--assuming the app isn't being forcibly killed or crashed--as a last chance to clean up. After this returns, SDL will call SDL_Quit so the app doesn't have to (but it's safe for the app to call it, too). Process termination proceeds as if the app returned normally from main(), so atexit handles will run, if your platform supports that.
The app does not implement SDL_main if using this. To turn this on, define SDL_MAIN_USE_CALLBACKS before including SDL_main.h. Defines like SDL_MAIN_HANDLED and SDL_MAIN_NOIMPL are also respected for callbacks, if the app wants to do some sort of magic main implementation thing.
In theory, on most platforms these can be implemented in the app itself, but this saves some #ifdefs in the app and lets everyone struggle less against some platforms, and might be more efficient in the long run, too.
On some platforms, it's possible this is the only reasonable way to go, but we haven't actually hit one that 100% requires it yet (but we will, if we want to write a RetroArch backend, for example).
Using the callback entry points works on every platform, because on platforms that don't require them, we can fake them with a simple loop in an internal implementation of the usual SDL_main.
The primary way we expect people to write SDL apps is with SDL_main, and this is not intended to replace it. If the app chooses to use this, it just removes some platform-specific details they might have to otherwise manage, and maybe removes a barrier to entry on some future platform.
Fixes #6785.
Reference PR #8247.
2023-11-01 16:40:41 -06:00
add_sdl_test_executable ( loopwave NEEDS_RESOURCES TESTUTILS MAIN_CALLBACKS SOURCES loopwave.c )
2023-03-17 12:23:56 -06:00
add_sdl_test_executable ( testsurround SOURCES testsurround.c )
add_sdl_test_executable ( testresample NEEDS_RESOURCES SOURCES testresample.c )
add_sdl_test_executable ( testaudioinfo SOURCES testaudioinfo.c )
2023-07-30 21:00:52 -06:00
add_sdl_test_executable ( testaudiostreamdynamicresample NEEDS_RESOURCES TESTUTILS SOURCES testaudiostreamdynamicresample.c )
2018-02-24 09:59:58 -07:00
file ( GLOB TESTAUTOMATION_SOURCE_FILES testautomation*.c )
2023-03-14 05:04:49 -06:00
add_sdl_test_executable ( testautomation NONINTERACTIVE NONINTERACTIVE_TIMEOUT 120 NEEDS_RESOURCES NO_C90 SOURCES ${ TESTAUTOMATION_SOURCE_FILES } )
2023-03-17 12:23:56 -06:00
add_sdl_test_executable ( testmultiaudio NEEDS_RESOURCES TESTUTILS SOURCES testmultiaudio.c )
add_sdl_test_executable ( testaudiohotplug NEEDS_RESOURCES TESTUTILS SOURCES testaudiohotplug.c )
main: Added _optional_ callback entry points.
This lets apps optionally have a handful of callbacks for their entry points instead of a single main function. If used, the actual main/SDL_main/whatever entry point will be implemented in the single-header library SDL_main.h and the app will implement four separate functions:
First:
int SDL_AppInit(int argc, char **argv);
This will be called once before anything else. argc/argv work like they always do. If this returns 0, the app runs. If it returns < 0, the app calls SDL_AppQuit and terminates with an exit code that reports an error to the platform. If it returns > 0, the app calls SDL_AppQuit and terminates with an exit code that reports success to the platform. This function should not go into an infinite mainloop; it should do any one-time startup it requires and then return.
Then:
int SDL_AppIterate(void);
This is called over and over, possibly at the refresh rate of the display or some other metric that the platform dictates. This is where the heart of your app runs. It should return as quickly as reasonably possible, but it's not a "run one memcpy and that's all the time you have" sort of thing. The app should do any game updates, and render a frame of video. If it returns < 0, SDL will call SDL_AppQuit and terminate the process with an exit code that reports an error to the platform. If it returns > 0, the app calls SDL_AppQuit and terminates with an exit code that reports success to the platform. If it returns 0, then SDL_AppIterate will be called again at some regular frequency. The platform may choose to run this more or less (perhaps less in the background, etc), or it might just call this function in a loop as fast as possible. You do not check the event queue in this function (SDL_AppEvent exists for that).
Next:
int SDL_AppEvent(const SDL_Event *event);
This will be called once for each event pushed into the SDL queue. This may be called from any thread, and possibly in parallel to SDL_AppIterate. The fields in event do not need to be free'd (as you would normally need to do for SDL_EVENT_DROP_FILE, etc), and your app should not call SDL_PollEvent, SDL_PumpEvent, etc, as SDL will manage this for you. Return values are the same as from SDL_AppIterate(), so you can terminate in response to SDL_EVENT_QUIT, etc.
Finally:
void SDL_AppQuit(void);
This is called once before terminating the app--assuming the app isn't being forcibly killed or crashed--as a last chance to clean up. After this returns, SDL will call SDL_Quit so the app doesn't have to (but it's safe for the app to call it, too). Process termination proceeds as if the app returned normally from main(), so atexit handles will run, if your platform supports that.
The app does not implement SDL_main if using this. To turn this on, define SDL_MAIN_USE_CALLBACKS before including SDL_main.h. Defines like SDL_MAIN_HANDLED and SDL_MAIN_NOIMPL are also respected for callbacks, if the app wants to do some sort of magic main implementation thing.
In theory, on most platforms these can be implemented in the app itself, but this saves some #ifdefs in the app and lets everyone struggle less against some platforms, and might be more efficient in the long run, too.
On some platforms, it's possible this is the only reasonable way to go, but we haven't actually hit one that 100% requires it yet (but we will, if we want to write a RetroArch backend, for example).
Using the callback entry points works on every platform, because on platforms that don't require them, we can fake them with a simple loop in an internal implementation of the usual SDL_main.
The primary way we expect people to write SDL apps is with SDL_main, and this is not intended to replace it. If the app chooses to use this, it just removes some platform-specific details they might have to otherwise manage, and maybe removes a barrier to entry on some future platform.
Fixes #6785.
Reference PR #8247.
2023-11-01 16:40:41 -06:00
add_sdl_test_executable ( testaudiocapture MAIN_CALLBACKS SOURCES testaudiocapture.c )
2023-03-17 12:23:56 -06:00
add_sdl_test_executable ( testatomic NONINTERACTIVE SOURCES testatomic.c )
add_sdl_test_executable ( testintersections SOURCES testintersections.c )
add_sdl_test_executable ( testrelative SOURCES testrelative.c )
add_sdl_test_executable ( testhittesting SOURCES testhittesting.c )
add_sdl_test_executable ( testdraw SOURCES testdraw.c )
add_sdl_test_executable ( testdrawchessboard SOURCES testdrawchessboard.c )
add_sdl_test_executable ( testdropfile SOURCES testdropfile.c )
add_sdl_test_executable ( testerror NONINTERACTIVE SOURCES testerror.c )
2022-05-04 06:15:12 -06:00
2023-07-16 11:38:17 -06:00
set ( build_options_dependent_tests )
add_sdl_test_executable ( testevdev BUILD_DEPENDENT NONINTERACTIVE SOURCES testevdev.c )
2023-03-16 17:25:39 -06:00
2023-07-16 11:38:17 -06:00
if ( APPLE )
add_sdl_test_executable ( testnative BUILD_DEPENDENT NEEDS_RESOURCES TESTUTILS
S O U R C E S
t e s t n a t i v e . c
t e s t n a t i v e c o c o a . m
t e s t n a t i v e x 1 1 . c
)
cmake_push_check_state ( )
check_c_compiler_flag ( -Wno-error=deprecated-declarations HAVE_WNO_ERROR_DEPRECATED_DECLARATIONS )
cmake_pop_check_state ( )
target_link_libraries ( testnative PRIVATE "-Wl,-framework,Cocoa" )
if ( HAVE_WNO_ERROR_DEPRECATED_DECLARATIONS )
set_property ( SOURCE "testnativecocoa.m" APPEND_STRING PROPERTY COMPILE_FLAGS " -Wno-error=deprecated-declarations" )
endif ( )
elseif ( WINDOWS )
add_sdl_test_executable ( testnative BUILD_DEPENDENT NEEDS_RESOURCES TESTUTILS SOURCES testnative.c testnativew32.c )
2024-01-09 09:38:38 -07:00
elseif ( HAVE_X11 OR HAVE_WAYLAND )
add_sdl_test_executable ( testnative BUILD_DEPENDENT NO_C90 NEEDS_RESOURCES TESTUTILS SOURCES testnative.c )
if ( HAVE_X11 )
target_sources ( testnative PRIVATE testnativex11.c )
target_link_libraries ( testnative PRIVATE X11 )
endif ( )
if ( HAVE_WAYLAND )
set_property ( SOURCE ${ SDL3_BINARY_DIR } /wayland-generated-protocols/xdg-shell-protocol.c PROPERTY GENERATED 1 )
target_sources ( testnative PRIVATE testnativewayland.c ${ SDL3_BINARY_DIR } /wayland-generated-protocols/xdg-shell-protocol.c )
# Needed to silence the documentation warning in the generated header file
target_compile_options ( testnative PRIVATE -Wno-documentation-unknown-command )
target_link_libraries ( testnative PRIVATE wayland-client )
endif ( )
2022-05-04 06:15:12 -06:00
endif ( )
2023-09-04 13:10:30 -06:00
find_package ( Python3 )
function ( files2headers OUTPUT )
set ( xxd "${CMAKE_CURRENT_SOURCE_DIR}/../cmake/xxd.py" )
set ( inputs ${ ARGN } )
set ( outputs )
foreach ( input IN LISTS inputs )
get_filename_component ( file_we "${input}" NAME_WE )
set ( intermediate "${CMAKE_CURRENT_BINARY_DIR}/${file_we}.h" )
set ( output "${CMAKE_CURRENT_SOURCE_DIR}/${file_we}.h" )
list ( APPEND outputs "${output}" )
if ( Python3_FOUND AND Python3_VERSION VERSION_GREATER_EQUAL "3.2" )
list ( APPEND outputs "${intermediate}" )
# Don't add the 'output' header to the output, to avoid marking them as GENERATED
# (generated files are removed when running the CLEAN target)
add_custom_command ( OUTPUT "${intermediate}"
C O M M A N D P y t h o n 3 : : I n t e r p r e t e r " $ { x x d } " - i " $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / $ { i n p u t } " " - o " " $ { i n t e r m e d i a t e } "
C O M M A N D " $ { C M A K E _ C O M M A N D } " - E c o p y _ i f _ d i f f e r e n t " $ { i n t e r m e d i a t e } " " $ { o u t p u t } "
D E P E N D S " $ { x x d } " " $ { b m p } "
)
endif ( )
endforeach ( )
set ( ${ OUTPUT } "${outputs}" PARENT_SCOPE )
endfunction ( )
files2headers ( gamepad_image_headers
2023-07-16 07:50:32 -06:00
g a m e p a d _ a x i s _ a r r o w . b m p
g a m e p a d _ a x i s . b m p
g a m e p a d _ b a c k . b m p
g a m e p a d _ b a t t e r y _ e m p t y . b m p
g a m e p a d _ b a t t e r y _ f u l l . b m p
g a m e p a d _ b a t t e r y _ l o w . b m p
g a m e p a d _ b a t t e r y _ m e d i u m . b m p
g a m e p a d _ b a t t e r y _ u n k n o w n . b m p
g a m e p a d _ b a t t e r y _ w i r e d . b m p
g a m e p a d _ b u t t o n _ b a c k g r o u n d . b m p
g a m e p a d _ b u t t o n . b m p
g a m e p a d _ b u t t o n _ s m a l l . b m p
g a m e p a d _ f a c e _ a b x y . b m p
g a m e p a d _ f a c e _ b a y x . b m p
g a m e p a d _ f a c e _ s o n y . b m p
g a m e p a d _ f r o n t . b m p
g a m e p a d _ t o u c h p a d . b m p
)
2023-09-04 13:10:30 -06:00
files2headers ( icon_bmp_header icon.bmp )
2024-02-09 08:09:59 -07:00
files2headers ( glass_bmp_header glass.bmp )
2023-07-16 07:50:32 -06:00
main: Added _optional_ callback entry points.
This lets apps optionally have a handful of callbacks for their entry points instead of a single main function. If used, the actual main/SDL_main/whatever entry point will be implemented in the single-header library SDL_main.h and the app will implement four separate functions:
First:
int SDL_AppInit(int argc, char **argv);
This will be called once before anything else. argc/argv work like they always do. If this returns 0, the app runs. If it returns < 0, the app calls SDL_AppQuit and terminates with an exit code that reports an error to the platform. If it returns > 0, the app calls SDL_AppQuit and terminates with an exit code that reports success to the platform. This function should not go into an infinite mainloop; it should do any one-time startup it requires and then return.
Then:
int SDL_AppIterate(void);
This is called over and over, possibly at the refresh rate of the display or some other metric that the platform dictates. This is where the heart of your app runs. It should return as quickly as reasonably possible, but it's not a "run one memcpy and that's all the time you have" sort of thing. The app should do any game updates, and render a frame of video. If it returns < 0, SDL will call SDL_AppQuit and terminate the process with an exit code that reports an error to the platform. If it returns > 0, the app calls SDL_AppQuit and terminates with an exit code that reports success to the platform. If it returns 0, then SDL_AppIterate will be called again at some regular frequency. The platform may choose to run this more or less (perhaps less in the background, etc), or it might just call this function in a loop as fast as possible. You do not check the event queue in this function (SDL_AppEvent exists for that).
Next:
int SDL_AppEvent(const SDL_Event *event);
This will be called once for each event pushed into the SDL queue. This may be called from any thread, and possibly in parallel to SDL_AppIterate. The fields in event do not need to be free'd (as you would normally need to do for SDL_EVENT_DROP_FILE, etc), and your app should not call SDL_PollEvent, SDL_PumpEvent, etc, as SDL will manage this for you. Return values are the same as from SDL_AppIterate(), so you can terminate in response to SDL_EVENT_QUIT, etc.
Finally:
void SDL_AppQuit(void);
This is called once before terminating the app--assuming the app isn't being forcibly killed or crashed--as a last chance to clean up. After this returns, SDL will call SDL_Quit so the app doesn't have to (but it's safe for the app to call it, too). Process termination proceeds as if the app returned normally from main(), so atexit handles will run, if your platform supports that.
The app does not implement SDL_main if using this. To turn this on, define SDL_MAIN_USE_CALLBACKS before including SDL_main.h. Defines like SDL_MAIN_HANDLED and SDL_MAIN_NOIMPL are also respected for callbacks, if the app wants to do some sort of magic main implementation thing.
In theory, on most platforms these can be implemented in the app itself, but this saves some #ifdefs in the app and lets everyone struggle less against some platforms, and might be more efficient in the long run, too.
On some platforms, it's possible this is the only reasonable way to go, but we haven't actually hit one that 100% requires it yet (but we will, if we want to write a RetroArch backend, for example).
Using the callback entry points works on every platform, because on platforms that don't require them, we can fake them with a simple loop in an internal implementation of the usual SDL_main.
The primary way we expect people to write SDL apps is with SDL_main, and this is not intended to replace it. If the app chooses to use this, it just removes some platform-specific details they might have to otherwise manage, and maybe removes a barrier to entry on some future platform.
Fixes #6785.
Reference PR #8247.
2023-11-01 16:40:41 -06:00
add_sdl_test_executable ( testaudio MAIN_CALLBACKS NEEDS_RESOURCES TESTUTILS SOURCES testaudio.c )
2024-01-29 19:32:27 -07:00
add_sdl_test_executable ( testcolorspace SOURCES testcolorspace.c )
2023-03-17 12:23:56 -06:00
add_sdl_test_executable ( testfile NONINTERACTIVE SOURCES testfile.c )
2023-07-16 07:50:32 -06:00
add_sdl_test_executable ( testcontroller TESTUTILS SOURCES testcontroller.c gamepadutils.c ${ gamepad_image_headers } )
2023-03-17 12:23:56 -06:00
add_sdl_test_executable ( testgeometry TESTUTILS SOURCES testgeometry.c )
add_sdl_test_executable ( testgl SOURCES testgl.c )
add_sdl_test_executable ( testgles SOURCES testgles.c )
2023-03-27 16:38:07 -06:00
if ( ANDROID )
target_link_libraries ( testgles PRIVATE GLESv1_CM )
endif ( )
2024-03-22 19:56:41 -06:00
check_include_file ( "GLES2/gl2platform.h" HAVE_GLES2_GL2PLATFORM_H )
if ( HAVE_GLES2_GL2PLATFORM_H OR ( TARGET SDL3-static OR SDL3-shared ) )
add_sdl_test_executable ( testgles2 SOURCES testgles2.c )
add_sdl_test_executable ( testgles2_sdf NEEDS_RESOURCES TESTUTILS SOURCES testgles2_sdf.c )
endif ( )
2023-03-17 12:23:56 -06:00
add_sdl_test_executable ( testhaptic SOURCES testhaptic.c )
add_sdl_test_executable ( testhotplug SOURCES testhotplug.c )
API for pressure-sensitive pens + XInput2/Wayland
This patch adds an API for querying pressure-
sensitive pens, cf. SDL_pen.h:
- Enumerate all pens
- Get pen capabilities, names, GUIDs
- Distinguishes pens and erasers
- Distinguish attached and detached pens
- Pressure and tilt support
- Rotation, distance, throttle wheel support
(throttle wheel untested)
- Pen type and meta-information reporting
(partially tested)
Pen event reporting:
- Three new event structures: PenTip, PenMotion, and
PenButton
- Report location with sub-pixel precision
- Include axis and button status, is-eraser flag
Internal pen tracker, intended to be independent
of platform APIs, cf. SDL_pen_c.h:
- Track known pens
- Handle pen hotplugging
Automatic test:
- testautomation_pen.c
Other features:
- XInput2 implementation, incl. hotplugging
- Wayland implementation, incl. hotplugging
- Backward compatibility: pen events default to
emulating pens with mouse ID SDL_PEN_MOUSEID
- Can be toggled via SDL_HINT_PEN_NOT_MOUSE
- Test/demo program (testpen)
- Wacom pen feature identification by pen ID
Acknowledgements:
- Ping Cheng (Wacom) provided extensive feedback
on Wacom pen features and detection so that
hopefully untested Wacom devices have a
realistic chance of working out of the box.
2023-08-27 00:20:29 -06:00
add_sdl_test_executable ( testpen SOURCES testpen.c )
2023-03-17 12:23:56 -06:00
add_sdl_test_executable ( testrumble SOURCES testrumble.c )
add_sdl_test_executable ( testthread NONINTERACTIVE NONINTERACTIVE_TIMEOUT 40 SOURCES testthread.c )
add_sdl_test_executable ( testiconv NEEDS_RESOURCES TESTUTILS SOURCES testiconv.c )
add_sdl_test_executable ( testime NEEDS_RESOURCES TESTUTILS SOURCES testime.c )
add_sdl_test_executable ( testkeys SOURCES testkeys.c )
add_sdl_test_executable ( testloadso SOURCES testloadso.c )
add_sdl_test_executable ( testlocale NONINTERACTIVE SOURCES testlocale.c )
2023-05-24 17:15:12 -06:00
add_sdl_test_executable ( testlock NO_C90 SOURCES testlock.c )
2023-04-23 23:07:59 -06:00
add_sdl_test_executable ( testrwlock SOURCES testrwlock.c )
2023-03-17 12:23:56 -06:00
add_sdl_test_executable ( testmouse SOURCES testmouse.c )
add_sdl_test_executable ( testoverlay NEEDS_RESOURCES TESTUTILS SOURCES testoverlay.c )
add_sdl_test_executable ( testplatform NONINTERACTIVE SOURCES testplatform.c )
add_sdl_test_executable ( testpower NONINTERACTIVE SOURCES testpower.c )
add_sdl_test_executable ( testfilesystem NONINTERACTIVE SOURCES testfilesystem.c )
2023-09-07 19:28:01 -06:00
if ( WIN32 AND CMAKE_SIZEOF_VOID_P EQUAL 4 )
2023-09-24 13:35:41 -06:00
add_sdl_test_executable ( pretest SOURCES pretest.c NONINTERACTIVE NONINTERACTIVE_TIMEOUT 60 )
2023-09-07 19:28:01 -06:00
endif ( )
2023-03-17 12:23:56 -06:00
add_sdl_test_executable ( testrendertarget NEEDS_RESOURCES TESTUTILS SOURCES testrendertarget.c )
add_sdl_test_executable ( testscale NEEDS_RESOURCES TESTUTILS SOURCES testscale.c )
add_sdl_test_executable ( testsem NONINTERACTIVE NONINTERACTIVE_ARGS 10 NONINTERACTIVE_TIMEOUT 30 SOURCES testsem.c )
add_sdl_test_executable ( testsensor SOURCES testsensor.c )
add_sdl_test_executable ( testshader NEEDS_RESOURCES TESTUTILS SOURCES testshader.c )
2024-02-09 08:09:59 -07:00
add_sdl_test_executable ( testshape NEEDS_RESOURCES SOURCES testshape.c ${ glass_bmp_header } )
main: Added _optional_ callback entry points.
This lets apps optionally have a handful of callbacks for their entry points instead of a single main function. If used, the actual main/SDL_main/whatever entry point will be implemented in the single-header library SDL_main.h and the app will implement four separate functions:
First:
int SDL_AppInit(int argc, char **argv);
This will be called once before anything else. argc/argv work like they always do. If this returns 0, the app runs. If it returns < 0, the app calls SDL_AppQuit and terminates with an exit code that reports an error to the platform. If it returns > 0, the app calls SDL_AppQuit and terminates with an exit code that reports success to the platform. This function should not go into an infinite mainloop; it should do any one-time startup it requires and then return.
Then:
int SDL_AppIterate(void);
This is called over and over, possibly at the refresh rate of the display or some other metric that the platform dictates. This is where the heart of your app runs. It should return as quickly as reasonably possible, but it's not a "run one memcpy and that's all the time you have" sort of thing. The app should do any game updates, and render a frame of video. If it returns < 0, SDL will call SDL_AppQuit and terminate the process with an exit code that reports an error to the platform. If it returns > 0, the app calls SDL_AppQuit and terminates with an exit code that reports success to the platform. If it returns 0, then SDL_AppIterate will be called again at some regular frequency. The platform may choose to run this more or less (perhaps less in the background, etc), or it might just call this function in a loop as fast as possible. You do not check the event queue in this function (SDL_AppEvent exists for that).
Next:
int SDL_AppEvent(const SDL_Event *event);
This will be called once for each event pushed into the SDL queue. This may be called from any thread, and possibly in parallel to SDL_AppIterate. The fields in event do not need to be free'd (as you would normally need to do for SDL_EVENT_DROP_FILE, etc), and your app should not call SDL_PollEvent, SDL_PumpEvent, etc, as SDL will manage this for you. Return values are the same as from SDL_AppIterate(), so you can terminate in response to SDL_EVENT_QUIT, etc.
Finally:
void SDL_AppQuit(void);
This is called once before terminating the app--assuming the app isn't being forcibly killed or crashed--as a last chance to clean up. After this returns, SDL will call SDL_Quit so the app doesn't have to (but it's safe for the app to call it, too). Process termination proceeds as if the app returned normally from main(), so atexit handles will run, if your platform supports that.
The app does not implement SDL_main if using this. To turn this on, define SDL_MAIN_USE_CALLBACKS before including SDL_main.h. Defines like SDL_MAIN_HANDLED and SDL_MAIN_NOIMPL are also respected for callbacks, if the app wants to do some sort of magic main implementation thing.
In theory, on most platforms these can be implemented in the app itself, but this saves some #ifdefs in the app and lets everyone struggle less against some platforms, and might be more efficient in the long run, too.
On some platforms, it's possible this is the only reasonable way to go, but we haven't actually hit one that 100% requires it yet (but we will, if we want to write a RetroArch backend, for example).
Using the callback entry points works on every platform, because on platforms that don't require them, we can fake them with a simple loop in an internal implementation of the usual SDL_main.
The primary way we expect people to write SDL apps is with SDL_main, and this is not intended to replace it. If the app chooses to use this, it just removes some platform-specific details they might have to otherwise manage, and maybe removes a barrier to entry on some future platform.
Fixes #6785.
Reference PR #8247.
2023-11-01 16:40:41 -06:00
add_sdl_test_executable ( testsprite MAIN_CALLBACKS NEEDS_RESOURCES TESTUTILS SOURCES testsprite.c )
2023-09-04 13:10:30 -06:00
add_sdl_test_executable ( testspriteminimal SOURCES testspriteminimal.c ${ icon_bmp_header } )
2023-03-17 12:23:56 -06:00
add_sdl_test_executable ( teststreaming NEEDS_RESOURCES TESTUTILS SOURCES teststreaming.c )
2023-08-28 16:03:05 -06:00
add_sdl_test_executable ( testtimer NONINTERACTIVE NONINTERACTIVE_ARGS --no-interactive NONINTERACTIVE_TIMEOUT 60 SOURCES testtimer.c )
2023-03-17 12:23:56 -06:00
add_sdl_test_executable ( testurl SOURCES testurl.c )
add_sdl_test_executable ( testver NONINTERACTIVE SOURCES testver.c )
2024-02-19 10:20:11 -07:00
add_sdl_test_executable ( testcamera MAIN_CALLBACKS SOURCES testcamera.c )
2023-03-17 12:23:56 -06:00
add_sdl_test_executable ( testviewport NEEDS_RESOURCES TESTUTILS SOURCES testviewport.c )
add_sdl_test_executable ( testwm SOURCES testwm.c )
add_sdl_test_executable ( testyuv NONINTERACTIVE NONINTERACTIVE_ARGS "--automated" NEEDS_RESOURCES TESTUTILS SOURCES testyuv.c testyuv_cvt.c )
add_sdl_test_executable ( torturethread NONINTERACTIVE NONINTERACTIVE_TIMEOUT 30 SOURCES torturethread.c )
add_sdl_test_executable ( testrendercopyex NEEDS_RESOURCES TESTUTILS SOURCES testrendercopyex.c )
add_sdl_test_executable ( testmessage SOURCES testmessage.c )
add_sdl_test_executable ( testdisplayinfo SOURCES testdisplayinfo.c )
add_sdl_test_executable ( testqsort NONINTERACTIVE SOURCES testqsort.c )
add_sdl_test_executable ( testbounds NONINTERACTIVE SOURCES testbounds.c )
add_sdl_test_executable ( testcustomcursor SOURCES testcustomcursor.c )
2023-05-24 17:15:12 -06:00
add_sdl_test_executable ( testvulkan NO_C90 SOURCES testvulkan.c )
2023-03-17 12:23:56 -06:00
add_sdl_test_executable ( testoffscreen SOURCES testoffscreen.c )
add_sdl_test_executable ( testpopup SOURCES testpopup.c )
2024-03-10 15:27:42 -06:00
add_sdl_test_executable ( testdialog SOURCES testdialog.c )
Add time and realtime clock functions
Adds functions to query the system's realtime clock, convert time intervals to/from a calendar date and time in either UTC or the local time, and perform time related calculations.
An SDL_Time type (a time interval represented in nanoseconds), and SDL_DateTime struct (broken down calendar date and time) were added to facilitate this functionality.
Querying the system time results in a value expressed in nanoseconds since the Unix epoch (Jan 1, 1970) in UTC +0000. Conversions to and from the various platform epochs and units are performed when required.
Any direct handling of timezones and DST were intentionally avoided. The offset from UTC is provided when converting from UTC to a local time by calculating the difference between the original UTC and the resulting local time, but no other timezone or DST information is used.
The preferred date formatting and 12/24 hour time for the system locale can be retrieved via global preferences.
Helper functions for obtaining the day of week or day or year for calendar date, and getting the number of days in a month in a given year are provided for convenience. These are simple, but useful for performing various time related calculations.
An automated test for time conversion is included, as is a simple standalone test to display the current system date and time onscreen along with a calendar, the rendering of which demonstrates the use of the utility functions (press up/down to increment or decrement the current month, and keys 1-5 to change the date and time formats).
2024-02-29 11:06:26 -07:00
add_sdl_test_executable ( testtime SOURCES testtime.c )
2018-02-24 09:59:58 -07:00
2024-01-06 13:37:38 -07:00
if ( HAVE_WAYLAND )
# Set the GENERATED property on the protocol file, since it is first created at build time
set_property ( SOURCE ${ SDL3_BINARY_DIR } /wayland-generated-protocols/xdg-shell-protocol.c PROPERTY GENERATED 1 )
add_sdl_test_executable ( testwaylandcustom NO_C90 NEEDS_RESOURCES SOURCES testwaylandcustom.c ${ SDL3_BINARY_DIR } /wayland-generated-protocols/xdg-shell-protocol.c )
# Needed to silence the documentation warning in the generated header file
target_compile_options ( testwaylandcustom PRIVATE -Wno-documentation-unknown-command )
target_link_libraries ( testwaylandcustom PRIVATE wayland-client )
endif ( )
2022-10-05 16:31:00 -06:00
check_c_compiler_flag ( -Wformat-overflow HAVE_WFORMAT_OVERFLOW )
if ( HAVE_WFORMAT_OVERFLOW )
target_compile_definitions ( testautomation PRIVATE HAVE_WFORMAT_OVERFLOW )
endif ( )
check_c_compiler_flag ( -Wformat HAVE_WFORMAT )
if ( HAVE_WFORMAT )
target_compile_definitions ( testautomation PRIVATE HAVE_WFORMAT )
endif ( )
2023-01-07 14:25:09 -07:00
cmake_push_check_state ( )
if ( HAVE_WFORMAT )
# Some compilers ignore -Wformat-extra-args without -Wformat
2023-02-27 20:20:30 -07:00
string ( APPEND CMAKE_REQUIRED_FLAGS " -Wformat" )
2023-01-07 14:25:09 -07:00
endif ( )
2022-10-05 16:31:00 -06:00
check_c_compiler_flag ( -Wformat-extra-args HAVE_WFORMAT_EXTRA_ARGS )
2023-01-07 14:25:09 -07:00
cmake_pop_check_state ( )
2022-10-05 16:31:00 -06:00
if ( HAVE_WFORMAT_EXTRA_ARGS )
target_compile_definitions ( testautomation PRIVATE HAVE_WFORMAT_EXTRA_ARGS )
endif ( )
2022-05-18 10:04:12 -06:00
if ( SDL_DUMMYAUDIO )
2023-03-17 12:23:56 -06:00
set_property ( TARGET testaudioinfo PROPERTY SDL_NONINTERACTIVE 1 )
2022-05-18 10:04:12 -06:00
endif ( )
2022-04-12 06:33:58 -06:00
2022-05-18 10:04:12 -06:00
if ( SDL_DUMMYVIDEO )
2023-03-17 12:23:56 -06:00
set_property ( TARGET testkeys PROPERTY SDL_NONINTERACTIVE 1 )
set_property ( TARGET testbounds PROPERTY SDL_NONINTERACTIVE 1 )
set_property ( TARGET testdisplayinfo PROPERTY SDL_NONINTERACTIVE 1 )
2022-05-18 10:04:12 -06:00
endif ( )
2022-04-12 06:33:58 -06:00
2021-03-04 08:28:10 -07:00
if ( OPENGL_FOUND )
2022-11-01 04:33:39 -06:00
if ( TARGET OpenGL::GL )
2022-11-30 15:40:34 -07:00
target_link_libraries ( testshader PRIVATE OpenGL::GL )
2023-01-03 11:28:18 -07:00
target_link_libraries ( testgl PRIVATE OpenGL::GL )
2022-11-01 04:33:39 -06:00
else ( )
2022-11-01 06:40:19 -06:00
if ( EMSCRIPTEN AND OPENGL_gl_LIBRARY STREQUAL "nul" )
set ( OPENGL_gl_LIBRARY GL )
endif ( )
2022-11-01 04:33:39 -06:00
# emscripten's FindOpenGL.cmake does not create OpenGL::GL
2022-11-30 15:40:34 -07:00
target_link_libraries ( testshader PRIVATE ${ OPENGL_gl_LIBRARY } )
2023-01-03 11:28:18 -07:00
target_link_libraries ( testgl PRIVATE ${ OPENGL_gl_LIBRARY } )
2022-11-01 04:33:39 -06:00
endif ( )
2021-03-04 08:28:10 -07:00
endif ( )
2022-11-01 06:09:52 -06:00
if ( EMSCRIPTEN )
2022-11-30 15:40:34 -07:00
set_property ( TARGET testshader APPEND_STRING PROPERTY LINK_FLAGS " -sLEGACY_GL_EMULATION" )
2023-08-09 11:05:56 -06:00
find_package ( Python3 COMPONENTS Interpreter )
if ( TARGET Python3::Interpreter )
add_custom_target ( serve-sdl-tests
C O M M A N D P y t h o n 3 : : I n t e r p r e t e r " $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / e m s c r i p t e n / s e r v e r . p y " - d " $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } " )
endif ( )
2022-11-01 06:09:52 -06:00
endif ( )
2021-03-04 08:28:10 -07:00
2022-01-05 03:33:51 -07:00
if ( PSP )
# Build EBOOT files if building for PSP
2022-11-30 15:40:34 -07:00
foreach ( APP ${ SDL_TEST_EXECUTABLES } )
2022-01-03 10:41:21 -07:00
create_pbp_file (
T A R G E T $ { A P P }
T I T L E S D L - $ { A P P }
I C O N _ P A T H N U L L
B A C K G R O U N D _ P A T H N U L L
P R E V I E W _ P A T H N U L L
)
add_custom_command (
T A R G E T $ { A P P } P O S T _ B U I L D
C O M M A N D $ { C M A K E _ C O M M A N D } - E m a k e _ d i r e c t o r y
2022-01-03 10:56:02 -07:00
$ < T A R G E T _ F I L E _ D I R : $ { A R G _ T A R G E T } > / s d l - $ { A P P }
2022-01-03 10:41:21 -07:00
)
add_custom_command (
T A R G E T $ { A P P } P O S T _ B U I L D
C O M M A N D $ { C M A K E _ C O M M A N D } - E r e n a m e
$ < T A R G E T _ F I L E _ D I R : $ { A R G _ T A R G E T } > / E B O O T . P B P
2022-01-03 10:56:02 -07:00
$ < T A R G E T _ F I L E _ D I R : $ { A R G _ T A R G E T } > / s d l - $ { A P P } / E B O O T . P B P
2022-01-03 10:41:21 -07:00
)
2022-11-30 15:40:34 -07:00
if ( BUILD_PRX )
2022-01-03 10:56:02 -07:00
add_custom_command (
T A R G E T $ { A P P } P O S T _ B U I L D
C O M M A N D $ { C M A K E _ C O M M A N D } - E c o p y
$ < T A R G E T _ F I L E _ D I R : $ { A R G _ T A R G E T } > / $ { A P P }
$ < T A R G E T _ F I L E _ D I R : $ { A R G _ T A R G E T } > / s d l - $ { A P P } / $ { A P P }
)
add_custom_command (
T A R G E T $ { A P P } P O S T _ B U I L D
C O M M A N D $ { C M A K E _ C O M M A N D } - E r e n a m e
$ < T A R G E T _ F I L E _ D I R : $ { A R G _ T A R G E T } > / $ { A P P } . p r x
$ < T A R G E T _ F I L E _ D I R : $ { A R G _ T A R G E T } > / s d l - $ { A P P } / $ { A P P } . p r x
)
endif ( )
2022-01-03 10:41:21 -07:00
add_custom_command (
T A R G E T $ { A P P } P O S T _ B U I L D
C O M M A N D $ { C M A K E _ C O M M A N D } - E r e m o v e
$ < T A R G E T _ F I L E _ D I R : $ { A R G _ T A R G E T } > / P A R A M . S F O
)
endforeach ( )
endif ( )
2021-03-30 02:32:39 -06:00
if ( N3DS )
set ( ROMFS_DIR "${CMAKE_CURRENT_BINARY_DIR}/romfs" )
file ( COPY ${ RESOURCE_FILES } DESTINATION "${ROMFS_DIR}" )
2022-11-30 15:40:34 -07:00
foreach ( APP ${ SDL_TEST_EXECUTABLES } )
2021-03-30 02:32:39 -06:00
get_target_property ( TARGET_BINARY_DIR ${ APP } BINARY_DIR )
set ( SMDH_FILE "${TARGET_BINARY_DIR}/${APP}.smdh" )
2023-01-07 08:15:28 -07:00
ctr_generate_smdh ( "${SMDH_FILE}"
2021-03-30 02:32:39 -06:00
N A M E " S D L - $ { A P P } "
2022-11-21 21:28:58 -07:00
D E S C R I P T I O N " S D L 3 T e s t s u i t e "
A U T H O R " S D L 3 C o n t r i b u t o r s "
2021-03-30 02:32:39 -06:00
I C O N " $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / n 3 d s / l o g o 4 8 x 4 8 . p n g "
)
ctr_create_3dsx (
$ { A P P }
R O M F S " $ { R O M F S _ D I R } "
S M D H " $ { S M D H _ F I L E } "
)
endforeach ( )
endif ( )
2022-05-19 16:11:22 -06:00
if ( RISCOS )
2022-11-01 04:04:45 -06:00
set ( SDL_TEST_EXECUTABLES_AIF )
2022-11-30 15:40:34 -07:00
foreach ( APP ${ SDL_TEST_EXECUTABLES } )
set_property ( TARGET ${ APP } APPEND_STRING PROPERTY LINK_FLAGS " -static" )
2022-05-19 16:11:22 -06:00
add_custom_command (
O U T P U T $ { A P P } , f f 8
C O M M A N D e l f 2 a i f $ { A P P } $ { A P P } , f f 8
D E P E N D S $ { A P P }
)
add_custom_target ( ${ APP } -aif ALL DEPENDS ${ APP } ,ff8 )
2022-11-01 04:04:45 -06:00
list ( APPEND SDL_TEST_EXECUTABLES_AIF ${ CMAKE_CURRENT_BINARY_DIR } / ${ APP } ,ff8 )
2022-05-19 16:11:22 -06:00
endforeach ( )
endif ( )
CMake: iOS support added
When using a recent version of CMake (3.14+), this should make it possible to:
- build SDL for iOS, both static and dynamic
- build SDL test apps (as iOS .app bundles)
- generate a working SDL_config.h for iOS (using SDL_config.h.cmake as a basis)
To use, set the following CMake variables when running CMake's configuration stage:
- CMAKE_SYSTEM_NAME=iOS
- CMAKE_OSX_SYSROOT=<SDK> (examples: iphoneos, iphonesimulator, iphoneos12.4, /full/path/to/iPhoneOS.sdk, etc.)
- CMAKE_OSX_ARCHITECTURES=<semicolon-separated list of CPU architectures> (example: "arm64;armv7s")
Examples:
- for Simulator, using the latest, installed SDK:
cmake path/to/SDL -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_SYSROOT=iphonesimulator -DCMAKE_OSX_ARCHITECTURES=x86_64
- for Device, using the latest, installed SDK, 64-bit only
cmake path/to/SDL -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_SYSROOT=iphoneos -DCMAKE_OSX_ARCHITECTURES=arm64
- for Device, using the latest, installed SDK, mixed 32/64 bit
cmake path/to/SDL -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_SYSROOT=iphoneos -DCMAKE_OSX_ARCHITECTURES="arm64;armv7s"
- for Device, using a specific SDK revision (iOS 12.4, in this example):
cmake path/to/SDL -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_SYSROOT=iphoneos12.4 -DCMAKE_OSX_ARCHITECTURES=arm64
- for Simulator, using the latest, installed SDK, and building SDL test apps (as .app bundles):
cmake path/to/SDL -DSDL_TEST=1 -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_SYSROOT=iphonesimulator -DCMAKE_OSX_ARCHITECTURES=x86_64
2019-08-27 09:07:43 -06:00
# Set Apple App ID / Bundle ID. This is needed to launch apps on some Apple
# platforms (iOS, for example).
if ( APPLE )
2023-02-27 20:20:30 -07:00
foreach ( CURRENT_TARGET ${ SDL_TEST_EXECUTABLES } )
set_target_properties ( "${CURRENT_TARGET}" PROPERTIES
M A C O S X _ B U N D L E _ G U I _ I D E N T I F I E R " o r g . l i b s d l . $ { C U R R E N T _ T A R G E T } "
M A C O S X _ B U N D L E _ B U N D L E _ V E R S I O N " $ { S D L 3 _ V E R S I O N } "
M A C O S X _ B U N D L E _ S H O R T _ V E R S I O N _ S T R I N G " $ { S D L 3 _ V E R S I O N } "
)
endforeach ( )
CMake: iOS support added
When using a recent version of CMake (3.14+), this should make it possible to:
- build SDL for iOS, both static and dynamic
- build SDL test apps (as iOS .app bundles)
- generate a working SDL_config.h for iOS (using SDL_config.h.cmake as a basis)
To use, set the following CMake variables when running CMake's configuration stage:
- CMAKE_SYSTEM_NAME=iOS
- CMAKE_OSX_SYSROOT=<SDK> (examples: iphoneos, iphonesimulator, iphoneos12.4, /full/path/to/iPhoneOS.sdk, etc.)
- CMAKE_OSX_ARCHITECTURES=<semicolon-separated list of CPU architectures> (example: "arm64;armv7s")
Examples:
- for Simulator, using the latest, installed SDK:
cmake path/to/SDL -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_SYSROOT=iphonesimulator -DCMAKE_OSX_ARCHITECTURES=x86_64
- for Device, using the latest, installed SDK, 64-bit only
cmake path/to/SDL -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_SYSROOT=iphoneos -DCMAKE_OSX_ARCHITECTURES=arm64
- for Device, using the latest, installed SDK, mixed 32/64 bit
cmake path/to/SDL -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_SYSROOT=iphoneos -DCMAKE_OSX_ARCHITECTURES="arm64;armv7s"
- for Device, using a specific SDK revision (iOS 12.4, in this example):
cmake path/to/SDL -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_SYSROOT=iphoneos12.4 -DCMAKE_OSX_ARCHITECTURES=arm64
- for Simulator, using the latest, installed SDK, and building SDL test apps (as .app bundles):
cmake path/to/SDL -DSDL_TEST=1 -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_SYSROOT=iphonesimulator -DCMAKE_OSX_ARCHITECTURES=x86_64
2019-08-27 09:07:43 -06:00
endif ( )
2022-04-12 06:33:58 -06:00
set ( TESTS_ENVIRONMENT
2022-12-08 02:40:01 -07:00
S D L _ A U D I O _ D R I V E R = d u m m y
S D L _ V I D E O _ D R I V E R = d u m m y
2023-01-20 17:57:10 -07:00
P A T H = $ < T A R G E T _ F I L E _ D I R : S D L 3 : : $ { s d l _ n a m e _ c o m p o n e n t } >
2022-04-12 06:33:58 -06:00
)
2023-03-17 12:23:56 -06:00
foreach ( TEST ${ SDL_TEST_EXECUTABLES } )
get_property ( noninteractive TARGET ${ TEST } PROPERTY SDL_NONINTERACTIVE )
if ( noninteractive )
set ( command ${ TEST } )
get_property ( noninteractive_arguments TARGET ${ TEST } PROPERTY SDL_NONINTERACTIVE_ARGUMENTS )
if ( noninteractive_arguments )
list ( APPEND command ${ noninteractive_arguments } )
endif ( )
add_test (
N A M E $ { T E S T }
C O M M A N D $ { c o m m a n d }
W O R K I N G _ D I R E C T O R Y $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R }
2022-05-04 06:53:15 -06:00
)
2023-03-17 12:23:56 -06:00
set_tests_properties ( ${ TEST } PROPERTIES ENVIRONMENT "${TESTS_ENVIRONMENT}" )
get_property ( noninteractive_timeout TARGET ${ TEST } PROPERTY SDL_NONINTERACTIVE_TIMEOUT )
if ( NOT noninteractive_timeout )
set ( noninteractive_timeout 10 )
endif ( )
math ( EXPR noninteractive_timeout "${noninteractive_timeout}*${SDL_TESTS_TIMEOUT_MULTIPLIER}" )
set_tests_properties ( ${ TEST } PROPERTIES TIMEOUT "${noninteractive_timeout}" )
if ( SDL_INSTALL_TESTS )
set ( exe ${ TEST } )
set ( installedtestsdir "${CMAKE_INSTALL_FULL_LIBEXECDIR}/installed-tests/SDL3" )
configure_file ( template.test.in "${exe}.test" @ONLY )
install (
F I L E S " $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / $ { e x e } . t e s t "
D E S T I N A T I O N $ { C M A K E _ I N S T A L L _ D A T A D I R } / i n s t a l l e d - t e s t s / S D L 3
)
endif ( )
2023-09-24 13:35:41 -06:00
if ( TARGET pretest AND NOT "${TEST}" MATCHES "pretest" )
set_property ( TEST ${ TEST } APPEND PROPERTY DEPENDS pretest )
endif ( )
2022-05-04 06:53:15 -06:00
endif ( )
2022-04-12 06:33:58 -06:00
endforeach ( )
2020-11-25 06:30:29 -07:00
if ( SDL_INSTALL_TESTS )
2022-05-19 16:11:22 -06:00
if ( RISCOS )
install (
2022-11-01 04:04:45 -06:00
F I L E S $ { S D L _ T E S T _ E X E C U T A B L E S _ A I F }
2022-11-21 21:28:58 -07:00
D E S T I N A T I O N $ { C M A K E _ I N S T A L L _ L I B E X E C D I R } / i n s t a l l e d - t e s t s / S D L 3
2022-05-19 16:11:22 -06:00
)
else ( )
install (
2022-11-01 04:04:45 -06:00
T A R G E T S $ { S D L _ T E S T _ E X E C U T A B L E S }
2022-11-21 21:28:58 -07:00
D E S T I N A T I O N $ { C M A K E _ I N S T A L L _ L I B E X E C D I R } / i n s t a l l e d - t e s t s / S D L 3
2022-05-19 16:11:22 -06:00
)
endif ( )
2023-10-11 16:49:43 -06:00
if ( MSVC )
foreach ( test IN LISTS SDL_TEST_EXECUTABLES )
2023-11-08 16:24:10 -07:00
SDL_install_pdb ( ${ test } "${CMAKE_INSTALL_LIBEXECDIR}/installed-tests/SDL3" )
2023-10-11 16:49:43 -06:00
endforeach ( )
endif ( )
2020-11-25 06:30:29 -07:00
install (
F I L E S $ { R E S O U R C E _ F I L E S }
2022-11-21 21:28:58 -07:00
D E S T I N A T I O N $ { C M A K E _ I N S T A L L _ L I B E X E C D I R } / i n s t a l l e d - t e s t s / S D L 3
2020-11-25 06:30:29 -07:00
)
endif ( )
2023-03-27 04:03:42 -06:00
2023-11-22 15:28:39 -07:00
if ( ANDROID AND TARGET SDL3::Jar )
2023-03-27 04:03:42 -06:00
list ( APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/../cmake/android" )
find_package ( SdlAndroid MODULE )
if ( SdlAndroid_FOUND )
set ( apks "" )
set ( packages "" )
include ( SdlAndroidFunctions )
sdl_create_android_debug_keystore ( SDL_test-debug-keystore )
sdl_android_compile_resources ( SDL_test-resources RESFOLDER android/res )
add_custom_target ( sdl-test-apks )
foreach ( TEST ${ SDL_TEST_EXECUTABLES } )
set ( ANDROID_MANIFEST_APP_NAME "${TEST}" )
set ( ANDROID_MANIFEST_LABEL "${TEST}" )
set ( ANDROID_MANIFEST_LIB_NAME "$<TARGET_FILE_BASE_NAME:${TEST}>" )
set ( ANDROID_MANIFEST_PACKAGE "org.libsdl.sdl.test.${TEST}" )
set ( generated_manifest_path "${CMAKE_CURRENT_BINARY_DIR}/android/${TEST}-src/AndroidManifest.xml" )
string ( REPLACE "." "/" JAVA_PACKAGE_DIR "${ANDROID_MANIFEST_PACKAGE}" )
set ( GENERATED_SRC_FOLDER "${CMAKE_CURRENT_BINARY_DIR}/android/${TEST}-src" )
set ( GENERATED_RES_FOLDER "${GENERATED_SRC_FOLDER}/res" )
set ( JAVA_PACKAGE_DIR "${GENERATED_SRC_FOLDER}/${JAVA_PACKAGE_DIR}" )
configure_file ( android/cmake/SDLEntryTestActivity.java.cmake "${JAVA_PACKAGE_DIR}/SDLEntryTestActivity.java" @ONLY )
configure_file ( android/cmake/SDLTestActivity.java.cmake "${JAVA_PACKAGE_DIR}/SDLTestActivity.java" @ONLY )
configure_file ( android/cmake/res/values/strings.xml.cmake android/res/values/strings- ${ TEST } .xml @ONLY )
configure_file ( android/cmake/res/xml/shortcuts.xml.cmake "${GENERATED_RES_FOLDER}/xml/shortcuts.xml" @ONLY )
configure_file ( android/cmake/AndroidManifest.xml.cmake "${generated_manifest_path}" @ONLY )
file ( GENERATE
O U T P U T " $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / a n d r o i d / $ { T E S T } - $ < C O N F I G > / r e s / v a l u e s / s t r i n g s . x m l "
I N P U T " $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / a n d r o i d / r e s / v a l u e s / s t r i n g s - $ { T E S T } . x m l "
)
sdl_android_compile_resources ( ${ TEST } -resources
R E S O U R C E S
" $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / a n d r o i d / $ { T E S T } - $ < C O N F I G > / r e s / v a l u e s / s t r i n g s . x m l "
" $ { G E N E R A T E D _ R E S _ F O L D E R } / x m l / s h o r t c u t s . x m l "
)
sdl_android_link_resources ( ${ TEST } -apk-linked
M A N I F E S T " $ { g e n e r a t e d _ m a n i f e s t _ p a t h } "
P A C K A G E $ { A N D R O I D _ M A N I F E S T _ P A C K A G E }
R E S _ T A R G E T S S D L _ t e s t - r e s o u r c e s $ { T E S T } - r e s o u r c e s
T A R G E T _ S D K _ V E R S I O N 3 1
)
set ( CMAKE_JAVA_COMPILE_FLAGS "-encoding;utf-8" )
set ( classes_path "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${TEST}-java.dir/classes" )
# Some CMake versions have a slow `cmake -E make_directory` implementation
if ( NOT IS_DIRECTORY "${classes_path}" )
execute_process ( COMMAND ${ CMAKE_COMMAND } -E make_directory "${classes_path}" )
endif ( )
set ( OUT_JAR "${CMAKE_CURRENT_BINARY_DIR}/${TEST}.jar" )
add_custom_command (
O U T P U T " $ { O U T _ J A R } "
C O M M A N D $ { C M A K E _ C O M M A N D } - E r m - r f " $ { c l a s s e s _ p a t h } "
C O M M A N D $ { C M A K E _ C O M M A N D } - E m a k e _ d i r e c t o r y " $ { c l a s s e s _ p a t h } "
C O M M A N D $ { J a v a _ J A V A C _ E X E C U T A B L E }
- s o u r c e 1 . 8 - t a r g e t 1 . 8
2023-11-22 15:28:39 -07:00
- b o o t c l a s s p a t h " $ < T A R G E T _ P R O P E R T Y : S D L 3 : : J a r , J A R _ F I L E > "
2023-03-27 04:03:42 -06:00
" $ { J A V A _ P A C K A G E _ D I R } / S D L E n t r y T e s t A c t i v i t y . j a v a "
" $ { J A V A _ P A C K A G E _ D I R } / S D L T e s t A c t i v i t y . j a v a "
$ < T A R G E T _ P R O P E R T Y : $ { T E S T } - a p k - l i n k e d , J A V A _ R >
2023-11-22 15:28:39 -07:00
- c p " $ < T A R G E T _ P R O P E R T Y : S D L 3 : : J a r , J A R _ F I L E > : $ { S D L _ A N D R O I D _ P L A T F O R M _ A N D R O I D _ J A R } "
2023-03-27 04:03:42 -06:00
- d " $ { c l a s s e s _ p a t h } "
C O M M A N D $ { J a v a _ J A R _ E X E C U T A B L E } c f " $ { O U T _ J A R } " - C " $ { c l a s s e s _ p a t h } " .
2023-11-22 15:28:39 -07:00
D E P E N D S $ < T A R G E T _ P R O P E R T Y : $ { T E S T } - a p k - l i n k e d , O U T P U T S > " $ < T A R G E T _ P R O P E R T Y : S D L 3 : : J a r , J A R _ F I L E > " " $ { J A V A _ P A C K A G E _ D I R } / S D L T e s t A c t i v i t y . j a v a " " $ { J A V A _ P A C K A G E _ D I R } / S D L E n t r y T e s t A c t i v i t y . j a v a "
2023-03-27 04:03:42 -06:00
)
add_custom_target ( ${ TEST } -jar DEPENDS "${OUT_JAR}" )
set_property ( TARGET ${ TEST } -jar PROPERTY OUTPUT "${OUT_JAR}" )
set ( dexworkdir "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${TEST}-dex.dir" )
# Some CMake versions have a slow `cmake -E make_directory` implementation
if ( NOT IS_DIRECTORY "${dexworkdir}" )
execute_process ( COMMAND "${CMAKE_COMMAND}" -E make_directory "${dexworkdir}" )
endif ( )
set ( classes_dex_base_name "classes.dex" )
set ( classes_dex "${dexworkdir}/${classes_dex_base_name}" )
add_custom_command (
O U T P U T " $ { c l a s s e s _ d e x } "
C O M M A N D S d l A n d r o i d : : d 8
$ < T A R G E T _ P R O P E R T Y : $ { T E S T } - j a r , O U T P U T >
2023-11-22 15:28:39 -07:00
$ < T A R G E T _ P R O P E R T Y : S D L 3 : : J a r , J A R _ F I L E >
- - l i b " $ { S D L _ A N D R O I D _ P L A T F O R M _ A N D R O I D _ J A R } "
2023-03-27 04:03:42 -06:00
- - o u t p u t " $ { d e x w o r k d i r } "
2023-11-22 15:28:39 -07:00
D E P E N D S $ < T A R G E T _ P R O P E R T Y : $ { T E S T } - j a r , O U T P U T > $ < T A R G E T _ P R O P E R T Y : S D L 3 : : J a r , J A R _ F I L E >
2023-03-27 04:03:42 -06:00
)
add_custom_target ( ${ TEST } -dex DEPENDS "${classes_dex}" )
set_property ( TARGET ${ TEST } -dex PROPERTY OUTPUT "${classes_dex}" )
set_property ( TARGET ${ TEST } -dex PROPERTY OUTPUT_BASE_NAME "${classes_dex_base_name}" )
sdl_add_to_apk_unaligned ( ${ TEST } -unaligned-apk
A P K _ I N $ { T E S T } - a p k - l i n k e d
O U T D I R " $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / i n t e r m e d i a t e s "
A S S E T S $ { R E S O U R C E _ F I L E S }
N A T I V E _ L I B S S D L 3 : : S D L 3 - s h a r e d $ { T E S T }
D E X $ { T E S T } - d e x
)
sdl_apk_align ( ${ TEST } -aligned-apk ${ TEST } -unaligned-apk
O U T D I R " $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / i n t e r m e d i a t e s "
)
sdl_apk_sign ( ${ TEST } -apk ${ TEST } -aligned-apk
K E Y S T O R E S D L _ t e s t - d e b u g - k e y s t o r e
)
add_dependencies ( sdl-test-apks ${ TEST } -apk )
if ( TARGET SdlAndroid::adb )
add_custom_target ( install- ${ TEST }
C O M M A N D " $ { C M A K E _ C O M M A N D } " - D A C T I O N = i n s t a l l " - D A P K S = $ < T A R G E T _ P R O P E R T Y : $ { T E S T } - a p k , O U T P U T > " - P " $ { S D L 3 _ S O U R C E _ D I R } / c m a k e / a n d r o i d / S d l A n d r o i d S c r i p t . c m a k e "
D E P E N D S " $ { T E S T } - a p k "
)
add_custom_target ( start- ${ TEST }
C O M M A N D " $ { A D B _ B I N } " s h e l l a m s t a r t - a c t i v i t y - S " $ { A N D R O I D _ M A N I F E S T _ P A C K A G E } / . S D L T e s t A c t i v i t y "
)
add_custom_target ( build-install-start- ${ TEST }
C O M M A N D " $ { C M A K E _ C O M M A N D } " - D A C T I O N = b u i l d - i n s t a l l - r u n " - D E X E C U T A B L E S = $ { T E S T } " " - D B U I L D _ F O L D E R = $ { C M A K E _ B I N A R Y _ D I R } " - P " $ { S D L 3 _ S O U R C E _ D I R } / c m a k e / a n d r o i d / S d l A n d r o i d S c r i p t . c m a k e "
)
endif ( )
list ( APPEND packages "${ANDROID_MANIFEST_PACKAGE}" )
list ( APPEND install_targets install- ${ TEST } )
endforeach ( )
if ( TARGET SdlAndroid::adb )
add_custom_target ( install-sdl-test-apks
D E P E N D S $ { i n s t a l l _ t a r g e t s }
V E R B A T I M
)
add_custom_target ( uninstall-sdl-test-apks
C O M M A N D " $ { C M A K E _ C O M M A N D } " " - D A D B = $ < T A R G E T _ F I L E : S d l A n d r o i d : : a d b > " - D A C T I O N = u n i n s t a l l " - D P A C K A G E S = $ { p a c k a g e s } " - P " $ { S D L 3 _ S O U R C E _ D I R } / c m a k e / a n d r o i d / S d l A n d r o i d S c r i p t . c m a k e "
V E R B A T I M
)
endif ( )
endif ( )
endif ( )