github / cmark-gfm

GitHub's fork of cmark, a CommonMark parsing and rendering library and program in C
Other
906 stars 174 forks source link

Update CMakeLists.txt to fix build error #266

Open yamavol opened 2 years ago

yamavol commented 2 years ago

When this cmake project is added as subdirectory and linked to another executable target, the build can fail, due to 2 reasons:

The first one, the compiler complains that "cmark-gfm.h" contains non-ASCII letters, because MSVC cannot handle UTF8 (without BOM). "/WX" is not used in the original (commonmark/cmark). Can this flag be removed?

The second issue is just reporting. It is fixed in the the original and should be fixed when 0.30 is merged, but it can be fix in advance if necessary. (ref: b6c73d8)

Lemmingh commented 2 years ago

MSVC cannot handle UTF8 (without BOM)

MSVC understands UTF-8 (without BOM).

MSVC (cl.exe) uses active system code page by default. But you can and it's generally good to always specify the encoding via the /source-charset option.

For UTF-8, there is a shorthand option /utf-8, which sets the source character set and the execution character set, and enables conversion validation.

I'd recommend adding /utf-8.

Removing /WX can make things worse.

yamavol commented 2 years ago

You are right. I will take down that request. I confirmed it can be successfully built with /utf-8 and /WX flags on.
(/source-charset:utf-8 didn't work, because of the warning C4566)

Just reporting, I also had to to define CMARK_GFM_STATIC_DEFINE and CMARK_GFM_EXTENSIONS_STATIC_DEFINE for my executable for successful build. Using target_compile_definitions in this project instead of set_target_properties and COMPILE_FLAGS fixes the issue, as these symbols will be propagated to the external executables.