Skip to content

Commit

Permalink
extensions: avoid useless duplication of headers
Browse files Browse the repository at this point in the history
The export header is identical between the main library and the
extensions. It is generated from the same template, the libraries share
the same properties, and the only difference is that they use different
symbol names. Let them share a header.
  • Loading branch information
eli-schwartz committed Oct 26, 2022
1 parent 855bf90 commit e08c552
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 21 deletions.
13 changes: 2 additions & 11 deletions extensions/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ include_directories(
${PROJECT_BINARY_DIR}/src
)

include (GenerateExportHeader)

include_directories(. ${CMAKE_CURRENT_BINARY_DIR})

set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_RELEASE} -pg")
Expand All @@ -30,6 +28,7 @@ if (CMARK_SHARED)

set_target_properties(${LIBRARY} PROPERTIES
OUTPUT_NAME "cmark-gfm-extensions"
DEFINE_SYMBOL "cmark-gfm"
SOVERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}.gfm.${PROJECT_VERSION_GFM}
VERSION ${PROJECT_VERSION})

Expand All @@ -39,9 +38,6 @@ if (CMARK_SHARED)
# Avoid name clash between PROGRAM and LIBRARY pdb files.
set_target_properties(${LIBRARY} PROPERTIES PDB_NAME cmark-gfm-extensions_dll)

generate_export_header(${LIBRARY}
BASE_NAME cmark-gfm-extensions)

list(APPEND CMARK_INSTALL ${LIBRARY})
target_link_libraries(${LIBRARY} libcmark-gfm)

Expand All @@ -52,6 +48,7 @@ if (CMARK_STATIC)

set_target_properties(${STATICLIBRARY} PROPERTIES
COMPILE_FLAGS "-DCMARK_GFM_STATIC_DEFINE -DCMARK_GFM_EXTENSIONS_STATIC_DEFINE"
DEFINE_SYMBOL "cmark-gfm"
POSITION_INDEPENDENT_CODE ON)

if (MSVC)
Expand All @@ -64,11 +61,6 @@ if (CMARK_STATIC)
VERSION ${PROJECT_VERSION})
endif(MSVC)

if (NOT CMARK_SHARED)
generate_export_header(${STATICLIBRARY}
BASE_NAME cmark-gfm-extensions)
endif()

list(APPEND CMARK_INSTALL ${STATICLIBRARY})
endif()

Expand All @@ -85,7 +77,6 @@ install(TARGETS ${CMARK_INSTALL}
if (CMARK_SHARED OR CMARK_STATIC)
install(FILES
cmark-gfm-core-extensions.h
${CMAKE_CURRENT_BINARY_DIR}/cmark-gfm-extensions_export.h
DESTINATION include
)

Expand Down
20 changes: 10 additions & 10 deletions extensions/cmark-gfm-core-extensions.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,45 +6,45 @@ extern "C" {
#endif

#include "cmark-gfm-extension_api.h"
#include "cmark-gfm-extensions_export.h"
#include "cmark-gfm_export.h"
#include "config.h" // for bool
#include <stdint.h>

CMARK_GFM_EXTENSIONS_EXPORT
CMARK_GFM_EXPORT
void cmark_gfm_core_extensions_ensure_registered(void);

CMARK_GFM_EXTENSIONS_EXPORT
CMARK_GFM_EXPORT
uint16_t cmark_gfm_extensions_get_table_columns(cmark_node *node);

/** Sets the number of columns for the table, returning 1 on success and 0 on error.
*/
CMARK_GFM_EXTENSIONS_EXPORT
CMARK_GFM_EXPORT
int cmark_gfm_extensions_set_table_columns(cmark_node *node, uint16_t n_columns);

CMARK_GFM_EXTENSIONS_EXPORT
CMARK_GFM_EXPORT
uint8_t *cmark_gfm_extensions_get_table_alignments(cmark_node *node);

/** Sets the alignments for the table, returning 1 on success and 0 on error.
*/
CMARK_GFM_EXTENSIONS_EXPORT
CMARK_GFM_EXPORT
int cmark_gfm_extensions_set_table_alignments(cmark_node *node, uint16_t ncols, uint8_t *alignments);

CMARK_GFM_EXTENSIONS_EXPORT
CMARK_GFM_EXPORT
int cmark_gfm_extensions_get_table_row_is_header(cmark_node *node);

/** Sets whether the node is a table header row, returning 1 on success and 0 on error.
*/
CMARK_GFM_EXTENSIONS_EXPORT
CMARK_GFM_EXPORT
int cmark_gfm_extensions_set_table_row_is_header(cmark_node *node, int is_header);

CMARK_GFM_EXTENSIONS_EXPORT
CMARK_GFM_EXPORT
bool cmark_gfm_extensions_get_tasklist_item_checked(cmark_node *node);
/* For backwards compatibility */
#define cmark_gfm_extensions_tasklist_is_checked cmark_gfm_extensions_get_tasklist_item_checked

/** Sets whether a tasklist item is "checked" (completed), returning 1 on success and 0 on error.
*/
CMARK_GFM_EXTENSIONS_EXPORT
CMARK_GFM_EXPORT
int cmark_gfm_extensions_set_tasklist_item_checked(cmark_node *node, bool is_checked);

#ifdef __cplusplus
Expand Down

0 comments on commit e08c552

Please sign in to comment.