From 91f090a4db1eb2febe39ac7b8005e42a0260461c Mon Sep 17 00:00:00 2001
From: Frederik Vannoote <frederik.vannoote@barco.com>
Date: Fri, 17 Aug 2018 10:33:03 +0200
Subject: [PATCH 1/2] Added manifest functionality.

---
 CommonConfig.cmake         |  1 +
 manifest/AddManifest.cmake | 41 ++++++++++++++++++++++++++++++++++++++
 manifest/dll.manifest.in   |  2 ++
 manifest/exe.manifest.in   |  9 +++++++++
 4 files changed, 53 insertions(+)
 create mode 100644 manifest/AddManifest.cmake
 create mode 100644 manifest/dll.manifest.in
 create mode 100644 manifest/exe.manifest.in

diff --git a/CommonConfig.cmake b/CommonConfig.cmake
index 33982e2..deec0ba 100644
--- a/CommonConfig.cmake
+++ b/CommonConfig.cmake
@@ -125,3 +125,4 @@ include(Doxygen)
 # Generate information (name, description, version, etc.) for applications and libraries
 include(GetGitRevisionDescription)
 include(AddResourceInfo)
+include(manifest/AddManifest)
diff --git a/manifest/AddManifest.cmake b/manifest/AddManifest.cmake
new file mode 100644
index 0000000..665aeb9
--- /dev/null
+++ b/manifest/AddManifest.cmake
@@ -0,0 +1,41 @@
+macro(add_manifest PROJECT TYPE)
+if(CMAKE_BUILD_TYPE MATCHES Release)
+    if(WIN32 AND NOT UNIX)
+        # Search for the mt binary
+        find_program(MT_TOOL NAMES mt PATHS "C:/Program Files/Microsoft SDKs/Windows/v7.1/Bin/" "C:/Program Files (x86)/Windows Kits/8.1/bin/x86")
+        # Get the full output name for the target
+        set(OUTPUT_FILE_PATH $<TARGET_FILE:${PROJECT}>)
+
+        if(MT_TOOL)
+            # select type
+            if(${TYPE} STREQUAL "LIB" OR ${TYPE} STREQUAL "QMLLIB")
+                set(MANIFEST_FILE_IN ${CMAKE_CURRENT_LIST_DIR}/dll.manifest.in)
+                set(MANIFEST_FILE_OUT ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.dll.manifest)
+            elseif(${TYPE} STREQUAL "BIN")
+                set(MANIFEST_FILE_IN ${CMAKE_CURRENT_LIST_DIR}/exe.manifest.in)
+                set(MANIFEST_FILE_OUT ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.exe.manifest)
+            endif()
+
+            # fill in the appropriate information into dll.manifest
+            configure_file(${MANIFEST_FILE_IN} ${MANIFEST_FILE_OUT})
+
+            add_custom_command(
+                TARGET ${PROJECT}
+                POST_BUILD
+                COMMAND ${MT_TOOL} -manifest ${MANIFEST_FILE_OUT} -outputresource:${OUTPUT_FILE_PATH};#1
+                WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIRs}
+                DEPENDS ${MANIFEST_FILE_OUT}
+            )
+
+            # return info
+            message(STATUS "Prepared embedded manifest for ${PROJECT_NAME} of type ${TYPE}")
+
+        else()
+            message(SEND_ERROR "Manifest creation of ${PROJECT} failed")
+        endif()
+    endif(WIN32 AND NOT UNIX)
+endif(CMAKE_BUILD_TYPE MATCHES Release)
+endmacro()
+
+# More info:
+# http://blogs.msdn.com/b/cheller/archive/2006/08/24/how-to-embed-a-manifest-in-an-assembly-let-me-count-the-ways.aspx
diff --git a/manifest/dll.manifest.in b/manifest/dll.manifest.in
new file mode 100644
index 0000000..9552504
--- /dev/null
+++ b/manifest/dll.manifest.in
@@ -0,0 +1,2 @@
+<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
+</assembly>
diff --git a/manifest/exe.manifest.in b/manifest/exe.manifest.in
new file mode 100644
index 0000000..6e15cd6
--- /dev/null
+++ b/manifest/exe.manifest.in
@@ -0,0 +1,9 @@
+<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
+    <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
+        <security>
+            <requestedPrivileges>
+                <requestedExecutionLevel level="asInvoker" uiAccess="false" />
+            </requestedPrivileges>
+        </security>
+    </trustInfo>
+</assembly>

From f5de07c46fac27d6c43d7f3949c3e91e39f084df Mon Sep 17 00:00:00 2001
From: Frederik Vannoote <frederik.vannoote@barco.com>
Date: Fri, 17 Aug 2018 11:13:18 +0200
Subject: [PATCH 2/2] Added doc.

---
 manifest/AddManifest.cmake | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/manifest/AddManifest.cmake b/manifest/AddManifest.cmake
index 665aeb9..a1c22a8 100644
--- a/manifest/AddManifest.cmake
+++ b/manifest/AddManifest.cmake
@@ -1,3 +1,5 @@
+# Add manifest: executables may require administrative privileges.
+
 macro(add_manifest PROJECT TYPE)
 if(CMAKE_BUILD_TYPE MATCHES Release)
     if(WIN32 AND NOT UNIX)