[Orxonox-commit 3111] r7805 - in code/forks/sandbox_qt: cmake/tools src src/orxonox

rgrieder at orxonox.net rgrieder at orxonox.net
Sat Dec 25 23:58:26 CET 2010


Author: rgrieder
Date: 2010-12-25 23:58:25 +0100 (Sat, 25 Dec 2010)
New Revision: 7805

Modified:
   code/forks/sandbox_qt/cmake/tools/SourceFileUtilities.cmake
   code/forks/sandbox_qt/cmake/tools/TargetUtilities.cmake
   code/forks/sandbox_qt/src/CMakeLists.txt
   code/forks/sandbox_qt/src/orxonox/CMakeLists.txt
Log:
Changed source file handling procedure, especially for Qt moc files.

Modified: code/forks/sandbox_qt/cmake/tools/SourceFileUtilities.cmake
===================================================================
--- code/forks/sandbox_qt/cmake/tools/SourceFileUtilities.cmake	2010-12-25 20:32:34 UTC (rev 7804)
+++ code/forks/sandbox_qt/cmake/tools/SourceFileUtilities.cmake	2010-12-25 22:58:25 UTC (rev 7805)
@@ -33,54 +33,18 @@
  #
 
 FUNCTION(PREPARE_SOURCE_FILES)
-  SET(_fullpath_sources)
+  SET(_source_files)
   FOREACH(_file ${ARGN})
-    IF(_file STREQUAL "COMPILATION_BEGIN")
-      SET(_compile TRUE)
-      # Next file is the name of the compilation
-      SET(_get_name TRUE)
-    ELSEIF(_get_name)
-      SET(_get_name FALSE)
-      SET(_compilation_name ${_file})
-    ELSEIF(_file STREQUAL "COMPILATION_END")
-      IF(NOT _compilation_name)
-        MESSAGE(FATAL_ERROR "No name provided for source file compilation")
-      ENDIF()
-      IF(NOT DISABLE_COMPILATIONS)
-        SET(_compilation_file ${CMAKE_CURRENT_BINARY_DIR}/${_compilation_name})
-        SET(_include_string)
-        FOREACH(_file2 ${_compilation})
-          SET(_include_string "${_include_string}#include \"${_file2}\"\n")
-        ENDFOREACH(_file2)
-        IF(EXISTS ${_compilation_file})
-          FILE(READ ${_compilation_file} _include_string_file)
-        ENDIF()
-        IF(NOT _include_string STREQUAL "${_include_string_file}")
-          FILE(WRITE ${_compilation_file} "${_include_string}")
-        ENDIF()
-        LIST(APPEND _fullpath_sources ${_compilation_file})
-        # MSVC hack that excludes the compilations from the intellisense database
-        # (There is a bug with the "-" instead of "/". Only works for "Zm#" argument)
-        # 2nd Note: Exploiting this results in a strange separation of the compilation
-        # file, causing the compiler not to use multi processing --> slower compiling.
-        #IF(MSVC)
-        #    SET_SOURCE_FILES_PROPERTIES(${_compilation_file} PROPERTIES COMPILE_FLAGS "-Zm1000")
-        #ENDIF()
-      ENDIF()
-      SET(_compilation_name)
-      SET(_compilation)
-      SET(_compile FALSE)
+    IF(_file MATCHES "^(COMPILATION_BEGIN|COMPILATION_END|QT)$")
+      # Append keywords verbatim
+      LIST(APPEND _source_files ${_file})
     ELSE()
-      # Prefix the full path
-      GET_SOURCE_FILE_PROPERTY(_filepath ${_file} LOCATION)
-      LIST(APPEND _fullpath_sources ${_filepath})
-      IF(_compile AND NOT DISABLE_COMPILATIONS)
-        LIST(APPEND _compilation ${_filepath})
-        LIST(APPEND _fullpath_sources "H")
-      ENDIF()
+      # Store file with path relative to the root source directory
+      FILE(RELATIVE_PATH _file_rel ${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/${_file})
+      LIST(APPEND _source_files ${_file_rel})
     ENDIF()
   ENDFOREACH(_file)
-  SET(_fullpath_sources ${_fullpath_sources} PARENT_SCOPE)
+  SET(_source_files ${_source_files} PARENT_SCOPE)
 ENDFUNCTION(PREPARE_SOURCE_FILES)
 
 
@@ -88,7 +52,7 @@
 FUNCTION(ADD_SOURCE_FILES _varname)
   PREPARE_SOURCE_FILES(${ARGN})
   # Write into the cache to avoid variable scoping in subdirs
-  SET(${_varname} ${${_varname}} ${_fullpath_sources} CACHE INTERNAL "Do not edit")
+  SET(${_varname} ${${_varname}} ${_source_files} CACHE INTERNAL "Do not edit")
 ENDFUNCTION(ADD_SOURCE_FILES)
 
 
@@ -96,7 +60,7 @@
 FUNCTION(SET_SOURCE_FILES _varname)
   PREPARE_SOURCE_FILES(${ARGN})
   # Write into the cache to avoid variable scoping in subdirs
-  SET(${_varname} ${_fullpath_sources} CACHE INTERNAL "Do not edit")
+  SET(${_varname} ${_source_files} CACHE INTERNAL "Do not edit")
 ENDFUNCTION(SET_SOURCE_FILES)
 
 
@@ -112,7 +76,7 @@
   FOREACH(_file ${ARGN})
     GET_SOURCE_FILE_PROPERTY(_full_filepath ${_file} LOCATION)
     FILE(RELATIVE_PATH _relative_path ${CMAKE_CURRENT_SOURCE_DIR} ${_full_filepath})
-    IF(NOT _relative_path MATCHES "^\\.\\.")
+    IF(NOT _relative_path MATCHES "^\\.\\./") # Has "../" at the beginning
       GET_FILENAME_COMPONENT(_relative_path ${_relative_path} PATH)
       STRING(REPLACE "/" "\\\\" _group_path "${_relative_path}")
       SOURCE_GROUP("Source\\${_group_path}" FILES ${_file})

Modified: code/forks/sandbox_qt/cmake/tools/TargetUtilities.cmake
===================================================================
--- code/forks/sandbox_qt/cmake/tools/TargetUtilities.cmake	2010-12-25 20:32:34 UTC (rev 7804)
+++ code/forks/sandbox_qt/cmake/tools/TargetUtilities.cmake	2010-12-25 22:58:25 UTC (rev 7805)
@@ -47,8 +47,6 @@
  #      PCH_FILE:          Precompiled header file
  #      PCH_EXCLUDE:       Source files to be excluded from PCH support
  #      OUTPUT_NAME:       If you want a different name than the target name
- #      QT_MOC_FILES:      List of files to be processed by Qt MOC
- #      QT_UIC_FILES:      List of files to be processed by Qt UIC
  #  Note:
  #    This function also installs the target!
  #  Prerequisistes:
@@ -84,19 +82,72 @@
                   NO_INSTALL         NO_VERSION        ${_additional_switches})
   SET(_list_names LINK_LIBRARIES     VERSION           SOURCE_FILES
                   DEFINE_SYMBOL      PCH_FILE          PCH_EXCLUDE
-                  OUTPUT_NAME        QT_MOC_FILES      QT_UIC_FILES)
+                  OUTPUT_NAME)
 
   PARSE_MACRO_ARGUMENTS("${_switches}" "${_list_names}" ${ARGN})
 
 
-  # Workaround: Source file properties get lost when leaving a subdirectory
-  # Therefore an "H" after a file means we have to set it as HEADER_FILE_ONLY
+  # Process source files with support for compilations and QT special files
+  # Note: All file paths are relative to the root source directory, even the
+  #       name of the compilation file.
+  SET(_${_target_name}_source_files)
+  SET(_get_compilation_file FALSE)
+  SET(_add_to_compilation FALSE)
+  SET(_compile_qt_next FALSE)
   FOREACH(_file ${_arg_SOURCE_FILES})
-    IF(_file STREQUAL "H")
-      SET_SOURCE_FILES_PROPERTIES(${_last_file} PROPERTIES HEADER_FILE_ONLY TRUE)
+    IF(_file STREQUAL "COMPILATION_BEGIN")
+      # Next file is the name of the compilation
+      SET(_get_compilation_file TRUE)
+    ELSEIF(_file STREQUAL "COMPILATION_END")
+      IF(NOT _compilation_file)
+        MESSAGE(FATAL_ERROR "No name provided for source file compilation")
+      ENDIF()
+      IF(NOT _compilation_include_string)
+        MESSAGE(STATUS "Warning: Empty source file compilation!")
+      ENDIF()
+      IF(NOT DISABLE_COMPILATIONS)
+        IF(EXISTS ${_compilation_file})
+          FILE(READ ${_compilation_file} _include_string_file)
+        ENDIF()
+        IF(NOT _compilation_include_string STREQUAL "${_include_string_file}")
+          FILE(WRITE ${_compilation_file} "${_compilation_include_string}")
+        ENDIF()
+        LIST(APPEND _${_target_name}_source_files ${_compilation_file})
+      ENDIF()
+      SET(_add_to_compilation FALSE)
+    ELSEIF(_get_compilation_file)
+      SET(_compilation_file ${CMAKE_BINARY_DIR}/${_file})
+      SET(_get_compilation_file FALSE)
+      SET(_add_to_compilation TRUE)
+      SET(_compilation_include_string)
+    ELSEIF(_file STREQUAL "QT")
+      SET(_compile_qt_next TRUE)
     ELSE()
-      SET(_last_file ${_file})
+      # Default, add source file
+      SET(_file ${CMAKE_SOURCE_DIR}/${_file})
       LIST(APPEND _${_target_name}_source_files ${_file})
+
+      # Handle compilations
+      IF(_add_to_compilation AND NOT DISABLE_COMPILATIONS)
+        IF(_file MATCHES "\\.(c|cc|cpp|cxx)$")
+          SET(_compilation_include_string "${_compilation_include_string}#include \"${_file}\"\n")
+        ENDIF()
+        # Don't compile these files, even if they are source files
+        SET_SOURCE_FILES_PROPERTIES(${_file} PROPERTIES HEADER_FILE_ONLY TRUE)
+      ENDIF()
+
+      # Handle Qt MOC and UI files
+      IF(_compile_qt_next)
+        GET_FILENAME_COMPONENT(_ext ${_file} EXT)
+        IF(_ext STREQUAL ".ui")
+          QT4_WRAP_UI(_${_target_name}_source_files ${_file})
+        ELSEIF(_ext STREQUAL ".qrc")
+          QT4_ADD_RESOURCES(_${_target_name}_source_files ${_file})
+        ELSEIF(_ext MATCHES "^\\.(h|hpp|hxx)$")
+          QT4_WRAP_CPP(_${_target_name}_source_files ${_file})
+        ENDIF()
+        SET(_compile_qt_next FALSE)
+      ENDIF()
     ENDIF()
   ENDFOREACH(_file)
 
@@ -105,23 +156,14 @@
     GET_ALL_HEADER_FILES(_${_target_name}_header_files)
   ENDIF()
 
-  # Combine source, header and QT designer files
+  # Combine source and header files
   SET(_${_target_name}_files
     ${_${_target_name}_header_files}
     ${_${_target_name}_source_files}
-    ${_arg_QT_UIC_FILES}
   )
   # Remove potential duplicates
   LIST(REMOVE_DUPLICATES _${_target_name}_files)
 
-  # QT MOC and UIC preprocessing
-  IF(_arg_QT_MOC_FILES)
-      QT4_WRAP_CPP(_${_target_name}_files ${_arg_QT_MOC_FILES})
-  ENDIF()
-  IF(_arg_QT_UIC_FILES)
-      QT4_WRAP_UI(_${_target_name}_files ${_arg_QT_UIC_FILES})
-  ENDIF()
-
   # First part (pre target) of precompiled header files
   IF(PCH_COMPILER_SUPPORT AND _arg_PCH_FILE)
     # Provide convenient option to control PCH
@@ -173,7 +215,7 @@
 
   # Don't compile header files
   FOREACH(_file ${_${_target_name}_files})
-    IF(NOT _file MATCHES "\\.(c|cc|cpp)")
+    IF(NOT _file MATCHES "\\.(c|cc|cpp|cxx)$")
       SET_SOURCE_FILES_PROPERTIES(${_file} PROPERTIES HEADER_FILE_ONLY TRUE)
     ENDIF()
   ENDFOREACH(_file)

Modified: code/forks/sandbox_qt/src/CMakeLists.txt
===================================================================
--- code/forks/sandbox_qt/src/CMakeLists.txt	2010-12-25 20:32:34 UTC (rev 7804)
+++ code/forks/sandbox_qt/src/CMakeLists.txt	2010-12-25 22:58:25 UTC (rev 7805)
@@ -79,6 +79,8 @@
 
 ################## Executable ###################
 
+SET_SOURCE_FILES(ORXONOX_MAIN_SRC_FILES Orxonox.cc)
+
 INCLUDE_DIRECTORIES(
   ${CMAKE_CURRENT_SOURCE_DIR}/libraries
   ${CMAKE_CURRENT_SOURCE_DIR}/orxonox
@@ -96,7 +98,7 @@
     ${QT_QTMAIN_LIBRARY}
     orxonox
   SOURCE_FILES
-    Orxonox.cc
+    ${ORXONOX_MAIN_SRC_FILES}
   OUTPUT_NAME orxonox
 )
 

Modified: code/forks/sandbox_qt/src/orxonox/CMakeLists.txt
===================================================================
--- code/forks/sandbox_qt/src/orxonox/CMakeLists.txt	2010-12-25 20:32:34 UTC (rev 7804)
+++ code/forks/sandbox_qt/src/orxonox/CMakeLists.txt	2010-12-25 22:58:25 UTC (rev 7805)
@@ -19,22 +19,20 @@
 
 INCLUDE_DIRECTORIES(
   ${CMAKE_SOURCE_DIR}/src/libraries
-  ${CMAKE_CURRENT_SOURCE_DIR}
+  # Make Qt UIC generated header files visible
+  ${CMAKE_CURRENT_BINARY_DIR}
 )
 
 SET_SOURCE_FILES(ORXONOX_SRC_FILES
   Main.cc
-  MainWindow.cc
+
+  QT MainWindow.h       MainWindow.cc
+  QT MainWindow.ui
 )
 
 #ADD_SUBDIRECTORY(subdir)
 
 ORXONOX_ADD_LIBRARY(orxonox
-  FIND_HEADER_FILES
-  QT_MOC_FILES
-    MainWindow.h
-  QT_UIC_FILES
-    MainWindow.ui
   LINK_LIBRARIES
     ${QT_QTCORE_LIBRARY}
     ${QT_QTGUI_LIBRARY}




More information about the Orxonox-commit mailing list