diff --git a/CMakeLists.txt b/CMakeLists.txt
index 050191c1fe592e0f15fcf9fa7d0a2367ed025f51..843e8bc691fc29b1ad75aa7dc5969cd6cdb3e560 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -211,6 +211,7 @@ if( CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
     set( CMAKE_SHARED_LINKER_FLAGS "-Wl,--no-undefined" )
 
     set( CALAMARES_AUTOMOC_OPTIONS "-butils/moc-warnings.h" )
+    set( CALAMARES_AUTOUIC_OPTIONS --include utils/moc-warnings.h )
 else()
     set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,--no-undefined" )
     set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,--fatal-warnings -Wnon-virtual-dtor -Woverloaded-virtual -Werror=return-type" )
diff --git a/CMakeModules/CalamaresAddLibrary.cmake b/CMakeModules/CalamaresAddLibrary.cmake
index e731e2b156970e5254ac817595bae02852abe234..0829d919e381f63a81b02226b88611b4a8eea3eb 100644
--- a/CMakeModules/CalamaresAddLibrary.cmake
+++ b/CMakeModules/CalamaresAddLibrary.cmake
@@ -61,11 +61,6 @@ function(calamares_add_library)
     include_directories(${CMAKE_CURRENT_LIST_DIR})
     include_directories(${CMAKE_CURRENT_BINARY_DIR})
 
-    if(LIBRARY_UI)
-        qt5_wrap_ui(LIBRARY_UI_SOURCES ${LIBRARY_UI})
-        list(APPEND LIBRARY_SOURCES ${LIBRARY_UI_SOURCES})
-    endif()
-
     # add resources from current dir
     if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/${LIBRARY_RESOURCES}")
         qt5_add_resources(LIBRARY_RC_SOURCES "${LIBRARY_RESOURCES}")
@@ -83,7 +78,10 @@ function(calamares_add_library)
     endif()
 
     calamares_automoc(${target})
-    
+    if(LIBRARY_UI)
+        calamares_autouic(${target} ${LIBRARY_UI})
+    endif()
+
     if(LIBRARY_EXPORT_MACRO)
         set_target_properties(${target} PROPERTIES COMPILE_DEFINITIONS ${LIBRARY_EXPORT_MACRO})
     endif()
diff --git a/CMakeModules/CalamaresAutomoc.cmake b/CMakeModules/CalamaresAutomoc.cmake
index 0ca5cd89a2aa8f59df5b6225233d7e7164ab18ee..f8aa7faefab894ce9565e908b5f89961c51f5bf7 100644
--- a/CMakeModules/CalamaresAutomoc.cmake
+++ b/CMakeModules/CalamaresAutomoc.cmake
@@ -18,7 +18,7 @@
 #
 ###
 #
-# Helper function for doing automoc on a target.
+# Helper function for doing automoc on a target, and autoui on a .ui file.
 #
 # Sets AUTOMOC TRUE for a target.
 #
@@ -27,6 +27,8 @@
 # libcalamares/utils/moc-warnings.h file to the moc, which in turn
 # reduces compiler warnings in generated MOC code.
 #
+# If the global variable CALAMARES_AUTOUIC_OPTIONS is set, adds that
+# to the options passed to uic.
 
 function(calamares_automoc TARGET)
     set_target_properties( ${TARGET} PROPERTIES AUTOMOC TRUE )
@@ -34,3 +36,12 @@ function(calamares_automoc TARGET)
         set_target_properties( ${TARGET} PROPERTIES AUTOMOC_MOC_OPTIONS "${CALAMARES_AUTOMOC_OPTIONS}" )
     endif()
 endfunction()
+
+function(calamares_autouic TARGET)
+    set_target_properties( ${TARGET} PROPERTIES AUTOUIC TRUE )
+    if ( CALAMARES_AUTOUIC_OPTIONS )
+        foreach(S ${ARGN})
+            set_property(SOURCE ${S} PROPERTY AUTOUIC_OPTIONS "${CALAMARES_AUTOUIC_OPTIONS}")
+        endforeach()
+    endif()
+endfunction()