From a22d8040708b77f7a59071665a994555cc18d57b Mon Sep 17 00:00:00 2001 From: Krishna Ayyalasomayajula Date: Tue, 24 Feb 2026 17:18:41 -0600 Subject: [PATCH] started changes --- .gitignore | 37 +++++++++++++++ .gitmodules | 3 ++ .opencode/AGENTS.md | 90 ++++++++++++++++++++++++++++++++++++ .opencode/cmake-plan.md | 68 +++++++++++++++++++++++++++ CMakeLists.txt | 70 ++++++++++++++++++++++++++++ external/spdlog | 1 + solution-docs/problem-810.md | 0 src/main-810.cpp | 5 ++ src/main.cpp | 7 +++ 9 files changed, 281 insertions(+) create mode 100644 .gitignore create mode 100644 .gitmodules create mode 100644 .opencode/AGENTS.md create mode 100644 .opencode/cmake-plan.md create mode 100644 CMakeLists.txt create mode 160000 external/spdlog create mode 100644 solution-docs/problem-810.md create mode 100644 src/main-810.cpp create mode 100644 src/main.cpp diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1c29c49 --- /dev/null +++ b/.gitignore @@ -0,0 +1,37 @@ +# OS junk +.DS_Store +Thumbs.db + +# Editor settings +.vscode/** +.idea/** +*.swp +*.swo +.claude/** +# Build system metadata (keep actual build dirs tracked) +CMakeFiles/** +CMakeCache.txt +cmake_install.cmake +Makefile +compile_commands.json + +# Logs and temp files +*.log +*.tmp +*.bak +*.old + +build/** +*.toml +.cache/** + + +**/*.aux +**/*.fdb_latexmk +**/*.fls +**/*.log +**/*.synctex.gz +**/*.blg +**/*.bcf +**/*.run.xml +**/*.bbl diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..6c66587 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "external/spdlog"] + path = external/spdlog + url = https://github.com/gabime/spdlog.git diff --git a/.opencode/AGENTS.md b/.opencode/AGENTS.md new file mode 100644 index 0000000..3d9c213 --- /dev/null +++ b/.opencode/AGENTS.md @@ -0,0 +1,90 @@ +# Project Agent Guidelines + +## Build, Lint, and Test Commands + +### Build Commands +```bash +# Create build directory and configure +mkdir -p build && cd build && cmake .. + +# Build all targets +make + +# Build specific target +make + +# Build with specific configuration +make Release +``` + +### Lint Commands +```bash +# C++ linting with clang-tidy (if available) +clang-tidy src/*.cpp -- -std=c++23 -I include/ + +# C++ formatting with clang-format +clang-format -i src/*.cpp include/*.h +``` + +### Test Commands +```bash +# Run all tests (if any exist) +make test + +# Run a single test (if using a testing framework like Google Test) +./build/ + +# For CMake-based projects with tests +ctest -R +``` + +## Code Style Guidelines + +### General +- Use C++23 standard features +- Follow Google C++ Style Guide principles +- Keep functions small and focused +- Use meaningful, descriptive names +- Write clear, self-documenting code +- Add comments for complex logic + +### Naming Conventions +- Classes: PascalCase (e.g., `MyClass`) +- Functions: camelCase (e.g., `calculateSum`) +- Variables: camelCase (e.g., `myVariable`) +- Constants: UPPER_SNAKE_CASE (e.g., `MAX_SIZE`) +- Files: snake_case (e.g., `my_file.cpp`) + +### Imports and Includes +- Use angle brackets for system headers: `#include ` +- Use quotes for local headers: `#include "my_header.h"` +- Order includes: system headers, then local headers +- Avoid `using namespace` in headers +- Use forward declarations when possible + +### Formatting +- Use 2-space indentation (no tabs) +- No trailing whitespace +- Single space around operators +- Function parameters on same line if short, otherwise one parameter per line +- Braces on same line for functions, new line for control structures + +### Types +- Use `auto` when type is obvious from initialization +- Prefer `const` and `constexpr` for immutable values +- Use smart pointers (`std::unique_ptr`, `std::shared_ptr`) instead of raw pointers +- Use `std::optional` for optional values +- Use `std::string_view` for string views + +### Error Handling +- Use exceptions for error conditions +- Prefer RAII for resource management +- Use `std::optional` or `std::expected` for operations that can fail +- Don't ignore return values of functions that can fail + +### Code Structure +- Keep lines under 100 characters +- Separate logical sections with blank lines +- Group related functions together +- Use namespaces to avoid naming conflicts +- Break large functions into smaller, reusable components \ No newline at end of file diff --git a/.opencode/cmake-plan.md b/.opencode/cmake-plan.md new file mode 100644 index 0000000..695d9d2 --- /dev/null +++ b/.opencode/cmake-plan.md @@ -0,0 +1,68 @@ +# CMake 2026 Project Setup Plan + +## Overview +This document outlines the technical plan for setting up a CMake-based C++ project with the following requirements: +- clang++ compiler with C++23 defaults +- Automatic source file discovery in src/ directory +- Executable generation from files containing 'main' in filename +- External dependency handling for git submodules +- Organized compile flags and variables + +## Key Components + +### 1. Compiler Configuration +- Use clang++ as the C++ compiler +- Set C++ standard to C++23 +- Configure appropriate compiler flags for clang + +### 2. Source File Discovery +- Scan src/ directory for all .cpp files +- Use regex pattern `.*main.*\.cpp$` to identify main files +- Separate main files from other source files + +### 3. Executable Generation +- Automatically create executables from files with 'main' in filename +- Create a library from all non-main source files +- Link the library to each executable + +### 4. External Dependency Management +- Handle dependencies in external/ directory +- Example: spdlog in external/spdlog with namespace spdlog +- Create interface libraries for external dependencies + +### 5. Compile Flags Organization +- Debug build flags: -g -O0 -Wall -Wextra +- Release build flags: -O3 -DNDEBUG -Wall -Wextra +- Common flags: -std=c++23 -fPIC + +## Implementation Details + +### Regex Pattern +``` +.*main.*\.cpp$ +``` +Used to detect files containing 'main' in their filename. + +### Directory Structure +- `src/` - Source files directory +- `external/` - Git submodules directory +- `include/` - Header files directory + +### File Processing Logic +1. Find all .cpp files in src/ +2. Separate main files from other source files +3. Create library from non-main files +4. Generate executables from main files +5. Link library and external dependencies to each executable + +## CMake Commands Used +- `cmake_minimum_required(VERSION 3.15)` +- `project(ProjectEuler CXX)` +- `file(GLOB_RECURSE)` +- `list(APPEND)` +- `add_executable()` +- `add_library()` +- `target_link_libraries()` +- `target_compile_features()` +- `find_package()` +- `add_subdirectory()` \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..376db5e --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,70 @@ +# CMakeLists.txt +cmake_minimum_required(VERSION 3.15) +project(ProjectEuler CXX) + +# Set C++ standard to C++23 +set(CMAKE_CXX_STANDARD 23) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) + +# Use system default C++ compiler +# set(CMAKE_CXX_COMPILER clang++) + +# Set compile flags +set(CMAKE_CXX_FLAGS_DEBUG "-g -O0 -Wall -Wextra") +set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG -Wall -Wextra") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++23 -fPIC") + +# Find required packages +find_package(PkgConfig REQUIRED) +find_package(Threads REQUIRED) + +# Include directories +include_directories(${CMAKE_SOURCE_DIR}/include) + +# Add spdlog as a subdirectory +add_subdirectory(external/spdlog) + +# Find all cpp files in src directory +file(GLOB_RECURSE ALL_SOURCE_FILES "src/*.cpp") + +# Separate main files from other source files +set(NON_MAIN_SOURCE_FILES "") +set(MAIN_SOURCE_FILES "") + +foreach(file ${ALL_SOURCE_FILES}) + # Check if file name contains 'main' + if(file MATCHES ".*main.*\\.cpp$") + list(APPEND MAIN_SOURCE_FILES ${file}) + else() + list(APPEND NON_MAIN_SOURCE_FILES ${file}) + endif() +endforeach() + +# Create a library from non-main source files +if(NON_MAIN_SOURCE_FILES) + add_library(project_euler_lib ${NON_MAIN_SOURCE_FILES}) + target_link_libraries(project_euler_lib spdlog::spdlog) + target_compile_features(project_euler_lib PRIVATE cxx_std_23) +endif() + +# Create executables from main files +foreach(file ${MAIN_SOURCE_FILES}) + # Get the filename without extension + get_filename_component(EXEC_NAME ${file} NAME_WE) + + # Create executable with project prefix + set(FINAL_EXEC_NAME "ProjectEuler_${EXEC_NAME}") + add_executable(${FINAL_EXEC_NAME} ${file}) + + # Link the library to executable (if it exists) + if(NON_MAIN_SOURCE_FILES) + target_link_libraries(${FINAL_EXEC_NAME} project_euler_lib) + endif() + + # Link spdlog library + target_link_libraries(${FINAL_EXEC_NAME} spdlog::spdlog) + + # Set compile features + target_compile_features(${FINAL_EXEC_NAME} PRIVATE cxx_std_23) +endforeach() \ No newline at end of file diff --git a/external/spdlog b/external/spdlog new file mode 160000 index 0000000..d5af52d --- /dev/null +++ b/external/spdlog @@ -0,0 +1 @@ +Subproject commit d5af52d903ed69f96c7350155e94aeff248b31eb diff --git a/solution-docs/problem-810.md b/solution-docs/problem-810.md new file mode 100644 index 0000000..e69de29 diff --git a/src/main-810.cpp b/src/main-810.cpp new file mode 100644 index 0000000..f978703 --- /dev/null +++ b/src/main-810.cpp @@ -0,0 +1,5 @@ +#include +int main (int argc, char *argv[]) { + spdlog::info("Running solution to problem 810"); + return 0; +} diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..df6d08a --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,7 @@ +#include +#include +int main() { + + spdlog::info("Hello world from logger"); + return 0; +}