Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DO NOT MERGE] aggregate all changes necessary for Swift to build #37

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
2f75026
build: export targets info
QuietMisdreavus Nov 15, 2021
f2139c2
link to pthreads on non-apple/non-windows
QuietMisdreavus Mar 8, 2022
78b85b7
use CMake-generated config.h if available
QuietMisdreavus Mar 11, 2022
4347ac2
tweak static export header definitions
QuietMisdreavus Mar 11, 2022
06c298a
don't use /include on generated-header include paths
QuietMisdreavus Mar 11, 2022
f7b7b91
remove unused section from static export headers
QuietMisdreavus Mar 11, 2022
91cbac3
clean up config headers
QuietMisdreavus Mar 11, 2022
32891c2
include windows.h instead of synchapi.h for win32
QuietMisdreavus Mar 11, 2022
7c1be38
fix uninitialized-variable warning
QuietMisdreavus Mar 11, 2022
7e40c73
use CMake-generated {project}_export.h if available
QuietMisdreavus Mar 12, 2022
60b6240
use underscored visibility attribute
QuietMisdreavus Mar 14, 2022
fbefbc3
use WIN32_LEAN_AND_MEAN to avoid symbol collisions
QuietMisdreavus Mar 14, 2022
5bc7a26
use C standard version to guard stdbool.h
QuietMisdreavus Mar 14, 2022
c505c99
build with C11 on MSVC where it's supported
QuietMisdreavus Mar 14, 2022
e5e596e
check for unistd.h during CMake or with more-compatible checks
QuietMisdreavus Mar 14, 2022
6688253
use CMake headers via a build-time switch instead of __has_include
QuietMisdreavus Mar 14, 2022
48dd1d8
use CMAKE_C_STANDARD to set C standard
QuietMisdreavus Mar 15, 2022
492f0b5
set CMARK_USE_CMAKE_HEADERS at the top level
QuietMisdreavus Mar 15, 2022
4d1fe42
use const char * for string literals
QuietMisdreavus Mar 15, 2022
87fa5e7
use __declspec(deprecated) for deprecated functions on Windows
QuietMisdreavus Mar 15, 2022
685699f
Merge branch 'QuietMisdreavus/cmake-targets' into QuietMisdreavus/swi…
QuietMisdreavus Mar 16, 2022
f5016c2
Merge branch 'QuietMisdreavus/more-build-tweaks' into QuietMisdreavus…
QuietMisdreavus Mar 16, 2022
fe486ef
Merge branch 'QuietMisdreavus/strict-strings' into QuietMisdreavus/sw…
QuietMisdreavus Mar 16, 2022
07f45bf
disable MSVC warning C5105
QuietMisdreavus Mar 17, 2022
0ac8d7b
Merge branch 'QuietMisdreavus/windows-warnings' into QuietMisdreavus/…
QuietMisdreavus Mar 18, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.0)
cmake_minimum_required(VERSION 3.12)
project(cmark-gfm)

set(PROJECT_VERSION_MAJOR 0)
Expand All @@ -20,6 +20,17 @@ option(CMARK_SHARED "Build shared libcmark-gfm library" ON)
option(CMARK_LIB_FUZZER "Build libFuzzer fuzzing harness" OFF)
option(CMARK_THREADING "Add locks around static accesses" OFF)

# set a required C standard so we can load stdbool.h
if(MSVC)
set(CMAKE_C_STANDARD 11)
else()
set(CMAKE_C_STANDARD 99)
endif()
set(CMAKE_C_STANDARD_REQUIRED YES)

# Use CMake's generated headers instead of the Swift package prebuilt ones
add_compile_definitions(CMARK_USE_CMAKE_HEADERS)

add_subdirectory(src)
add_subdirectory(extensions)
if(CMARK_TESTS AND (CMARK_SHARED OR CMARK_STATIC))
Expand Down
6 changes: 3 additions & 3 deletions api_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ add_executable(api_test
)
include_directories(
${PROJECT_SOURCE_DIR}/src/include
${PROJECT_BINARY_DIR}/src/include
${PROJECT_BINARY_DIR}/src
${PROJECT_SOURCE_DIR}/extensions/include
${PROJECT_BINARY_DIR}/extensions/include
${PROJECT_BINARY_DIR}/extensions
)
if(CMARK_SHARED)
target_link_libraries(api_test libcmark-gfm-extensions libcmark-gfm)
Expand All @@ -24,7 +24,7 @@ if(MSVC)
else()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4")
endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4706 /D_CRT_SECURE_NO_WARNINGS")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4706 /wd5105 /D_CRT_SECURE_NO_WARNINGS")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /TP")
elseif(CMAKE_COMPILER_IS_GNUCC OR "${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -std=c99 -pedantic")
Expand Down
4 changes: 2 additions & 2 deletions api_test/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1192,7 +1192,7 @@ static void inline_only_opt(test_batch_runner *runner) {
cmark_node_free(doc);
}

static void check_markdown_plaintext(test_batch_runner *runner, char *markdown) {
static void check_markdown_plaintext(test_batch_runner *runner, const char *markdown) {
cmark_node *doc = cmark_parse_document(markdown, strlen(markdown), CMARK_OPT_PRESERVE_WHITESPACE);
cmark_node *pg = cmark_node_first_child(doc);
INT_EQ(runner, cmark_node_get_type(pg), CMARK_NODE_PARAGRAPH, "markdown '%s' did not produce a paragraph node", markdown);
Expand Down Expand Up @@ -1228,7 +1228,7 @@ static void preserve_whitespace_opt(test_batch_runner *runner) {
check_markdown_plaintext(runner, "\nHello\n");
}

static void check_markdown_attributes_node(test_batch_runner *runner, char *markdown, cmark_node_type expectedType, char *expectedAttributes) {
static void check_markdown_attributes_node(test_batch_runner *runner, const char *markdown, cmark_node_type expectedType, const char *expectedAttributes) {
cmark_node *doc = cmark_parse_document(markdown, strlen(markdown), CMARK_OPT_DEFAULT);
cmark_node *pg = cmark_node_first_child(doc);
INT_EQ(runner, cmark_node_get_type(pg), CMARK_NODE_PARAGRAPH, "markdown '%s' did not produce a paragraph node", markdown);
Expand Down
12 changes: 4 additions & 8 deletions extensions/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ set(LIBRARY_SOURCES

include_directories(
${PROJECT_SOURCE_DIR}/src/include
${PROJECT_BINARY_DIR}/src/include
${PROJECT_BINARY_DIR}/src
)

include (GenerateExportHeader)
Expand Down Expand Up @@ -86,7 +86,7 @@ install(TARGETS ${CMARK_INSTALL}
if (CMARK_SHARED OR CMARK_STATIC)
install(FILES
${CMAKE_CURRENT_SOURCE_DIR}/include/cmark-gfm-core-extensions.h
${CMAKE_CURRENT_SOURCE_DIR}/include/cmark-gfm-extensions_export.h
${CMAKE_CURRENT_SOURCE_DIR}/include/extensions-export.h
DESTINATION include
)

Expand All @@ -98,14 +98,10 @@ include(CheckIncludeFile)
include(CheckCSourceCompiles)
include(CheckCSourceRuns)
include(CheckSymbolExists)
CHECK_INCLUDE_FILE(stdbool.h HAVE_STDBOOL_H)
CHECK_INCLUDE_FILE(unistd.h HAVE_UNISTD_H)
CHECK_C_SOURCE_COMPILES(
"int main() { __builtin_expect(0,0); return 0; }"
HAVE___BUILTIN_EXPECT)
CHECK_C_SOURCE_COMPILES("
int f(void) __attribute__ (());
int main() { return 0; }
" HAVE___ATTRIBUTE__)

# Always compile with warnings
if(MSVC)
Expand All @@ -115,7 +111,7 @@ if(MSVC)
else()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4")
endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /WX /wd4706 /wd4204 /wd4221 /wd4100 /D_CRT_SECURE_NO_WARNINGS")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /WX /wd4706 /wd4204 /wd4221 /wd4100 /wd5105 /D_CRT_SECURE_NO_WARNINGS")
elseif(CMAKE_COMPILER_IS_GNUCC OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wno-unused-parameter -std=c99 -pedantic")
endif()
Expand Down
2 changes: 1 addition & 1 deletion extensions/include/cmark-gfm-core-extensions.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ extern "C" {
#endif

#include "cmark-gfm-extension_api.h"
#include "cmark-gfm-extensions_export.h"
#include "extensions-export.h"
#include "cmark-gfm_config.h" // for bool
#include <stdint.h>

Expand Down
42 changes: 0 additions & 42 deletions extensions/include/cmark-gfm-extensions_export.h

This file was deleted.

60 changes: 60 additions & 0 deletions extensions/include/extensions-export.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#ifndef CMARK_GFM_EXTENSIONS_EXPORT_H
#define CMARK_GFM_EXTENSIONS_EXPORT_H

#ifdef CMARK_USE_CMAKE_HEADERS
// if the CMake config header exists, use that instead of this Swift package prebuilt one
// we need to undefine the header guard, since export.h uses the same one
#undef CMARK_GFM_EXTENSIONS_EXPORT_H
#include "cmark-gfm-extensions_export.h"
#else

#ifdef CMARK_GFM_EXTENSIONS_STATIC_DEFINE
# define CMARK_GFM_EXTENSIONS_EXPORT
# define CMARK_GFM_EXTENSIONS_NO_EXPORT
#else
# if defined(_WIN32)
# ifndef CMARK_GFM_EXTENSIONS_EXPORT
# ifdef libcmark_gfm_extensions_EXPORTS
# define CMARK_GFM_EXTENSIONS_EXPORT __declspec(dllexport)
# else
# define CMARK_GFM_EXTENSIONS_EXPORT __declspec(dllimport)
# endif
# endif

# ifndef CMARK_GFM_EXTENSIONS_NO_EXPORT
# define CMARK_GFM_EXTENSIONS_NO_EXPORT
# endif
# else
# ifndef CMARK_GFM_EXTENSIONS_EXPORT
# ifdef libcmark_gfm_extensions_EXPORTS
# define CMARK_GFM_EXTENSIONS_EXPORT __attribute__((__visibility__("default")))
# else
# define CMARK_GFM_EXTENSIONS_EXPORT __attribute__((__visibility__("default")))
# endif
# endif

# ifndef CMARK_GFM_EXTENSIONS_NO_EXPORT
# define CMARK_GFM_EXTENSIONS_NO_EXPORT __attribute__((__visibility__("hidden")))
# endif
# endif
#endif

#ifndef CMARK_GFM_EXTENSIONS_DEPRECATED
# if defined(_WIN32)
# define CMARK_GFM_EXTENSIONS_DEPRECATED __declspec(deprecated)
# else
# define CMARK_GFM_EXTENSIONS_DEPRECATED __attribute__ ((__deprecated__))
# endif
#endif

#ifndef CMARK_GFM_EXTENSIONS_DEPRECATED_EXPORT
# define CMARK_GFM_EXTENSIONS_DEPRECATED_EXPORT CMARK_GFM_EXTENSIONS_EXPORT CMARK_GFM_EXTENSIONS_DEPRECATED
#endif

#ifndef CMARK_GFM_EXTENSIONS_DEPRECATED_NO_EXPORT
# define CMARK_GFM_EXTENSIONS_DEPRECATED_NO_EXPORT CMARK_GFM_EXTENSIONS_NO_EXPORT CMARK_GFM_EXTENSIONS_DEPRECATED
#endif

#endif /* CMARK_GFM_EXTENSIONS_EXPORT_H */

#endif /* "cmark-gfm-extensions_export.h" */
25 changes: 17 additions & 8 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ set(PROGRAM_SOURCES "${PROJECT_SOURCE_DIR}/bin/main.c")
include_directories(include ${CMAKE_CURRENT_BINARY_DIR})
include_directories(
${PROJECT_SOURCE_DIR}/extensions/include
${PROJECT_BINARY_DIR}/extensions/include
${PROJECT_BINARY_DIR}/extensions
)

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmark-gfm_version.h.in
Expand Down Expand Up @@ -152,27 +152,36 @@ if(CMARK_SHARED OR CMARK_STATIC)
${CMAKE_CURRENT_SOURCE_DIR}/include/cmark-gfm.h
${CMAKE_CURRENT_SOURCE_DIR}/include/cmark-gfm_config.h
${CMAKE_CURRENT_SOURCE_DIR}/include/cmark-gfm-extension_api.h
${CMAKE_CURRENT_SOURCE_DIR}/include/cmark-gfm_export.h
${CMAKE_CURRENT_SOURCE_DIR}/include/export.h
${CMAKE_CURRENT_SOURCE_DIR}/include/cmark-gfm_version.h
DESTINATION include
)

install(EXPORT cmark-gfm DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake)

set(CMARK_TARGETS_FILE ${CMAKE_CURRENT_BINARY_DIR}/cmarkTargets.cmake)
export(TARGETS ${CMARK_INSTALL} FILE ${CMARK_TARGETS_FILE})

if(CMARK_THREADING AND NOT APPLE AND NOT MSVC)
if(CMARK_SHARED)
target_link_libraries(${LIBRARY} pthread)
endif(CMARK_SHARED)

if(CMARK_STATIC)
target_link_libraries(${STATICLIBRARY} pthread)
endif(CMARK_STATIC)
endif()
endif()

# Feature tests
include(CheckIncludeFile)
include(CheckCSourceCompiles)
include(CheckCSourceRuns)
include(CheckSymbolExists)
CHECK_INCLUDE_FILE(stdbool.h HAVE_STDBOOL_H)
CHECK_INCLUDE_FILE(unistd.h HAVE_UNISTD_H)
CHECK_C_SOURCE_COMPILES(
"int main() { __builtin_expect(0,0); return 0; }"
HAVE___BUILTIN_EXPECT)
CHECK_C_SOURCE_COMPILES("
int f(void) __attribute__ (());
int main() { return 0; }
" HAVE___ATTRIBUTE__)

CONFIGURE_FILE(
${CMAKE_CURRENT_SOURCE_DIR}/config.h.in
Expand All @@ -186,7 +195,7 @@ if(MSVC)
else()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4")
endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /WX /wd4706 /wd4204 /wd4221 /wd4100 /D_CRT_SECURE_NO_WARNINGS")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /WX /wd4706 /wd4204 /wd4221 /wd4100 /wd5105 /D_CRT_SECURE_NO_WARNINGS")
elseif(CMAKE_COMPILER_IS_GNUCC OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wno-unused-parameter -std=c99 -pedantic")
endif()
Expand Down
14 changes: 3 additions & 11 deletions src/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,18 @@
extern "C" {
#endif

#cmakedefine HAVE_STDBOOL_H

#ifdef HAVE_STDBOOL_H
#if __STDC_VERSION__ >= 199901l
#include <stdbool.h>
#elif !defined(__cplusplus)
typedef char bool;
#endif

#cmakedefine HAVE___BUILTIN_EXPECT
#cmakedefine HAVE_UNISTD_H

#cmakedefine HAVE___ATTRIBUTE__
#cmakedefine HAVE___BUILTIN_EXPECT

#cmakedefine CMARK_THREADING

#ifdef HAVE___ATTRIBUTE__
#define CMARK_ATTRIBUTE(list) __attribute__ (list)
#else
#define CMARK_ATTRIBUTE(list)
#endif

#ifndef CMARK_INLINE
#if defined(_MSC_VER) && !defined(__cplusplus)
#define CMARK_INLINE __inline
Expand Down
4 changes: 2 additions & 2 deletions src/include/cmark-gfm.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include <stdio.h>
#include <stdint.h>
#include "cmark-gfm_export.h"
#include "export.h"
#include "cmark-gfm_version.h"

#ifdef __cplusplus
Expand Down Expand Up @@ -807,7 +807,7 @@ const char *cmark_version_string(void);
* John MacFarlane, Vicent Marti, Kārlis Gaņģis, Nick Wellnhofer.
*/

#ifndef CMARK_NO_SHORT_NAMES
#if !defined(CMARK_NO_SHORT_NAMES)
#define NODE_DOCUMENT CMARK_NODE_DOCUMENT
#define NODE_BLOCK_QUOTE CMARK_NODE_BLOCK_QUOTE
#define NODE_LIST CMARK_NODE_LIST
Expand Down
32 changes: 20 additions & 12 deletions src/include/cmark-gfm_config.h
Original file line number Diff line number Diff line change
@@ -1,30 +1,36 @@
#ifndef CMARK_CONFIG_H
#define CMARK_CONFIG_H

#ifdef CMARK_USE_CMAKE_HEADERS
// if the CMake config header exists, use that instead of this Swift package prebuilt one
// we need to undefine the header guard, since config.h uses the same one
#undef CMARK_CONFIG_H
#include "config.h"
#else

#ifdef __cplusplus
extern "C" {
#endif

#define HAVE_STDBOOL_H

#ifdef HAVE_STDBOOL_H
#if __STDC_VERSION__ >= 199901l
#include <stdbool.h>
#elif !defined(__cplusplus)
typedef char bool;
#endif

#define HAVE___BUILTIN_EXPECT
#if defined(__has_include)
# if __has_include(<unistd.h>)
# define HAVE_UNISTD_H
# endif
#elif defined(unix) || defined(__unix__) || defined(__unix) || defined(__APPLE__)
// Apple Clang does not define any of the unix symbols, even though it provides unistd.h
# define HAVE_UNISTD_H
#endif

#define HAVE___ATTRIBUTE__
#define HAVE___BUILTIN_EXPECT

#define CMARK_THREADING

#ifdef HAVE___ATTRIBUTE__
#define CMARK_ATTRIBUTE(list) __attribute__ (list)
#else
#define CMARK_ATTRIBUTE(list)
#endif

#ifndef CMARK_INLINE
#if defined(_MSC_VER) && !defined(__cplusplus)
#define CMARK_INLINE __inline
Expand Down Expand Up @@ -75,4 +81,6 @@ CMARK_INLINE int c99_snprintf(char *outBuf, size_t size, const char *format, ...
}
#endif

#endif
#endif /* not CMARK_USE_CMAKE_HEADERS */

#endif /* not CMARK_CONFIG_H */
2 changes: 1 addition & 1 deletion src/include/cmark_ctype.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
extern "C" {
#endif

#include "cmark-gfm_export.h"
#include "export.h"

/** Locale-independent versions of functions from ctype.h.
* We want cmark to behave the same no matter what the system locale.
Expand Down
Loading