From aa83ad6bb7add34e2071875148edfb5cd2e2679e Mon Sep 17 00:00:00 2001 From: Keith Derrick Date: Fri, 6 Mar 2026 13:44:09 -0800 Subject: [PATCH 1/2] Clean up tests CMake --- tests/CMakeLists.txt | 8 -------- tests/data/CertManagementPdu.dat | Bin 153 -> 0 bytes 2 files changed, 8 deletions(-) delete mode 100644 tests/data/CertManagementPdu.dat diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 984d7a1..3615da6 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -24,12 +24,4 @@ target_include_directories(api_tests add_test(NAME api_tests COMMAND api_tests) -# file(GLOB TEST_JSON CONFIGURE_DEPENDS "*.json") file(GLOB TEST_CSV -# CONFIGURE_DEPENDS "*.csv") file(GLOB TEST_TXT CONFIGURE_DEPENDS "*.txt") - -# foreach(TEST_FILE ${TEST_JSON} ${TEST_CSV} ${TEST_TXT}) cmake_path(GET -# TEST_FILE FILENAME TEST_BASENAME) message(STATUS "Configuring TEST FILE: -# ${TEST_BASENAME}") configure_file(${TEST_BASENAME} ${TEST_BASENAME} COPYONLY) -# endforeach() - gtest_discover_tests(api_tests) diff --git a/tests/data/CertManagementPdu.dat b/tests/data/CertManagementPdu.dat deleted file mode 100644 index f1046450079fd129564acbb7f6bdbcd092e85cb5..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 153 zcmZQ-X>nj=W#If0yiNB(qZI?AM)wCPIG2$Dh0DN%%4J67vVgdZEDX#Z3{W8ZZ$c}A l%c!QWmWkjpsXyc|XZQ~RKn-g97n^DHid8T&sH+@#2LNYcE|vfQ From 0150809abf257424131a95859d560efed4f95f74 Mon Sep 17 00:00:00 2001 From: Keith Derrick Date: Mon, 9 Mar 2026 08:42:40 -0700 Subject: [PATCH 2/2] Use CMake Helpers --- CMakeLists.txt | 152 ++++--------------------------------------------- README.md | 21 ++++--- 2 files changed, 22 insertions(+), 151 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ed71500..0de7a96 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,154 +14,22 @@ # # SPDX-License-Identifier: Apache-2.0 -# Enforce out-of-source builds -if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR) - message( - FATAL_ERROR - "In-source builds are not allowed. Please create a build directory and run CMake from there.\n" - "You will need to remove CMakeCache.txt and CMakeFiles/ to clean up the generated files." - ) -endif() - -# Ensure one of the two acceptable build types are selected: DEBUG or RELEASE. -# Default to DEBUG -if(NOT CMAKE_BUILD_TYPE) - # No build type specified, default to Debug and force it into the cache - message(STATUS "No build type specified, defaulting to Debug") - set(CMAKE_BUILD_TYPE - Debug - CACHE STRING "Build type" FORCE) -else() - # Check they chose an acceptable one - set(valid_build_types "Debug" "Release") - list(FIND valid_build_types ${CMAKE_BUILD_TYPE} _index) - if(${_index} EQUAL -1) - message( - FATAL_ERROR - "Unknown build type ${CMAKE_BUILD_TYPE}. Supported build types are Debug and Release" - ) - endif() - unset(valid_build_types) -endif() - cmake_minimum_required(VERSION 3.28.3) project( OscmsApi + DESCRIPTION "OpenSCMS Codecs Abstract API" VERSION 1.0.0 - LANGUAGES C CXX) # CXX added for testig support - -# set cmake build options -option(BUILD_TESTS "Build unit tests" ON) -option(RUN_CPPCHECK "Enable cppcheck" ON) - -# set compiler flags Standard compile options -set(CMAKE_C_STANDARD 11) -set(CMAKE_C_STANDARD_REQUIRED TRUE) -set(C_EXTENSIONS ON) # Enable gnu11 -set(CMAKE_CXX_STANDARD 17) -set(CMAKE_CXX_STANDARD_REQUIRED TRUE) -set(CXX_EXTENSIONS ON) # Enable gnu11 - -# Enforce C compiler minimum version of 11 (which is what comes with Ubuntu -# 22.04). CI jobs actually use gcc:12 -# -# C++ is only used for unit tests, so we don't care about its version - -if(CMAKE_C_COMPILER_ID STREQUAL "GNU") - if(CMAKE_C_COMPILER_VERSION VERSION_LESS 11) - message( - FATAL_ERROR - "C compiler version must be at least 11.0.0, you are running ${CMAKE_C_COMPILER_VERSION}. Please update your C compiler.\n" - "You will need to remove CMakeCache.txt and CMakeFiles/ to clean up the generated files." - ) - endif() -else() - message( - FATAL_ERROR - "C compiler must be GNU, version >= 11. Please update your C compiler.\n" - "You will need to remove CMakeCache.txt and CMakeFiles/ to clean up the generated files." - ) -endif() - -# Find cppcheck -if(RUN_CPPCHECK) - find_program(CPPCHECK cppcheck) - if(NOT CPPCHECK) - message(WARNING "cppcheck not found. Disabling cppcheck.") - set(RUN_CPPCHECK OFF) - else() - message(STATUS "Found cppcheck: ${CPPCHECK}") - set(CPPCHECK_OPTIONS - --language=c - --inline-suppr - --platform=unix64 - --enable=all - "--suppressions-list=${PROJECT_SOURCE_DIR}/.cppcheck-suppress" - --force - --error-exitcode=1) - endif() -endif() + LANGUAGES C CXX) # CXX added for testing support -if(BUILD_TESTS) - # Set up for unit testing using googletest - include(FetchContent) - - # Disable installation of googletest into the install tree - set(INSTALL_GTEST - OFF - CACHE BOOL "" FORCE) - - # Disable installation of gmock - set(INSTALL_GMOCK - OFF - CACHE BOOL "" FORCE) - - # Download and unpack googletest at configure time - FetchContent_Declare( - googletest # Specify the commit you depend on and update it regularly. - URL https://github.com/google/googletest/archive/refs/tags/v1.16.0.zip) - - # For Windows: Prevent overriding the parent project's compiler/linker - # settings - set(gtest_force_shared_crt - ON - CACHE BOOL "" FORCE) - - # Add googletest directly to our build. This adds the following targets: * - # gtest * gtest_main - FetchContent_MakeAvailable(googletest) - # FetchContent_MakeAvailable(googlemock) - - # Enable unit testing - enable_testing() +include(FetchContent) +FetchContent_Declare( + oscms_cmake_helpers + GIT_REPOSITORY https://github.com/OpenSCMS/oscms-cmake-helpers.git + GIT_TAG main) +FetchContent_MakeAvailable(oscms_cmake_helpers) - include(GoogleTest) - - set(MEMORYCHECK_COMMAND_OPTIONS - "--tool=memcheck --leak-check=full --num-callers=50 --show-reachable=yes ${EXTRA_MEMCHECK_OPTIONS}" - ) - include(CTest) -endif() - -# Ensure the explicit_bzero function is available -include(CheckSourceCompiles) - -check_source_compiles( - C - " - #include - int main() { - char buf[10]; - explicit_bzero(buf, 10); - return 0; - } -" - HAVE_EXPLICIT_BZERO) - -if(NOT HAVE_EXPLICIT_BZERO) - message( - FATAL_ERROR "Target platform does not provide explicit_bzero() function") -endif() +oscms_enable_cppcheck() +oscms_enable_testing() # add source files file(GLOB SOURCES "src/*.c" CMAKE_CONFIGURE_DEPENDS) diff --git a/README.md b/README.md index 8d31e19..a14cde8 100644 --- a/README.md +++ b/README.md @@ -31,15 +31,15 @@ At present, the API is restricted to only those entities sent or received by the ## Table of Contents -- [Development](#development) - - [Installing Dependencies](#installing-dependencies) - - [Using Docker](#using-docker) - - [Getting the Code](#getting-the-code) - - [Building the code](#building-the-code) - - [Running Unit Tests](#running-unit-tests) - - [Running Valgrind](#running-valgrind) -- [Contributing](#contributing) -- [License](#license) +* [Development](#development) + * [Installing Dependencies](#installing-dependencies) + * [Using Docker](#using-docker) + * [Getting the Code](#getting-the-code) + * [Building the code](#building-the-code) + * [Running Unit Tests](#running-unit-tests) + * [Running Valgrind](#running-valgrind) +* [Contributing](#contributing) +* [License](#license) ## Development @@ -107,6 +107,8 @@ The list of repositories, and their relative submodule dependencies, is as follo * [etsi_ts103097-asn]() * [ieee1609dot2dot1-asn]() +The project also makes use of the [Cmake Helpers project](https://github.com/OpenSCMS/oscms-cmake-helpers.git) + ### Building the code All C code is built using `CMake` and the `CMake` scripts will enforce out-of-source builds. @@ -130,6 +132,7 @@ All CMake scripts support a common set of options and command line definitions. | CMAKE_BUILD_TYPE | Debug | Defines the build type. Acceptable values are Debug or Release. This primarily affects debug symbols and optimization levels. | | EXTRA_MEMCHECK_OPTIONS | empty | Allows the specification of additional arguments to `valgrind`| | RUN_CPPCHECK | On | Enables or disables running `cppcheck` on all code during the build. | +| SKIP_INSTALL | Off | If set to On, suppresses generation of any `install` targets | ### Running Unit Tests