diff --git a/CMakeLists.txt b/CMakeLists.txt index 3250ab1..555c156 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,5 +3,5 @@ cmake_minimum_required (VERSION 3.5) project (browser LANGUAGES C CXX) add_subdirectory (lib/commonmarker/src) -# add_subdirectory (lib/commonmarker/extensions) +add_subdirectory (lib/commonmarker/extensions) add_subdirectory (src) \ No newline at end of file diff --git a/lib/commonmarker/src/CMakeLists.txt b/lib/commonmarker/src/CMakeLists.txt index 195fd5d..61fe1d4 100644 --- a/lib/commonmarker/src/CMakeLists.txt +++ b/lib/commonmarker/src/CMakeLists.txt @@ -61,12 +61,65 @@ include_directories( ${PROJECT_BINARY_DIR}/extensions ) -configure_file ( +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmark-gfm_version.h.in + ${CMAKE_CURRENT_BINARY_DIR}/cmark-gfm_version.h) + +include (GenerateExportHeader) + +# Disable the PUBLIC declarations when compiling the executable: +set_target_properties(${PROGRAM} PROPERTIES + COMPILE_FLAGS "-DCMARK_STATIC_DEFINE -DCMARKEXTENSIONS_STATIC_DEFINE") + +# Check integrity of node structure when compiled as debug: +set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DCMARK_DEBUG_NODES -DDEBUG") +set(CMAKE_LINKER_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG}") + +set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_RELEASE} -pg") +set(CMAKE_LINKER_PROFILE "${CMAKE_LINKER_FLAGS_RELEASE} -pg") + +# Feature tests +include(CheckIncludeFile) +include(CheckCSourceCompiles) +include(CheckCSourceRuns) +include(CheckSymbolExists) +CHECK_INCLUDE_FILE(stdbool.h HAVE_STDBOOL_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 ${CMAKE_CURRENT_BINARY_DIR}/config.h) + +# Always compile with warnings +if(MSVC) + # Force to always compile with W4 + if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]") + string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") + 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") +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() + +# Compile as C++ under MSVC older than 12.0 +if(MSVC AND MSVC_VERSION LESS 1800) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /TP") +endif() + +if(CMAKE_BUILD_TYPE STREQUAL "Ubsan") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=undefined") +endif() configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmark-gfm_version.h.in ${CMAKE_CURRENT_BINARY_DIR}/cmark-gfm_version.h) add_library (CommonMarker ${LIBRARY_SOURCES}) target_include_directories(CommonMarker PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 12f1859..4ff3471 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -42,5 +42,5 @@ else() ) endif() -target_link_libraries (browser LINK_PUBLIC CommonMarker) +target_link_libraries (browser LINK_PUBLIC CommonMarker CommonMarkerExtensions) target_link_libraries (browser PRIVATE Qt5::Widgets) diff --git a/src/markdown-render.cpp b/src/markdown-render.cpp index c1edb76..e2e569c 100644 --- a/src/markdown-render.cpp +++ b/src/markdown-render.cpp @@ -1,6 +1,6 @@ #include "markdown-render.h" -// #include +#include #include #include @@ -35,11 +35,9 @@ MarkdownRender::MarkdownRender() * This is a function that will make enabling extensions easier */ void MarkdownRender::addMarkdownExtension(cmark_parser *parser, char *extName) { -/* cmark_syntax_extension *ext = cmark_find_syntax_extension(extName); if ( ext ) cmark_parser_attach_syntax_extension(parser, ext); -*/ } // A function to convert HTML to markdown @@ -53,8 +51,8 @@ char * MarkdownRender::to_html(const char *markdown_string) cmark_parser *parser = cmark_parser_new(options); // Add extensions - //addMarkdownExtension(parser, "strikethrough"); - //addMarkdownExtension(parser, "table"); + addMarkdownExtension(parser, "strikethrough"); + addMarkdownExtension(parser, "table"); // cmark AST cmark_node *doc;