diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 08fd699..cae9cb6 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -94,7 +94,11 @@ endif()
 
 if (WIN32 AND NOT MINGW AND NOT MSYS)
   #	SET_TARGET_PROPERTIES(${GD_LIB} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:msvcrt.lib")
-  SET_PROPERTY(TARGET ${GD_LIB_STATIC} APPEND PROPERTY COMPILE_DEFINITIONS NONDLL=1)
+
+  if (BUILD_STATIC_LIBS)
+    SET_PROPERTY(TARGET ${GD_LIB_STATIC} APPEND PROPERTY COMPILE_DEFINITIONS NONDLL=1)
+  endif()
+
 ENDIF(WIN32 AND NOT MINGW AND NOT MSYS)
 
 if (MINGW OR MSYS)
