Skip to content

Commit db831d2

Browse files
committed
Update wikiheaders.pl and PrivateSdlFunctions.cmake
1 parent ee90d1e commit db831d2

File tree

2 files changed

+53
-27
lines changed

2 files changed

+53
-27
lines changed

build-scripts/wikiheaders.pl

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@
3737
my $versionmajorregex = '\A\#define\s+SDL_MAJOR_VERSION\s+(\d+)\Z';
3838
my $versionminorregex = '\A\#define\s+SDL_MINOR_VERSION\s+(\d+)\Z';
3939
my $versionmicroregex = '\A\#define\s+SDL_MICRO_VERSION\s+(\d+)\Z';
40+
my $wikidocsectionsym = 'SDL_WIKI_DOCUMENTATION_SECTION';
41+
my $forceinlinesym = 'SDL_FORCE_INLINE';
42+
my $deprecatedsym = 'SDL_DEPRECATED';
43+
my $declspecsym = '(?:SDLMAIN_|SDL_)?DECLSPEC';
44+
my $callconvsym = 'SDLCALL';
4045
my $mainincludefname = 'SDL.h';
4146
my $selectheaderregex = '\ASDL.*?\.h\Z';
4247
my $projecturl = 'https://libsdl.org/';
@@ -147,6 +152,12 @@
147152
$envvardesc = $val, next if $key eq 'envvardesc';
148153
$envvarsymregex = $val, next if $key eq 'envvarsymregex';
149154
$envvarsymreplace = $val, next if $key eq 'envvarsymreplace';
155+
$wikidocsectionsym = $val, next if $key eq 'wikidocsectionsym';
156+
$forceinlinesym = $val, next if $key eq 'forceinlinesym';
157+
$deprecatedsym = $val, next if $key eq 'deprecatedsym';
158+
$declspecsym = $val, next if $key eq 'declspecsym';
159+
$callconvsym = $val, next if $key eq 'callconvsym';
160+
150161
}
151162
}
152163
close(OPTIONS);
@@ -750,6 +761,7 @@ sub print_undocumented_section {
750761
}
751762
}
752763

764+
# !!! FIXME: generalize this for other libraries to use.
753765
sub strip_fn_declaration_metadata {
754766
my $decl = shift;
755767
$decl =~ s/SDL_(PRINTF|SCANF)_FORMAT_STRING\s*//; # don't want this metadata as part of the documentation.
@@ -1153,7 +1165,7 @@ sub generate_envvar_wiki_page {
11531165
} elsif ($ignoring_lines) {
11541166
push @contents, $_;
11551167
next;
1156-
} elsif (/\A\s*\#\s*ifndef\s+SDL_WIKI_DOCUMENTATION_SECTION\s*\Z/) {
1168+
} elsif (/\A\s*\#\s*ifndef\s+$wikidocsectionsym\s*\Z/) {
11571169
$ignoring_lines = 1;
11581170
push @contents, $_;
11591171
next;
@@ -1162,13 +1174,13 @@ sub generate_envvar_wiki_page {
11621174
#print("CATEGORY FOR '$dent' CHANGED TO " . (defined($current_wiki_category) ? "'$current_wiki_category'" : '(undef)') . "\n");
11631175
push @contents, $_;
11641176
next;
1165-
} elsif (/\A\s*extern\s+(SDL_DEPRECATED\s+|)(SDLMAIN_|SDL_)?DECLSPEC/) { # a function declaration without a doxygen comment?
1177+
} elsif (/\A\s*extern\s+(?:$deprecatedsym\s+|)$declspecsym/) { # a function declaration without a doxygen comment?
11661178
$symtype = 1; # function declaration
11671179
@templines = ();
11681180
$decl = $_;
11691181
$str = '';
11701182
$has_doxygen = 0;
1171-
} elsif (/\A\s*SDL_FORCE_INLINE/) { # a (forced-inline) function declaration without a doxygen comment?
1183+
} elsif (/\A\s*$forceinlinesym/) { # a (forced-inline) function declaration without a doxygen comment?
11721184
$symtype = 1; # function declaration
11731185
@templines = ();
11741186
$decl = $_;
@@ -1235,9 +1247,9 @@ sub generate_envvar_wiki_page {
12351247
$lineno++ if defined $decl;
12361248
$decl = '' if not defined $decl;
12371249
chomp($decl);
1238-
if ($decl =~ /\A\s*extern\s+(SDL_DEPRECATED\s+|)(SDLMAIN_|SDL_)?DECLSPEC/) {
1250+
if ($decl =~ /\A\s*extern\s+(?:$deprecatedsym\s+|)$declspecsym/) {
12391251
$symtype = 1; # function declaration
1240-
} elsif ($decl =~ /\A\s*SDL_FORCE_INLINE/) {
1252+
} elsif ($decl =~ /\A\s*$forceinlinesym/) {
12411253
$symtype = 1; # (forced-inline) function declaration
12421254
} elsif ($decl =~ /\A\s*\#\s*define\s+/) {
12431255
$symtype = 2; # macro
@@ -1274,7 +1286,7 @@ sub generate_envvar_wiki_page {
12741286
}
12751287
$headercategorydocs{$current_wiki_category} = $sym;
12761288
} elsif ($symtype == 1) { # a function
1277-
my $is_forced_inline = ($decl =~ /\A\s*SDL_FORCE_INLINE/);
1289+
my $is_forced_inline = ($decl =~ /\A\s*$forceinlinesym/);
12781290

12791291
if ($is_forced_inline) {
12801292
if (not $decl =~ /\)\s*(\{.*|)\s*\Z/) {
@@ -1311,14 +1323,14 @@ sub generate_envvar_wiki_page {
13111323

13121324
my $paramsstr = undef;
13131325

1314-
if (!$is_forced_inline && $decl =~ /\A\s*extern\s+(SDL_DEPRECATED\s+|)(SDLMAIN_|SDL_)?DECLSPEC\w*\s+(const\s+|)(unsigned\s+|)(.*?)([\*\s]+)(\*?)\s*SDLCALL\s+(.*?)\s*\((.*?)\);/) {
1315-
$sym = $8;
1316-
$rettype = "$3$4$5$6";
1317-
$paramsstr = $9;
1318-
} elsif ($is_forced_inline && $decl =~ /\A\s*SDL_FORCE_INLINE\s+(SDL_DEPRECATED\s+|)(const\s+|)(unsigned\s+|)(.*?)([\*\s]+)(.*?)\s*\((.*?)\);/) {
1326+
if (!$is_forced_inline && $decl =~ /\A\s*extern\s+(?:$deprecatedsym\s+|)$declspecsym\w*\s+(const\s+|)(unsigned\s+|)(.*?)([\*\s]+)(\*?)\s*$callconvsym\s+(.*?)\s*\((.*?)\);/) {
13191327
$sym = $6;
1320-
$rettype = "$2$3$4$5";
1328+
$rettype = "$1$2$3$4$5";
13211329
$paramsstr = $7;
1330+
} elsif ($is_forced_inline && $decl =~ /\A\s*$forceinlinesym\s+(?:$deprecatedsym\s+|)(const\s+|)(unsigned\s+|)(.*?)([\*\s]+)(.*?)\s*\((.*?)\);/) {
1331+
$sym = $5;
1332+
$rettype = "$1$2$3$4";
1333+
$paramsstr = $6;
13221334
} else {
13231335
#print "Found doxygen but no function sig:\n$str\n\n";
13241336
foreach (@templines) {
@@ -1384,7 +1396,7 @@ sub generate_envvar_wiki_page {
13841396

13851397
$decl = $_;
13861398
$temp = $decl;
1387-
$temp =~ s/\Aextern\s+(SDL_DEPRECATED\s+|)(SDLMAIN_|SDL_)?DECLSPEC\w*\s+(.*?)\s+(\*?)SDLCALL\s+/$3$4 /;
1399+
$temp =~ s/\Aextern\s+(?:$deprecatedsym\s+|)$declspecsym\w*\s+(.*?)\s+(\*?)$callconvsym\s+/$1$2 /;
13881400
$shrink_length = length($decl) - length($temp);
13891401
$decl = $temp;
13901402
} else {
@@ -2259,10 +2271,10 @@ sub generate_envvar_wiki_page {
22592271

22602272
$desc =~ s/[\s\n]+\Z//ms;
22612273

2262-
if (0) { # !!! FIXME: disabled because it's not currently suitable for general use, but for manually inspecting the output, it can be useful.
2263-
if (($desc =~ /\A[A-Z]/) && (not $desc =~ /\ASDL_/)) {
2264-
print STDERR "WARNING: $sym\'s '\\param $arg' text starts with a capital letter: '$desc'. Fixing.\n";
2265-
$desc = lcfirst($desc);
2274+
if (0) {
2275+
if (($desc =~ /\A[a-z]/) && (not $desc =~ /$apiprefixregex/)) {
2276+
print STDERR "WARNING: $sym\'s '\\param $arg' text starts with a lowercase letter: '$desc'. Fixing.\n";
2277+
$desc = ucfirst($desc);
22662278
}
22672279
}
22682280

@@ -2306,8 +2318,8 @@ sub generate_envvar_wiki_page {
23062318
}
23072319
$desc =~ s/[\s\n]+\Z//ms;
23082320

2309-
if (0) { # !!! FIXME: disabled because it's not currently suitable for general use, but for manually inspecting the output, it can be useful.
2310-
if (($desc =~ /\A[A-Z]/) && (not $desc =~ /\ASDL_/)) {
2321+
if (0) {
2322+
if (($desc =~ /\A[A-Z]/) && (not $desc =~ /$apiprefixregex/)) {
23112323
print STDERR "WARNING: $sym\'s '\\returns' text starts with a capital letter: '$desc'. Fixing.\n";
23122324
$desc = lcfirst($desc);
23132325
}
@@ -2451,7 +2463,7 @@ sub generate_envvar_wiki_page {
24512463
} else {
24522464
die("Unexpected symbol type $symtype!");
24532465
}
2454-
my $str = "This $symtypename is available since SDL 3.0.0.";
2466+
my $str = "This $symtypename is available since $projectshortname 3.0.0.";
24552467
$sections{'Version'} = wordwrap(wikify($wikitype, $str)) . "\n";
24562468
}
24572469
}
@@ -2916,7 +2928,7 @@ sub generate_envvar_wiki_page {
29162928
$str .= ".\\\" Please report issues in this manpage's content at:\n";
29172929
$str .= ".\\\" $bugreporturl\n";
29182930
$str .= ".\\\" Please report issues in the generation of this manpage from the wiki at:\n";
2919-
$str .= ".\\\" https://github.com/libsdl-org/SDL/issues/new?title=Misgenerated%20manpage%20for%20$sym\n";
2931+
$str .= ".\\\" https://github.com/libsdl-org/SDL/issues/new?title=Misgenerated%20manpage%20for%20$sym\n"; # !!! FIXME: if this becomes a problem for other projects, we'll generalize this.
29202932
$str .= ".\\\" $projectshortname can be found at $projecturl\n";
29212933

29222934
# Define a .URL macro. The "www.tmac" thing decides if we're using GNU roff (which has a .URL macro already), and if so, overrides the macro we just created.

cmake/PrivateSdlFunctions.cmake

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
include(CheckCCompilerFlag)
44
include(CheckCSourceCompiles)
55
include(CMakePushCheckState)
6+
if(NOT CMAKE_VERSION VERSION_LESS "3.18")
7+
include(CheckLinkerFlag)
8+
endif()
69

710
macro(sdl_calculate_derived_version_variables MAJOR MINOR MICRO)
811
set(SO_VERSION_MAJOR "0")
@@ -241,11 +244,14 @@ function(sdl_check_project_in_subfolder relative_subfolder name vendored_option)
241244
endfunction()
242245

243246
macro(sdl_check_linker_flag flag var)
244-
# FIXME: Use CheckLinkerFlag module once cmake minimum version >= 3.18
245-
cmake_push_check_state(RESET)
246-
set(CMAKE_REQUIRED_LINK_OPTIONS "${flag}")
247-
check_c_source_compiles("int main() { return 0; }" ${var} FAIL_REGEX "(unsupported|syntax error|unrecognized option)")
248-
cmake_pop_check_state()
247+
if(NOT CMAKE_VERSION VERSION_LESS "3.18")
248+
check_linker_flag(C "${flag}" "${var}")
249+
else()
250+
cmake_push_check_state(RESET)
251+
set(CMAKE_REQUIRED_LINK_OPTIONS "${flag}")
252+
check_c_source_compiles("int main() { return 0; }" ${var} FAIL_REGEX "(unsupported|syntax error|unrecognized option)")
253+
cmake_pop_check_state()
254+
endif()
249255
endmacro()
250256

251257
function(SDL_detect_linker)
@@ -283,7 +289,6 @@ endfunction()
283289
function(sdl_target_link_options_no_undefined TARGET)
284290
if(NOT MSVC AND NOT CMAKE_SYSTEM_NAME MATCHES ".*OpenBSD.*")
285291
if(CMAKE_C_COMPILER_ID MATCHES "AppleClang")
286-
target_link_options(${TARGET} PRIVATE "-Wl,-undefined,error")
287292
else()
288293
sdl_check_linker_flag("-Wl,--no-undefined" HAVE_WL_NO_UNDEFINED)
289294
if(HAVE_WL_NO_UNDEFINED AND NOT ((CMAKE_C_COMPILER_ID MATCHES "Clang") AND WIN32))
@@ -318,6 +323,15 @@ function(sdl_add_warning_options TARGET)
318323
else()
319324
target_compile_options(${TARGET} PRIVATE -Werror)
320325
endif()
326+
get_property(target_type TARGET ${TARGET} PROPERTY TYPE)
327+
if(NOT (APPLE OR MSVC))
328+
if(target_type MATCHES "SHARED_LIBRARY|MODULE_LIBRARY")
329+
sdl_check_linker_flag("-Wl,-fatal-warnings" HAVE_WL_FATAL_WARNINGS)
330+
if(HAVE_WL_FATAL_WARNINGS)
331+
target_link_options(${TARGET} PRIVATE "-Wl,-fatal-warnings")
332+
endif()
333+
endif()
334+
endif()
321335
endif()
322336
endfunction()
323337

0 commit comments

Comments
 (0)