Skip to content

various CMake fixes and cleanup #40

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

Merged
merged 17 commits into from
Mar 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
4 changes: 2 additions & 2 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 Down
10 changes: 3 additions & 7 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 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" */
10 changes: 3 additions & 7 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,7 +152,7 @@ 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
)
Expand All @@ -165,14 +165,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__)

CONFIGURE_FILE(
${CMAKE_CURRENT_SOURCE_DIR}/config.h.in
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
28 changes: 15 additions & 13 deletions src/include/cmark-gfm_export.h → src/include/export.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@

#ifndef CMARK_GFM_EXPORT_H
#define CMARK_GFM_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_EXPORT_H
#include "cmark-gfm_export.h"
#else

#ifdef CMARK_GFM_STATIC_DEFINE
# define CMARK_GFM_EXPORT
# define CMARK_GFM_NO_EXPORT
Expand All @@ -15,11 +21,7 @@
# define CMARK_GFM_NO_EXPORT
# else
# if defined(libcmark_gfm_EXPORTS)
# if defined(__linux__)
# define CMARK_GFM_EXPORT __attribute__((__visibility__("protected")))
# else
# define CMARK_GFM_EXPORT __attribute__((__visibility__("default")))
# endif
# define CMARK_GFM_EXPORT __attribute__((__visibility__("default")))
# else
# define CMARK_GFM_EXPORT __attribute__((__visibility__("default")))
# endif
Expand All @@ -28,7 +30,11 @@
#endif

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

#ifndef CMARK_GFM_DEPRECATED_EXPORT
Expand All @@ -39,10 +45,6 @@
# define CMARK_GFM_DEPRECATED_NO_EXPORT CMARK_GFM_NO_EXPORT CMARK_GFM_DEPRECATED
#endif

#if 0 /* DEFINE_NO_DEPRECATED */
# ifndef CMARK_GFM_NO_DEPRECATED
# define CMARK_GFM_NO_DEPRECATED
# endif
#endif
#endif /* not CMARK_USE_CMAKE_HEADERS */

#endif /* CMARK_GFM_EXPORT_H */
#endif /* not CMARK_GFM_EXPORT_H */
Loading