Skip to content

Commit 0a10a01

Browse files
elupushefloryd
authored andcommitted
feat: support building on windows with gcc
Allow osal to be built on windows platforms but using GCC as the compiler.
1 parent 4bf20cd commit 0a10a01

File tree

2 files changed

+84
-5
lines changed

2 files changed

+84
-5
lines changed

cmake/Windows.cmake

+17-5
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,24 @@ target_sources(osal PRIVATE
2020

2121
target_compile_options(osal
2222
PRIVATE
23-
/W4
24-
/WX
25-
/wd4100
26-
/wd4152
23+
$<$<C_COMPILER_ID:MSVC>:
24+
/W4
25+
/WX
26+
/wd4100
27+
/wd4152
28+
>
29+
30+
$<$<C_COMPILER_ID:GCC>:
31+
-Wall
32+
-Wextra
33+
-Werror
34+
-Wno-unused-parameter
35+
>
36+
2737
PUBLIC
28-
/wd4200
38+
$<$<C_COMPILER_ID:MSVC>:
39+
/wd4200
40+
>
2941
)
3042

3143
target_link_libraries(osal

src/windows/sys/osal_cc.h

+67
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,71 @@
2020
extern "C" {
2121
#endif
2222

23+
#if defined(__GNUC__) || defined(__GNUG__)
24+
25+
#include <assert.h>
26+
27+
#define CC_PACKED_BEGIN
28+
#define CC_PACKED_END
29+
#define CC_PACKED __attribute__ ((packed))
30+
31+
#define CC_FORMAT(str, arg) __attribute__ ((format (printf, str, arg)))
32+
33+
#if BYTE_ORDER == LITTLE_ENDIAN
34+
#define CC_TO_LE16(x) ((uint16_t)(x))
35+
#define CC_TO_LE32(x) ((uint32_t)(x))
36+
#define CC_TO_LE64(x) ((uint64_t)(x))
37+
#define CC_FROM_LE16(x) ((uint16_t)(x))
38+
#define CC_FROM_LE32(x) ((uint32_t)(x))
39+
#define CC_FROM_LE64(x) ((uint64_t)(x))
40+
#define CC_TO_BE16(x) ((uint16_t)__builtin_bswap16 (x))
41+
#define CC_TO_BE32(x) ((uint32_t)__builtin_bswap32 (x))
42+
#define CC_TO_BE64(x) ((uint64_t)__builtin_bswap64 (x))
43+
#define CC_FROM_BE16(x) ((uint16_t)__builtin_bswap16 (x))
44+
#define CC_FROM_BE32(x) ((uint32_t)__builtin_bswap32 (x))
45+
#define CC_FROM_BE64(x) ((uint64_t)__builtin_bswap64 (x))
46+
#else
47+
#define CC_TO_LE16(x) ((uint16_t)__builtin_bswap16 (x))
48+
#define CC_TO_LE32(x) ((uint32_t)__builtin_bswap32 (x))
49+
#define CC_TO_LE64(x) ((uint64_t)__builtin_bswap64 (x))
50+
#define CC_FROM_LE16(x) ((uint16_t)__builtin_bswap16 (x))
51+
#define CC_FROM_LE32(x) ((uint32_t)__builtin_bswap32 (x))
52+
#define CC_FROM_LE64(x) ((uint64_t)__builtin_bswap64 (x))
53+
#define CC_TO_BE16(x) ((uint16_t)(x))
54+
#define CC_TO_BE32(x) ((uint32_t)(x))
55+
#define CC_TO_BE64(x) ((uint64_t)(x))
56+
#define CC_FROM_BE16(x) ((uint16_t)(x))
57+
#define CC_FROM_BE32(x) ((uint32_t)(x))
58+
#define CC_FROM_BE64(x) ((uint64_t)(x))
59+
#endif
60+
61+
#define CC_ATOMIC_GET8(p) __atomic_load_n ((p), __ATOMIC_SEQ_CST)
62+
#define CC_ATOMIC_GET16(p) __atomic_load_n ((p), __ATOMIC_SEQ_CST)
63+
#define CC_ATOMIC_GET32(p) __atomic_load_n ((p), __ATOMIC_SEQ_CST)
64+
#define CC_ATOMIC_GET64(p) __atomic_load_n ((p), __ATOMIC_SEQ_CST)
65+
66+
#define CC_ATOMIC_SET8(p, v) __atomic_store_n ((p), (v), __ATOMIC_SEQ_CST)
67+
#define CC_ATOMIC_SET16(p, v) __atomic_store_n ((p), (v), __ATOMIC_SEQ_CST)
68+
#define CC_ATOMIC_SET32(p, v) __atomic_store_n ((p), (v), __ATOMIC_SEQ_CST)
69+
#define CC_ATOMIC_SET64(p, v) __atomic_store_n ((p), (v), __ATOMIC_SEQ_CST)
70+
71+
#define CC_ASSERT(exp) cc_assert (exp)
72+
73+
#ifdef __cplusplus
74+
#define CC_STATIC_ASSERT(exp) static_assert (exp, "")
75+
#else
76+
#define CC_STATIC_ASSERT(exp) _Static_assert(exp, "")
77+
#endif
78+
79+
#define CC_UNUSED(var) (void)(var)
80+
81+
static inline void cc_assert (int exp)
82+
{
83+
assert (exp); // LCOV_EXCL_LINE
84+
}
85+
86+
#elif defined(_MSC_VER)
87+
2388
#include <assert.h>
2489

2590
#define CC_PACKED_BEGIN __pragma (pack (push, 1))
@@ -65,6 +130,8 @@ static uint8_t __inline cc_ctz (uint32_t x)
65130
#define CC_ASSERT(exp) assert (exp)
66131
#define CC_STATIC_ASSERT(exp) static_assert ((exp), "")
67132

133+
#endif
134+
68135
#ifdef __cplusplus
69136
}
70137
#endif

0 commit comments

Comments
 (0)