$NetBSD$

--- CMakeLists.txt.orig	2016-08-26 18:28:16.000000000 +0000
+++ CMakeLists.txt
@@ -58,6 +58,27 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL Darwin
     endif()
     set(CLR_CMAKE_PLATFORM_DARWIN 1)
 else()
+elseif(CMAKE_SYSTEM_NAME STREQUAL NetBSD)
+    add_definitions(
+        -DPLATFORM_UNIX
+    )
+
+    if(NOT ICULIB)
+      set(ICULIB "icuuc")
+      add_definitions(
+        -DU_DISABLE_RENAMING=1 #in case we link against to an older binary of icu
+        )
+      message("using ICU from system default: ${ICULIB}")
+    endif()
+
+    set(CLR_CMAKE_PLATFORM_UNIX 1)
+    if(CMAKE_SYSTEM_PROCESSOR STREQUAL x86_64)
+        set(CLR_CMAKE_PLATFORM_UNIX_TARGET_AMD64 1)
+    else()
+        clr_unknown_arch()
+    endif()
+    set(CLR_CMAKE_PLATFORM_NETBSD 1)
+else()
     clr_unknown_arch()
 endif()
 
@@ -90,6 +111,16 @@ if(CLR_CMAKE_PLATFORM_UNIX)
         endif(CLR_CMAKE_PLATFORM_UNIX_TARGET_AMD64)
     endif(CLR_CMAKE_PLATFORM_LINUX)
 
+    if(CLR_CMAKE_PLATFORM_NETBSD)
+        add_definitions(-D__NETBSD__=1)
+        if(CLR_CMAKE_PLATFORM_UNIX_TARGET_AMD64)
+            message("Detected NetBSD x86_64")
+            add_definitions(-DNETBSD64)
+        else()
+            clr_unknown_arch()
+        endif(CLR_CMAKE_PLATFORM_UNIX_TARGET_AMD64)
+    endif(CLR_CMAKE_PLATFORM_NETBSD)
+
     if(CMAKE_SYSTEM_PROCESSOR STREQUAL x86_64 OR CMAKE_SYSTEM_PROCESSOR STREQUAL amd64)
         set(IS_64BIT_BUILD 1)
         add_definitions(-D_M_X64 -D_M_AMD64 -D_AMD64_)
