diff --git a/CMakeLists.txt b/CMakeLists.txt index 40f4fd1..0a877fd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,6 +6,10 @@ option(USE_OPTIONAL "Enable the _Optional qualifier" OFF) option(USE_FORTIFY "Enable Fortify memory-allocation checking" OFF) option(ENABLE_CLANG_TIDY "Run clang-tidy during compilation" OFF) +FetchContent_Declare(CBUtil GIT_REPOSITORY https://github.com/chrisbazley/CBUtilLib.git GIT_TAG main) + +FetchContent_MakeAvailable(CBUtil) + if(USE_OPTIONAL) if(NOT CMAKE_C_COMPILER_ID MATCHES "Clang|AppleClang") message(FATAL_ERROR @@ -78,13 +82,7 @@ set_target_properties(GKey PROPERTIES DEBUG_POSTFIX "dbg" ) -if(USE_OPTIONAL) - FetchContent_Declare(CBUtil GIT_REPOSITORY https://github.com/chrisbazley/CBUtilLib.git GIT_TAG main) - - FetchContent_MakeAvailable(CBUtil) - - target_link_libraries(GKey PRIVATE CBUtil) -endif() +target_link_libraries(GKey PRIVATE CBUtil) target_include_directories(GKey PUBLIC .) diff --git a/Internal/GKeyMisc.h b/Internal/GKeyMisc.h index cc180c7..756fe2e 100644 --- a/Internal/GKeyMisc.h +++ b/Internal/GKeyMisc.h @@ -20,11 +20,14 @@ /* History: CJB: 08-Apr-25: Dogfooding the _Optional qualifier. CJB: 15-Jun-26: Send the debug log to stderr not stdout. + CJB: 22-Sep-26: Use common macro definitions from CBUtilLib. */ #ifndef GKeyMisc_h #define GKeyMisc_h +#include "MacroUtils.h" + #ifdef FORTIFY #include "fortify.h" #endif @@ -58,15 +61,4 @@ #define _Optional #endif -#define LOWEST(a, b) ((a) < (b) ? (a) : (b)) - -#define FREE_SAFE(memptr) do { \ - free(memptr); \ - (memptr) = NULL; \ -} while (0) - -#define NOT_USED(x) ((void)(x)) - -#define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0])) - #endif /* GKeyMisc_h */ diff --git a/README.md b/README.md index ae3b829..3f82aac 100644 --- a/README.md +++ b/README.md @@ -148,12 +148,12 @@ files with .c and .h suffixes into subdirectories named 'c' and 'h' and remove those suffixes from their names. You probably also need to create 'o', 'oz', 'd' and 'debug' subdirectories for compiler output. - You should ensure that the standard C library and CBDebugLib (by the same -author as GKeyLib) are on your header include path (C$Path if using the -supplied make files on RISC OS), otherwise the compiler won't be able to find -the required header files. The dependency on CBDebugLib isn't very strong: it -can be eliminated by modifying the make file so that the macro USE_CBDEBUG is -no longer predefined. + You should ensure that the standard C library, CBUtilLib and CBDebugLib (by +the same author as GKeyLib) are on your header include path (C$Path if using +the supplied make files on RISC OS), otherwise the compiler won't be able to +find the required header files. The dependency on CBDebugLib isn't very strong: +it can be eliminated by modifying the make file so that the macro USE_CBDEBUG +is no longer predefined. Licence and disclaimer ---------------------- diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 1d9e66b..197c288 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -2,9 +2,5 @@ file(GLOB SOURCES "*.c") file(GLOB PRIVATE_HEADERS "*.h") add_executable(GKeyTests ${SOURCES} ${PRIVATE_HEADERS}) -target_link_libraries(GKeyTests PRIVATE GKey) +target_link_libraries(GKeyTests PRIVATE GKey CBUtil) add_test(NAME "GKeyTests" COMMAND GKeyTests) - -if(USE_OPTIONAL) - target_link_libraries(GKeyTests PRIVATE CBUtil) -endif() diff --git a/tests/Tests.h b/tests/Tests.h index 5243095..1321900 100644 --- a/tests/Tests.h +++ b/tests/Tests.h @@ -22,6 +22,8 @@ #undef NDEBUG +#include "MacroUtils.h" + #ifdef FORTIFY #include "fortify.h" #else @@ -50,9 +52,6 @@ #define _Optional #endif -#define NOT_USED(x) ((void)(x)) -#define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0])) - extern void GKeyComp_tests(void); extern void GKeyDecomp_tests(void); extern void RingBuffer_tests(void);