|
14 | 14 | # |
15 | 15 | # SPDX-License-Identifier: Apache-2.0 |
16 | 16 |
|
17 | | -# Enforce out-of-source builds |
18 | | -if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR) |
19 | | - message( |
20 | | - FATAL_ERROR |
21 | | - "In-source builds are not allowed. Please create a build directory and run CMake from there.\n" |
22 | | - "You will need to remove CMakeCache.txt and CMakeFiles/ to clean up the generated files." |
23 | | - ) |
24 | | -endif() |
25 | | - |
26 | | -# Ensure one of the two acceptable build types are selected: DEBUG or RELEASE. |
27 | | -# Default to DEBUG |
28 | | -if(NOT CMAKE_BUILD_TYPE) |
29 | | - # No build type specified, default to Debug and force it into the cache |
30 | | - message(STATUS "No build type specified, defaulting to Debug") |
31 | | - set(CMAKE_BUILD_TYPE |
32 | | - Debug |
33 | | - CACHE STRING "Build type" FORCE) |
34 | | -else() |
35 | | - # Check they chose an acceptable one |
36 | | - set(valid_build_types "Debug" "Release") |
37 | | - list(FIND valid_build_types ${CMAKE_BUILD_TYPE} _index) |
38 | | - if(${_index} EQUAL -1) |
39 | | - message( |
40 | | - FATAL_ERROR |
41 | | - "Unknown build type ${CMAKE_BUILD_TYPE}. Supported build types are Debug and Release" |
42 | | - ) |
43 | | - endif() |
44 | | - unset(valid_build_types) |
45 | | -endif() |
46 | | - |
47 | 17 | cmake_minimum_required(VERSION 3.28.3) |
48 | 18 | project( |
49 | 19 | OscmsApi |
| 20 | + DESCRIPTION "OpenSCMS Codecs Abstract API" |
50 | 21 | VERSION 1.0.0 |
51 | | - LANGUAGES C CXX) # CXX added for testig support |
52 | | - |
53 | | -# set cmake build options |
54 | | -option(BUILD_TESTS "Build unit tests" ON) |
55 | | -option(RUN_CPPCHECK "Enable cppcheck" ON) |
56 | | - |
57 | | -# set compiler flags Standard compile options |
58 | | -set(CMAKE_C_STANDARD 11) |
59 | | -set(CMAKE_C_STANDARD_REQUIRED TRUE) |
60 | | -set(C_EXTENSIONS ON) # Enable gnu11 |
61 | | -set(CMAKE_CXX_STANDARD 17) |
62 | | -set(CMAKE_CXX_STANDARD_REQUIRED TRUE) |
63 | | -set(CXX_EXTENSIONS ON) # Enable gnu11 |
64 | | - |
65 | | -# Enforce C compiler minimum version of 11 (which is what comes with Ubuntu |
66 | | -# 22.04). CI jobs actually use gcc:12 |
67 | | -# |
68 | | -# C++ is only used for unit tests, so we don't care about its version |
69 | | - |
70 | | -if(CMAKE_C_COMPILER_ID STREQUAL "GNU") |
71 | | - if(CMAKE_C_COMPILER_VERSION VERSION_LESS 11) |
72 | | - message( |
73 | | - FATAL_ERROR |
74 | | - "C compiler version must be at least 11.0.0, you are running ${CMAKE_C_COMPILER_VERSION}. Please update your C compiler.\n" |
75 | | - "You will need to remove CMakeCache.txt and CMakeFiles/ to clean up the generated files." |
76 | | - ) |
77 | | - endif() |
78 | | -else() |
79 | | - message( |
80 | | - FATAL_ERROR |
81 | | - "C compiler must be GNU, version >= 11. Please update your C compiler.\n" |
82 | | - "You will need to remove CMakeCache.txt and CMakeFiles/ to clean up the generated files." |
83 | | - ) |
84 | | -endif() |
85 | | - |
86 | | -# Find cppcheck |
87 | | -if(RUN_CPPCHECK) |
88 | | - find_program(CPPCHECK cppcheck) |
89 | | - if(NOT CPPCHECK) |
90 | | - message(WARNING "cppcheck not found. Disabling cppcheck.") |
91 | | - set(RUN_CPPCHECK OFF) |
92 | | - else() |
93 | | - message(STATUS "Found cppcheck: ${CPPCHECK}") |
94 | | - set(CPPCHECK_OPTIONS |
95 | | - --language=c |
96 | | - --inline-suppr |
97 | | - --platform=unix64 |
98 | | - --enable=all |
99 | | - "--suppressions-list=${PROJECT_SOURCE_DIR}/.cppcheck-suppress" |
100 | | - --force |
101 | | - --error-exitcode=1) |
102 | | - endif() |
103 | | -endif() |
| 22 | + LANGUAGES C CXX) # CXX added for testing support |
104 | 23 |
|
105 | | -if(BUILD_TESTS) |
106 | | - # Set up for unit testing using googletest |
107 | | - include(FetchContent) |
108 | | - |
109 | | - # Disable installation of googletest into the install tree |
110 | | - set(INSTALL_GTEST |
111 | | - OFF |
112 | | - CACHE BOOL "" FORCE) |
113 | | - |
114 | | - # Disable installation of gmock |
115 | | - set(INSTALL_GMOCK |
116 | | - OFF |
117 | | - CACHE BOOL "" FORCE) |
118 | | - |
119 | | - # Download and unpack googletest at configure time |
120 | | - FetchContent_Declare( |
121 | | - googletest # Specify the commit you depend on and update it regularly. |
122 | | - URL https://github.com/google/googletest/archive/refs/tags/v1.16.0.zip) |
123 | | - |
124 | | - # For Windows: Prevent overriding the parent project's compiler/linker |
125 | | - # settings |
126 | | - set(gtest_force_shared_crt |
127 | | - ON |
128 | | - CACHE BOOL "" FORCE) |
129 | | - |
130 | | - # Add googletest directly to our build. This adds the following targets: * |
131 | | - # gtest * gtest_main |
132 | | - FetchContent_MakeAvailable(googletest) |
133 | | - # FetchContent_MakeAvailable(googlemock) |
134 | | - |
135 | | - # Enable unit testing |
136 | | - enable_testing() |
| 24 | +include(FetchContent) |
| 25 | +FetchContent_Declare( |
| 26 | + oscms_cmake_helpers |
| 27 | + GIT_REPOSITORY https://github.com/OpenSCMS/oscms-cmake-helpers.git |
| 28 | + GIT_TAG main) |
| 29 | +FetchContent_MakeAvailable(oscms_cmake_helpers) |
137 | 30 |
|
138 | | - include(GoogleTest) |
139 | | - |
140 | | - set(MEMORYCHECK_COMMAND_OPTIONS |
141 | | - "--tool=memcheck --leak-check=full --num-callers=50 --show-reachable=yes ${EXTRA_MEMCHECK_OPTIONS}" |
142 | | - ) |
143 | | - include(CTest) |
144 | | -endif() |
145 | | - |
146 | | -# Ensure the explicit_bzero function is available |
147 | | -include(CheckSourceCompiles) |
148 | | - |
149 | | -check_source_compiles( |
150 | | - C |
151 | | - " |
152 | | - #include <string.h> |
153 | | - int main() { |
154 | | - char buf[10]; |
155 | | - explicit_bzero(buf, 10); |
156 | | - return 0; |
157 | | - } |
158 | | -" |
159 | | - HAVE_EXPLICIT_BZERO) |
160 | | - |
161 | | -if(NOT HAVE_EXPLICIT_BZERO) |
162 | | - message( |
163 | | - FATAL_ERROR "Target platform does not provide explicit_bzero() function") |
164 | | -endif() |
| 31 | +oscms_enable_cppcheck() |
| 32 | +oscms_enable_testing() |
165 | 33 |
|
166 | 34 | # add source files |
167 | 35 | file(GLOB SOURCES "src/*.c" CMAKE_CONFIGURE_DEPENDS) |
|
0 commit comments