diff --git a/CMakeLists.txt b/CMakeLists.txt
index 7034bb6..27e90de 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -217,13 +217,16 @@ ADD_CUSTOM_TARGET(geotag-test COMMAND env EXIV2_BINDIR="${CMAKE_BINARY_DIR}"/bin
 # effectively does a make doc on the root directory
 # has to run 'make config' and './configure'
 # and copy bin/taglist to <exiv2dir>/bin/taglist for use by 'make doc'
-IF( MINGW OR UNIX OR APPLE)
-  ADD_CUSTOM_TARGET(doc
-    WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/doc"
-    COMMAND chmod +x ./cmake_doc.sh
-    COMMAND ./cmake_doc.sh "${CMAKE_BINARY_DIR}"
-  )
-ENDIF()
+# IF( MINGW OR UNIX OR APPLE)
+#   ADD_CUSTOM_TARGET(doc
+#     WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/doc"
+#     COMMAND chmod +x ./cmake_doc.sh
+#     COMMAND ./cmake_doc.sh "${CMAKE_BINARY_DIR}"
+#   )
+# ENDIF()
+
+include(config/generateDoc.cmake REQUIRED)
+generate_documentation("${PROJECT_SOURCE_DIR}/config/Doxyfile")

 # That's all Folks!
 ##
diff --git a/config/Doxyfile b/config/Doxyfile
index db62e1d..5d357a7 100644
--- a/config/Doxyfile
+++ b/config/Doxyfile
@@ -52,7 +52,7 @@ PROJECT_LOGO           =
 # If a relative path is entered, it will be relative to the location
 # where doxygen was started. If left blank the current directory will be used.

-OUTPUT_DIRECTORY       =
+OUTPUT_DIRECTORY       = doc

 # If the CREATE_SUBDIRS tag is set to YES, then doxygen will create
 # 4096 sub-directories (in 2 levels) under the output directory of each output
@@ -1637,7 +1637,7 @@ TAGFILES               =
 # When a file name is specified after GENERATE_TAGFILE, doxygen will create
 # a tag file that is based on the input files it reads.

-GENERATE_TAGFILE       = html/exiv2.xml
+GENERATE_TAGFILE       = doc/html/exiv2.xml

 # If the ALLEXTERNALS tag is set to YES all external classes will be listed
 # in the class index. If set to NO only the inherited external classes
diff --git a/config/generateDoc.cmake b/config/generateDoc.cmake
new file mode 100644
index 0000000..2b66078
--- /dev/null
+++ b/config/generateDoc.cmake
@@ -0,0 +1,28 @@
+# -helper macro to add a "doc" target with CMake build system.
+# and configure doxy.config.in to doxy.config
+#
+# target "doc" allows building the documentation with doxygen/dot on WIN32, Linux and Mac
+#
+
+find_package(Doxygen REQUIRED)
+
+macro(generate_documentation DOX_CONFIG_FILE)
+    if(NOT EXISTS "${DOX_CONFIG_FILE}")
+        message(FATAL_ERROR "Configuration file for doxygen not found")
+    endif()
+
+    #Define variables
+    set(INCDIR  "${PROJECT_SOURCE_DIR}/include/exiv2")
+    set(SRCDIR  "${PROJECT_SOURCE_DIR}/src")
+    set(ROOTDIR "${PROJECT_SOURCE_DIR}")
+    #set(TESTSDIR "${PROJECT_SOURCE_DIR}/tests")
+
+    configure_file(${DOX_CONFIG_FILE} ${CMAKE_CURRENT_BINARY_DIR}/doxy.config @ONLY) #OUT-OF-PLACE LOCATION
+    set(DOXY_CONFIG "${CMAKE_CURRENT_BINARY_DIR}/doxy.config")
+    add_custom_target(doc ${DOXYGEN_EXECUTABLE} ${DOXY_CONFIG})
+
+    install(DIRECTORY "${PROJECT_BINARY_DIR}/doc/html/" DESTINATION "share/doc/html/lib${PROJECT_NAME}")
+
+    set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES doc)
+endmacro()
+
