Skip to content

Commit 9636b19

Browse files
committed
feat: allow osal to support multiple compilers
Instead of making this choice compile time, install all supported compiler headers by default.
1 parent 5b1047c commit 9636b19

11 files changed

Lines changed: 115 additions & 68 deletions

File tree

CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,17 @@ install(FILES
123123
DESTINATION include
124124
)
125125

126+
install(FILES
127+
include/sys/osal_cc_clang.h
128+
include/sys/osal_cc_gcc.h
129+
include/sys/osal_cc_msvc.h
130+
include/sys/osal_cc_rtk.h
131+
include/sys/osal_cc.h
132+
include/osal_log.h
133+
DESTINATION include
134+
)
135+
136+
126137
if (CMAKE_PROJECT_NAME STREQUAL OSAL AND BUILD_TESTING)
127138
add_subdirectory (test)
128139
include(AddGoogleTest)

cmake/Linux.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ target_link_libraries(osal PUBLIC
4747
)
4848

4949
install(FILES
50-
src/linux/sys/osal_cc.h
5150
src/linux/sys/osal_sys.h
5251
DESTINATION include/sys
5352
)

cmake/STM32Cube.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ target_include_directories(osal PUBLIC
3131
)
3232

3333
install(FILES
34-
src/freertos/sys/osal_cc.h
3534
src/freertos/sys/osal_sys.h
3635
DESTINATION include/sys
3736
)

cmake/Windows.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ target_include_directories(osal PUBLIC
4848
)
4949

5050
install(FILES
51-
src/windows/sys/osal_cc.h
5251
src/windows/sys/osal_sys.h
5352
DESTINATION include/sys
5453
)

cmake/iMX8MM.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ target_include_directories(osal PUBLIC
2424
)
2525

2626
install(FILES
27-
src/freertos/sys/osal_cc.h
2827
src/freertos/sys/osal_sys.h
2928
DESTINATION include/sys
3029
)

cmake/rt-kernel.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ target_include_directories(osal PUBLIC
3535
)
3636

3737
install(FILES
38-
src/rt-kernel/sys/osal_cc.h
3938
src/rt-kernel/sys/osal_sys.h
4039
DESTINATION include/sys
4140
)

include/sys/osal_cc.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*********************************************************************
2+
* _ _ _
3+
* _ __ | |_ _ | | __ _ | |__ ___
4+
* | '__|| __|(_)| | / _` || '_ \ / __|
5+
* | | | |_ _ | || (_| || |_) |\__ \
6+
* |_| \__|(_)|_| \__,_||_.__/ |___/
7+
*
8+
* www.rt-labs.com
9+
* Copyright 2017 rt-labs AB, Sweden.
10+
*
11+
* This software is licensed under the terms of the BSD 3-clause
12+
* license. See the file LICENSE distributed with this software for
13+
* full license information.
14+
********************************************************************/
15+
16+
#if defined(__rtk__)
17+
#include "osal_cc_rtk.h"
18+
#elif defined(__GNUC__) || defined(__GNUG__)
19+
#include "osal_cc_gcc.h"
20+
#elif defined(__clang__)
21+
#include "osal_cc_clang.h"
22+
#elif defined(_MSC_VER)
23+
#include "osal_cc_msvc.h"
24+
#else
25+
#error "Unsupported compiler"
26+
#endif
Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,10 @@ extern "C" {
2222

2323
#include <assert.h>
2424

25-
#if defined(__clang__)
26-
#if !defined(CLANG_ANALYZER_NORETURN)
2725
#if __has_feature(attribute_analyzer_noreturn)
2826
#define CLANG_ANALYZER_NORETURN __attribute__ ((analyzer_noreturn))
2927
#else
3028
#define CLANG_ANALYZER_NORETURN
31-
#endif
32-
#endif
33-
#else
34-
#define CLANG_ANALYZER_NORETURN
35-
#endif
3629

3730
static inline void cc_assert (int exp) CLANG_ANALYZER_NORETURN
3831
{
Lines changed: 6 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,17 @@
2020
extern "C" {
2121
#endif
2222

23-
#if defined(__GNUC__) || defined(__GNUG__)
24-
2523
#include <assert.h>
2624

25+
static inline void cc_assert (int exp)
26+
{
27+
assert (exp); // LCOV_EXCL_LINE
28+
}
29+
2730
#define CC_PACKED_BEGIN
2831
#define CC_PACKED_END
2932
#define CC_PACKED __attribute__ ((packed))
33+
#define CC_ALIGNED(n) __attribute__((aligned (n)))
3034

3135
#define CC_FORMAT(str, arg) __attribute__ ((format (printf, str, arg)))
3236

@@ -78,60 +82,6 @@ extern "C" {
7882

7983
#define CC_UNUSED(var) (void)(var)
8084

81-
static inline void cc_assert (int exp)
82-
{
83-
assert (exp); // LCOV_EXCL_LINE
84-
}
85-
86-
#elif defined(_MSC_VER)
87-
88-
#include <assert.h>
89-
90-
#define CC_PACKED_BEGIN __pragma (pack (push, 1))
91-
#define CC_PACKED_END __pragma (pack (pop))
92-
#define CC_PACKED
93-
94-
#define CC_FORMAT(str, arg)
95-
96-
#define CC_TO_LE16(x) ((uint16_t)(x))
97-
#define CC_TO_LE32(x) ((uint32_t)(x))
98-
#define CC_TO_LE64(x) ((uint64_t)(x))
99-
#define CC_FROM_LE16(x) ((uint16_t)(x))
100-
#define CC_FROM_LE32(x) ((uint32_t)(x))
101-
#define CC_FROM_LE64(x) ((uint64_t)(x))
102-
#define CC_TO_BE16(x) ((uint16_t)_byteswap_ushort (x))
103-
#define CC_TO_BE32(x) ((uint32_t)_byteswap_ulong (x))
104-
#define CC_TO_BE64(x) ((uint64_t)_byteswap_uint64 (x))
105-
#define CC_FROM_BE16(x) ((uint16_t)_byteswap_ushort (x))
106-
#define CC_FROM_BE32(x) ((uint32_t)_byteswap_ulong (x))
107-
#define CC_FROM_BE64(x) ((uint64_t)_byteswap_uint64 (x))
108-
109-
/* TODO */
110-
#define CC_ATOMIC_GET8(p) (*p)
111-
#define CC_ATOMIC_GET16(p) (*p)
112-
#define CC_ATOMIC_GET32(p) (*p)
113-
#define CC_ATOMIC_GET64(p) (*p)
114-
115-
/* TODO */
116-
#define CC_ATOMIC_SET8(p, v) ((*p) = (v))
117-
#define CC_ATOMIC_SET16(p, v) ((*p) = (v))
118-
#define CC_ATOMIC_SET32(p, v) ((*p) = (v))
119-
#define CC_ATOMIC_SET64(p, v) ((*p) = (v))
120-
121-
static uint8_t __inline cc_ctz (uint32_t x)
122-
{
123-
DWORD n = 0;
124-
_BitScanForward (&n, x);
125-
return (uint8_t)n;
126-
}
127-
128-
#define __builtin_ctz(x) cc_ctz (x)
129-
130-
#define CC_ASSERT(exp) assert (exp)
131-
#define CC_STATIC_ASSERT(exp) static_assert ((exp), "")
132-
133-
#endif
134-
13585
#ifdef __cplusplus
13686
}
13787
#endif

include/sys/osal_cc_msvc.h

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*********************************************************************
2+
* _ _ _
3+
* _ __ | |_ _ | | __ _ | |__ ___
4+
* | '__|| __|(_)| | / _` || '_ \ / __|
5+
* | | | |_ _ | || (_| || |_) |\__ \
6+
* |_| \__|(_)|_| \__,_||_.__/ |___/
7+
*
8+
* www.rt-labs.com
9+
* Copyright 2017 rt-labs AB, Sweden.
10+
*
11+
* This software is licensed under the terms of the BSD 3-clause
12+
* license. See the file LICENSE distributed with this software for
13+
* full license information.
14+
********************************************************************/
15+
16+
#ifndef CC_H
17+
#define CC_H
18+
19+
#ifdef __cplusplus
20+
extern "C" {
21+
#endif
22+
23+
#include <assert.h>
24+
25+
#define CC_PACKED_BEGIN __pragma (pack (push, 1))
26+
#define CC_PACKED_END __pragma (pack (pop))
27+
#define CC_PACKED
28+
29+
#define CC_FORMAT(str, arg)
30+
31+
#define CC_TO_LE16(x) ((uint16_t)(x))
32+
#define CC_TO_LE32(x) ((uint32_t)(x))
33+
#define CC_TO_LE64(x) ((uint64_t)(x))
34+
#define CC_FROM_LE16(x) ((uint16_t)(x))
35+
#define CC_FROM_LE32(x) ((uint32_t)(x))
36+
#define CC_FROM_LE64(x) ((uint64_t)(x))
37+
#define CC_TO_BE16(x) ((uint16_t)_byteswap_ushort (x))
38+
#define CC_TO_BE32(x) ((uint32_t)_byteswap_ulong (x))
39+
#define CC_TO_BE64(x) ((uint64_t)_byteswap_uint64 (x))
40+
#define CC_FROM_BE16(x) ((uint16_t)_byteswap_ushort (x))
41+
#define CC_FROM_BE32(x) ((uint32_t)_byteswap_ulong (x))
42+
#define CC_FROM_BE64(x) ((uint64_t)_byteswap_uint64 (x))
43+
44+
/* TODO */
45+
#define CC_ATOMIC_GET8(p) (*p)
46+
#define CC_ATOMIC_GET16(p) (*p)
47+
#define CC_ATOMIC_GET32(p) (*p)
48+
#define CC_ATOMIC_GET64(p) (*p)
49+
50+
/* TODO */
51+
#define CC_ATOMIC_SET8(p, v) ((*p) = (v))
52+
#define CC_ATOMIC_SET16(p, v) ((*p) = (v))
53+
#define CC_ATOMIC_SET32(p, v) ((*p) = (v))
54+
#define CC_ATOMIC_SET64(p, v) ((*p) = (v))
55+
56+
static uint8_t __inline cc_ctz (uint32_t x)
57+
{
58+
DWORD n = 0;
59+
_BitScanForward (&n, x);
60+
return (uint8_t)n;
61+
}
62+
63+
#define __builtin_ctz(x) cc_ctz (x)
64+
65+
#define CC_ASSERT(exp) assert (exp)
66+
#define CC_STATIC_ASSERT(exp) static_assert ((exp), "")
67+
68+
#ifdef __cplusplus
69+
}
70+
#endif
71+
72+
#endif /* CC_H */

0 commit comments

Comments
 (0)