waifu2x (waifu2x-converter-cpp tanakamura版) を Mac でコンパイル

waifu2x-converter-cpp WL-Amigo 版のコンパイル方法は既に yuuki-arc さんが書かれていますが、tanakamura 版はなかったので自分の為に書いておきます。

環境

  1. OS X High Sierra 10.13.3

無理矢理コンパイルが通るようにしたパッチ (git clone した後に waifu2x-converter-cpp フォルダに waifu2x-converter-cpp.diff という名前のテキストファイルにして入れておきます。)

diff -uprN waifu2x-converter-cpp.orig/CMakeLists.txt waifu2x-converter-cpp/CMakeLists.txt
--- waifu2x-converter-cpp.orig/CMakeLists.txt	2018-02-07 16:44:37.000000000 +0900
+++ waifu2x-converter-cpp/CMakeLists.txt	2017-08-26 23:12:27.000000000 +0900
@@ -9,6 +9,7 @@ pkg_check_modules(OPENCV_PKG opencv)
 
 string(TIMESTAMP TS)
 add_definitions(-DBUILD_TS="${TS}")
+set(CMAKE_MACOSX_RPATH 1)
 
 if (${OPENCV_PKG_FOUND})
   set(CMAKE_REQUIRED_INCLUDES ${OPENCV_PKG_INCLUDE_DIRS})
@@ -26,10 +27,10 @@ check_include_file_cxx("opencv2/opencv.h
 find_library(IMGCODECS_LIBRARY NAMES opencv_imgcodecs opencv_highgui
   HINTS ${OPENCV_PKG_INCLUDE_DIRS} ${OPENCV_PREFIX}/lib)
 
-if(HAVE_OPENCV)
+#if(HAVE_OPENCV)
   add_definitions(-DHAVE_OPENCV)
   set(OPENCV_LIBRARIES opencv_core opencv_imgproc ${IMGCODECS_LIBRARY} opencv_features2d)
-endif()
+#endif()
 
 if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
   # include_directories("/usr")
@@ -225,20 +226,20 @@ add_custom_target(gensrcs ALL
 
 enable_testing()
 
-if (${HAVE_OPENCV})
+#if (${HAVE_OPENCV})
   add_executable(waifu2x-converter-cpp
     src/main.cpp)
   target_link_libraries(waifu2x-converter-cpp LINK_PUBLIC w2xc)
-  add_executable(runtest w32-apps/runtest.c)
-  target_link_libraries(runtest w2xc)
-  add_test(runtest runtest)
+#  add_executable(runtest w32-apps/runtest.c)
+#  target_link_libraries(runtest w2xc)
+#  add_test(runtest runtest)
 
   install(TARGETS w2xc waifu2x-converter-cpp
     RUNTIME DESTINATION bin
     LIBRARY DESTINATION "lib${LIB_SUFFIX}"
     ARCHIVE DESTINATION "lib${LIB_SUFFIX}"
     )
-endif()
+#endif()
 
 add_executable(runbench w32-apps/runbench.c)
 target_link_libraries(runbench LINK_PUBLIC w2xc)
diff -uprN waifu2x-converter-cpp.orig/src/common.cpp waifu2x-converter-cpp/src/common.cpp
--- waifu2x-converter-cpp.orig/src/common.cpp	2018-02-07 16:44:38.000000000 +0900
+++ waifu2x-converter-cpp/src/common.cpp	2017-11-20 21:51:39.000000000 +0900
@@ -198,11 +198,11 @@ update_test(const char *dst_path,
 	struct stat src_st;
 	stat(src_path, &src_st);
 
-	if (src_st.st_mtim.tv_sec > dst_st.st_mtim.tv_sec) {
+	if (src_st.st_mtimespec.tv_sec > dst_st.st_mtimespec.tv_sec) {
 		return true;
 	}
 
-	if (src_st.st_mtim.tv_nsec > dst_st.st_mtim.tv_nsec) {
+	if (src_st.st_mtimespec.tv_nsec > dst_st.st_mtimespec.tv_nsec) {
 		return true;
 	}

OpenCV が無い場合は Homebrew などであらかじめインストールしておくこと。
あとは以下のコマンドを打ちます。

% git clone https://github.com/tanakamura/waifu2x-converter-cpp.git
% cd waifu2x-converter-cpp
% patch -p1 < waifu2x-converter-cpp.diff
% cmake .
% make

すると waifu2x-converter-cpp が出来ているので、このまま使うなり GUI をかぶせるなり自由に使いましょう。