--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -285,7 +285,7 @@
 
 SET(CONFIGURATION_TYPES "Debug;Release;RelWithDebInfo")
 
-IF (WIN32)
+IF (WIN32 AND NOT MINGW)
   IF (NOT DEFAULT_CMAKE_CONFIGURATION_TYPES_SET)
     SET(CMAKE_CONFIGURATION_TYPES "${CONFIGURATION_TYPES}" CACHE STRING "List of generated configurations." FORCE)
     SET(DEFAULT_CMAKE_CONFIGURATION_TYPES_SET ON CACHE INTERNAL "Default CMake configuration types set.")
@@ -397,7 +397,7 @@
     OPTION(EMBREE_ISA_SSE42 "Enables SSE4.2 ISA." ON)
     OPTION(EMBREE_ISA_AVX "Enables AVX ISA." ${COMPILER_SUPPORTS_AVX})
     OPTION(EMBREE_ISA_AVX2 "Enables AVX2 ISA." ${COMPILER_SUPPORTS_AVX2})
-    IF (WIN32 OR APPLE)
+    IF (MSVC OR APPLE)
       OPTION(EMBREE_ISA_AVX512 "Enables AVX512 ISA." OFF)
     ELSE()
       OPTION(EMBREE_ISA_AVX512 "Enables AVX512 ISA." ${COMPILER_SUPPORTS_AVX512})
--- a/common/math/emath.h
+++ b/common/math/emath.h
@@ -48,7 +48,7 @@
   __forceinline int   toInt  (const float& a) { return int(a); }
   __forceinline float toFloat(const int&   a) { return float(a); }
 
-#if defined(__WIN32__)
+#if defined(_MSC_VER)
   __forceinline bool finite ( const float x ) { return _finite(x) != 0; }
 #endif
 
@@ -293,7 +293,7 @@
   }
 #endif
 
-#if defined(__WIN32__) || defined(__FreeBSD__)
+#if defined(_MSC_VER) || defined(__FreeBSD__)
   __forceinline void sincosf(float x, float *s, float *c) {
     *s = sinf(x); *c = cosf(x);
   }
--- a/common/sys/sysinfo.cpp
+++ b/common/sys/sysinfo.cpp
@@ -294,7 +294,7 @@
     int cpuid_leaf_e1[4] = { 0,0,0,0 };
     if (nIds >= 1) __cpuid (cpuid_leaf_1,0x00000001);
 #if _WIN32
-#if _MSC_VER && (_MSC_FULL_VER < 160040219)
+#if defined(_MSC_VER) && (_MSC_FULL_VER < 160040219)
 #else
     if (nIds >= 7) __cpuidex(cpuid_leaf_7,0x00000007,0);
 #endif
--- a/common/cmake/clang.cmake
+++ b/common/cmake/clang.cmake
@@ -21,7 +21,7 @@
   _SET_IF_EMPTY(FLAGS_AVX512 "-march=skx")
 ENDIF ()
 
-IF (WIN32)
+IF (MSVC)
 
   SET(COMMON_CXX_FLAGS "")
   SET(COMMON_CXX_FLAGS "${COMMON_CXX_FLAGS} /EHsc")        # catch C++ exceptions only and extern "C" functions never throw a C++ exception
@@ -92,6 +92,7 @@
   SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-strict-aliasing")        # disables strict aliasing rules
   SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-tree-vectorize")         # disable auto vectorizer
   SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_FORTIFY_SOURCE=2")         # perform extra security checks for some standard library calls
+  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_USE_MATH_DEFINES")
   IF (EMBREE_STACK_PROTECTOR)
     SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector")           # protects against return address overrides
   ENDIF()
@@ -132,8 +133,8 @@
   ELSE(APPLE)
     IF (NOT EMBREE_ADDRESS_SANITIZER) # for address sanitizer this causes link errors
       SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined") # issues link error for undefined symbols in shared library
-      SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pie")                     # enables position independent execution for executable
-      IF (NOT EMSCRIPTEN)
+      IF (NOT EMSCRIPTEN AND NOT MINGW)
+        SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pie")                     # enables position independent execution for executable
         SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -z relro -z now")    # re-arranges data sections to increase security
         SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -z noexecstack")     # we do not need an executable stack
         SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -z relro -z now")          # re-arranges data sections to increase security
--- a/common/cmake/gnu.cmake
+++ b/common/cmake/gnu.cmake
@@ -56,6 +56,7 @@
 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-strict-aliasing")        # disables strict aliasing rules
 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-tree-vectorize")         # disable auto vectorizer
 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_FORTIFY_SOURCE=2")         # perform extra security checks for some standard library calls
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_USE_MATH_DEFINES")
 IF (EMBREE_STACK_PROTECTOR)
   SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector")           # protects against return address overrides
 ENDIF()
@@ -95,10 +96,12 @@
 ELSE(APPLE)
   IF (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
     SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined") # issues link error for undefined symbols in shared library
+    IF (NOT MINGW)
     SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -z noexecstack")     # we do not need an executable stack
     SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -z relro -z now")    # re-arranges data sections to increase security
     SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -z noexecstack")           # we do not need an executable stack
     SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -z relro -z now")          # re-arranges data sections to increase security
+    ENDIF ()
   ENDIF ()
   SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pie")                       # enables position independent execution for executable
 ENDIF(APPLE) 
--- a/common/cmake/package.cmake
+++ b/common/cmake/package.cmake
@@ -118,7 +118,7 @@
 # Install MSVC runtime
 ##############################################################
 
-IF (WIN32)
+IF (MSVC)
 
   SET(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_SKIP TRUE)
   SET(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_NO_WARNINGS TRUE)
@@ -133,7 +133,7 @@
 ##############################################################
 
 INSTALL(DIRECTORY include/embree4 DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" COMPONENT devel)
-IF (NOT WIN32)
+IF (NOT MSVC)
   INSTALL(DIRECTORY man/man3 DESTINATION "${CMAKE_INSTALL_MANDIR}" COMPONENT devel)
 ENDIF()
 
--- a/common/math/constants.h
+++ b/common/math/constants.h
@@ -7,8 +7,7 @@
 
 #include <limits>
 
-#define _USE_MATH_DEFINES
-#include <math.h> // using cmath causes issues under Windows
+#include <cmath> // using cmath causes issues under Windows
 #include <cfloat>
 #include <climits>
 
