Skip to content

Commit

Permalink
Add Compiler.h
Browse files Browse the repository at this point in the history
  • Loading branch information
flagarde committed May 13, 2024
1 parent 4b028d8 commit 935f325
Show file tree
Hide file tree
Showing 18 changed files with 1,995 additions and 245 deletions.
2 changes: 1 addition & 1 deletion .cmake-linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ lint:
internal_var_pattern: '[_A-Za-z][0-9a-zA-Z_]+'
local_var_pattern: '[A-Za-z][A-Za-z0-9_]+'
private_var_pattern: _[0-9a-z_]+
public_var_pattern: '[A-Z][0-9A-Z_]+'
public_var_pattern: '[A-Za-z][0-9A-Za-z_]+'
argument_var_pattern: '[A-Za-z][A-Za-z0-9_]+'
keyword_pattern: '[A-Z][0-9A-Z_]+'
max_conditionals_custom_parser: 2
Expand Down
2 changes: 1 addition & 1 deletion cmake/KhaosConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

include(${CMAKE_CURRENT_LIST_DIR}/KhaosTargets.cmake)

check_required_components(Khaos)
check_required_components(Khaos)
3 changes: 3 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
add_executable(KhaosVersion.example KhaosVersion.cpp)
target_link_libraries(KhaosVersion.example PRIVATE Khaos::Khaos)

add_executable(Compiler.example Compiler.cpp)
target_link_libraries(Compiler.example PRIVATE Khaos::Khaos)
24 changes: 24 additions & 0 deletions examples/Compiler.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Khaos
* C/C++ library for writing cross-platform codes.
*
* SPDX-FileCopyrightText: 2024-2024 flagarde
*
* SPDX-License-Identifier: MIT
*/

#include <Khaos/Compiler.h>
#include <iostream>

int main()
{
#if COMPILER_IS(Clang)
std::cout << "I'm Clang" << std::endl;
#elif COMPILER_IS(GCC)
std::cout << "I'm GCC" << std::endl;
#elif COMPILER_IS(MSVC)
std::cout << "I'm MSVC" << std::endl;
#endif

std::cout << "Compiler version : " << GET_VERSION_MAJOR(Compiler) << "." << GET_VERSION_MINOR(Compiler) << "." << GET_VERSION_PATCH(Compiler) << "." << GET_VERSION_TWEAK(Compiler) << std::endl;
}
53 changes: 27 additions & 26 deletions include/Khaos/CompareVersions.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,39 +12,40 @@

#include "Khaos/Version.h"

/** \file CompareVersion.h
* \brief Define macros to compare versions.
* \note Use these macros only if you need preprocessor version checking.
* \note For example :
* \code{.cpp}
* #if CHECK_VERSIONS(version1,==,version2)
* ...
* #else
* ...
* #endif
* \endcode
/*!
* \brief Define macros to compare versions.
* \note Use these macros only if you need preprocessor version checking.
* \note For example :
* \code{.cpp}
* #if CHECK_VERSIONS(version1,==,version2)
* ...
* #else
* ...
* #endif
* \endcode
*/

/** \hideinitializer
* \brief Check the \b version with \b major, \b minor, \b patch, \b tweak using the operator \b op
* \param[in] version version to compare.
* \param[in] op operator =, !=, >=, <= >, < .
* \param[in] major major part.
* \param[in] minor minor part.
* \param[in] patch patch part.
* \param[in] tweak tweak part.
/*!
* \hideinitializer
* \brief Check the \b version with \b major, \b minor, \b patch, \b tweak using the operator \b op
* \param[in] version version to compare.
* \param[in] op operator =, !=, >=, <= >, < .
* \param[in] major major part.
* \param[in] minor minor part.
* \param[in] patch patch part.
* \param[in] tweak tweak part.
*
* \note Value can be directly used in both preprocessor and compiler expressions for comparison to other similarly defined values.
* \note Value can be directly used in both preprocessor and compiler expressions for comparison to other similarly defined values.
*/
#define CHECK_VERSION(version, op, major, minor, patch, tweak) ((KHAOS_DEFINE_##version##_VERSION_PRIVATE())op(SET_VERSION(major, minor, patch, tweak)))

/** \hideinitializer
* \brief Check the \b versiona with \b versionb using the operator \b op
* \param[in] versiona version to compare.
* \param[in] op operator =, !=, >=, <= >, < .
* \param[in] versionb version to compare.
/*!
* \brief Check the \b versiona with \b versionb using the operator \b op
* \param[in] versiona version to compare.
* \param[in] op operator =, !=, >=, <= >, < .
* \param[in] versionb version to compare.
*
* \note Value can be directly used in both preprocessor and compiler expressions for comparison to other similarly defined values.
* \note Value can be directly used in both preprocessor and compiler expressions for comparison to other similarly defined values.
*/

#define CHECK_VERSIONS(a, op, b) ((KHAOS_DEFINE_##a##_VERSION_PRIVATE())op(KHAOS_DEFINE_##b##_VERSION_PRIVATE()))
Expand Down
Loading

0 comments on commit 935f325

Please sign in to comment.