diff options
| -rw-r--r-- | .gitignore | 20 | ||||
| -rw-r--r-- | CMakeLists.txt | 30 | ||||
| -rw-r--r-- | LICENSE | 21 | ||||
| -rwxr-xr-x | build.sh | 101 | ||||
| -rw-r--r-- | cmake/BoltDbgOptions.cmake | 10 | ||||
| -rw-r--r-- | cmake/FindGLFW.cmake | 30 | ||||
| -rw-r--r-- | cmake/PlatformConfig.cmake | 26 | ||||
| -rw-r--r-- | cmake/Sanitizer.cmake | 28 | ||||
| -rw-r--r-- | cmake/compiler_warnings.cmake | 7 | ||||
| -rw-r--r-- | include/boltdbg.h | 6 | ||||
| -rw-r--r-- | src/CMakeLists.txt | 5 | ||||
| -rw-r--r-- | src/main.cpp | 6 | ||||
| -rw-r--r-- | tests/CMakeLists.txt | 20 | ||||
| -rw-r--r-- | tests/test_logger.cpp | 15 | ||||
| -rw-r--r-- | tests/test_main.cpp | 14 |
15 files changed, 339 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..000c70c --- /dev/null +++ b/.gitignore @@ -0,0 +1,20 @@ +# build artifacts +/build/ +/build-*/ +CMakeFiles/ +CMakeCache.txt +Makefile +*.o +*.obj +*.exe +*.dll +*.so +*.dylib + +# editors +.vscode/ +.idea/ +*.swp + +# OS +.DS_Store diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..3669e77 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,30 @@ +cmake_minimum_required(VERSION 3.15) +project(boltdbg VERSION 0.1.0 LANGUAGES C CXX) + +# Load BoltDBG option definitions first +list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") +include(BoltDbgOptions) + +# Some basic options +set(CMAKE_CXX_STANDARD 23) +set(CMAKE_C_STANDARD 11) + +# include helper modules +include(compiler_warnings) +include(Sanitizer) +include(PlatformConfig) +#include(CodeStyle) + +# src +add_subdirectory(src) + +# add optional format targets if enabled +if (BOLTDBG_ENABLE_FORMAT_TARGET) + #add_clang_format_target(boltdbg) +endif() + +# Tests +if (BOLTDBG_BUILD_TESTS) + enable_testing() + add_subdirectory(tests) +endif() @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2025 Levent Kaya + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..f9a5a9e --- /dev/null +++ b/build.sh @@ -0,0 +1,101 @@ +#!/usr/bin/env bash +# run.sh - simple build+test helper for BoltDBG +# Usage: +# ./run.sh # default: Debug build, ASAN off, run tests +# BUILD_TYPE=Release ./run.sh +# ASAN=ON ./run.sh +# CLEAN=1 ./run.sh # remove build/ then do everything +# INSTALL=1 ./run.sh # run `cmake --install` after build +# +set -euo pipefail + +# Defaults (can be overridden by environment variables) +: "${BUILD_TYPE:=Debug}" +: "${ASAN:=OFF}" # ON or OFF +: "${CLEAN:=0}" # 1 to remove build dir first +: "${JOBS:=auto}" # number of parallel build jobs; auto = detect +: "${INSTALL:=0}" # 1 to install after build +: "${CMAKE_EXTRA_ARGS:=""}" # any extra args for cmake + +# Detect number of processors +if [ "$JOBS" = "auto" ]; then + if command -v nproc >/dev/null 2>&1; then + JOBS=$(nproc) + elif [ "$(uname)" = "Darwin" ] && command -v sysctl >/dev/null 2>&1; then + JOBS=$(sysctl -n hw.ncpu) + else + JOBS=2 + fi +fi + +ROOT_DIR="$(cd "$(dirname "$0")" && pwd)" +BUILD_DIR="${ROOT_DIR}/build" + +echo "=== BoltDBG build helper ===" +echo "Root: ${ROOT_DIR}" +echo "Build dir: ${BUILD_DIR}" +echo "Build type: ${BUILD_TYPE}" +echo "ASAN: ${ASAN}" +echo "Jobs: ${JOBS}" +echo "Clean: ${CLEAN}" +echo "Install: ${INSTALL}" +echo "Extra args: ${CMAKE_EXTRA_ARGS}" +echo + +# Step 0: optionally clean +if [ "${CLEAN}" = "1" ]; then + echo "[1/6] Cleaning build directory..." + rm -rf "${BUILD_DIR}" +fi + +# Step 1: init/update submodules (if any) +if [ -f .gitmodules ]; then + echo "[2/6] Initializing/updating git submodules..." + git submodule sync --recursive || true + git submodule update --init --recursive --depth 1 || true +else + echo "[2/6] No .gitmodules found — skipping submodule init." +fi + +# Step 2: create build dir +echo "[3/6] Preparing build directory..." +mkdir -p "${BUILD_DIR}" +cd "${BUILD_DIR}" + +# Step 3: run cmake configure +echo "[4/6] Configuring with CMake..." +cmake \ + -DCMAKE_BUILD_TYPE="${BUILD_TYPE}" \ + -DBOLTDBG_ENABLE_ASAN="${ASAN}" \ + ${CMAKE_EXTRA_ARGS} \ + "${ROOT_DIR}" + +# Step 4: build +echo "[5/6] Building (parallel jobs: ${JOBS})..." +# Use cmake --build for multi-config generators as well +cmake --build . -- -j"${JOBS}" + +# Step 5: run tests (if enabled in CMake) +if cmake --build . --target help | grep -q "RUN_TESTS" || true; then + echo "[6/6] Running ctest (if any tests present)..." + # Prefer ctest binary if available + if command -v ctest >/dev/null 2>&1; then + ctest --output-on-failure -j "${JOBS}" || { + echo "Some tests failed." + # do not exit immediately so user sees build artifacts; still return non-zero + exit 1 + } + else + echo "ctest not found; skipping tests." + fi +else + echo "[6/6] No tests target detected; skipping ctest." +fi + +# Optional install +if [ "${INSTALL}" = "1" ]; then + echo "[+] Installing to CMAKE_INSTALL_PREFIX..." + cmake --install . --prefix "${CMAKE_INSTALL_PREFIX:-/usr/local}" +fi + +echo "=== Build finished successfully ===" diff --git a/cmake/BoltDbgOptions.cmake b/cmake/BoltDbgOptions.cmake new file mode 100644 index 0000000..2d9ccd6 --- /dev/null +++ b/cmake/BoltDbgOptions.cmake @@ -0,0 +1,10 @@ +# cmake/BoltDbgOptions.cmake +# +# Define project-wide options for BoltDBG + +option(BOLTDBG_BUILD_TESTS "Build boltdbg tests" ON) +option(BOLTDBG_ENABLE_ASAN "Enable AddressSanitizer (Address/Undefined)" OFF) +option(BOLTDBG_USE_SYSTEM_LIBS "Prefer system libraries (if available) over bundled" ON) +option(BOLTDBG_ENABLE_FORMAT_TARGET "Add clang-format target" ON) + +set(BOLTDBG_DEFAULT_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}" CACHE PATH "Default install prefix") diff --git a/cmake/FindGLFW.cmake b/cmake/FindGLFW.cmake new file mode 100644 index 0000000..1abc863 --- /dev/null +++ b/cmake/FindGLFW.cmake @@ -0,0 +1,30 @@ +# cmake/FindGLFW.cmake +# +# Lightweight helper: tries find_package(GLFW3) then pkg-config fallback + +# Try the standard find_package +find_package(GLFW3 QUIET) + +if (GLFW3_FOUND) + set(GLFW3_LIBRARIES GLFW) + set(GLFW3_INCLUDE_DIRS ${GLFW_INCLUDE_DIR}) + set(GLFW3_FOUND TRUE) +else() + find_package(PkgConfig QUIET) + if (PKG_CONFIG_FOUND) + pkg_check_modules(GLFW_PKG glfw3) + if (GLFW_PKG_FOUND) + set(GLFW3_FOUND TRUE) + set(GLFW3_LIBRARIES ${GLFW_PKG_LIBRARIES}) + set(GLFW3_INCLUDE_DIRS ${GLFW_PKG_INCLUDE_DIRS}) + link_directories(${GLFW_PKG_LIBRARY_DIRS}) + include_directories(${GLFW_PKG_INCLUDE_DIRS}) + endif() + endif() +endif() + +if (NOT GLFW3_FOUND) + set(GLFW3_FOUND FALSE) +endif() + +mark_as_advanced(GLFW3_FOUND) diff --git a/cmake/PlatformConfig.cmake b/cmake/PlatformConfig.cmake new file mode 100644 index 0000000..f2f5252 --- /dev/null +++ b/cmake/PlatformConfig.cmake @@ -0,0 +1,26 @@ +# cmake/PlatformConfig.cmake +# +# Set platform-specific compile definitions and helper variables + +function(configure_platform target) + if (CMAKE_SYSTEM_NAME STREQUAL "Linux") + target_compile_definitions(${target} PRIVATE BOLTDBG_PLATFORM_LINUX=1) + message(STATUS "Configuring for Linux") + elseif (CMAKE_SYSTEM_NAME STREQUAL "Darwin") + target_compile_definitions(${target} PRIVATE BOLTDBG_PLATFORM_MACOS=1) + message(STATUS "Configuring for macOS") + elseif (CMAKE_SYSTEM_NAME MATCHES "Windows") + target_compile_definitions(${target} PRIVATE BOLTDBG_PLATFORM_WINDOWS=1) + message(STATUS "Configuring for Windows") + else() + target_compile_definitions(${target} PRIVATE BOLTDBG_PLATFORM_UNKNOWN=1) + message(WARNING "Unknown platform: ${CMAKE_SYSTEM_NAME}") + endif() + + # Example: helper macro for visibility + if (MSVC) + target_compile_definitions(${target} PRIVATE BOLTDBG_EXPORT=__declspec(dllexport)) + else() + target_compile_definitions(${target} PRIVATE BOLTDBG_EXPORT=__attribute__((visibility(\"default\")))) + endif() +endfunction() diff --git a/cmake/Sanitizer.cmake b/cmake/Sanitizer.cmake new file mode 100644 index 0000000..6e633a9 --- /dev/null +++ b/cmake/Sanitizer.cmake @@ -0,0 +1,28 @@ +# cmake/Sanitizers.cmake +# +# Adds sanitizers compile/link flags when requested. +# Usage: include(Sanitizers) ; enable_sanitizers(<target>) + +function(enable_sanitizers target) + if (NOT BOLTDBG_ENABLE_ASAN) + message(VERBOSE "Sanitizers disabled (BOLTDBG_ENABLE_ASAN=OFF)") + return() + endif() + + if (MSVC) + message(WARNING "AddressSanitizer is not fully supported on MSVC. Skipping.") + return() + endif() + + # AddressSanitizer + UndefinedBehaviorSanitizer recommended combo + target_compile_options(${target} PRIVATE -fsanitize=address,undefined -fno-omit-frame-pointer) + target_link_options(${target} PRIVATE -fsanitize=address,undefined) + + # Optional: ThreadSanitizer for race conditions (enable manually if needed) + # target_compile_options(${target} PRIVATE -fsanitize=thread -fno-omit-frame-pointer) + # target_link_options(${target} PRIVATE -fsanitize=thread) + + # Recommended debug symbols + target_compile_options(${target} PRIVATE -g) + message(STATUS "Enabled AddressSanitizer and UndefinedBehaviorSanitizer for target ${target}") +endfunction() diff --git a/cmake/compiler_warnings.cmake b/cmake/compiler_warnings.cmake new file mode 100644 index 0000000..bc557eb --- /dev/null +++ b/cmake/compiler_warnings.cmake @@ -0,0 +1,7 @@ +function(set_project_warnings target) + if (MSVC) + target_compile_options(${target} PRIVATE /W4 /permissive-) + else() + target_compile_options(${target} PRIVATE -Wall -Wextra -Wpedantic -Werror) + endif() +endfunction() diff --git a/include/boltdbg.h b/include/boltdbg.h new file mode 100644 index 0000000..282f0c4 --- /dev/null +++ b/include/boltdbg.h @@ -0,0 +1,6 @@ +#ifndef BOLTDBG_H +#define BOLTDBG_H + +#define BOLTDBG_VERSION "0.1.0" + +#endif // BOLTDBG_H diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..34791b0 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,5 @@ +add_library(libboltdbg INTERFACE) +target_include_directories(libboltdbg INTERFACE ${CMAKE_SOURCE_DIR}/include) + +add_executable(boltdbg main.cpp) +target_link_libraries(boltdbg PRIVATE libboltdbg) diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..7bd7cfb --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,6 @@ +#include <iostream> + +int main(int argc, char** argv) { + std::cout << "BoltDBG (bootstrap) v0.1.0\n"; + return 0; +} diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000..67baeda --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,20 @@ +# Unit tests for BoltDBG + +# Optionally enable sanitizers for test builds +if(BOLTDBG_ENABLE_ASAN) + add_compile_options(-fsanitize=address -fno-omit-frame-pointer) + add_link_options(-fsanitize=address) +endif() + +# Collect test sources +set(TEST_SOURCES + test_main.cpp + test_logger.cpp +) + +add_executable(boltdbg_tests ${TEST_SOURCES}) +target_include_directories(boltdbg_tests PRIVATE ${CMAKE_SOURCE_DIR}/include) +target_link_libraries(boltdbg_tests PRIVATE libboltdbg) + +# If using CTest (already enabled from top-level) +add_test(NAME boltdbg_tests COMMAND boltdbg_tests) diff --git a/tests/test_logger.cpp b/tests/test_logger.cpp new file mode 100644 index 0000000..536383b --- /dev/null +++ b/tests/test_logger.cpp @@ -0,0 +1,15 @@ +#include <iostream> +//#include "../src/util/logger.h" + +void run_logger_tests(int &passed, int &failed) { + std::cout << "Running logger tests...\n"; + + try { + //log(LogLevel::Info, "Test info message"); + //log(LogLevel::Warn, "Test warning message"); + //log(LogLevel::Error, "Test error message"); + //passed++; + } catch (...) { + failed++; + } +} diff --git a/tests/test_main.cpp b/tests/test_main.cpp new file mode 100644 index 0000000..5b22560 --- /dev/null +++ b/tests/test_main.cpp @@ -0,0 +1,14 @@ +#include <iostream> + +int main() { + std::cout << "[BoltDBG] Running tests...\n"; + int passed = 0, failed = 0; + + extern void run_logger_tests(int&, int&); + run_logger_tests(passed, failed); + + std::cout << "Tests passed: " << passed << "\n"; + std::cout << "Tests failed: " << failed << "\n"; + + return failed > 0 ? 1 : 0; +} |
