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 tests and libs separate view in qt creator

cmake tests and libs separate view in qt creator

Scheduled Pinned Locked Moved Unsolved Qt Creator and other tools
21 Posts 4 Posters 1.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.
  • S Offline
    S Offline
    Sandon
    wrote on 12 Jul 2024, 07:44 last edited by Sandon 7 Dec 2024, 07:45
    #1

    Hi all,

    I've just switched to cmake and I'm trying to do one thing that in qmake was very simple.

    I have many libraries, each of them with many tests under the tests directory.

    In the past I had a .pro file that referenced to other .pro files: one for the .pro of all the libs and another one for the .pro of all the tests.
    In this way in Qt creator I had the two things, libs and tests, separated.

    I'm trying to make the same thing now with cmake, both using add_subdirectory() and include(). I have tried all the possible ways BUT it does not seem possible to achieve this simple goal.
    In all cases the tests appear under the library folder. I am starting to thing that the problem is not cmake but how qt creator manages cmake projects. I hope there is a way because I really liked that organization.

    The only alternative way I can think of is to open two separate cmake projects in qt creator, one for libs and another for the tests,but this is not what I want to.

    Thank you in advance

    Edit: I am not using ctest but google test and it would be awesome to make this work not only for tests but for any combination of libs

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sierdzio
      Moderators
      wrote on 12 Jul 2024, 08:09 last edited by
      #2

      I simply have tests in different folder than other code, which also means separate cmake file (add_subdirectory). I think this is the most natural way to do it, since the unit tests need to link to your library anyway (so they need to treat your library as a separate part of the project).

      (Z(:^

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Sandon
        wrote on 12 Jul 2024, 08:38 last edited by Sandon 7 Dec 2024, 08:48
        #3

        I don't know if I have understood what you're saying. I'll try to clarify:

        My repo is divided in N libraries: libA libB libC .. libN
        Each lib has (at least) two sub-directories: src and tests.
        Each lib has a CMakeLists.txt file with inside add_subdirectory of the src and tests folders.
        The tests folder contains more directories, for different test executables, each of them containing a CMakeLists.txt file.

        I prefer to have tests for libX inside the libX tests subfolder as in this case the library is self-contained.
        In this way I can just do whatever I want: open a single lib as a project, open all of them or open them as a group in the particular view I need for the moment. This is because, visually, it's much better to have some libs/tests organized in a particular way.

        Again, with qmake, there was no problem and I could really customize everything as I wanted. Cmake should have been an improvement, but if this simple thing is not possible , I'm starting to have some doubts about this switch.

        A visual view of my repo:

        project/
        ├── CMakeLists.txt
        ├── libA/
        │   ├── CMakeLists.txt
        │   ├── src/
        │   └── tests/
        │       ├── test1/
        │       ├── test2/
        │       └── CMakeLists.txt
        ├── libB/
        │   ├── CMakeLists.txt
        │   ├── src/
        │   └── tests/
        │       ├── test1/
        │       ├── test2/
        │       └── CMakeLists.txt
        └── ...other libs...
        
        

        what I'd like to see is something like this:

        libA
        libB
        tests
        

        then you can click on tests and see the other tests.
        Instead, right now, I just see:

        libA
        libB
        

        and the tests are inside those folders

        Edit2: add_custom_target -> didn't know this, it looks like what I need

        1 Reply Last reply
        0
        • C Offline
          C Offline
          cristian-adam
          wrote on 12 Jul 2024, 09:15 last edited by
          #4

          https://bugreports.qt.io/browse/QTCREATORBUG-28873 has a suggestion for using the FOLDER property on targets.

          This would allow customisation of the project tree in regards where targets are located.

          In this case the obvious folder for tests would be tests.

          A future version of Qt Creator will be having this feature, so make sure to watch that bug report! 😀

          S 1 Reply Last reply 12 Jul 2024, 09:42
          1
          • C cristian-adam
            12 Jul 2024, 09:15

            https://bugreports.qt.io/browse/QTCREATORBUG-28873 has a suggestion for using the FOLDER property on targets.

            This would allow customisation of the project tree in regards where targets are located.

            In this case the obvious folder for tests would be tests.

            A future version of Qt Creator will be having this feature, so make sure to watch that bug report! 😀

            S Offline
            S Offline
            Sandon
            wrote on 12 Jul 2024, 09:42 last edited by Sandon 7 Dec 2024, 09:43
            #5

            @cristian-adam thank you, I hope there's a workaround though ;)

            1 Reply Last reply
            0
            • S Offline
              S Offline
              Sandon
              wrote on 12 Jul 2024, 10:44 last edited by Sandon 7 Dec 2024, 10:44
              #6

              I am trying to play with add_custom_target but no real progress so far. I just succeeded in adding external files grouped inside a custom target (using add_custom_target(tests SOURCES myfolder/file.txt) . Does anyone has ever used this function ?

              1 Reply Last reply
              0
              • S Offline
                S Offline
                Sandon
                wrote on 16 Jul 2024, 07:34 last edited by
                #7

                Still trying wih add_custom_target, but no way to make it work

                1 Reply Last reply
                0
                • C Offline
                  C Offline
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on 16 Jul 2024, 07:38 last edited by
                  #8

                  I don't see what add_custom_target should have to do with how QtCreator is showing the targets... You have to wait until QtCreator supports the SOURCES property.

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

                  S 1 Reply Last reply 16 Jul 2024, 07:44
                  0
                  • C Christian Ehrlicher
                    16 Jul 2024, 07:38

                    I don't see what add_custom_target should have to do with how QtCreator is showing the targets... You have to wait until QtCreator supports the SOURCES property.

                    S Offline
                    S Offline
                    Sandon
                    wrote on 16 Jul 2024, 07:44 last edited by Sandon
                    #9

                    @Christian-Ehrlicher Well, you'll never know. Many times there are tricks to make things work.
                    I was also thinking to open two projects, one for the libraries and another for the tests, but again, it does not feel like the right approach.

                    It is really disappointing not to have this simple feature.

                    C 1 Reply Last reply 16 Jul 2024, 07:46
                    0
                    • S Sandon
                      16 Jul 2024, 07:44

                      @Christian-Ehrlicher Well, you'll never know. Many times there are tricks to make things work.
                      I was also thinking to open two projects, one for the libraries and another for the tests, but again, it does not feel like the right approach.

                      It is really disappointing not to have this simple feature.

                      C Offline
                      C Offline
                      Christian Ehrlicher
                      Lifetime Qt Champion
                      wrote on 16 Jul 2024, 07:46 last edited by
                      #10

                      @Sandon said in cmake tests and libs separate view in qt creator:

                      this simple feature.

                      Feel free to provide a patch when you are so confident that this is a simple task. QtCreator is open source.

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

                      S 1 Reply Last reply 16 Jul 2024, 07:54
                      0
                      • C Christian Ehrlicher
                        16 Jul 2024, 07:46

                        @Sandon said in cmake tests and libs separate view in qt creator:

                        this simple feature.

                        Feel free to provide a patch when you are so confident that this is a simple task. QtCreator is open source.

                        S Offline
                        S Offline
                        Sandon
                        wrote on 16 Jul 2024, 07:54 last edited by
                        #11

                        @Christian-Ehrlicher I wish had more time, but yes.. good reply

                        1 Reply Last reply
                        0
                        • C Offline
                          C Offline
                          cristian-adam
                          wrote on 16 Jul 2024, 13:26 last edited by
                          #12

                          CMake already has the SOURCES property, you just need to use cmake generator expressions to use it.

                          Take this example:

                          cmake_minimum_required(VERSION 3.16)
                          
                          project(WidgetsApp VERSION 0.1 LANGUAGES CXX)
                          
                          add_subdirectory(app)
                          add_subdirectory(tests)
                          
                          add_custom_target(MyApp
                              SOURCES $<LIST:TRANSFORM,$<LIST:FILTER,$<TARGET_PROPERTY:WidgetsApp,SOURCES>,EXCLUDE,.*_autogen/.*>,PREPEND,app/>
                          )
                          

                          global_custom_targets.png

                          C 1 Reply Last reply 16 Jul 2024, 14:29
                          3
                          • C cristian-adam
                            16 Jul 2024, 13:26

                            CMake already has the SOURCES property, you just need to use cmake generator expressions to use it.

                            Take this example:

                            cmake_minimum_required(VERSION 3.16)
                            
                            project(WidgetsApp VERSION 0.1 LANGUAGES CXX)
                            
                            add_subdirectory(app)
                            add_subdirectory(tests)
                            
                            add_custom_target(MyApp
                                SOURCES $<LIST:TRANSFORM,$<LIST:FILTER,$<TARGET_PROPERTY:WidgetsApp,SOURCES>,EXCLUDE,.*_autogen/.*>,PREPEND,app/>
                            )
                            

                            global_custom_targets.png

                            C Offline
                            C Offline
                            Christian Ehrlicher
                            Lifetime Qt Champion
                            wrote on 16 Jul 2024, 14:29 last edited by
                            #13

                            @cristian-adam this looks more like a hack to me... 🙂

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

                            1 Reply Last reply
                            0
                            • C Offline
                              C Offline
                              Christian Ehrlicher
                              Lifetime Qt Champion
                              wrote on 16 Jul 2024, 14:36 last edited by Christian Ehrlicher
                              #14

                              I just saw that I mixed SOURCES And FOLDERS properties - I meant FOLDERS, sorry for the confusion.
                              https://cmake.org/cmake/help/latest/prop_tgt/FOLDER.html

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

                              1 Reply Last reply
                              1
                              • S Offline
                                S Offline
                                Sandon
                                wrote on 16 Jul 2024, 14:53 last edited by Sandon
                                #15

                                @Christian-Ehrlicher thank you very much! This is quite new to me, so it will take time to understand and rewrite it in a way that works for what I need.. but it could be the "hack/trick" I was looking for.

                                Edit: after reading it carefully, I am still not sure if this applies to my case. Going to read the documentation. Basically I will need a way to read specific CMakeFiles and associate them to a specific target.

                                1 Reply Last reply
                                0
                                • C Offline
                                  C Offline
                                  cristian-adam
                                  wrote on 16 Jul 2024, 15:51 last edited by
                                  #16

                                  Regarding FOLDER, yes, I'll have to fix https://bugreports.qt.io/browse/QTCREATORBUG-28873 first.

                                  Currently Qt Creator is abusing FOLDER to make a target runnable. See https://doc.qt.io/qtcreator/creator-run-settings.html#cmake-run-targets

                                  Well, actually, I could keep the qtc_runnable special handling, and have original intent. One wouldn't be able to have both.

                                  1 Reply Last reply
                                  1
                                  • S Offline
                                    S Offline
                                    Sandon
                                    wrote on 17 Jul 2024, 07:56 last edited by
                                    #17

                                    @cristian-adam thank you for your reply.

                                    Do you think is it possible to achieve what I asked with current Qt creator capabilities?

                                    C 1 Reply Last reply 18 Jul 2024, 17:43
                                    0
                                    • S Sandon
                                      17 Jul 2024, 07:56

                                      @cristian-adam thank you for your reply.

                                      Do you think is it possible to achieve what I asked with current Qt creator capabilities?

                                      C Offline
                                      C Offline
                                      cristian-adam
                                      wrote on 18 Jul 2024, 17:43 last edited by
                                      #18

                                      @Sandon said in cmake tests and libs separate view in qt creator:

                                      @cristian-adam thank you for your reply.

                                      Do you think is it possible to achieve what I asked with current Qt creator capabilities?

                                      Nope. I have a fix for https://bugreports.qt.io/browse/QTCREATORBUG-28873, you can take an artifact from https://github.com/cristianadam/qt-creator/actions/runs/9979288965 and try it out.

                                      After the code review is done, you can have a Qt Creator 15 snapshot from https://download.qt.io/development_releases/qtcreator/ when they are available.

                                      1 Reply Last reply
                                      0
                                      • C Offline
                                        C Offline
                                        cristian-adam
                                        wrote on 18 Jul 2024, 17:44 last edited by
                                        #19

                                        Alternatively you can fork Qt Creator on github, apply the patch from https://codereview.qt-project.org/c/qt-creator/qt-creator/+/576805 and push a release tag on github.

                                        This will get you a Qt Creator 14 release with the patch in.

                                        1 Reply Last reply
                                        0
                                        • C Offline
                                          C Offline
                                          cristian-adam
                                          wrote on 18 Jul 2024, 17:46 last edited by
                                          #20

                                          Qt Creator is open source, Qt Creator is written in C++, and you don't have to do much in order to get a build on GitHub.

                                          1 Reply Last reply
                                          0

                                          1/21

                                          12 Jul 2024, 07:44

                                          • Login

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