From 59239ce13f8ecf882a5a7f9c1dc4a72405d5b345 Mon Sep 17 00:00:00 2001 From: jacob Date: Wed, 3 Apr 2024 02:33:29 -0500 Subject: [PATCH] cleanup - move linker lib imports to source code --- CMakeLists.txt | 35 +++++++++++++++-------------------- build.bat | 4 ++-- src/common.h | 5 +++-- src/memory.h | 1 - src/mp3_mmf.c | 4 ++++ src/playback_wasapi.c | 2 ++ src/renderer_d3d11.c | 8 ++++---- src/sys_win32.c | 11 ++++++++--- src/ttf_dwrite.cpp | 10 +++------- 9 files changed, 41 insertions(+), 39 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 23cb846b..338eac40 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -137,14 +137,6 @@ target_precompile_headers(powerplay_exe PRIVATE src/common.h) # Compiler flags ################################################################################ -# Common flags -set(COMPILER_FLAGS " --fno-strict-aliasing \ --fno-finite-loops \ --fwrapv \ --msse4.2 \ -") - # TODO: # Enable - # -Wconversion \ @@ -166,10 +158,20 @@ set(COMPILER_WARNINGS " \ ") # -Wno-unused-variable -Wno-unused-but-set-variable -Wno-unused-parameter +set(COMPILER_FLAGS " +-fno-strict-aliasing \ +-fno-finite-loops \ +-fwrapv \ +-msse4.2 \ +") + set(LINKER_FLAGS " \ -fuse-ld=lld-link \ ${rc_res_sources} \ --luser32.lib -lkernel32.lib -lgdi32.lib -lshell32.lib -ldwmapi.lib -lole32.lib -ld3d11.lib -ld3dcompiler.lib -ldxgi.lib -ldxguid.lib -ldwrite.lib -lwinmm.lib -ladvapi32.lib -lmfplat.lib -lmfreadwrite.lib -lavrt.lib -lshlwapi.lib \ +-fno-strict-aliasing \ +-fno-finite-loops \ +-fwrapv \ +-msse4.2 \ ") # RTC (Runtime checks) @@ -179,38 +181,31 @@ if (RTC) endif() # Enable UBSan set(COMPILER_FLAGS "${COMPILER_FLAGS} -fsanitize=undefined -fsanitize-trap=all -DRTC=1") - set(LINKER_FLAGS "${LINKER_FLAGS} -fsanitize=undefined -fsanitize-trap=all") # set(COMPILER_FLAGS "${COMPILER_FLAGS} -fsanitize=undefined -DRTC=1") - # set(LINKER_FLAGS "${LINKER_FLAGS} -fsanitize=undefined") endif() # CRTLIB (C runtime library) if (CRTLIB) set(COMPILER_FLAGS "${COMPILER_FLAGS} -DCRTLIB=1") else() - set(COMPILER_FLAGS "${COMPILER_FLAGS} -mno-stack-arg-probe -fno-builtin") - set(LINKER_FLAGS "${LINKER_FLAGS} -nostdlib") + set(COMPILER_FLAGS "${COMPILER_FLAGS} -mno-stack-arg-probe -fno-builtin -nostdlib") endif() # Optimization if (UNOPTIMIZED) - set(COMPILER_FLAGS "${COMPILER_FLAGS} -O0 -DUNOPTIMIZED=1") - set(LINKER_FLAGS "${LINKER_FLAGS} -O0") + set(COMPILER_FLAGS "${COMPILER_FLAGS} -O0 -DUNOPTIMIZED=1") else() - set(COMPILER_FLAGS "${COMPILER_FLAGS} -O3 -flto") - set(LINKER_FLAGS "${LINKER_FLAGS} -O3 -flto -fwhole-program") + set(COMPILER_FLAGS "${COMPILER_FLAGS} -O3 -flto") endif() # Debug info if (DEBINFO) set(COMPILER_FLAGS "${COMPILER_FLAGS} -g -DDEBINFO=1") - set(LINKER_FLAGS "${LINKER_FLAGS} -g") endif() # ASAN if (ASAN) set(COMPILER_FLAGS "${COMPILER_FLAGS} -fsanitize=address -DASAN=1") - set(LINKER_FLAGS "${LINKER_FLAGS} -fsanitize=address") endif() # Developer mode @@ -238,4 +233,4 @@ endif() set(CMAKE_C_FLAGS "${COMPILER_FLAGS} ${COMPILER_WARNINGS} -std=c99") set(CMAKE_CXX_FLAGS "${COMPILER_FLAGS} ${COMPILER_WARNINGS} -std=c++14") -set(CMAKE_EXE_LINKER_FLAGS "${LINKER_FLAGS}") +set(CMAKE_EXE_LINKER_FLAGS "${COMPILER_FLAGS} ${LINKER_FLAGS}") diff --git a/build.bat b/build.bat index 64155350..69c58019 100644 --- a/build.bat +++ b/build.bat @@ -30,7 +30,7 @@ where /q lld-link || ( echo ERROR: "lld-link.exe" not found - please run this from the MSVC x64 native tools command prompt. exit /b 1 ) -echo lld-link version: +echo lld-link version lld-link --version echo --------------- @@ -38,7 +38,7 @@ where /q ninja.exe || ( echo ERROR: "ninja.exe" not found - please run this from the MSVC x64 native tools command prompt. exit /b 1 ) -echo ninja version: +echo ninja version ninja --version echo --------------- diff --git a/src/common.h b/src/common.h index 08cdb211..e8b6a2b0 100644 --- a/src/common.h +++ b/src/common.h @@ -139,8 +139,9 @@ extern "C" { /* Address sanitization */ #if ASAN - void __asan_poison_memory_region(void *, size_t); - void __asan_unpoison_memory_region(void *, size_t); +#pragma comment(lib, "clang_rt.asan-x86_64.lib") +void __asan_poison_memory_region(void *, size_t); +void __asan_unpoison_memory_region(void *, size_t); # define ASAN_POISON(addr, size) __asan_poison_memory_region(addr, size); # define ASAN_UNPOISON(addr, size) __asan_unpoison_memory_region(addr, size); #else diff --git a/src/memory.h b/src/memory.h index ac2eed19..58f0cd75 100644 --- a/src/memory.h +++ b/src/memory.h @@ -10,7 +10,6 @@ #define MEMSET(ptr, val, count) memset(ptr, val, count) - #if CRTLIB # include #else diff --git a/src/mp3_mmf.c b/src/mp3_mmf.c index cca37280..1f870519 100644 --- a/src/mp3_mmf.c +++ b/src/mp3_mmf.c @@ -15,6 +15,10 @@ #include #include +#pragma comment(lib, "mfplat") +#pragma comment(lib, "mfreadwrite") +#pragma comment(lib, "shlwapi") + struct mp3_decode_result mp3_decode(struct arena *arena, struct buffer encoded, u32 flags) { struct mp3_decode_result res = { 0 }; diff --git a/src/playback_wasapi.c b/src/playback_wasapi.c index e9637608..b424b886 100644 --- a/src/playback_wasapi.c +++ b/src/playback_wasapi.c @@ -20,6 +20,8 @@ #include #include +#pragma comment(lib, "avrt") + DEFINE_GUID(CLSID_MMDeviceEnumerator, 0xbcde0395, 0xe52f, 0x467c, 0x8e, 0x3d, 0xc4, 0x57, 0x92, 0x91, 0x69, 0x2e); DEFINE_GUID(IID_IMMDeviceEnumerator, 0xa95664d2, 0x9614, 0x4f35, 0xa7, 0x46, 0xde, 0x8d, 0xb6, 0x36, 0x17, 0xe6); DEFINE_GUID(IID_IAudioClient, 0x1cb9ad4c, 0xdbfa, 0x4c32, 0xb1, 0x78, 0xc2, 0xf5, 0x68, 0xa7, 0x03, 0xb2); diff --git a/src/renderer_d3d11.c b/src/renderer_d3d11.c index e431b299..52de568e 100644 --- a/src/renderer_d3d11.c +++ b/src/renderer_d3d11.c @@ -9,9 +9,6 @@ #include "tar.h" #include -#pragma warning(push) -#pragma warning(disable : 4201) -#pragma warning(disable : 4115) #define CINTERFACE #define COBJMACROS #include @@ -20,7 +17,10 @@ #include #undef CINTERFACE #undef COBJMACROS -#pragma warning(pop) + +#pragma comment(lib, "d3d11") +#pragma comment(lib, "dxguid") +#pragma comment(lib, "d3dcompiler") #define MAX_CANVASES 1024 diff --git a/src/sys_win32.c b/src/sys_win32.c index ec13db7f..3bb82a86 100644 --- a/src/sys_win32.c +++ b/src/sys_win32.c @@ -18,6 +18,14 @@ #include #include +#pragma comment(lib, "kernel32") +#pragma comment(lib, "user32") +#pragma comment(lib, "shell32") +#pragma comment(lib, "ole32") +#pragma comment(lib, "advapi32") +#pragma comment(lib, "winmm") +#pragma comment(lib, "dwmapi") + #define SYS_WINDOW_EVENT_LISTENERS_MAX 512 struct win32_thread_params { @@ -176,10 +184,7 @@ void *sys_memory_commit(void *address, u64 size) void sys_memory_decommit(void *address, u64 size) { -#pragma warning(push) -#pragma warning(disable : 6250) /* Disable warning "Calling 'VirtualFree' without MEM_RELEASE flag"*/ VirtualFree(address, size, MEM_DECOMMIT); -#pragma warning(pop) } /* ========================== * diff --git a/src/ttf_dwrite.cpp b/src/ttf_dwrite.cpp index 45280229..0fcf2f26 100644 --- a/src/ttf_dwrite.cpp +++ b/src/ttf_dwrite.cpp @@ -1,27 +1,23 @@ /* Based on Allen Webster's dwrite rasterizer example - * https://github.com/4th-dimention/examps */ -#pragma warning( push, 0 ) -#pragma warning(disable : 4576) extern "C" { #include "ttf.h" #include "scratch.h" #include "util.h" - -/* TODO: remove this */ #include "string.h" #include "memory.h" #include "arena.h" - #include "font.h" } -#pragma warning( pop ) #include -//#include #include +#pragma comment(lib, "dwrite") +#pragma comment(lib, "gdi32") + /* TODO: Determine DPI accurately? */ #define DPI (96.0f)