]> Creatis software - clitk.git/commitdiff
Improve code reading in the CMakeLists.txt
authortbaudier <thomas.baudier@creatis.insa-lyon.fr>
Thu, 18 Feb 2016 14:51:40 +0000 (15:51 +0100)
committertbaudier <thomas.baudier@creatis.insa-lyon.fr>
Thu, 18 Feb 2016 14:51:40 +0000 (15:51 +0100)
To distinguish Qt4 and Qt5

vv/CMakeLists.txt

index c61497546f75320380adbb17de22be78d44e2c5e..5d7746177c34a1b4cf4e8320264bf76e6efe9c6a 100644 (file)
@@ -110,14 +110,24 @@ set(vv_SRCS
 
 #=========================================================
 # Qt related commands
+
 if(vv_QT_VERSION VERSION_GREATER "4")
   find_package(Qt5Widgets REQUIRED)
   find_package(Qt5Network REQUIRED)
   find_package(Qt5Designer REQUIRED)
+else()
+  find_package(Qt4 REQUIRED)
+endif()
 
+if(vv_QT_VERSION VERSION_GREATER "4")
   link_directories(${QT5Widgets_LIBRARIES})
   link_directories(${QT5Network_LIBRARIES})
   link_directories(${QT5Designer_LIBRARIES})
+else()
+  link_directories(${QT_LIBRARY_DIR})
+endif()
+
+if(vv_QT_VERSION VERSION_GREATER "4")
   qt5_wrap_cpp(vv_SRCS
     vvMainWindowBase.h
     QTreePushButton.h
@@ -130,69 +140,7 @@ if(vv_QT_VERSION VERSION_GREATER "4")
     vvROIActor.h
     vvToolCreatorBase.h
     )
-  
-  qt5_wrap_ui(vv_UI_CXX
-    qt_ui/vvHelpDialog.ui
-    qt_ui/vvDocumentation.ui
-    qt_ui/vvDicomSeriesSelector.ui
-    qt_ui/vvDummyWindow.ui #For testing
-    )
-  
-  QT5_add_resources(vv_SRCS vvIcons.qrc)
-  
-  # Add the autotools in the header vvToolsList.h for initialization of the dummy
-  # variables in vv.cxx for the tools contained in vvLib
-  if(${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt IS_NEWER_THAN ${CMAKE_CURRENT_BINARY_DIR}/vvToolsList.h)
-    file(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/vvToolsList.h)
-    foreach(tool ${vv_TOOLS})
-      file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/vvToolsList.h "#include \"${tool}.h\"\n")
-      file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/vvToolsList.h "extern const vvToolCreator<${tool}> *dummy${tool};\n")
-      file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/vvToolsList.h "const vvToolCreator<${tool}> *dummy${tool}2 = dummy${tool};\n\n")
-    endforeach(tool)
-  endif(${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt IS_NEWER_THAN ${CMAKE_CURRENT_BINARY_DIR}/vvToolsList.h)
-  
-  # Add the autotools and the common files ui
-  foreach(tool ${vv_TOOLS} ${vv_COMMON_WITH_UI})
-      set(vv_SRCS ${vv_SRCS} ${tool}.cxx)
-      QT5_WRAP_CPP(vv_SRCS ${tool}.h)
-      QT5_WRAP_UI(vv_UI_CXX qt_ui/${tool}.ui)
-  endforeach(tool)
-  
-  # Add the common source files
-  foreach(tool ${vv_COMMON})
-      set(vv_SRCS ${vv_SRCS} ${tool}.cxx)
-      QT5_WRAP_CPP(vv_SRCS ${tool}.h)
-  endforeach(tool)
-  
-  # if Windows and Qt was built as a static lib then don't set QT_DLL flag
-  set(QT_STATIC 0)
-  if(WIN32)
-    if(EXISTS ${Qt5Widgets_LIBRARIES}/QtCore.prl)
-      file(READ ${Qt5Widgets_LIBRARIES}/QtCore.prl QT_CORE_PRL)
-      if(${QT_CORE_PRL} MATCHES "static")
-        set(QT_STATIC 1)
-      endif(${QT_CORE_PRL} MATCHES "static")
-    endif(EXISTS ${Qt5Widgets_LIBRARIES}/QtCore.prl)
-  endif(WIN32)
-  if(NOT QT_STATIC)
-    add_definitions(-DQT_DLL)
-  endif(NOT QT_STATIC)
-  add_definitions(-DQT_THREAD_SUPPORT)
-  include_directories(
-    ${Qt5Widgets_INCLUDE_DIRS}
-    ${Qt5Gui_INCLUDE_DIRS}
-    ${Qt5Core_INCLUDE_DIRS}
-    ${Qt5Network_INCLUDE_DIRS}
-    ${Qt5Designer_INCLUDE_DIRS}
-    ${CMAKE_CURRENT_BINARY_DIR}
-    ${CMAKE_CURRENT_SOURCE_DIR}
-    )
 else()
-  find_package(Qt4 REQUIRED)
-  link_directories(${QT_LIBRARY_DIR})
-  
-  
   QT4_WRAP_CPP(vv_SRCS
     vvMainWindowBase.h
     QTreePushButton.h
@@ -204,15 +152,29 @@ else()
     vvROIActor.h
     vvToolCreatorBase.h
     )
-  
+endif()
+
+if(vv_QT_VERSION VERSION_GREATER "4")
+  qt5_wrap_ui(vv_UI_CXX
+    qt_ui/vvHelpDialog.ui
+    qt_ui/vvDocumentation.ui
+    qt_ui/vvDicomSeriesSelector.ui
+    qt_ui/vvDummyWindow.ui #For testing
+    )
+else()
   QT4_WRAP_UI(vv_UI_CXX
     qt_ui/vvHelpDialog.ui
     qt_ui/vvDocumentation.ui
     qt_ui/vvDicomSeriesSelector.ui
     qt_ui/vvDummyWindow.ui #For testing
     )
-  
+endif()
+
+if(vv_QT_VERSION VERSION_GREATER "4")
+  QT5_add_resources(vv_SRCS vvIcons.qrc)
+else()
   QT4_ADD_RESOURCES(vv_SRCS vvIcons.qrc)
+endif()
   
   # Add the autotools in the header vvToolsList.h for initialization of the dummy
   # variables in vv.cxx for the tools contained in vvLib
@@ -228,41 +190,69 @@ else()
   # Add the autotools and the common files ui
   foreach(tool ${vv_TOOLS} ${vv_COMMON_WITH_UI})
       set(vv_SRCS ${vv_SRCS} ${tool}.cxx)
-      QT4_WRAP_CPP(vv_SRCS ${tool}.h)
-      QT4_WRAP_UI(vv_UI_CXX qt_ui/${tool}.ui)
+      if(vv_QT_VERSION VERSION_GREATER "4")
+        QT5_WRAP_CPP(vv_SRCS ${tool}.h)
+        QT5_WRAP_UI(vv_UI_CXX qt_ui/${tool}.ui)
+      else()
+        QT4_WRAP_CPP(vv_SRCS ${tool}.h)
+        QT4_WRAP_UI(vv_UI_CXX qt_ui/${tool}.ui)
+      endif()
   endforeach(tool)
   
   # Add the common source files
   foreach(tool ${vv_COMMON})
       set(vv_SRCS ${vv_SRCS} ${tool}.cxx)
-      QT4_WRAP_CPP(vv_SRCS ${tool}.h)
+      if(vv_QT_VERSION VERSION_GREATER "4")
+        QT5_WRAP_CPP(vv_SRCS ${tool}.h)
+      else()
+        QT4_WRAP_CPP(vv_SRCS ${tool}.h)
+      endif()
   endforeach(tool)
   
   # if Windows and Qt was built as a static lib then don't set QT_DLL flag
   set(QT_STATIC 0)
   if(WIN32)
-    if(EXISTS ${QT_LIBRARY_DIR}/QtCore.prl)
-      file(READ ${QT_LIBRARY_DIR}/QtCore.prl QT_CORE_PRL)
-      if(${QT_CORE_PRL} MATCHES "static")
-        set(QT_STATIC 1)
-      endif(${QT_CORE_PRL} MATCHES "static")
-    endif(EXISTS ${QT_LIBRARY_DIR}/QtCore.prl)
+    if(vv_QT_VERSION VERSION_GREATER "4")
+      if(EXISTS ${Qt5Widgets_LIBRARIES}/QtCore.prl)
+        file(READ ${Qt5Widgets_LIBRARIES}/QtCore.prl QT_CORE_PRL)
+        if(${QT_CORE_PRL} MATCHES "static")
+          set(QT_STATIC 1)
+        endif(${QT_CORE_PRL} MATCHES "static")
+      endif(EXISTS ${Qt5Widgets_LIBRARIES}/QtCore.prl)
+    else()
+      if(EXISTS ${QT_LIBRARY_DIR}/QtCore.prl)
+        file(READ ${QT_LIBRARY_DIR}/QtCore.prl QT_CORE_PRL)
+        if(${QT_CORE_PRL} MATCHES "static")
+          set(QT_STATIC 1)
+        endif(${QT_CORE_PRL} MATCHES "static")
+      endif(EXISTS ${QT_LIBRARY_DIR}/QtCore.prl)
+    endif()
   endif(WIN32)
   if(NOT QT_STATIC)
     add_definitions(-DQT_DLL)
   endif(NOT QT_STATIC)
-  
+
   add_definitions(-DQT_THREAD_SUPPORT)
-  
-  include_directories(
-    ${QT_INCLUDES}
-    ${QT_INCLUDE_DIR}
-    ${QT_QTGUI_INCLUDE_DIR}
-    ${QT_QTCORE_INCLUDE_DIR}
-    ${CMAKE_CURRENT_BINARY_DIR}
-    ${CMAKE_CURRENT_SOURCE_DIR}
-  )
-endif()
+  if(vv_QT_VERSION VERSION_GREATER "4")
+    include_directories(
+      ${Qt5Widgets_INCLUDE_DIRS}
+      ${Qt5Gui_INCLUDE_DIRS}
+      ${Qt5Core_INCLUDE_DIRS}
+      ${Qt5Network_INCLUDE_DIRS}
+      ${Qt5Designer_INCLUDE_DIRS}
+      ${CMAKE_CURRENT_BINARY_DIR}
+      ${CMAKE_CURRENT_SOURCE_DIR}
+    )
+  else()
+    include_directories(
+      ${QT_INCLUDES}
+      ${QT_INCLUDE_DIR}
+      ${QT_QTGUI_INCLUDE_DIR}
+      ${QT_QTCORE_INCLUDE_DIR}
+      ${CMAKE_CURRENT_BINARY_DIR}
+      ${CMAKE_CURRENT_SOURCE_DIR}
+    )
+  endif()
 #=========================================================
 
 #=========================================================