Skip to content

Commit 967a044

Browse files
committed
Got .lib and .dlls setup for the C11 library
1 parent b5cf633 commit 967a044

8 files changed

Lines changed: 158 additions & 88 deletions

File tree

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@
5656
"new": "cpp",
5757
"typeinfo": "cpp",
5858
"unordered_map": "cpp",
59-
"xstddef": "cpp"
59+
"xstddef": "cpp",
60+
"gen_singleheader.h": "c"
6061
},
6162
"C_Cpp.intelliSenseEngineFallback": "disabled",
6263
"mesonbuild.configureOnOpen": true,

base/dependencies/macros.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
#if GEN_COMPILER_MSVC
99
#ifdef GEN_DYN_LINK
10-
#ifdef GEN_EXPORTS
10+
#ifdef GEN_DYN_EXPORT
1111
#define GEN_API __declspec(dllexport)
1212
#else
1313
#define GEN_API __declspec(dllimport)

gen_c_library/c_library.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ do \
641641
if ( array_token->Front == array_entry )
642642
array_token->Front = next;
643643

644-
parser_types.append(array_entry);
644+
parser_types.append(array_entry);
645645
continue_for = false;
646646
}
647647
break;

gen_c_library/gen_c_lib.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#define GEN_IMPLEMENTATION
2+
#define GEN_DONT_ENFORCE_GEN_TIME_GUARD
3+
#include "gen/gen_singleheader.h"

scripts/build.ci.ps1

Lines changed: 51 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ Push-Location $path_root
1818
$vendor = $null
1919
$release = $null
2020
[bool] $verbose = $false
21-
[bool] $shared = $false
22-
[bool] $dyn_link = $false
2321
[bool] $base = $false
2422
[bool] $segmented = $false
2523
[bool] $singleheader = $false
26-
[bool] $c_library = $false
24+
[bool] $c_lib = $false
25+
[bool] $c_lib_static = $false
26+
[bool] $c_lib_dyn = $false
2727
[bool] $unreal = $false
2828
[bool] $test = $false
2929

@@ -37,12 +37,12 @@ if ( $args ) { $args | ForEach-Object {
3737
"verbose" { $verbose = $true }
3838
"release" { $release = $true }
3939
"debug" { $release = $false }
40-
"shared" { $shared = $true }
41-
"dyn_link" { $dyn_link = $true }
4240
"base" { $base = $true }
4341
"segmented" { $segmented = $true }
4442
"singleheader" { $singleheader = $true }
45-
"c_library" { $c_library = $true }
43+
"c_lib" { $c_lib = $true }
44+
"c_lib_static" { $c_lib_static = $true }
45+
"c_lib_dyn" { $c_lib_dyn = $true }
4646
"unreal" { $unreal = $true }
4747
"test" { $test = $true }
4848
}
@@ -75,7 +75,9 @@ else {
7575
$cannot_build = $base -eq $false
7676
$cannot_build = $cannot_build -and $segmented -eq $false
7777
$cannot_build = $cannot_build -and $singleheader -eq $false
78-
$cannot_build = $cannot_build -and $c_library -eq $false
78+
$cannot_build = $cannot_build -and $c_lib -eq $false
79+
$cannot_build = $cannot_build -and $c_lib_static -eq $false
80+
$cannot_build = $cannot_build -and $c_lib_dyn -eq $false
7981
$cannot_build = $cannot_build -and $unreal -eq $false
8082
$cannot_build = $cannot_build -and $test -eq $false
8183
if ( $cannot_build ) {
@@ -213,7 +215,7 @@ if ( $singleheader )
213215
Pop-Location
214216
}
215217

216-
if ( $c_library )
218+
if ( $c_lib -or $c_lib_static -or $c_lib_dyn )
217219
{
218220
$path_build = join-path $path_c_library build
219221
$path_gen = join-path $path_c_library gen
@@ -249,34 +251,38 @@ if ( $c_library )
249251
write-host "`nc_library generator completed in $($time_taken.TotalMilliseconds) ms"
250252
}
251253
Pop-Location
254+
}
252255

253-
$includes = @( $path_c_library )
254-
$unit = join-path $path_c_library "gen.c"
255-
$executable = join-path $path_build "gen_c_library_test.exe"
256-
257-
if ($vendor -eq "clang") {
258-
$compiler_args += '-x'
259-
$compiler_args += 'c'
260-
$compiler_args += '-std=c11'
261-
} elseif ($vendor -eq "msvc") {
262-
$compiler_args += "/TC" # Compile as C
263-
$compiler_args += "/Zc:__cplusplus" # Fix __cplusplus macro
264-
$compiler_args += "/std:c11"
265-
}
256+
if ( $c_lib_static )
257+
{
258+
$includes = @( $path_c_library )
259+
$unit = join-path $path_c_library "gen_c_lib.c"
260+
$path_lib = join-path $path_build "gencpp_c11.lib"
266261

267-
$result = build-simple $path_build $includes $compiler_args $linker_args $unit $executable
262+
$compiler_args = @()
263+
$compiler_args += $flag_all_c
264+
$compiler_args += $flag_updated_cpp_macro
265+
$compiler_args += $flag_c11
268266

269-
Push-Location $path_c_library
270-
if ( Test-Path( $executable ) ) {
271-
write-host "`nRunning c_library test"
272-
$time_taken = Measure-Command { & $executable
273-
| ForEach-Object {
274-
write-host `t $_ -ForegroundColor Green
275-
}
276-
}
277-
write-host "`nc_library generator completed in $($time_taken.TotalMilliseconds) ms"
278-
}
279-
Pop-Location
267+
$linker_args = @()
268+
$result = build-simple $path_build $includes $compiler_args $linker_args $unit $path_lib
269+
}
270+
271+
if ( $c_lib_dyn )
272+
{
273+
$includes = @( $path_c_library )
274+
$unit = join-path $path_c_library "gen_c_lib.c"
275+
$path_dll = join-path $path_build "gencpp_c11.dll"
276+
277+
$compiler_args = @()
278+
$compiler_args += $flag_all_c
279+
$compiler_args += $flag_updated_cpp_macro
280+
$compiler_args += $flag_c11
281+
$compiler_args += ( $flag_define + 'GEN_DYN_LINK' )
282+
$compiler_args += ( $flag_define + 'GEN_DYN_EXPORT' )
283+
284+
$linker_args = @()
285+
$result = build-simple $path_build $includes $compiler_args $linker_args $unit $path_dll
280286
}
281287

282288
if ( $unreal )
@@ -319,64 +325,40 @@ if ( $unreal )
319325
. $refactor_unreal
320326
}
321327

322-
# TODO(Ed): The unit testing needs a full rewrite
323-
if ( $test -and $false )
328+
if ( $test )
324329
{
325-
$path_gen = join-path $path_test gen
326-
$path_gen_build = join-path $path_gen build
327-
$path_build = join-path $path_test build
328-
$path_original = join-path $path_gen original
329-
$path_components = join-path $path_original components
330-
$path_dependencies = join-path $path_original dependencies
331-
$path_helpers = join-path $path_original helpers
330+
$path_test_c_lib = join-path $path_test c_library
331+
$path_build = join-path $path_test_c_lib build
332332

333333
if ( -not(Test-Path($path_build) )) {
334334
New-Item -ItemType Directory -Path $path_build
335335
}
336-
if ( -not(Test-Path($path_gen) )) {
337-
New-Item -ItemType Directory -Path $path_gen
338-
}
339-
if ( -not(Test-Path($path_gen_build) )) {
340-
New-Item -ItemType Directory -Path $path_gen_build
341-
}
342-
if ( -not(test-path $path_original)) {
343-
new-item -ItemType Directory -Path $path_original
344-
}
345-
if ( -not(test-path $path_components)) {
346-
new-item -ItemType Directory -Path $path_components
347-
}
348-
if ( -not(test-path $path_dependencies)) {
349-
new-item -ItemType Directory -Path $path_dependencies
350-
}
351-
if ( -not(test-path $path_helpers)) {
352-
new-item -ItemType Directory -Path $path_helpers
353-
}
354336

355-
$path_bootstrap = join-path $path_project gen
356-
357-
$includes = @( $path_bootstrap )
358-
$unit = join-path $path_test "test.cpp"
359-
$executable = join-path $path_build "test.exe"
337+
$includes = @( $path_c_library )
338+
$unit = join-path $path_test_c_lib "gen.c"
339+
$executable = join-path $path_build "gen_c_library_test.exe"
360340

361341
$compiler_args = @()
362342
$compiler_args += ( $flag_define + 'GEN_TIME' )
343+
$compiler_args += $flag_all_c
344+
$compiler_args += $flag_updated_cpp_macro
345+
$compiler_args += $flag_c11
363346

364347
$linker_args = @(
365348
$flag_link_win_subsystem_console
366349
)
367350

368351
$result = build-simple $path_build $includes $compiler_args $linker_args $unit $executable
369352

370-
Push-Location $path_test
371-
Write-Host $path_test
353+
Push-Location $path_test_c_lib
372354
if ( Test-Path( $executable ) ) {
373-
write-host "`nRunning test generator"
355+
write-host "`nRunning c_library test"
374356
$time_taken = Measure-Command { & $executable
375357
| ForEach-Object {
376358
write-host `t $_ -ForegroundColor Green
377359
}
378360
}
379-
write-host "`nTest generator completed in $($time_taken.TotalMilliseconds) ms"
361+
write-host "`nc_library generator completed in $($time_taken.TotalMilliseconds) ms"
380362
}
381363
Pop-Location
382364
}

0 commit comments

Comments
 (0)