Update CMakeLists.txt to fix build error
yamavol opened this issue · 2 comments
When this cmake project is added as subdirectory and linked to another executable target, the build can fail, due to 2 reasons:
- The compiler option "/WX" reports warning C4819 as error (MSVC only)
- The file generated by generate_export_header() is not included
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)
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.
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.