Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added code for version macro for code to check. #150

Merged
merged 10 commits into from
Jun 3, 2024
12 changes: 12 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ set(LIBTOOL_INTERFACE 2)
set(LIBTOOL_REVISION 3)
set(LIBTOOL_AGE 2)

# VERSION is XYYYZZ X: Major Y Minor Z PATCH
set(GOTCHA_VERSION 100006)
hariharan-devarajan marked this conversation as resolved.
Show resolved Hide resolved


set(DEFAULT_SYMBOL_VISIBILITY hidden)

if(GOTCHA_ENABLE_TESTS)
Expand All @@ -22,6 +26,7 @@ if(GOTCHA_ENABLE_TESTS)
endif()
endif()
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
include_directories(${CMAKE_BINARY_DIR}/include)
add_subdirectory(include)
add_subdirectory(src)
if(GOTCHA_ENABLE_TESTS)
Expand Down Expand Up @@ -50,3 +55,10 @@ configure_package_config_file(
install(
FILES "${CMAKE_CURRENT_BINARY_DIR}/gotcha-config.cmake" "${CMAKE_CURRENT_BINARY_DIR}/gotcha-config-version.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/gotcha")

# Write the configure file
configure_file("${CMAKE_SOURCE_DIR}/cmake/gotcha_config.h.in"
"${CMAKE_CURRENT_BINARY_DIR}/include/gotcha/gotcha_config.h" @ONLY)
install(
FILES "${CMAKE_CURRENT_BINARY_DIR}/include/gotcha/gotcha_config.h"
DESTINATION "${gotcha_INSTALL_INCLUDE_DIR}/gotcha/gotcha_config.h")
10 changes: 10 additions & 0 deletions cmake/gotcha_config.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef GOTCHA_CONFIG_HPP
#define GOTCHA_CONFIG_HPP

#define GOTCHA_VERSION @GOTCHA_VERSION@
#define GOTCHA_VERSION_MAJOR (GOTCHA_VERSION / 100000)
#define GOTCHA_VERSION_MINOR ((GOTCHA_VERSION / 100) % 1000)
#define GOTCHA_VERSION_PATCH (GOTCHA_VERSION % 100)
#define GOTCHA_GET_VERSION(MAJOR, MINOR, PATCH) MAJOR * 100000 + MINOR * 100 + PATCH
hariharan-devarajan marked this conversation as resolved.
Show resolved Hide resolved

#endif /* HPC_AIO_CONFIG_H */
hariharan-devarajan marked this conversation as resolved.
Show resolved Hide resolved
24 changes: 24 additions & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -178,5 +178,29 @@ The default filter of gotcha selects all libraries loaded. This function set the

.. explicit external hyperlink targets

---------------------------
Using Gotcha Version Macros
---------------------------

The source version of GOTCHA is defined by the `GOTCHA_VERSION` macro which uses the XYYYZZ format.
Here, X signifies the major version, Y is the minor version, and Z is the patch.
Additionally, we define `GOTCHA_VERSION_MAJOR`, `GOTCHA_VERSION_MINOR`, and `GOTCHA_VERSION_PATCH` macros for convienience.
The codes can use the macros like
hariharan-devarajan marked this conversation as resolved.
Show resolved Hide resolved


.. code-block:: c

#if GOTCHA_VERSION > 100006 // this will check of version greater than 1.0.6
#endif

#if GOTCHA_VERSION_MAJOR > 1 // this will check of version greater than 2.0.0
#endif

#if GOTCHA_VERSION > GOTCHA_GET_VERSION(1,0,6) // this will check of version greater than 1.0.6
#endif




.. _`gnu constructor`: https://gcc.gnu.org/onlinedocs/gcc-4.7.2/gcc/Function-Attributes.html
.. _symbol: https://refspecs.linuxfoundation.org/LSB_3.0.0/LSB-PDA/LSB-PDA.junk/symversion.html
4 changes: 2 additions & 2 deletions include/gotcha/gotcha.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#ifndef GOTCHA_H
#define GOTCHA_H

#include <gotcha/gotcha_config.h>
#include <gotcha/gotcha_types.h>
#include <link.h>

#include "gotcha/gotcha_types.h"

#if defined(__cplusplus)
extern "C" {
#endif
Expand Down
Loading