From 2f8f7025db1bd34fd2de2c2a4934a5450eb2614a Mon Sep 17 00:00:00 2001 From: dev0 Date: Fri, 26 Dec 2025 00:14:15 +0530 Subject: [PATCH] [DOCS]: Building & Using --- CMake/IAProjectConfig.cmake | 29 +++++++++++++ CMakeLists.txt | 84 ++++++++++++++----------------------- Docs/BUILDING.md | 43 +++++++++++++++++++ Docs/USING.md | 26 ++++++++++++ README.md | 49 +++++++++++----------- Src/IACore/CMakeLists.txt | 2 +- 6 files changed, 155 insertions(+), 78 deletions(-) create mode 100644 CMake/IAProjectConfig.cmake create mode 100644 Docs/BUILDING.md create mode 100644 Docs/USING.md diff --git a/CMake/IAProjectConfig.cmake b/CMake/IAProjectConfig.cmake new file mode 100644 index 0000000..869134f --- /dev/null +++ b/CMake/IAProjectConfig.cmake @@ -0,0 +1,29 @@ +macro(iacore_setup_project) + + set(CMAKE_CXX_STANDARD 20) + set(CMAKE_CXX_STANDARD_REQUIRED ON) + set(CMAKE_CXX_EXTENSIONS OFF) + set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") + set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib") + set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib") + + if(MSVC) + add_compile_options(/W4) + if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") + add_compile_options(-Wno-c++98-compat -Wno-c++98-compat-pedantic) + endif() + elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU") + add_compile_options(-Wall -Wextra -Wpedantic -Wno-language-extension-token) + endif() + + if(CMAKE_SYSTEM_PROCESSOR MATCHES "amd64|x86_64|AMD64") + set(IACORE_ARCH_X64 TRUE CACHE INTERNAL "") + elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|arm64|ARM64") + set(IACORE_ARCH_ARM64 TRUE CACHE INTERNAL "") + elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "wasm32|emscripten") + set(IACORE_ARCH_WASM TRUE CACHE INTERNAL "") + endif() + +endmacro() diff --git a/CMakeLists.txt b/CMakeLists.txt index 45eca2c..14a42bb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,72 +1,50 @@ cmake_minimum_required(VERSION 3.28 FATAL_ERROR) -set(CMAKE_CXX_STANDARD 20) -set(CMAKE_CXX_EXTENSIONS OFF) -set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_EXPORT_COMPILE_COMMANDS ON) +set(IACORE_ROOT "${CMAKE_CURRENT_LIST_DIR}" CACHE INTERNAL "") +set(IACORE_TRIPLETS_DIR "${IACORE_ROOT}/CMake/Triplets" CACHE INTERNAL "") -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) -set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) -set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) - -project(IACore) - -enable_language(C) - -include(CMake/FindDeps.cmake) - -# Default to ON if root, OFF if dependency -option(IACore_BUILD_TESTS "Build unit tests" ${PROJECT_IS_TOP_LEVEL}) - -message(STATUS "Configured IACore for Multi-Config (Debug/Release rules generated)") - -message(STATUS "Detected Compiler ID: ${CMAKE_CXX_COMPILER_ID}") -# Check if the compiler is MSVC (cl.exe), but allow Clang acting like MSVC (clang-cl) -if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") - if (NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang") - message(FATAL_ERROR - "\n\n" - "-------------------------------------------------------------\n" - "CRITICAL ERROR: Unsupported Compiler Detected (MSVC/cl.exe)\n" - "-------------------------------------------------------------\n" - "IACore requires GCC or Clang to compile.\n" - "For compiling with IACore on Windows, please use Clang Tools for MSVC.\n" - "-------------------------------------------------------------\n" - ) +if(IACORE_TRIPLETS_DIR) + list(APPEND VCPKG_OVERLAY_TRIPLETS "${IACORE_TRIPLETS_DIR}") + if(NOT CMAKE_CURRENT_LIST_DIR STREQUAL CMAKE_SOURCE_DIR) + set(VCPKG_OVERLAY_TRIPLETS "${VCPKG_OVERLAY_TRIPLETS}" PARENT_SCOPE) endif() endif() -if(CMAKE_SYSTEM_PROCESSOR MATCHES "amd64|x86_64|AMD64") - set(IACORE_ARCH_X64 TRUE) -elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|arm64|ARM64") - set(IACORE_ARCH_ARM64 TRUE) -elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "wasm32|emscripten") - set(IACORE_ARCH_WASM TRUE) +project(IACore LANGUAGES C CXX) + +if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) + set(IACORE_IS_TOP_LEVEL ON) +else() + set(IACORE_IS_TOP_LEVEL OFF) endif() -if(MSVC) - add_compile_options(/W4) - if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") - add_compile_options( - -Wno-c++98-compat - -Wno-c++98-compat-pedantic - ) - endif() +set(IACORE_CMAKE_DIR "${IACORE_ROOT}/CMake" CACHE INTERNAL "") +list(APPEND CMAKE_MODULE_PATH "${IACORE_CMAKE_DIR}") -elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU") - add_compile_options( - -Wall -Wextra -Wpedantic - -Wno-language-extension-token +include(IAProjectConfig) +iacore_setup_project() + +message(STATUS "[IACore] Detected Compiler: ${CMAKE_CXX_COMPILER_ID}") + +if (MSVC AND NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang") + message(FATAL_ERROR + "\n-------------------------------------------------------------\n" + "CRITICAL ERROR: Unsupported Compiler (MSVC/cl.exe)\n" + "IACore requires GCC or Clang. On Windows, use 'Clang-cl' or MinGW.\n" + "-------------------------------------------------------------\n" ) endif() -add_subdirectory(Src/) +include(FindDeps) + +option(IACore_BUILD_TESTS "Build unit tests" ${IACORE_IS_TOP_LEVEL}) + +add_subdirectory(Src) if(IACore_BUILD_TESTS) add_subdirectory(Tests) endif() -# Local Development Sandbox (Not tracked in git) if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/Sandbox") - add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/Sandbox") + add_subdirectory(Sandbox) endif() diff --git a/Docs/BUILDING.md b/Docs/BUILDING.md new file mode 100644 index 0000000..377f720 --- /dev/null +++ b/Docs/BUILDING.md @@ -0,0 +1,43 @@ +## 🛠️ Building IACore + +IACore uses **CMake Presets** to manage toolchains and cross-compilation. This ensures that the correct compilers (Clang) and flags (AVX2/SIMD) are used automatically. + +### Prerequisites +* CMake 3.28+ +* Ninja Build System +* Vcpkg (Environment variable `VCPKG_ROOT` must be set) +* Clang / Clang-CL + +### Build Instructions + +**1. Configure** +Select the preset for your target platform. +```bash +# List available presets +cmake --list-presets + +# Configure for your platform (e.g., windows-x64, linux-arm64, wasm) +cmake --preset windows-x64 +``` + +**2. Build** + +```bash +cmake --build --preset windows-x64 +``` + +**3. Test (Optional)** + +```bash +ctest --preset windows-x64 +``` + +### Presets + +|Preset |Description |Toolchain | +|-------------|------------------------------|------------------------------------| +|windows-x64 |Windows (Clang-CL) |CMake/Toolchains/windows-x64.cmake | +|linux-x64 |Linux (Clang) |CMake/Toolchains/linux-x64.cmake | +|wasm |WebAssembly (Emscripten) |CMake/Toolchains/wasm.cmake | +|windows-arm64|Windows on ARM (Cross-compile)|CMake/Toolchains/windows-arm64.cmake| +|linux-arm64 |Linux on ARM (Cross-compile) |CMake/Toolchains/linux-arm64.cmake | diff --git a/Docs/USING.md b/Docs/USING.md new file mode 100644 index 0000000..50bad2a --- /dev/null +++ b/Docs/USING.md @@ -0,0 +1,26 @@ +## 🚀 Using IACore in a New Project + +IACore provides a CMake macro `iacore_setup_project()`, which standardizes your build environment. This macro automatically: + +* Enforces C++20 standard. +* Sets warning levels (-Wall -Wextra -Wpedantic for Clang/GCC, /W4 for MSVC/Clang-CL). +* Detects the target architecture (x64, ARM64, WASM) and sets internal cache variables. +* Suppresses C++98 compatibility warnings when using Clang on Windows. + +Example CMakeLists.txt +```cmake +cmake_minimum_required(VERSION 3.28) +project(MyGame) + +add_subdirectory(external/IACore) + +## Apply IACore's standard project configuration +# This applies C++20 and strict warning flags globally to your targets. +iacore_setup_project() + +# Define your target(s) +add_executable(MyGame src/main.cpp) + +# Link IACore +target_link_libraries(MyGame PRIVATE IACore) +``` diff --git a/README.md b/README.md index 3a75693..57555d8 100644 --- a/README.md +++ b/README.md @@ -28,30 +28,6 @@ Originally developed as the internal core for IASoft (PVT) LTD., it is now open- * **📜 Logging:** Thread-safe, colored console and disk logging. * **⚡ Modern C++:** Heavily utilizes modern C++20 concepts, `std::span`, and `tl::expected` for error handling. -## 🛠️ Integration - -IACore is built with CMake. You can include it in your project via `FetchContent` or by adding it as a subdirectory. - -**Note:** On Windows, you must have **VCPKG** installed and the `VCPKG_ROOT` environment variable set, for OpenSSL support. - -### CMake Example -```cmake -add_subdirectory(IACore) - -add_executable(MyApp Main.cpp) -target_link_libraries(MyApp PRIVATE IACore) -``` - -## 📦 Dependencies -IACore manages its own dependencies via CMake's FetchContent. You do not need to install these manually: - -* **Networking:** `cpp-httplib` -* **Compression:** `zlib-ng` & `zstd` -* **Utilities:** `tl-expected` & `unordered_dense` -* **JSON:** `glaze` - -**Note:** Following dependencies are not directly used by IACore, but bundles them (+ helper wrappers) for user convenience: `nlohmann_json`, `simdjson`, `pugixml` - ## 💡 Usage Examples ### 1. IPC (Manager & Node) IACore provides a manager/node architecture using shared memory. @@ -132,6 +108,20 @@ if (res) { } ``` +## 🛠️ Integration + +IACore is built with CMake. You can include it in your project via `FetchContent` or by adding it as a subdirectory. + +**Note:** On Windows, you must have **VCPKG** installed and the `VCPKG_ROOT` environment variable set, for OpenSSL support. + +### CMake Example +```cmake +add_subdirectory(IACore) + +add_executable(MyApp Main.cpp) +target_link_libraries(MyApp PRIVATE IACore) +``` + ## 🤝 Contributing We welcome contributions from the community! @@ -147,6 +137,17 @@ Currently, **we are not accepting Pull Requests that modify the core source code If you find a critical bug in `Src/`, please open an **Issue** rather than a PR, and the core team will implement a fix ASAP. +## 📦 Dependencies +IACore manages its own dependencies via CMake's FetchContent. You do not need to install these manually: + +* **JSON:** `glaze` +* **SIMD:** `google-highway` +* **Networking:** `cpp-httplib` +* **Compression:** `zlib-ng` & `zstd` +* **Utilities:** `tl-expected` & `unordered_dense` + +**Note:** Following dependencies are not directly used by IACore, but bundles them (+ helper wrappers) for user convenience: `nlohmann_json`, `simdjson`, `pugixml` + ## ⚖️ License This project is licensed under the Apache License Version 2.0. diff --git a/Src/IACore/CMakeLists.txt b/Src/IACore/CMakeLists.txt index 59e6c9f..6ef8ce9 100644 --- a/Src/IACore/CMakeLists.txt +++ b/Src/IACore/CMakeLists.txt @@ -78,7 +78,7 @@ if(IACORE_ARCH_X64) if(MSVC) target_compile_options(IACore INTERFACE /arch:AVX2) else() - target_compile_options(IACore INTERFACE -mavx2 -mfma) + target_compile_options(IACore INTERFACE -mavx2 -mfma -mpclmul -maes) endif() target_compile_definitions(IACore INTERFACE HWY_BASELINE_TARGETS=HWY_AVX2) elseif(IACORE_ARCH_ARM64)