Skip to content

Commit 72b412b

Browse files
use CMake headers via a build-time switch instead of __has_include
1 parent 5c78fb6 commit 72b412b

File tree

6 files changed

+33
-16
lines changed

6 files changed

+33
-16
lines changed

api_test/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,5 @@ endif()
3434
if (MSVC AND MSVC_VERSION GREATER_EQUAL 1910)
3535
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /std:c11")
3636
endif()
37+
38+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DCMARK_USE_CMAKE_HEADERS")

extensions/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ CHECK_C_SOURCE_COMPILES(
103103
"int main() { __builtin_expect(0,0); return 0; }"
104104
HAVE___BUILTIN_EXPECT)
105105

106+
# Use CMake's generated headers instead of the Swift package prebuilt ones
107+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DCMARK_USE_CMAKE_HEADERS")
108+
106109
# Always compile with warnings
107110
if(MSVC)
108111
# Force to always compile with W4

extensions/include/extensions-export.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
#if __has_include("cmark-gfm-extensions_export.h")
2-
#include "cmark-gfm-extensions_export.h"
3-
#else
4-
51
#ifndef CMARK_GFM_EXTENSIONS_EXPORT_H
62
#define CMARK_GFM_EXTENSIONS_EXPORT_H
73

4+
#ifdef CMARK_USE_CMAKE_HEADERS
5+
// if the CMake config header exists, use that instead of this Swift package prebuilt one
6+
// we need to undefine the header guard, since export.h uses the same one
7+
#undef CMARK_GFM_EXTENSIONS_EXPORT_H
8+
#include "cmark-gfm-extensions_export.h"
9+
#else
10+
811
#ifdef CMARK_GFM_EXTENSIONS_STATIC_DEFINE
912
# define CMARK_GFM_EXTENSIONS_EXPORT
1013
# define CMARK_GFM_EXTENSIONS_NO_EXPORT

src/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,9 @@ CONFIGURE_FILE(
187187
${CMAKE_CURRENT_SOURCE_DIR}/config.h.in
188188
${CMAKE_CURRENT_BINARY_DIR}/config.h)
189189

190+
# Use CMake's generated headers instead of the Swift package prebuilt ones
191+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DCMARK_USE_CMAKE_HEADERS")
192+
190193
# Always compile with warnings
191194
if(MSVC)
192195
# Force to always compile with W4

src/include/cmark-gfm_config.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
#if __has_include("config.h")
2-
#include "config.h"
3-
#else
4-
51
#ifndef CMARK_CONFIG_H
62
#define CMARK_CONFIG_H
73

4+
#ifdef CMARK_USE_CMAKE_HEADERS
5+
// if the CMake config header exists, use that instead of this Swift package prebuilt one
6+
// we need to undefine the header guard, since config.h uses the same one
7+
#undef CMARK_CONFIG_H
8+
#include "config.h"
9+
#else
10+
811
#ifdef __cplusplus
912
extern "C" {
1013
#endif
@@ -78,6 +81,6 @@ CMARK_INLINE int c99_snprintf(char *outBuf, size_t size, const char *format, ...
7881
}
7982
#endif
8083

81-
#endif /* CMARK_CONFIG_H */
84+
#endif /* not CMARK_USE_CMAKE_HEADERS */
8285

83-
#endif /* config.h */
86+
#endif /* not CMARK_CONFIG_H */

src/include/export.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
#if __has_include("cmark-gfm_export.h")
2-
#include "cmark-gfm_export.h"
3-
#else
4-
51
#ifndef CMARK_GFM_EXPORT_H
62
#define CMARK_GFM_EXPORT_H
73

4+
#ifdef CMARK_USE_CMAKE_HEADERS
5+
// if the CMake config header exists, use that instead of this Swift package prebuilt one
6+
// we need to undefine the header guard, since export.h uses the same one
7+
#undef CMARK_GFM_EXPORT_H
8+
#include "cmark-gfm_export.h"
9+
#else
10+
811
#ifdef CMARK_GFM_STATIC_DEFINE
912
# define CMARK_GFM_EXPORT
1013
# define CMARK_GFM_NO_EXPORT
@@ -42,6 +45,6 @@
4245
# define CMARK_GFM_DEPRECATED_NO_EXPORT CMARK_GFM_NO_EXPORT CMARK_GFM_DEPRECATED
4346
#endif
4447

45-
#endif /* CMARK_GFM_EXPORT_H */
48+
#endif /* not CMARK_USE_CMAKE_HEADERS */
4649

47-
#endif /* "cmark-gfm_export.h" */
50+
#endif /* not CMARK_GFM_EXPORT_H */

0 commit comments

Comments
 (0)