From 600f268c138cd341e7bbb620cdd5c2d3f741b8c0 Mon Sep 17 00:00:00 2001 From: FoxMoss Date: Sat, 2 May 2026 00:46:29 -0500 Subject: [PATCH 1/5] feat: cmake support --- .gitignore | 1 + 0xtest/CMakeLists.txt | 13 +++++++++ CMakeLists.txt | 63 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+) create mode 100644 .gitignore create mode 100644 0xtest/CMakeLists.txt create mode 100644 CMakeLists.txt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..567609b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +build/ diff --git a/0xtest/CMakeLists.txt b/0xtest/CMakeLists.txt new file mode 100644 index 0000000..ee2b384 --- /dev/null +++ b/0xtest/CMakeLists.txt @@ -0,0 +1,13 @@ + +file(GLOB TEST_SOURCES + unit/*.c + rand.c + main.c +) + +add_executable(0xtest + ${TEST_SOURCES} +) +target_include_directories(0xtest PUBLIC .) +target_compile_definitions(0xtest PRIVATE TARGET_0XTEST) +target_link_libraries(0xtest PUBLIC 0xc) diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..b5987e7 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,63 @@ +cmake_minimum_required(VERSION 4.0) +set(CMAKE_C_STANDARD 11) + +project(lib0xc) + +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + +file(GLOB LIB_SOURCES src/0xc/*.c + src/0xc/std/*.c + src/0xc/std/call/field/type/*.c + src/0xc/std/call/field/*.c + src/0xc/sys/*.c + src/0xc/sys/buff/*.c + src/0xc/sys/buff/type/*.c + src/0xc/sys/check/*.c + src/0xc/sys/log/*.c + posix/0xc/posix/std/alloc.c + posix/0xc/posix/sys/buff/type/mmap.c + posix/0xc/posix/sys/log/stream.c + posix/0xc/posix/sys/panic.c) + +file(GLOB LIB_HEADERS src/0xc/shim/*.h + src/0xc/std/*.h + src/0xc/sys/*.h + src/0xc/sys/buff/*.h) + +add_library(0xc + ${LIB_SOURCES} +) + +target_compile_options(0xc PUBLIC + -Werror + -Wall + -Wextra + -Wcast-qual + -Wconversion + -Wformat=2 + -Wformat-security + -Wnull-dereference + -Wvla + -Warray-bounds + -Wimplicit-fallthrough + -Wint-conversion + -Wdouble-promotion + -Wstrict-prototypes + -Wbad-function-cast + -Wfloat-equal + -Wpointer-arith +) + +target_include_directories(0xc PUBLIC src posix) + +if(CMAKE_SYSTEM_NAME STREQUAL "Linux") + target_compile_definitions(0xc PRIVATE POINTER_TAG_BITS_HI=16 POINTER_TAG_BITS_LO=3) +endif() +if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") + target_compile_definitions(0xc PRIVATE POINTER_TAG_BITS_HI=0 POINTER_TAG_BITS_LO=3) +endif() + +if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) + add_subdirectory(0xtest) +endif() + From 4e7d79374e0cc1d78340a5d10a5113c2ff7be89e Mon Sep 17 00:00:00 2001 From: FoxMoss Date: Sat, 2 May 2026 16:38:05 -0500 Subject: [PATCH 2/5] fix: add clang & gcc specific flags --- CMakeLists.txt | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b5987e7..f0d2867 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,9 +1,12 @@ cmake_minimum_required(VERSION 4.0) set(CMAKE_C_STANDARD 11) -project(lib0xc) +project(lib0xc C) -set(CMAKE_EXPORT_COMPILE_COMMANDS ON) +# only export debug symbols if someone is working on the project +if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) + set(CMAKE_EXPORT_COMPILE_COMMANDS ON) +endif() file(GLOB LIB_SOURCES src/0xc/*.c src/0xc/std/*.c @@ -48,6 +51,30 @@ target_compile_options(0xc PUBLIC -Wpointer-arith ) +if (CMAKE_C_COMPILER_ID STREQUAL "Clang") + target_compile_options(0xc PUBLIC + -Wshorten-64-to-32 + -Warray-bounds-pointer-arithmetic + -Wconditional-uninitialized + -Wloop-analysis + -Wshift-sign-overflow + -Wtautological-constant-in-range-compare + -Wcomma + -Wassign-enum + -Wformat-type-confusion + -Widiomatic-parentheses + -Wunreachable-code-aggressive + -Wthread-safety + -ftrivial-auto-var-init=zero + -Wno-duplicate-decl-specifier) +elseif (CMAKE_C_COMPILER_ID STREQUAL "GNU") + target_compile_options(0xc PUBLIC + -Wformat-signedness + -Wuninitialized + -Wlogical-op + -Wduplicated-cond) +endif() + target_include_directories(0xc PUBLIC src posix) if(CMAKE_SYSTEM_NAME STREQUAL "Linux") From 24dce58744956a4b45441e6f94b082f898585d79 Mon Sep 17 00:00:00 2001 From: FoxMoss Date: Sat, 2 May 2026 16:48:51 -0500 Subject: [PATCH 3/5] fix: add release and debug flags --- CMakeLists.txt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index f0d2867..90b8f9a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,6 +31,13 @@ add_library(0xc ${LIB_SOURCES} ) +if(CMAKE_BUILD_TYPE STREQUAL "Debug") + target_compile_options(0xc PRIVATE -g) +elseif(CMAKE_BUILD_TYPE STREQUAL "Release") + target_compile_options(0xc PRIVATE -O3) + target_link_options(0xc PRIVATE -O3) +endif() + target_compile_options(0xc PUBLIC -Werror -Wall From 238229cebed16090a0cb9f0cc6694230ba4f995c Mon Sep 17 00:00:00 2001 From: FoxMoss Date: Tue, 5 May 2026 16:16:35 -0500 Subject: [PATCH 4/5] chore: clean up cmake --- 0xtest/CMakeLists.txt | 4 +-- CMakeLists.txt | 76 +++++++++++++++++++++++-------------------- 2 files changed, 42 insertions(+), 38 deletions(-) diff --git a/0xtest/CMakeLists.txt b/0xtest/CMakeLists.txt index ee2b384..1ba12fe 100644 --- a/0xtest/CMakeLists.txt +++ b/0xtest/CMakeLists.txt @@ -5,9 +5,7 @@ file(GLOB TEST_SOURCES main.c ) -add_executable(0xtest - ${TEST_SOURCES} -) +add_executable(0xtest ${TEST_SOURCES}) target_include_directories(0xtest PUBLIC .) target_compile_definitions(0xtest PRIVATE TARGET_0XTEST) target_link_libraries(0xtest PUBLIC 0xc) diff --git a/CMakeLists.txt b/CMakeLists.txt index 90b8f9a..bc18450 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,24 +8,28 @@ if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) endif() -file(GLOB LIB_SOURCES src/0xc/*.c - src/0xc/std/*.c - src/0xc/std/call/field/type/*.c - src/0xc/std/call/field/*.c - src/0xc/sys/*.c - src/0xc/sys/buff/*.c - src/0xc/sys/buff/type/*.c - src/0xc/sys/check/*.c - src/0xc/sys/log/*.c - posix/0xc/posix/std/alloc.c - posix/0xc/posix/sys/buff/type/mmap.c - posix/0xc/posix/sys/log/stream.c - posix/0xc/posix/sys/panic.c) +file(GLOB LIB_SOURCES + src/0xc/*.c + src/0xc/std/*.c + src/0xc/std/call/field/type/*.c + src/0xc/std/call/field/*.c + src/0xc/sys/*.c + src/0xc/sys/buff/*.c + src/0xc/sys/buff/type/*.c + src/0xc/sys/check/*.c + src/0xc/sys/log/*.c + posix/0xc/posix/std/alloc.c + posix/0xc/posix/sys/buff/type/mmap.c + posix/0xc/posix/sys/log/stream.c + posix/0xc/posix/sys/panic.c +) -file(GLOB LIB_HEADERS src/0xc/shim/*.h - src/0xc/std/*.h - src/0xc/sys/*.h - src/0xc/sys/buff/*.h) +file(GLOB LIB_HEADERS + src/0xc/shim/*.h + src/0xc/std/*.h + src/0xc/sys/*.h + src/0xc/sys/buff/*.h +) add_library(0xc ${LIB_SOURCES} @@ -40,22 +44,22 @@ endif() target_compile_options(0xc PUBLIC -Werror - -Wall - -Wextra - -Wcast-qual - -Wconversion - -Wformat=2 - -Wformat-security - -Wnull-dereference - -Wvla - -Warray-bounds - -Wimplicit-fallthrough - -Wint-conversion - -Wdouble-promotion - -Wstrict-prototypes - -Wbad-function-cast - -Wfloat-equal - -Wpointer-arith + -Wall + -Wextra + -Wcast-qual + -Wconversion + -Wformat=2 + -Wformat-security + -Wnull-dereference + -Wvla + -Warray-bounds + -Wimplicit-fallthrough + -Wint-conversion + -Wdouble-promotion + -Wstrict-prototypes + -Wbad-function-cast + -Wfloat-equal + -Wpointer-arith ) if (CMAKE_C_COMPILER_ID STREQUAL "Clang") @@ -73,13 +77,15 @@ if (CMAKE_C_COMPILER_ID STREQUAL "Clang") -Wunreachable-code-aggressive -Wthread-safety -ftrivial-auto-var-init=zero - -Wno-duplicate-decl-specifier) + -Wno-duplicate-decl-specifier + ) elseif (CMAKE_C_COMPILER_ID STREQUAL "GNU") target_compile_options(0xc PUBLIC -Wformat-signedness -Wuninitialized -Wlogical-op - -Wduplicated-cond) + -Wduplicated-cond + ) endif() target_include_directories(0xc PUBLIC src posix) From 8b907c6f0ff51f99a0161af0e3248e11890a8c92 Mon Sep 17 00:00:00 2001 From: FoxMoss Date: Fri, 15 May 2026 09:13:14 -0500 Subject: [PATCH 5/5] chore: add -Wundef to cmake --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index bc18450..1552806 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -60,6 +60,7 @@ target_compile_options(0xc PUBLIC -Wbad-function-cast -Wfloat-equal -Wpointer-arith + -Wundef ) if (CMAKE_C_COMPILER_ID STREQUAL "Clang")