diff options
author | 3gg <3gg@shellblade.net> | 2024-05-04 16:51:29 -0700 |
---|---|---|
committer | 3gg <3gg@shellblade.net> | 2024-05-04 16:51:29 -0700 |
commit | 8222bfe56d4dabe8d92fc4b25ea1b0163b16f3e1 (patch) | |
tree | 763389e42276035ac134d94eb1dc32293b88d807 /src/contrib/SDL-2.30.2/cmake/test/CMakeLists.txt |
Initial commit.
Diffstat (limited to 'src/contrib/SDL-2.30.2/cmake/test/CMakeLists.txt')
-rw-r--r-- | src/contrib/SDL-2.30.2/cmake/test/CMakeLists.txt | 124 |
1 files changed, 124 insertions, 0 deletions
diff --git a/src/contrib/SDL-2.30.2/cmake/test/CMakeLists.txt b/src/contrib/SDL-2.30.2/cmake/test/CMakeLists.txt new file mode 100644 index 0000000..388e86c --- /dev/null +++ b/src/contrib/SDL-2.30.2/cmake/test/CMakeLists.txt | |||
@@ -0,0 +1,124 @@ | |||
1 | # This cmake build script is meant for verifying the various CMake configuration script. | ||
2 | |||
3 | cmake_minimum_required(VERSION 3.12) | ||
4 | project(sdl_test LANGUAGES C) | ||
5 | |||
6 | include(GenerateExportHeader) | ||
7 | |||
8 | if(ANDROID) | ||
9 | macro(add_executable NAME) | ||
10 | set(args ${ARGN}) | ||
11 | list(REMOVE_ITEM args WIN32) | ||
12 | add_library(${NAME} SHARED ${args}) | ||
13 | unset(args) | ||
14 | endmacro() | ||
15 | endif() | ||
16 | |||
17 | cmake_policy(SET CMP0074 NEW) | ||
18 | |||
19 | # Override CMAKE_FIND_ROOT_PATH_MODE to allow search for SDL2 outside of sysroot | ||
20 | set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE NEVER) | ||
21 | |||
22 | include(FeatureSummary) | ||
23 | |||
24 | option(TEST_SHARED "Test linking to shared SDL2 library" ON) | ||
25 | add_feature_info("TEST_SHARED" TEST_SHARED "Test linking with shared library") | ||
26 | |||
27 | option(TEST_STATIC "Test linking to static SDL2 library" ON) | ||
28 | add_feature_info("TEST_STATIC" TEST_STATIC "Test linking with static library") | ||
29 | |||
30 | if(TEST_SHARED) | ||
31 | find_package(SDL2 REQUIRED CONFIG COMPONENTS SDL2) | ||
32 | if(EMSCRIPTEN OR (WIN32 AND NOT WINDOWS_STORE)) | ||
33 | find_package(SDL2 REQUIRED CONFIG COMPONENTS SDL2main) | ||
34 | endif() | ||
35 | add_executable(gui-shared WIN32 main_gui.c) | ||
36 | if(TARGET SDL2::SDL2main) | ||
37 | target_link_libraries(gui-shared PRIVATE SDL2::SDL2main) | ||
38 | endif() | ||
39 | target_link_libraries(gui-shared PRIVATE SDL2::SDL2) | ||
40 | if(WIN32) | ||
41 | add_custom_command(TARGET gui-shared POST_BUILD | ||
42 | COMMAND ${CMAKE_COMMAND} -E copy_if_different "$<TARGET_FILE:SDL2::SDL2>" "$<TARGET_FILE_DIR:gui-shared>" | ||
43 | ) | ||
44 | endif() | ||
45 | |||
46 | add_library(sharedlib-shared SHARED main_lib.c) | ||
47 | target_link_libraries(sharedlib-shared PRIVATE SDL2::SDL2) | ||
48 | generate_export_header(sharedlib-shared EXPORT_MACRO_NAME MYLIBRARY_EXPORT) | ||
49 | target_compile_definitions(sharedlib-shared PRIVATE "EXPORT_HEADER=\"${CMAKE_CURRENT_BINARY_DIR}/sharedlib-shared_export.h\"") | ||
50 | set_target_properties(sharedlib-shared PROPERTIES C_VISIBILITY_PRESET "hidden") | ||
51 | |||
52 | add_executable(gui-shared-vars WIN32 main_gui.c) | ||
53 | target_link_libraries(gui-shared-vars PRIVATE ${SDL2_LIBRARIES}) | ||
54 | target_include_directories(gui-shared-vars PRIVATE ${SDL2_INCLUDE_DIRS}) | ||
55 | |||
56 | add_executable(cli-shared main_cli.c) | ||
57 | target_link_libraries(cli-shared PRIVATE SDL2::SDL2) | ||
58 | if(WIN32) | ||
59 | add_custom_command(TARGET cli-shared POST_BUILD | ||
60 | COMMAND ${CMAKE_COMMAND} -E copy_if_different "$<TARGET_FILE:SDL2::SDL2>" "$<TARGET_FILE_DIR:cli-shared>" | ||
61 | ) | ||
62 | endif() | ||
63 | |||
64 | # SDL2_LIBRARIES does not support creating a cli SDL2 application | ||
65 | # (it is possible that SDL2main is a stub, but we don't know for sure) | ||
66 | if(NOT TARGET SDL2::SDL2main) | ||
67 | add_executable(cli-shared-vars main_cli.c) | ||
68 | target_link_libraries(cli-shared-vars PRIVATE ${SDL2_LIBRARIES}) | ||
69 | target_include_directories(cli-shared-vars PRIVATE ${SDL2_INCLUDE_DIRS}) | ||
70 | endif() | ||
71 | |||
72 | add_library(sharedlib-shared-vars SHARED main_lib.c) | ||
73 | target_link_libraries(sharedlib-shared-vars PRIVATE ${SDL2_LIBRARIES}) | ||
74 | target_include_directories(sharedlib-shared-vars PRIVATE ${SDL2_INCLUDE_DIRS}) | ||
75 | generate_export_header(sharedlib-shared-vars EXPORT_MACRO_NAME MYLIBRARY_EXPORT) | ||
76 | target_compile_definitions(sharedlib-shared-vars PRIVATE "EXPORT_HEADER=\"${CMAKE_CURRENT_BINARY_DIR}/sharedlib-shared-vars_export.h\"") | ||
77 | set_target_properties(sharedlib-shared-vars PROPERTIES C_VISIBILITY_PRESET "hidden") | ||
78 | endif() | ||
79 | |||
80 | if(TEST_STATIC) | ||
81 | find_package(SDL2 REQUIRED CONFIG COMPONENTS SDL2-static) | ||
82 | if(EMSCRIPTEN OR (WIN32 AND NOT WINDOWS_STORE)) | ||
83 | find_package(SDL2 REQUIRED CONFIG COMPONENTS SDL2main) | ||
84 | endif() | ||
85 | add_executable(gui-static WIN32 main_gui.c) | ||
86 | if(TARGET SDL2::SDL2main) | ||
87 | target_link_libraries(gui-static PRIVATE SDL2::SDL2main) | ||
88 | endif() | ||
89 | target_link_libraries(gui-static PRIVATE SDL2::SDL2-static) | ||
90 | |||
91 | option(SDL_STATIC_PIC "SDL static library has been built with PIC") | ||
92 | if(SDL_STATIC_PIC OR WIN32) | ||
93 | add_library(sharedlib-static SHARED main_lib.c) | ||
94 | target_link_libraries(sharedlib-static PRIVATE SDL2::SDL2-static) | ||
95 | generate_export_header(sharedlib-static EXPORT_MACRO_NAME MYLIBRARY_EXPORT) | ||
96 | target_compile_definitions(sharedlib-static PRIVATE "EXPORT_HEADER=\"${CMAKE_CURRENT_BINARY_DIR}/sharedlib-static_export.h\"") | ||
97 | set_target_properties(sharedlib-static PROPERTIES C_VISIBILITY_PRESET "hidden") | ||
98 | endif() | ||
99 | |||
100 | add_executable(gui-static-vars WIN32 main_gui.c) | ||
101 | target_link_libraries(gui-static-vars PRIVATE ${SDL2MAIN_LIBRARY} ${SDL2_STATIC_LIBRARIES}) | ||
102 | target_include_directories(gui-static-vars PRIVATE ${SDL2_INCLUDE_DIRS}) | ||
103 | |||
104 | add_executable(cli-static main_cli.c) | ||
105 | target_link_libraries(cli-static PRIVATE SDL2::SDL2-static) | ||
106 | |||
107 | # SDL2_LIBRARIES does not support creating a cli SDL2 application (when SDL2::SDL2main is available) | ||
108 | # (it is possible that SDL2main is a stub, but we don't know for sure) | ||
109 | if(NOT TARGET SDL2::SDL2main) | ||
110 | add_executable(cli-static-vars main_cli.c) | ||
111 | target_link_libraries(cli-static-vars PRIVATE ${SDL2_STATIC_LIBRARIES}) | ||
112 | target_include_directories(cli-static-vars PRIVATE ${SDL2_INCLUDE_DIRS}) | ||
113 | endif() | ||
114 | endif() | ||
115 | |||
116 | message(STATUS "SDL2_PREFIX: ${SDL2_PREFIX}") | ||
117 | message(STATUS "SDL2_INCLUDE_DIR: ${SDL2_INCLUDE_DIR}") | ||
118 | message(STATUS "SDL2_INCLUDE_DIRS: ${SDL2_INCLUDE_DIRS}") | ||
119 | message(STATUS "SDL2_LIBRARIES: ${SDL2_LIBRARIES}") | ||
120 | message(STATUS "SDL2_STATIC_LIBRARIES: ${SDL2_STATIC_LIBRARIES}") | ||
121 | message(STATUS "SDL2MAIN_LIBRARY: ${SDL2MAIN_LIBRARY}") | ||
122 | message(STATUS "SDL2TEST_LIBRARY: ${SDL2TEST_LIBRARY}") | ||
123 | |||
124 | feature_summary(WHAT ALL) | ||