Skip to content

Commit

Permalink
Added proper and semi-clean support for MSVCRT, improved MSVC build s…
Browse files Browse the repository at this point in the history
…cripts, Updated readmes, Added Icons8 license snippet

Update .gitignore, CMakeLists.txt, and 12 more files...
  • Loading branch information
aziascreations committed Jul 16, 2024
1 parent b87c1a3 commit f28fe75
Show file tree
Hide file tree
Showing 14 changed files with 303 additions and 121 deletions.
14 changes: 12 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,20 @@ cmake*/
docs/html
docs/latex

# PureBasic stuff
*.pb.cfg
# Temp
rsc/libs/

# Build Artifacts
*.exe
*.dll
*.so
*.a
*.o
*.lib
*.exp

# PureBasic stuff
*.pb.cfg

# Misc.
*.pdn
Expand Down
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,10 @@ if(NP_GOODIES_IS_MAIN)
set_target_properties(np_clang_goodies_dll_static PROPERTIES ARCHIVE_OUTPUT_DIRECTORY "dll_static/")
set_target_properties(np_clang_goodies_dll_static PROPERTIES LIBRARY_OUTPUT_DIRECTORY "dll_static/")
set_target_properties(np_clang_goodies_dll_static PROPERTIES RUNTIME_OUTPUT_DIRECTORY "dll_static/")

# Targets > Dummy > MSVCRT Headers
file(GLOB_RECURSE src_msvcrt_dummy CONFIGURE_DEPENDS "msvcrt/main.cmakesilencer.c" "msvcrt/src/*.h" "msvcrt/src/*.c")
add_library(np_clang_goodies_msvcrt_dummy STATIC ${src_msvcrt_dummy})
else()
# Targets > DLLs > External Project
add_library(lib_np_clang_goodies SHARED ${src_all} ./rsc/np_clang_goodies.rc)
Expand Down
138 changes: 138 additions & 0 deletions build-msvc-internal.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
@echo off
setlocal

:: NEVER CALL THIS SCRIPT DIRECTLY !!!
:: USE THE 'build-msvc.cmd' ONE INSTEAD !!!

:: Grabbing launch arguments into distinct variables and removing the double quotes
echo Retrieving launch arguments
set _VCVARS_BATCH=%1
set _VCVARS_BATCH=%_VCVARS_BATCH:"=%
set _BUILD_DIR=%2
set _BUILD_DIR=%_BUILD_DIR:"=%
set _SRC_DIR=%3
set _SRC_DIR=%_SRC_DIR:"=%
set _BENCHMARK_DIR=%4
set _BENCHMARK_DIR=%_BENCHMARK_DIR:"=%
set _EXAMPLES_DIR=%5
set _EXAMPLES_DIR=%_EXAMPLES_DIR:"=%
set _RSC_DIR=%6
set _RSC_DIR=%_RSC_DIR:"=%
set _CC_FLAGS=%7
set _CC_FLAGS=%_CC_FLAGS:"=%
set _LINK_FLAGS=%8
set _LINK_FLAGS=%_LINK_FLAGS:"=%
echo ^> _VCVARS_BATCH=%_VCVARS_BATCH%
echo ^> _BUILD_DIR=%_BUILD_DIR%
echo ^> _SRC_DIR=%_SRC_DIR%
echo ^> _BENCHMARK_DIR=%_BENCHMARK_DIR%
echo ^> _EXAMPLES_DIR=%_EXAMPLES_DIR%
echo ^> _RSC_DIR=%_RSC_DIR%
echo ^> _CC_FLAGS=%_CC_FLAGS%
echo ^> _LINK_FLAGS=%_LINK_FLAGS%

:: Calling the given VS script to get 'CL' and 'LINK' in the PATH
echo Setting up VS environment
call "%_VCVARS_BATCH%" > nul

:: Preliminary checks
echo Checking the PATH
where /q cl
IF ERRORLEVEL 1 (
echo ^> Unable to find 'cl.exe'
goto end
)
echo ^> Found 'cl.exe'
where /q link
IF ERRORLEVEL 1 (
echo ^> Unable to find 'link.exe'
goto end
)
echo ^> Found 'link.exe'
where /q rc
IF ERRORLEVEL 1 (
echo ^> Unable to find 'rc.exe'
goto end
)
echo ^> Found 'rc.exe'

:: Compiling our library and everything else
echo Preparing build directory
rmdir /Q /S "%_BUILD_DIR%" 2> nul > nul
mkdir "%_BUILD_DIR%"
echo ^> Created '%_BUILD_DIR%' !

:: Going into the script's directory
pushd "%_BUILD_DIR%"

:: Getting other variables here since we couldn't before
echo Setting up even more variables and directories
set _BIN_DIR=%CD%\bin
set _OBJ_DIR=%CD%\obj
echo _BIN_DIR=%_BIN_DIR%
echo _OBJ_DIR=%_OBJ_DIR%
mkdir %_BIN_DIR%
mkdir %_OBJ_DIR%

:: Compiling the DLL
echo Library ^> UCRT DLL Dynamic
mkdir %_BIN_DIR%\dll_dynamic
mkdir %_OBJ_DIR%\dll_dynamic
mkdir %_OBJ_DIR%\dll_dynamic\arguments
mkdir %_OBJ_DIR%\dll_dynamic\hash
mkdir %_OBJ_DIR%\dll_dynamic\hash\crc32
mkdir %_OBJ_DIR%\dll_dynamic\hashmaps
mkdir %_OBJ_DIR%\dll_dynamic\hashmaps\chained
mkdir %_OBJ_DIR%\dll_dynamic\hashmaps\open
mkdir %_OBJ_DIR%\dll_dynamic\lists
mkdir %_OBJ_DIR%\dll_dynamic\lists\double
mkdir %_OBJ_DIR%\dll_dynamic\lists\single
mkdir %_OBJ_DIR%\dll_dynamic\uuid
cl %_CC_FLAGS% /DNP_GOODIES_EXPORT_ALL /Fo: "%_OBJ_DIR%\dll_dynamic\arguments\arguments.o" -c "%_SRC_DIR%\arguments\arguments.c"
cl %_CC_FLAGS% /DNP_GOODIES_EXPORT_ALL /Fo: "%_OBJ_DIR%\dll_dynamic\arguments\help.o" -c "%_SRC_DIR%\arguments\help.c"
cl %_CC_FLAGS% /DNP_GOODIES_EXPORT_ALL /Fo: "%_OBJ_DIR%\dll_dynamic\hash\crc32\crc32.o" -c "%_SRC_DIR%\hash\crc32\crc32.c"
cl %_CC_FLAGS% /DNP_GOODIES_EXPORT_ALL /Fo: "%_OBJ_DIR%\dll_dynamic\hashmaps\chained\hashmap.o" -c "%_SRC_DIR%\hashmaps\chained\hashmap.c"
cl %_CC_FLAGS% /DNP_GOODIES_EXPORT_ALL /Fo: "%_OBJ_DIR%\dll_dynamic\hashmaps\utils.o" -c "%_SRC_DIR%\hashmaps\utils.c"
cl %_CC_FLAGS% /DNP_GOODIES_EXPORT_ALL /Fo: "%_OBJ_DIR%\dll_dynamic\lists\double\dllist.o" -c "%_SRC_DIR%\lists\double\dllist.c"
cl %_CC_FLAGS% /DNP_GOODIES_EXPORT_ALL /Fo: "%_OBJ_DIR%\dll_dynamic\lists\single\sllist.o" -c "%_SRC_DIR%\lists\single\sllist.c"
cl %_CC_FLAGS% /DNP_GOODIES_EXPORT_ALL /Fo: "%_OBJ_DIR%\dll_dynamic\lists\commons.o" -c "%_SRC_DIR%\lists\commons.c"
cl %_CC_FLAGS% /DNP_GOODIES_EXPORT_ALL /Fo: "%_OBJ_DIR%\dll_dynamic\uuid\uuid.o" -c "%_SRC_DIR%\uuid\uuid.c"
cl %_CC_FLAGS% /DNP_GOODIES_EXPORT_ALL /Fo: "%_OBJ_DIR%\dll_dynamic\uuid\uuid4.o" -c "%_SRC_DIR%\uuid\uuid4.c"
cl %_CC_FLAGS% /DNP_GOODIES_EXPORT_ALL /Fo: "%_OBJ_DIR%\dll_dynamic\text.o" -c "%_SRC_DIR%\text.c"
rc /nologo /fo "%_OBJ_DIR%\dll_dynamic\np_clang_goodies.res" "%_RSC_DIR%\np_clang_goodies.rc"
set _DLL_OBJS=
set _DLL_OBJS=%_DLL_OBJS% "%_OBJ_DIR%\dll_dynamic\arguments\arguments.o"
set _DLL_OBJS=%_DLL_OBJS% "%_OBJ_DIR%\dll_dynamic\arguments\help.o"
set _DLL_OBJS=%_DLL_OBJS% "%_OBJ_DIR%\dll_dynamic\hash\crc32\crc32.o"
set _DLL_OBJS=%_DLL_OBJS% "%_OBJ_DIR%\dll_dynamic\hashmaps\chained\hashmap.o"
set _DLL_OBJS=%_DLL_OBJS% "%_OBJ_DIR%\dll_dynamic\hashmaps\utils.o"
set _DLL_OBJS=%_DLL_OBJS% "%_OBJ_DIR%\dll_dynamic\lists\double\dllist.o"
set _DLL_OBJS=%_DLL_OBJS% "%_OBJ_DIR%\dll_dynamic\lists\single\sllist.o"
set _DLL_OBJS=%_DLL_OBJS% "%_OBJ_DIR%\dll_dynamic\lists\commons.o"
set _DLL_OBJS=%_DLL_OBJS% "%_OBJ_DIR%\dll_dynamic\uuid\uuid.o"
set _DLL_OBJS=%_DLL_OBJS% "%_OBJ_DIR%\dll_dynamic\uuid\uuid4.o"
set _DLL_OBJS=%_DLL_OBJS% "%_OBJ_DIR%\dll_dynamic\text.o"
set _DLL_OBJS=%_DLL_OBJS% "%_OBJ_DIR%\dll_dynamic\np_clang_goodies.res"
link %_LINK_FLAGS% /DLL %_DLL_OBJS% /out:%_BIN_DIR%\dll_dynamic\np_clang_goodies.dll


echo Benchmarks
echo Benchmark ^> CRC32 Implementations
cl %_CC_FLAGS% /Fo: "%_OBJ_DIR%\bm_crc32_implementations.o" -c "%_BENCHMARK_DIR%\bm_crc32_implementations.c"
link %_LINK_FLAGS% "%_OBJ_DIR%\bm_crc32_implementations.o" /out:%_BIN_DIR%\bm_crc32_implementations.exe
echo Benchmark ^> Binary Powers
cl %_CC_FLAGS% /Fo: "%_OBJ_DIR%\bm_powers_of_two.o" -c "%_BENCHMARK_DIR%\bm_powers_of_two.c"
link %_LINK_FLAGS% "%_OBJ_DIR%\bm_powers_of_two.o" /out:%_BIN_DIR%\bm_powers_of_two.exe
echo Benchmark ^> Binary Roots
cl %_CC_FLAGS% /Fo: "%_OBJ_DIR%\bm_square_of_two_mask.o" -c "%_BENCHMARK_DIR%\bm_square_of_two_mask.c"
link %_LINK_FLAGS% "%_OBJ_DIR%\bm_square_of_two_mask.o" /out:%_BIN_DIR%\bm_square_of_two_mask.exe


:: Going back to the original directory
:end-context
popd

:: Letting the user check the logs
:end
endlocal
exit /b
172 changes: 79 additions & 93 deletions build-msvc.cmd
Original file line number Diff line number Diff line change
@@ -1,111 +1,97 @@
@echo off
setlocal enabledelayedexpansion
setlocal

:: Preparing some variables
echo.
echo Preparing MSVC
echo --------------
echo NibblePoker's C99 Goodies MSVC Build
echo ========================================

set NP_MSVC_LOCATION=D:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\
if exist "%NP_MSVC_LOCATION%" (
echo ^> Location: "%NP_MSVC_LOCATION%"
) else (
echo ^> Cannot find it in : "%NP_MSVC_LOCATION%"
goto end
)
:: You can edit these variables to fit your environment and desired build
set BUILD_DIR=%~dp0\build-msvc
set VCVARS_ROOT=C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build

if exist "%NP_MSVC_LOCATION%\vcvars64.bat" (
set NP_MSVC_x64="D:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat"
echo ^> Found the x64 script.
) else (
echo ^> Unable to find x64 script !
)
set FLAGS_CC=/nologo /Ot /Gy /Oy /TC /GS- /Gs9999999 /MD
set FLAGS_LINK=/nologo /MANIFEST:EMBED

if exist "%NP_MSVC_LOCATION%\vcvarsamd64_x86.bat" (
set NP_MSVC_x86="D:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsamd64_x86.bat"
echo ^> Found the amd64_x86 script.
) else (
echo ^> Unable to find amd64_x86 script !
)
set FLAGS_MSVCRT_CC=%FLAGS_CC%
set FLAGS_MSVCRT_LINK=%FLAGS_LINK%

:: Doesn't work properly yet !
::if exist "%NP_MSVC_LOCATION%\vcvarsamd64_arm.bat" (
:: set NP_MSVC_arm="D:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsamd64_arm.bat"
:: echo ^> Found the amd64_arm script.
::) else (
:: echo ^> Unable to find amd64_arm script !
::)
:: Stuff you don't have to touch
set BENCHMARK_DIR=%~dp0\benchmarks
set EXAMPLES_DIR=%~dp0\examples
set SRC_DIR=%~dp0\src
set RSC_DIR=%~dp0\rsc
set MSVCRT_DIR=%~dp0\msvcrt\src

if exist "%NP_MSVC_LOCATION%\vcvarsamd64_arm64.bat" (
set NP_MSVC_arm64="D:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsamd64_arm64.bat"
echo ^> Found the amd64_arm64 script.
) else (
echo ^> Unable to find amd64_arm64 script !
:: Checking the to make sure you ain't running of a VS console
echo Checking the PATH
where /q cl
IF NOT ERRORLEVEL 1 (
echo Found 'cl.exe' in your PATH !
echo Use a command prompt with a clean PATH !
goto end
)
where /q link
IF NOT ERRORLEVEL 1 (
echo Found 'link.exe' in your PATH !
echo Use a command prompt with a clean PATH !
goto end
)
where /q rc
IF NOT ERRORLEVEL 1 (
echo Found 'rc.exe' in your PATH !
echo Use a command prompt with a clean PATH !
goto end
)
echo ^> The PATH appears to be clean

:: Going into the script's directory
pushd %~dp0
rmdir cmake-build-win32-msvc-x64 /s /q 2> nul
rmdir cmake-build-win32-msvc-x86 /s /q 2> nul
rmdir cmake-build-win32-msvc-arm /s /q 2> nul
rmdir cmake-build-win32-msvc-arm64 /s /q 2> nul
:: Preparing the build folder
echo Preparing build directory
rmdir /Q /S %BUILD_DIR% 2> nul > nul
mkdir %BUILD_DIR%
echo ^> Created '%BUILD_DIR%' !
echo.

:: Doing x64 build
if defined NP_MSVC_x64 (
echo.
echo Building x64 target
echo -------------------
mkdir cmake-build-win32-msvc-x64
call %NP_MSVC_x64%
cd cmake-build-win32-msvc-x64
cmake ..
cmake --build . --config Release
cd..
)

:: Doing x86 build
if defined NP_MSVC_x86 (
echo.
echo Building x86 target
echo -------------------
mkdir cmake-build-win32-msvc-x86
call %NP_MSVC_x86%
cd cmake-build-win32-msvc-x86
cmake ..
cmake --build . --config Release
cd..
)
:: Calling the building script with distinct variable contexts
:build-x64-ucrt
echo C99 Goodies - x64 UCRT Build
echo ========================================
call build-msvc-internal.cmd "%VCVARS_ROOT%\vcvars64.bat" "%BUILD_DIR%\x64-ucrt" "%SRC_DIR%" ^
"%BENCHMARK_DIR%" "%EXAMPLES_DIR%" "%RSC_DIR%" ^
"%FLAGS_CC%" ^
"%FLAGS_LINK%"
echo.

:: Doing ARM build
if defined NP_MSVC_arm (
echo.
echo Building arm target
echo -------------------
mkdir cmake-build-win32-msvc-arm
call %NP_MSVC_arm%
cd cmake-build-win32-msvc-arm
cmake ..
cmake --build . --config Release
cd..
)
:build-x64-msvcrt
::/DNP_GOODIES_BUILD_WIN32_NODEFAULTLIB
echo C99 Goodies - x64 MSVCRT Build
echo ========================================
call build-msvc-internal.cmd "%VCVARS_ROOT%\vcvars64.bat" "%BUILD_DIR%\x64-msvcrt" "%SRC_DIR%" ^
"%BENCHMARK_DIR%" "%EXAMPLES_DIR%" "%RSC_DIR%" ^
"%FLAGS_MSVCRT_CC% /external:W4 /external:I ""%MSVCRT_DIR%""" ^
"%FLAGS_MSVCRT_LINK% /NODEFAULTLIB user32.lib kernel32.lib ^"%RSC_DIR%\libs\x64\msvcrt.lib^""
echo.

:build-x86-ucrt
echo C99 Goodies - x86 UCRT Build
echo ========================================
call build-msvc-internal.cmd "%VCVARS_ROOT%\vcvars32.bat" "%BUILD_DIR%\x86-ucrt" "%SRC_DIR%" ^
"%BENCHMARK_DIR%" "%EXAMPLES_DIR%" "%RSC_DIR%" ^
"%FLAGS_CC%" ^
"%FLAGS_LINK%"
echo.

:build-x86-msvcrt
echo C99 Goodies - x86 MSVCRT Build
echo ========================================
call build-msvc-internal.cmd "%VCVARS_ROOT%\vcvars32.bat" "%BUILD_DIR%\x86-msvcrt" "%SRC_DIR%" ^
"%BENCHMARK_DIR%" "%EXAMPLES_DIR%" "%RSC_DIR%" ^
"%FLAGS_MSVCRT_CC% /external:W4 /external:I ""%MSVCRT_DIR%""" ^
"%FLAGS_MSVCRT_LINK% /NODEFAULTLIB user32.lib kernel32.lib ^"%RSC_DIR%\libs\x86\msvcrt.lib^""
echo.

:: Doing ARM64 build
if defined NP_MSVC_arm64 (
echo.
echo Building arm64 target
echo -------------------
mkdir cmake-build-win32-msvc-arm64
call %NP_MSVC_arm64%
cd cmake-build-win32-msvc-arm64
cmake ..
cmake --build . --config Release
cd..
)

:: Going back to the original directory
popd

:: Letting the user check the logs
:end
echo.
endlocal
pause
2 changes: 1 addition & 1 deletion definitions.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* `NP_GOODIES_BUILD_BENCHMARKS` [](#build-benchmarks)
* `NP_GOODIES_BUILD_EXAMPLES` [](#build-examples)
* `NP_GOODIES_BUILD_TESTS` [](#build-tests)
* <s>`NP_GOODIES_BUILD_WIN32_NODEFAULTLIB` [](#build-with-no-default-lib)</s>
* <s>`NP_GOODIES_BUILD_WIN32_NODEFAULTLIB` [](#build-with-no-default-lib)</s> **Obsolete**
* [Library Exports Toggles](#library-exports-toggles) *(As a hierarchical list of priority)*
* `NP_GOODIES_EXPORT_ALL` [](#everything)
* `NP_GOODIES_EXPORT_ARGUMENTS` [](#arguments-parser)
Expand Down
Binary file added docs/images/windows_95.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions msvcrt/main.cmakesilencer.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include <windows.h>

/**
* This `DllMain` function is just here to make shut Cmake up about "unknown linker language" errors.
* This won't affect any usage of the headers in this directory and its sub-directories.
*/
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
return TRUE;
}
Loading

0 comments on commit f28fe75

Please sign in to comment.