OSDN Git Service

make it possible to build bootstrap_moc/moc as all-in-one
authorIvailo Monev <xakepa10@laimg.moc>
Thu, 3 Aug 2017 07:12:14 +0000 (07:12 +0000)
committerIvailo Monev <xakepa10@laimg.moc>
Thu, 3 Aug 2017 07:12:14 +0000 (07:12 +0000)
Signed-off-by: Ivailo Monev <xakepa10@laimg.moc>
cmake/modules/KatieBuildMacros.cmake
src/tools/moc/CMakeLists.txt

index b847b95..8a16611 100644 (file)
@@ -126,57 +126,60 @@ endfunction()
 # account all-in-one target build setting up proper dependency for the
 # moc/uic/rcc generated resources
 function(KATIE_SETUP_TARGET FORTARGET)
-    set(resourcesdep "${CMAKE_CURRENT_BINARY_DIR}/${FORTARGET}_resources.cpp")
-    if(NOT EXISTS "${resourcesdep}")
-        file(WRITE "${resourcesdep}" "enum { CompilersWorkaroundAlaAutomoc = 1 };\n")
-    endif()
-    set(targetresources)
-    foreach(tmpres ${ARGN})
-        get_filename_component(resource ${tmpres} ABSOLUTE)
-        get_filename_component(rscext ${resource} EXT)
-        get_filename_component(rscname ${resource} NAME_WE)
-        get_filename_component(rscpath ${resource} PATH)
-        string(REPLACE "${CMAKE_SOURCE_DIR}" "${CMAKE_BINARY_DIR}" rscpath "${rscpath}")
-        if("${rscext}" STREQUAL ".ui")
-            set(rscout "${rscpath}/ui_${rscname}.h")
-            set(targetresources ${targetresources} ${rscout})
-            make_directory(${rscpath})
-            add_custom_command(
-                COMMAND "${KATIE_UIC}" "${resource}" -o "${rscout}"
-                OUTPUT "${rscout}"
-            )
-        elseif("${rscext}" STREQUAL ".qrc")
-            set(rscout "${rscpath}/qrc_${rscname}.cpp")
-            set(targetresources ${targetresources} ${rscout})
-            make_directory(${rscpath})
-            add_custom_command(
-                COMMAND "${KATIE_RCC}" "${resource}" -o "${rscout}" -name "${rscname}"
-                OUTPUT "${rscout}"
-            )
-        elseif("${rscext}" MATCHES "(.h|.cpp|.mm)")
-            file(READ "${resource}" rsccontent)
-            if("${rsccontent}" MATCHES "(Q_OBJECT|Q_OBJECT_FAKE|Q_GADGET)")
-                set(rscout "${rscpath}/moc_${rscname}${rscext}")
+    # this can be simpler if continue() was supported by old CMake versions
+    if(NOT "${FORTARGET}" MATCHES "bootstrap_moc|moc")
+        set(resourcesdep "${CMAKE_CURRENT_BINARY_DIR}/${FORTARGET}_resources.cpp")
+        if(NOT EXISTS "${resourcesdep}")
+            file(WRITE "${resourcesdep}" "enum { CompilersWorkaroundAlaAutomoc = 1 };\n")
+        endif()
+        set(targetresources)
+        foreach(tmpres ${ARGN})
+            get_filename_component(resource ${tmpres} ABSOLUTE)
+            get_filename_component(rscext ${resource} EXT)
+            get_filename_component(rscname ${resource} NAME_WE)
+            get_filename_component(rscpath ${resource} PATH)
+            string(REPLACE "${CMAKE_SOURCE_DIR}" "${CMAKE_BINARY_DIR}" rscpath "${rscpath}")
+            if("${rscext}" STREQUAL ".ui")
+                set(rscout "${rscpath}/ui_${rscname}.h")
                 set(targetresources ${targetresources} ${rscout})
-                get_directory_property(dirdefs COMPILE_DEFINITIONS)
-                get_directory_property(dirincs INCLUDE_DIRECTORIES)
-                set(mocargs)
-                foreach(ddef ${dirdefs})
-                    # TODO: filter non -D, support -U too
-                    set(mocargs ${mocargs} -D${ddef})
-                endforeach()
-                foreach(incdir ${dirincs})
-                    set(mocargs ${mocargs} -I${incdir})
-                endforeach()
                 make_directory(${rscpath})
                 add_custom_command(
-                    COMMAND "${KATIE_MOC}" -nw "${resource}" -o "${rscout}" ${mocargs}
+                    COMMAND "${KATIE_UIC}" "${resource}" -o "${rscout}"
                     OUTPUT "${rscout}"
                 )
+            elseif("${rscext}" STREQUAL ".qrc")
+                set(rscout "${rscpath}/qrc_${rscname}.cpp")
+                set(targetresources ${targetresources} ${rscout})
+                make_directory(${rscpath})
+                add_custom_command(
+                    COMMAND "${KATIE_RCC}" "${resource}" -o "${rscout}" -name "${rscname}"
+                    OUTPUT "${rscout}"
+                )
+            elseif("${rscext}" MATCHES "(.h|.cpp|.mm)")
+                file(READ "${resource}" rsccontent)
+                if("${rsccontent}" MATCHES "(Q_OBJECT|Q_OBJECT_FAKE|Q_GADGET)")
+                    set(rscout "${rscpath}/moc_${rscname}${rscext}")
+                    set(targetresources ${targetresources} ${rscout})
+                    get_directory_property(dirdefs COMPILE_DEFINITIONS)
+                    get_directory_property(dirincs INCLUDE_DIRECTORIES)
+                    set(mocargs)
+                    foreach(ddef ${dirdefs})
+                        # TODO: filter non -D, support -U too
+                        set(mocargs ${mocargs} -D${ddef})
+                    endforeach()
+                    foreach(incdir ${dirincs})
+                        set(mocargs ${mocargs} -I${incdir})
+                    endforeach()
+                    make_directory(${rscpath})
+                    add_custom_command(
+                        COMMAND "${KATIE_MOC}" -nw "${resource}" -o "${rscout}" ${mocargs}
+                        OUTPUT "${rscout}"
+                    )
+                endif()
             endif()
-        endif()
-    endforeach()
-    set_source_files_properties(${resourcesdep} PROPERTIES OBJECT_DEPENDS "${targetresources}")
+        endforeach()
+        set_source_files_properties(${resourcesdep} PROPERTIES OBJECT_DEPENDS "${targetresources}")
+    endif()
 
     if(NOT KATIE_ALLINONE)
         set(filteredsources)
index 397b5da..fbda254 100644 (file)
@@ -83,10 +83,12 @@ set(BOOTSTRAP_SOURCES
     ${CMAKE_SOURCE_DIR}/src/core/tools/qlocale_unix.cpp
 )
 
-add_executable(bootstrap_moc ${BOOTSTRAP_SOURCES} ${MOC_SOURCES})
+katie_setup_target(bootstrap_moc ${BOOTSTRAP_SOURCES} ${MOC_SOURCES})
+add_executable(bootstrap_moc ${bootstrap_moc_SOURCES})
 target_compile_definitions(bootstrap_moc PRIVATE ${BOOTSTRAP_DEFINITIONS})
 
-add_executable(moc ${MOC_SOURCES})
+katie_setup_target(moc ${MOC_SOURCES})
+add_executable(moc ${moc_SOURCES})
 target_link_libraries(moc ${EXTRA_MOC_LIBS})
 
 set_target_properties(moc PROPERTIES