Skip to content

A simple, header-only C library designed to provide compile-time system information.

License

Notifications You must be signed in to change notification settings

KumarjitDas/kdapi

Repository files navigation

KDAPI

KDAPI is a simple, header-only C library designed to provide compile-time system information. This project targets both Windows and GNU/Linux (32-bit and 64-bit) platforms. The library aims to help developers easily retrieve details about the compiler, target operating system, target CPU, and endianness at compile-time.

Table of Contents

Features

  • Detects compiler type and version.
  • Identifies the target operating system.
  • Determines the target CPU architecture.
  • Checks system endianness.
  • Provides macros for import-export signatures, calling conventions, and extern indicators.
  • CMake target for ease of use with other CMake projects.

Installation

To get started with this project, download and install the following.

  • Download and install git

    • If you use Windows, then go to this link and download and install the suitable version.

    • If you use any stable version of Debian/Ubuntu then run this command in your terminal

      sudo apt-get install git
    • If you use macOS then install homebrew if you don't already have it, then run this command in your terminal

      brew install git
  • Run the command to clone this repository

    git clone https://github.com/KumarjitDas/kdapi.git
  • Download and install a C compiler

    • If you use Windows 8/10/11 then download Visual Studio 2017/2019/2022 from this link download and install a suitable version of clang from this link. For gcc, use the suitable MinGW version from this link.

    • If you use any stable version of Debian/Ubuntu then run these commands in your terminal to download and install clang and gcc compilers

      sudo apt install clang
      sudo apt install gcc
    • In macOS, clang is the default C compiler. To download and install gcc, run this command in your terminal

      brew install gcc

Requirements

  • For building on Linux 32-bit targets on a 64-bit platform, gcc-multilib must be installed:

    sudo apt install gcc-multilib

Usage

Include the kdapi.h header file in your C project to use KDAPI.

#include "kdapi.h"

Example

An example usage of KDAPI can be found in the test.c file.

#include <stdio.h>
#include "kdapi.h"

int main() {
    printf("KDAPI Version: %s\n", KD_VERSION_STR);
    
    printf("Current OS: %s\n",
    #ifdef KD_OS_LINUX
           "Linux"
    #elif KD_OS_WINDOWS
           "Windows"
    #else
           "Unknown"
    #endif
    );
    
    return 0;
}

Roadmap

See the open issues for a list of proposed features/functionalities (and known issues).

The list of features and functions implemented till now is given in Project Status.

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

  • Fork this project [kdapi]

  • Create your Feature Branch

    git checkout -b feature/AmazingFeature
  • Commit your Changes

    git commit -m 'Added some AmazingFeature'
  • Push to the Branch

    git push origin feature/AmazingFeature
  • Create a pull request

Naming Convention

The KDAPI project follows a consistent naming convention to ensure readability and maintainability. Here are the key aspects of the naming convention used:

  • Macro Names: Macro names are written in uppercase letters with underscores separating words. They typically start with the prefix KD_.

    • Examples: KD_COMPILER_GCC, KD_OS_LINUX, KD_CPU_X86_64, KD_VERSION_MAJOR
  • Function-Like Macros: Function-like macros also follow the uppercase with underscores convention and use parentheses to indicate parameters.

    • Examples: KD_EXTERN_BEGIN, KD_EXTERN_END
  • Constants: Constants are defined using uppercase letters with underscores and often include a descriptive name or version number.

    • Examples: KD_VERSION_STR, KD_VERSION_MAJOR
  • File Names: File names are in lowercase and use underscores to separate words.

    • Examples: kdapi.h, test.c, setup_env.sh

License

This project is distributed under the BSD 2-Clause License. See LICENSE for more information.

Project Status

List of functionalities/features implemented so far:

  • Compiler Detection: Macros for various compilers (Intel, GCC, LLVM, etc.).
  • OS Identification: Macros for target operating systems (Linux, Windows, etc.).
  • CPU Architecture Detection: Macros for target CPU architectures (x86, x64, ARM, etc.).
  • Endianness Determination: Macros for little-endian and big-endian.
  • DLL Handling: Import-export macros for DLLs.
  • Calling Conventions: Macros for cdecl, stdcall, fastcall.
  • Build Configuration: CMake configuration files for shared and static builds.
  • Example Program: Example demonstrating library usage.

Acknowledgment

I appreciate these websites which helped me to make such good README file, and helped me to learn about project versioning and keeping CHANGELOG.

Contact

Twitter: @kumarjitdas1999

LinkedIn: Kumarjit Das

E-mail: [email protected]

Project link: KDAPI

Versioning

This project uses MAJOR, MINOR, and PATCH version numbers for versioning (vMAJOR.MINOR.PATCH).

  • MAJOR version number indicates new changes which may be incompatible with older versions.
  • MINOR version number indicates addition of backwards-compatible features.
  • PATCH version number indicates backwards-compatible bug fixes, or minor mistake fixes like spelling, character cases, punctuations, and indentation.

Changelog

The Changelog file contains all the information about the changes made to this project till now.