Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
152 changes: 10 additions & 142 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 <string.h>
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)
Expand Down
21 changes: 12 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ At present, the API is restricted to only those entities sent or received by the
<!-- omit from toc -->
## 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

Expand Down Expand Up @@ -107,6 +107,8 @@ The list of repositories, and their relative submodule dependencies, is as follo
* [etsi_ts103097-asn](<https://github.com/OpenSCMS/etsi_ts103097-asn>)
* [ieee1609dot2dot1-asn](<https://github.com/OpenSCMS/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.
Expand All @@ -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

Expand Down
8 changes: 0 additions & 8 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Binary file removed tests/data/CertManagementPdu.dat
Binary file not shown.