Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. CMake folder path
QtWS25 Last Chance

CMake folder path

Scheduled Pinned Locked Moved Unsolved Qt Creator and other tools
qtcreatorcmakedirectories
9 Posts 5 Posters 4.9k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • SavizS Offline
    SavizS Offline
    Saviz
    wrote on last edited by
    #1

    I am currently trying to experiment with CMake by attempting to put my files in separate directories.

    I am trying to put all my header files into the Includes folder and my implementation files into Sources folder. My project does indeed build and run. However, something strange is happening in the project hierarchy. It displays the Sources folder correctly, but it doesn't seem to be able to detect the Includes folder.

    (I have created and added these folders using file explorer and then added them to my CMakeList)

    CMakeList:

    cmake_minimum_required(VERSION 3.5)
    
    project(QTextEditor VERSION 0.1 LANGUAGES CXX)
    
    set(CMAKE_INCLUDE_CURRENT_DIR ON)
    
    set(CMAKE_AUTOUIC ON)
    set(CMAKE_AUTOMOC ON)
    set(CMAKE_AUTORCC ON)
    
    set(CMAKE_CXX_STANDARD 17)
    set(CMAKE_CXX_STANDARD_REQUIRED ON)
    
    find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets)
    find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets)
    
    set(PROJECT_SOURCES
    
            # Header files
            # -----------------------------------------------------
            # -----------------------------------------------------
    
            # QMainWindows
            Includes/QMainWindows/MainWindow/mainwindow.h
    
            # QDialogs
            Includes/QDialogs/About/aboutdialog.h
            Includes/QDialogs/Find/finddialog.h
            Includes/QDialogs/Replace/replacedialog.h
    
            # Subclasses - QTextEdit
            Includes/Subclasses/QTextEdit/qtexteditsubclass.h
    
            # -----------------------------------------------------
            # -----------------------------------------------------
    
    
            # Implementation files
            # -----------------------------------------------------
            # -----------------------------------------------------
    
            # main application
            main.cpp
    
            # QMainWindows
            Sources/QMainWindows/MainWindow/mainwindow.cpp
            Sources/QMainWindows/MainWindow/mainwindow-connect-signal-slot.cpp
            Sources/QMainWindows/MainWindow/mainwindow-slots.cpp
            Sources/QMainWindows/MainWindow/mainwindow-methods.cpp
    
            # QDialogs
            Sources/QDialogs/About/aboutdialog.cpp
            Sources/QDialogs/Find/finddialog.cpp
            Sources/QDialogs/Replace/replacedialog.cpp
    
            # Subclasses - QTextEdit
            Sources/Subclasses/QTextEdit/qtexteditsubclass.cpp
    
            # -----------------------------------------------------
            # -----------------------------------------------------
    
    
            # UI files
            # -----------------------------------------------------
            # -----------------------------------------------------
    
            # QMainWindow
            mainwindow.ui
    
            # QDialogs
            aboutdialog.ui
            finddialog.ui
            replacedialog.ui
    
            # -----------------------------------------------------
            # -----------------------------------------------------
    
    
            # Resource files
            # -----------------------------------------------------
            # -----------------------------------------------------
    
            resources.qrc
    
            # -----------------------------------------------------
            # -----------------------------------------------------
    )
    

    Image:

    Image.png

    As you can see in the image above, the Sources folder is displayed correctly. But the Includes folder is no where to be found.

    Why is this happening? Is this a bug in QtCreator?

    JoeCFDJ 1 Reply Last reply
    0
    • cristian-adamC Offline
      cristian-adamC Offline
      cristian-adam
      wrote on last edited by
      #2

      Which version of Qt Creator are you using? If you open a header file in the text editor, where does it show in the Project Tree?

      1 Reply Last reply
      0
      • mzimmersM Offline
        mzimmersM Offline
        mzimmers
        wrote on last edited by
        #3
        This post is deleted!
        1 Reply Last reply
        0
        • mzimmersM Offline
          mzimmersM Offline
          mzimmers
          wrote on last edited by
          #4

          I don't have an explicit folder for source files or header files, but my Projects view behaves the way you want yours to. I do have a qt_add_executable() statement in which I enumerate all my sources and includes. I don't see this in your CMakeLists.txt file.

          1 Reply Last reply
          0
          • SavizS Saviz

            I am currently trying to experiment with CMake by attempting to put my files in separate directories.

            I am trying to put all my header files into the Includes folder and my implementation files into Sources folder. My project does indeed build and run. However, something strange is happening in the project hierarchy. It displays the Sources folder correctly, but it doesn't seem to be able to detect the Includes folder.

            (I have created and added these folders using file explorer and then added them to my CMakeList)

            CMakeList:

            cmake_minimum_required(VERSION 3.5)
            
            project(QTextEditor VERSION 0.1 LANGUAGES CXX)
            
            set(CMAKE_INCLUDE_CURRENT_DIR ON)
            
            set(CMAKE_AUTOUIC ON)
            set(CMAKE_AUTOMOC ON)
            set(CMAKE_AUTORCC ON)
            
            set(CMAKE_CXX_STANDARD 17)
            set(CMAKE_CXX_STANDARD_REQUIRED ON)
            
            find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets)
            find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets)
            
            set(PROJECT_SOURCES
            
                    # Header files
                    # -----------------------------------------------------
                    # -----------------------------------------------------
            
                    # QMainWindows
                    Includes/QMainWindows/MainWindow/mainwindow.h
            
                    # QDialogs
                    Includes/QDialogs/About/aboutdialog.h
                    Includes/QDialogs/Find/finddialog.h
                    Includes/QDialogs/Replace/replacedialog.h
            
                    # Subclasses - QTextEdit
                    Includes/Subclasses/QTextEdit/qtexteditsubclass.h
            
                    # -----------------------------------------------------
                    # -----------------------------------------------------
            
            
                    # Implementation files
                    # -----------------------------------------------------
                    # -----------------------------------------------------
            
                    # main application
                    main.cpp
            
                    # QMainWindows
                    Sources/QMainWindows/MainWindow/mainwindow.cpp
                    Sources/QMainWindows/MainWindow/mainwindow-connect-signal-slot.cpp
                    Sources/QMainWindows/MainWindow/mainwindow-slots.cpp
                    Sources/QMainWindows/MainWindow/mainwindow-methods.cpp
            
                    # QDialogs
                    Sources/QDialogs/About/aboutdialog.cpp
                    Sources/QDialogs/Find/finddialog.cpp
                    Sources/QDialogs/Replace/replacedialog.cpp
            
                    # Subclasses - QTextEdit
                    Sources/Subclasses/QTextEdit/qtexteditsubclass.cpp
            
                    # -----------------------------------------------------
                    # -----------------------------------------------------
            
            
                    # UI files
                    # -----------------------------------------------------
                    # -----------------------------------------------------
            
                    # QMainWindow
                    mainwindow.ui
            
                    # QDialogs
                    aboutdialog.ui
                    finddialog.ui
                    replacedialog.ui
            
                    # -----------------------------------------------------
                    # -----------------------------------------------------
            
            
                    # Resource files
                    # -----------------------------------------------------
                    # -----------------------------------------------------
            
                    resources.qrc
            
                    # -----------------------------------------------------
                    # -----------------------------------------------------
            )
            

            Image:

            Image.png

            As you can see in the image above, the Sources folder is displayed correctly. But the Includes folder is no where to be found.

            Why is this happening? Is this a bug in QtCreator?

            JoeCFDJ Offline
            JoeCFDJ Offline
            JoeCFD
            wrote on last edited by JoeCFD
            #5

            @Saviz try the following:
            include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/Includes )
            and more if needed
            include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/Includes/QDialogs )

            if you like to split them, you can add them into two separate file definitions and then add them to your project. I did it this way.

            file( GLOB MYPROJECT_SOURCES
                  ${CMAKE_CURRENT_SOURCE_DIR}/ Sources/QDialogs/About/aboutdialog.cpp
                   ...
            )
            file( GLOB MYPROJECT_HEADERS
                  ${CMAKE_CURRENT_SOURCE_DIR}/ Sources/QDialogs/About/aboutdialog.h
                           ...
            ) 
            
              add_executable( ${PROJECT_NAME}
                              ${MYPROJECT_SOURCES} 
                              ${MYPROJECT_HEADERS} )
                 
            

            this will be cleaner. Same with ui and qrc files.

            Christian EhrlicherC 1 Reply Last reply
            0
            • JoeCFDJ JoeCFD

              @Saviz try the following:
              include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/Includes )
              and more if needed
              include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/Includes/QDialogs )

              if you like to split them, you can add them into two separate file definitions and then add them to your project. I did it this way.

              file( GLOB MYPROJECT_SOURCES
                    ${CMAKE_CURRENT_SOURCE_DIR}/ Sources/QDialogs/About/aboutdialog.cpp
                     ...
              )
              file( GLOB MYPROJECT_HEADERS
                    ${CMAKE_CURRENT_SOURCE_DIR}/ Sources/QDialogs/About/aboutdialog.h
                             ...
              ) 
              
                add_executable( ${PROJECT_NAME}
                                ${MYPROJECT_SOURCES} 
                                ${MYPROJECT_HEADERS} )
                   
              

              this will be cleaner. Same with ui and qrc files.

              Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @JoeCFD said in CMake folder path:

              if you like to split them, you can add them into two separate file definitions and then add them to your project. I did it this way.
              file( GLOB MYPROJECT_SOURCES
              ${CMAKE_CURRENT_SOURCE_DIR}/ Sources/QDialogs/About/aboutdialog.cpp
              ...
              )
              file( GLOB MYPROJECT_HEADERS
              ${CMAKE_CURRENT_SOURCE_DIR}/ Sources/QDialogs/About/aboutdialog.h
              ...
              )

              add_executable( ${PROJECT_NAME}
              ${MYPROJECT_SOURCES}
              ${MYPROJECT_HEADERS} )

              this will be cleaner.

              Cleaner in which way? What does this help in the display issue above?

              Since the op did not answer the questions from @cristian-adam no more help can be done here.

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              JoeCFDJ 1 Reply Last reply
              0
              • Christian EhrlicherC Christian Ehrlicher

                @JoeCFD said in CMake folder path:

                if you like to split them, you can add them into two separate file definitions and then add them to your project. I did it this way.
                file( GLOB MYPROJECT_SOURCES
                ${CMAKE_CURRENT_SOURCE_DIR}/ Sources/QDialogs/About/aboutdialog.cpp
                ...
                )
                file( GLOB MYPROJECT_HEADERS
                ${CMAKE_CURRENT_SOURCE_DIR}/ Sources/QDialogs/About/aboutdialog.h
                ...
                )

                add_executable( ${PROJECT_NAME}
                ${MYPROJECT_SOURCES}
                ${MYPROJECT_HEADERS} )

                this will be cleaner.

                Cleaner in which way? What does this help in the display issue above?

                Since the op did not answer the questions from @cristian-adam no more help can be done here.

                JoeCFDJ Offline
                JoeCFDJ Offline
                JoeCFD
                wrote on last edited by JoeCFD
                #7

                @Christian-Ehrlicher Maybe a cleaner way to organize his cmake file. I have include in my cmake file and he does not have it.
                I am using 6.0.2 and Header Files and Sources Files are well split.

                1 Reply Last reply
                0
                • Christian EhrlicherC Offline
                  Christian EhrlicherC Offline
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on last edited by Christian Ehrlicher
                  #8
                  1. FILE(GLOB) is useless here and using globbing to collect the sources is discouraged
                  2. It's a matter of taste if

                  file( GLOB MYPROJECT_SOURCES
                  ${CMAKE_CURRENT_SOURCE_DIR}/ Sources/QDialogs/About/aboutdialog.cpp
                  ...
                  file( GLOB MYPROJECT_SOURCES
                  ${CMAKE_CURRENT_SOURCE_DIR}/ Sources/QDialogs/About/aboutdialog.cpp

                  or

                  set(MYPROJECT_SOURCES
                  Sources/QDialogs/About/aboutdialog.cpp
                  Sources/QDialogs/About/aboutdialog.h
                  Sources/QDialogs/About/aboutdialog.ui
                  ...
                  )

                  looks better - from my pov the latter one is more compact and therefore more readable.

                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                  Visit the Qt Academy at https://academy.qt.io/catalog

                  JoeCFDJ 1 Reply Last reply
                  0
                  • Christian EhrlicherC Christian Ehrlicher
                    1. FILE(GLOB) is useless here and using globbing to collect the sources is discouraged
                    2. It's a matter of taste if

                    file( GLOB MYPROJECT_SOURCES
                    ${CMAKE_CURRENT_SOURCE_DIR}/ Sources/QDialogs/About/aboutdialog.cpp
                    ...
                    file( GLOB MYPROJECT_SOURCES
                    ${CMAKE_CURRENT_SOURCE_DIR}/ Sources/QDialogs/About/aboutdialog.cpp

                    or

                    set(MYPROJECT_SOURCES
                    Sources/QDialogs/About/aboutdialog.cpp
                    Sources/QDialogs/About/aboutdialog.h
                    Sources/QDialogs/About/aboutdialog.ui
                    ...
                    )

                    looks better - from my pov the latter one is more compact and therefore more readable.

                    JoeCFDJ Offline
                    JoeCFDJ Offline
                    JoeCFD
                    wrote on last edited by JoeCFD
                    #9

                    @Christian-Ehrlicher True it is a taste thing. We did this long long ago and have got used to it.
                    I rechecked the usage of file. If all file names are explicitly added, GLOB is not needed.
                    It is also true that GLOB is not recommended. However, since we have a lot of files, it was simply applied. One problem is that some files are not used and will be included automatically in the project

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved