1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
https://github.com/libsdl-org/SDL/commit/329794daf3f58088b56a64bdfa36b2021903be20
https://github.com/libsdl-org/SDL/commit/62302d08f13ca5303135505c6b355afbbf069745
From: Anonymous Maarten <anonymous.maarten@gmail.com>
Date: Sun, 21 Aug 2022 04:03:32 +0200
Subject: [PATCH] cmake: add library directories & pthread to imported targets
of sdl2-config.cmake
This fixes linking to SDL2::SDL2-static on systems where external libraries such as X11 are not in a standard location.
Pthread also needs special care.
--- a/sdl2-config.cmake.in
+++ b/sdl2-config.cmake.in
@@ -39,18 +39,25 @@ unset(bindir)
unset(libdir)
unset(includedir)
-set(_sdl2_libraries "@SDL_LIBS@")
-set(_sdl2_static_private_libs "@SDL_STATIC_LIBS@")
+set(_sdl2_libraries_in "@SDL_LIBS@")
+set(_sdl2_static_private_libs_in "@SDL_STATIC_LIBS@")
-# Convert _sdl2_libraries to list and keep only libraries
-string(REGEX MATCHALL "-[lm]([-a-zA-Z0-9._]+)" _sdl2_libraries "${_sdl2_libraries}")
+# Convert _sdl2_libraries to list and keep only libraries + library directories
+string(REGEX MATCHALL "-[lm]([-a-zA-Z0-9._]+)" _sdl2_libraries "${_sdl2_libraries_in}")
string(REGEX REPLACE "^-l" "" _sdl2_libraries "${_sdl2_libraries}")
string(REGEX REPLACE ";-l" ";" _sdl2_libraries "${_sdl2_libraries}")
+string(REGEX MATCHALL "-L([-a-zA-Z0-9._/]+)" _sdl2_libdirs "${_sdl2_libraries_in}")
+string(REGEX REPLACE "^-L" "" _sdl2_libdirs "${_sdl2_libdirs}")
+string(REGEX REPLACE ";-L" ";" _sdl2_libdirs "${_sdl2_libdirs}")
+list(APPEND _sdl2_libdirs "${SDL2_LIBDIR}")
-# Convert _sdl2_static_private_libs to list and keep only libraries
-string(REGEX MATCHALL "(-[lm]([-a-zA-Z0-9._]+))|(-Wl,[^ ]*framework[^ ]*)" _sdl2_static_private_libs "${_sdl2_static_private_libs}")
+# Convert _sdl2_static_private_libs to list and keep only libraries + library directories
+string(REGEX MATCHALL "(-[lm]([-a-zA-Z0-9._]+))|(-Wl,[^ ]*framework[^ ]*)|(-pthread)" _sdl2_static_private_libs "${_sdl2_static_private_libs_in}")
string(REGEX REPLACE "^-l" "" _sdl2_static_private_libs "${_sdl2_static_private_libs}")
string(REGEX REPLACE ";-l" ";" _sdl2_static_private_libs "${_sdl2_static_private_libs}")
+string(REGEX MATCHALL "-L([-a-zA-Z0-9._/]+)" _sdl2_static_private_libdirs "${_sdl2_static_private_libs_in}")
+string(REGEX REPLACE "^-L" "" _sdl2_static_private_libdirs "${_sdl2_static_private_libdirs}")
+string(REGEX REPLACE ";-L" ";" _sdl2_static_private_libdirs "${_sdl2_static_private_libdirs}")
if(_sdl2_libraries MATCHES ".*SDL2main.*")
list(INSERT SDL2_LIBRARIES 0 SDL2::SDL2main)
@@ -103,6 +110,7 @@ if(WIN32)
set_target_properties(SDL2::SDL2 PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIR}"
INTERFACE_LINK_LIBRARIES "${_sdl2_link_libraries}"
+ INTERFACE_LINK_DIRECTORIES "${_sdl2_libdirs}"
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
IMPORTED_IMPLIB "${_sdl2_implib}"
IMPORTED_LOCATION "${_sdl2_dll}"
@@ -122,6 +130,7 @@ else()
set_target_properties(SDL2::SDL2 PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIR}"
INTERFACE_LINK_LIBRARIES "${_sdl2_link_libraries}"
+ INTERFACE_LINK_DIRECTORIES "${_sdl2_libdirs}"
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
IMPORTED_LOCATION "${_sdl2_shared}"
)
@@ -142,6 +151,7 @@ if(EXISTS "${_sdl2_static}")
IMPORTED_LOCATION "${_sdl2_static}"
INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIR}"
INTERFACE_LINK_LIBRARIES "${_sdl2_link_libraries};${_sdl2_static_private_libs}"
+ INTERFACE_LINK_DIRECTORIES "${_sdl2_libdirs};${_sdl2_static_private_libdirs}"
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
)
endif()
From: Anonymous Maarten <anonymous.maarten@gmail.com>
Date: Wed, 24 Aug 2022 04:14:52 +0200
Subject: [PATCH] cmake: always create SDL2::SDL2main target in autotools'
cmake config script
--- a/sdl2-config.cmake.in
+++ b/sdl2-config.cmake.in
@@ -62,38 +62,39 @@ string(REGEX REPLACE ";-L" ";" _sdl2_static_private_libdirs "${_sdl2_static_priv
if(_sdl2_libraries MATCHES ".*SDL2main.*")
list(INSERT SDL2_LIBRARIES 0 SDL2::SDL2main)
list(INSERT SDL2_STATIC_LIBRARIES 0 SDL2::SDL2main)
- set(_sdl2main_library ${SDL2_LIBDIR}/${CMAKE_STATIC_LIBRARY_PREFIX}SDL2main${CMAKE_STATIC_LIBRARY_SUFFIX})
- if(EXISTS "${_sdl2main_library}")
- set(SDL2MAIN_LIBRARY SDL2::SDL2main)
- if(NOT TARGET SDL2::SDL2main)
- add_library(SDL2::SDL2main STATIC IMPORTED)
- set_target_properties(SDL2::SDL2main
- PROPERTIES
- IMPORTED_LOCATION "${_sdl2main_library}"
- )
- if(WIN32)
- # INTERFACE_LINK_OPTIONS needs CMake 3.13
- cmake_minimum_required(VERSION 3.13)
- # Mark WinMain/WinMain@16 as undefined, such that it will be withheld by the linker.
- if(CMAKE_SIZEOF_VOID_P EQUAL 4)
- set_target_properties(SDL2::SDL2main
- PROPERTIES
- INTERFACE_LINK_OPTIONS "-Wl,--undefined=_WinMain@16"
- )
- else()
- set_target_properties(SDL2::SDL2main
- PROPERTIES
- INTERFACE_LINK_OPTIONS "-Wl,--undefined=WinMain"
- )
- endif()
+endif()
+
+set(_sdl2main_library ${SDL2_LIBDIR}/${CMAKE_STATIC_LIBRARY_PREFIX}SDL2main${CMAKE_STATIC_LIBRARY_SUFFIX})
+if(EXISTS "${_sdl2main_library}")
+ set(SDL2MAIN_LIBRARY SDL2::SDL2main)
+ if(NOT TARGET SDL2::SDL2main)
+ add_library(SDL2::SDL2main STATIC IMPORTED)
+ set_target_properties(SDL2::SDL2main
+ PROPERTIES
+ IMPORTED_LOCATION "${_sdl2main_library}"
+ )
+ if(WIN32)
+ # INTERFACE_LINK_OPTIONS needs CMake 3.13
+ cmake_minimum_required(VERSION 3.13)
+ # Mark WinMain/WinMain@16 as undefined, such that it will be withheld by the linker.
+ if(CMAKE_SIZEOF_VOID_P EQUAL 4)
+ set_target_properties(SDL2::SDL2main
+ PROPERTIES
+ INTERFACE_LINK_OPTIONS "-Wl,--undefined=_WinMain@16"
+ )
+ else()
+ set_target_properties(SDL2::SDL2main
+ PROPERTIES
+ INTERFACE_LINK_OPTIONS "-Wl,--undefined=WinMain"
+ )
endif()
endif()
- set(SDL2_SDL2main_FOUND TRUE)
- else()
- set(SDL2_SDL2main_FOUND FALSE)
endif()
- unset(_sdl2main_library)
+ set(SDL2_SDL2main_FOUND TRUE)
+else()
+ set(SDL2_SDL2main_FOUND FALSE)
endif()
+unset(_sdl2main_library)
# Remove SDL2 since this is the "central" library
# Remove SDL2main since this will be provided by SDL2::SDL2main (if available)
|