Skip to content

Commit 8087c9f

Browse files
committed
better config define
1 parent c359680 commit 8087c9f

6 files changed

Lines changed: 98 additions & 122 deletions

File tree

include/ccap_c.h

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -18,33 +18,7 @@
1818
#include <stdbool.h>
1919
#include <stddef.h>
2020

21-
// Define CCAP_EXPORT macro for C interface
22-
#if defined(CCAP_SHARED)
23-
#if defined(_WIN32) || defined(__CYGWIN__)
24-
#ifdef CCAP_BUILDING_DLL
25-
#ifdef __GNUC__
26-
#define CCAP_EXPORT __attribute__ ((dllexport))
27-
#else
28-
#define CCAP_EXPORT __declspec(dllexport)
29-
#endif
30-
#else
31-
#ifdef __GNUC__
32-
#define CCAP_EXPORT __attribute__ ((dllimport))
33-
#else
34-
#define CCAP_EXPORT __declspec(dllimport)
35-
#endif
36-
#endif
37-
#else
38-
#if __GNUC__ >= 4
39-
#define CCAP_EXPORT __attribute__ ((visibility ("default")))
40-
#else
41-
#define CCAP_EXPORT
42-
#endif
43-
#endif
44-
#else
45-
// Static library - no export needed
46-
#define CCAP_EXPORT
47-
#endif
21+
#include "ccap_config.h"
4822

4923
#ifdef __cplusplus
5024
extern "C" {
@@ -115,19 +89,7 @@ typedef enum {
11589
/** @brief Error callback function type for C interface */
11690
typedef void (*CcapErrorCallback)(CcapErrorCode errorCode, const char* errorDescription, void* userData);
11791

118-
/* ========== Constants ========== */
119-
120-
/** @brief Maximum number of camera devices */
121-
#define CCAP_MAX_DEVICES 32
122-
123-
/** @brief Maximum length for device name including null terminator */
124-
#define CCAP_MAX_DEVICE_NAME_LENGTH 128
125-
126-
/** @brief Maximum number of supported pixel formats */
127-
#define CCAP_MAX_PIXEL_FORMATS 32
128-
129-
/** @brief Maximum number of supported resolutions */
130-
#define CCAP_MAX_RESOLUTIONS 64
92+
/* ========== Constants (defined in ccap_config.h) ========== */
13193

13294
/* ========== Data Structures ========== */
13395

include/ccap_config.h

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/**
2+
* @file ccap_config.h
3+
* @author wysaid (this@wysaid.org)
4+
* @brief Common configuration and platform-specific definitions for ccap library.
5+
* @date 2025-09
6+
*
7+
* @note This file contains common macros, constants, and platform detection
8+
* that are shared across both C++ and C interfaces of the library.
9+
*/
10+
11+
#pragma once
12+
#ifndef CCAP_CONFIG_H
13+
#define CCAP_CONFIG_H
14+
15+
/* ========== Export/Import Macro Definitions ========== */
16+
17+
// Define CCAP_EXPORT macro for symbol export/import
18+
#if defined(CCAP_SHARED)
19+
#if defined(_WIN32) || defined(__CYGWIN__)
20+
#ifdef CCAP_BUILDING_DLL
21+
#ifdef __GNUC__
22+
#define CCAP_EXPORT __attribute__ ((dllexport))
23+
#else
24+
#define CCAP_EXPORT __declspec(dllexport)
25+
#endif
26+
#else
27+
#ifdef __GNUC__
28+
#define CCAP_EXPORT __attribute__ ((dllimport))
29+
#else
30+
#define CCAP_EXPORT __declspec(dllimport)
31+
#endif
32+
#endif
33+
#else
34+
#if __GNUC__ >= 4
35+
#define CCAP_EXPORT __attribute__ ((visibility ("default")))
36+
#else
37+
#define CCAP_EXPORT
38+
#endif
39+
#endif
40+
#else
41+
// Static library - no export needed
42+
#define CCAP_EXPORT
43+
#endif
44+
45+
/* ========== Platform Detection ========== */
46+
47+
#if __APPLE__
48+
#include <TargetConditionals.h>
49+
#if (defined(TARGET_OS_IOS) && TARGET_OS_IOS) || (defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE)
50+
#define CCAP_IOS 1
51+
#else
52+
#define CCAP_MACOS 1
53+
#endif
54+
#elif defined(__ANDROID__)
55+
#define CCAP_ANDROID 1
56+
#elif defined(_WIN32)
57+
#define CCAP_WINDOWS 1
58+
#if defined(_MSC_VER)
59+
#define CCAP_WINDOWS_MSVC 1
60+
#endif
61+
#endif
62+
63+
#if !defined(CCAP_IOS) && !defined(CCAP_ANDROID)
64+
#define CCAP_DESKTOP 1
65+
#endif
66+
67+
/* ========== Common Constants ========== */
68+
69+
// Maximum number of devices supported
70+
#define CCAP_MAX_DEVICES 32
71+
72+
// Maximum length for device name strings
73+
#define CCAP_MAX_DEVICE_NAME_LENGTH 128
74+
75+
// Maximum number of pixel formats per device
76+
#define CCAP_MAX_PIXEL_FORMATS 32
77+
78+
// Maximum number of resolutions per device
79+
#define CCAP_MAX_RESOLUTIONS 64
80+
81+
/* ========== Compatibility Macros ========== */
82+
83+
#ifdef __cplusplus
84+
#if __cplusplus >= 201703L
85+
#define CCAP_CONSTEXPR constexpr
86+
#else
87+
#define CCAP_CONSTEXPR
88+
#endif
89+
#else
90+
#define CCAP_CONSTEXPR
91+
#endif
92+
93+
#endif /* CCAP_CONFIG_H */

include/ccap_convert_c.h

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,33 +14,7 @@
1414
#include <stdbool.h>
1515
#include <stdint.h>
1616

17-
// Define CCAP_EXPORT for C interface
18-
#if defined(CCAP_SHARED)
19-
#if defined(_WIN32) || defined(__CYGWIN__)
20-
#ifdef CCAP_BUILDING_DLL
21-
#ifdef __GNUC__
22-
#define CCAP_EXPORT __attribute__ ((dllexport))
23-
#else
24-
#define CCAP_EXPORT __declspec(dllexport)
25-
#endif
26-
#else
27-
#ifdef __GNUC__
28-
#define CCAP_EXPORT __attribute__ ((dllimport))
29-
#else
30-
#define CCAP_EXPORT __declspec(dllimport)
31-
#endif
32-
#endif
33-
#else
34-
#if __GNUC__ >= 4
35-
#define CCAP_EXPORT __attribute__ ((visibility ("default")))
36-
#else
37-
#define CCAP_EXPORT
38-
#endif
39-
#endif
40-
#else
41-
// Static library - no export needed
42-
#define CCAP_EXPORT
43-
#endif
17+
#include "ccap_config.h"
4418

4519
#ifdef __cplusplus
4620
extern "C" {

include/ccap_def.h

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -16,54 +16,7 @@
1616
#ifndef CCAP_DEF_H
1717
#define CCAP_DEF_H
1818

19-
// Define CCAP_EXPORT macro for symbol export/import
20-
#if defined(CCAP_SHARED)
21-
#if defined(_WIN32) || defined(__CYGWIN__)
22-
#ifdef CCAP_BUILDING_DLL
23-
#ifdef __GNUC__
24-
#define CCAP_EXPORT __attribute__ ((dllexport))
25-
#else
26-
#define CCAP_EXPORT __declspec(dllexport)
27-
#endif
28-
#else
29-
#ifdef __GNUC__
30-
#define CCAP_EXPORT __attribute__ ((dllimport))
31-
#else
32-
#define CCAP_EXPORT __declspec(dllimport)
33-
#endif
34-
#endif
35-
#else
36-
#if __GNUC__ >= 4
37-
#define CCAP_EXPORT __attribute__ ((visibility ("default")))
38-
#else
39-
#define CCAP_EXPORT
40-
#endif
41-
#endif
42-
#else
43-
// Static library - no export needed
44-
#define CCAP_EXPORT
45-
#endif
46-
47-
#if __APPLE__
48-
#include <TargetConditionals.h>
49-
#if (defined(TARGET_OS_IOS) && TARGET_OS_IOS) || (defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE)
50-
#define CCAP_IOS 1
51-
#else
52-
#define CCAP_MACOS 1
53-
#endif
54-
55-
#elif defined(__ANDROID__)
56-
#define CCAP_ANDROID 1
57-
#elif defined(WIN32) || defined(_WIN32)
58-
#define CCAP_WINDOWS 1
59-
#if defined(_MSC_VER)
60-
#define CCAP_WINDOWS_MSVC 1
61-
#endif
62-
#endif
63-
64-
#if !defined(CCAP_DESKTOP) && (CCAP_WINDOWS || CCAP_MACOS)
65-
#define CCAP_DESKTOP 1
66-
#endif
19+
#include "ccap_config.h"
6720

6821
#include <cstdint>
6922
#include <functional>

include/ccap_utils.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,6 @@ inline bool verboseLogEnabled() { return globalLogLevel & kLogLevelVerboseBit; }
126126
#define CCAP_LOG_V(...) CCAP_LOG(LogLevel::Verbose, __VA_ARGS__)
127127
#else
128128

129-
#if __cplusplus >= 201703L
130-
#define CCAP_CONSTEXPR constexpr
131-
#else
132-
#define CCAP_CONSTEXPR
133-
#endif
134-
135129
inline CCAP_CONSTEXPR bool errorLogEnabled() { return false; }
136130
inline CCAP_CONSTEXPR bool warningLogEnabled() { return false; }
137131
inline CCAP_CONSTEXPR bool infoLogEnabled() { return false; }

include/ccap_utils_c.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include <stdint.h>
1616
#include <stdbool.h>
1717

18-
// CCAP_EXPORT is already defined in ccap_c.h
18+
// CCAP_EXPORT is defined in ccap_config.h (included by ccap_c.h)
1919

2020
#ifdef __cplusplus
2121
extern "C" {

0 commit comments

Comments
 (0)