cmark

My personal build of CMark ✏️

Commit
be834300a31ffac837b6434650c206aa8e292e1b
Parent
6bd809b6b4836e1026998c2d4c1fc76506de3e8f
Author
John MacFarlane <jgm@berkeley.edu>
Date

Merge pull request #218 from nwellnhof/windows_fixes

Windows fixes

Diffstat

7 files changed, 28 insertions, 10 deletions

Status File Name N° Changes Insertions Deletions
Modified CMakeLists.txt 6 6 0
Modified Makefile 3 2 1
Modified Makefile.nmake 2 1 1
Modified README.md 4 4 0
Modified api_test/CMakeLists.txt 17 11 6
Modified src/CMakeLists.txt 3 2 1
Modified src/blocks.c 3 2 1
diff --git a/CMakeLists.txt b/CMakeLists.txt
@@ -27,6 +27,12 @@ add_test(spectest_library
    "${CMAKE_SOURCE_DIR}/spec.txt" "--library-dir" "${CMAKE_BINARY_DIR}/src"
 )
 add_test(NAME api_test COMMAND api_test)
+if (WIN32)
+  file(TO_NATIVE_PATH ${CMAKE_BINARY_DIR}/src WIN_DLL_DIR)
+  set_tests_properties(api_test PROPERTIES
+    ENVIRONMENT "PATH=${WIN_DLL_DIR};$ENV{PATH}"
+  )
+endif(WIN32)
 add_test(spectest_executable
    python "${CMAKE_SOURCE_DIR}/runtests.py" "--no-normalize" "--spec" "${CMAKE_SOURCE_DIR}/spec.txt" "--program" "${CMAKE_BINARY_DIR}/src/cmark"
 )
diff --git a/Makefile b/Makefile
@@ -1,6 +1,7 @@
 SRCDIR?=src
 DATADIR?=data
 BUILDDIR?=build
+GENERATOR?=Unix Makefiles
 MINGW_BUILDDIR?=build-mingw
 MINGW_INSTALLDIR?=windows
 SPEC=spec.txt
@@ -28,7 +29,7 @@ check:
 $(BUILDDIR): check
 	mkdir -p $(BUILDDIR); \
 	cd $(BUILDDIR); \
-	cmake .. -DCMAKE_BUILD_TYPE=$(BUILD_TYPE)
+	cmake .. -G "$(GENERATOR)" -DCMAKE_BUILD_TYPE=$(BUILD_TYPE)
 
 install: $(BUILDDIR) man/man1/cmark.1
 	make -C $(BUILDDIR) install
diff --git a/Makefile.nmake b/Makefile.nmake
@@ -33,7 +33,7 @@ man\man1\cmark.1: man\cmark.1.md
 	pandoc $? -o $@ -s -t man
 
 test: $(SPEC) all
-	@pushd $(BUILDDIR) && $(MAKE) test ARGS="-V" && popd
+	@pushd $(BUILDDIR) && $(MAKE) /nologo test ARGS="-V" && popd
 
 distclean: clean
 	del /q src\scanners.c 2> nul
diff --git a/README.md b/README.md
@@ -104,6 +104,10 @@ To test the archives:
 Compiling for Windows
 ---------------------
 
+To compile with MSVC and NMAKE:
+
+    nmake
+
 You can cross-compile a Windows binary and dll on linux if you have the
 `mingw32` compiler:
 
diff --git a/api_test/CMakeLists.txt b/api_test/CMakeLists.txt
@@ -10,10 +10,15 @@ include_directories(
 target_link_libraries(api_test libcmark)
 
 # Compiler flags
-if(CMAKE_COMPILER_IS_GNUCC OR "${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
-  set_target_properties(api_test PROPERTIES COMPILE_FLAGS
-    "-std=c99 -Wall -Wextra"
-  )
-elseif ("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC")
-  set_target_properties(api_test PROPERTIES COMPILE_FLAGS "/TP /W4")
+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} /wd4127 /wd4244 /wd4267 /wd4706 /wd4800 /D_CRT_SECURE_NO_WARNINGS")
+  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /TP")
+elseif(CMAKE_COMPILER_IS_GNUCC OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
+  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -std=c99 -pedantic")
 endif()
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
@@ -121,13 +121,14 @@ if(MSVC)
   else()
     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4")
   endif()
+  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4127 /wd4244 /wd4267 /wd4706 /wd4800 /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 -std=c99 -pedantic")
 endif()
 
 # Compile as C++ under MSVC
 if(MSVC)
-  set(CMAKE_C_FLAGS "/TP")
+  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /TP")
 endif()
 
 if($ENV{TIMER})
diff --git a/src/blocks.c b/src/blocks.c
@@ -439,7 +439,8 @@ extern cmark_node *cmark_parse_document(const char *buffer, size_t len)
 	cmark_node *document;
 
 	while (buffer < end) {
-		const char *eol = memchr(buffer, '\n', end - buffer);
+		const char *eol
+			= (const char *)memchr(buffer, '\n', end - buffer);
 		offset = eol ? (eol - buffer) + 1 : end - buffer;
 		cmark_process_line(parser, buffer, offset);
 		buffer += offset;