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..1ba12fe --- /dev/null +++ b/0xtest/CMakeLists.txt @@ -0,0 +1,11 @@ + +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..1552806 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,104 @@ +cmake_minimum_required(VERSION 4.0) +set(CMAKE_C_STANDARD 11) + +project(lib0xc C) + +# 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 + 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} +) + +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 + -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 + -Wundef +) + +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") + 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() +