Uploaded image for project: 'Qt Creator'
  1. Qt Creator
  2. QTCREATORBUG-27432

QtCreator: cmake source_group not working properly

    XMLWordPrintable

    Details

    • Platform/s:
      All
    • Commits:
      6431932569 (qt-creator/qt-creator/master)

      Description

      Hi,

      the cmake source_group setting is still a bit buggy in QtCreator

      Example:

      #              "" ->empty named group, i.e. toplevel - directly under target
        source_group("" FILES
          ${CMAKE_BINARY_DIR}/src/a/a1.cpp
          ${CMAKE_BINARY_DIR}/src/a/a2.cpp
          )
        source_group("" FILES
          ${CMAKE_BINARY_DIR}/inc/a/a1.h
          ${CMAKE_BINARY_DIR}/inc/a/a2.h
          )
      

      results in the following wrong buggy tree-browser:

          

      It should be fixed, to look like this:

            

      In other words: both cpp files and h header under the same named group! (in this special case the named group is "", meaning: toplevel - directly under target).

       

      To reproduce, simply grab this CMakeLists.txt and try it!

      cmake_minimum_required(VERSION 3.18)
      
      project(go LANGUAGES CXX)
      
      file(WRITE ${CMAKE_BINARY_DIR}/src/a/a1.cpp "")
      file(WRITE ${CMAKE_BINARY_DIR}/src/a/a2.cpp "")
      
      file(WRITE ${CMAKE_BINARY_DIR}/inc/a/a1.h "")
      file(WRITE ${CMAKE_BINARY_DIR}/inc/a/a2.h "")
      
      add_library(a
        ${CMAKE_BINARY_DIR}/src/a/a1.cpp
        ${CMAKE_BINARY_DIR}/src/a/a2.cpp
        ${CMAKE_BINARY_DIR}/inc/a/a1.h
        ${CMAKE_BINARY_DIR}/inc/a/a2.h
        )
      
      set(SG_VARIANT "1a" CACHE STRING "variant")
      set(SG_VARIANT_CHOICES "1a" "1b" "2a" "2b")
      set_property(CACHE SG_VARIANT  PROPERTY STRINGS ${SG_VARIANT_CHOICES})
      if (NOT SG_VARIANT IN_LIST SG_VARIANT_CHOICES)
        message(FATAL_ERROR "SG_VARIANT must be one of ${SG_VARIANT_CHOICES}")
      endif ()
      message(STATUS "SG_VARIANT " ${SG_VARIANT})
      
      if ("${SG_VARIANT}" STREQUAL "1a")
        ## variant 1a
        source_group("" FILES
          ${CMAKE_BINARY_DIR}/src/a/a1.cpp
          ${CMAKE_BINARY_DIR}/src/a/a2.cpp
          )
        source_group("" FILES
          ${CMAKE_BINARY_DIR}/inc/a/a1.h
          ${CMAKE_BINARY_DIR}/inc/a/a2.h
          )
      elseif ("${SG_VARIANT}" STREQUAL "1b")
        ## variant 1b
        source_group(TREE ${CMAKE_BINARY_DIR}/src/a FILES
          ${CMAKE_BINARY_DIR}/src/a/a1.cpp
          ${CMAKE_BINARY_DIR}/src/a/a2.cpp
          )
        source_group(TREE ${CMAKE_BINARY_DIR}/inc/a FILES
          ${CMAKE_BINARY_DIR}/inc/a/a1.h
          ${CMAKE_BINARY_DIR}/inc/a/a2.h
          )
      elseif ("${SG_VARIANT}" STREQUAL "2a")
        ## variant 2a
        source_group("here\\sources" FILES
          ${CMAKE_BINARY_DIR}/src/a/a1.cpp
          ${CMAKE_BINARY_DIR}/src/a/a2.cpp
          )
        source_group("here\\includes" FILES
          ${CMAKE_BINARY_DIR}/inc/a/a1.h
          ${CMAKE_BINARY_DIR}/inc/a/a2.h
          )
      elseif ("${SG_VARIANT}" STREQUAL "2b")
        ## variant 2b
        source_group(TREE ${CMAKE_BINARY_DIR}/src/a PREFIX "here\\sources" FILES
          ${CMAKE_BINARY_DIR}/src/a/a1.cpp
          ${CMAKE_BINARY_DIR}/src/a/a2.cpp
          )
        source_group(TREE ${CMAKE_BINARY_DIR}/inc/a PREFIX "here\\includes" FILES
          ${CMAKE_BINARY_DIR}/inc/a/a1.h
          ${CMAKE_BINARY_DIR}/inc/a/a2.h
          )
      endif()
      
      

       

      CmakeVariable SG_VARIANT is  "1a" or "1b"

      Bug (current):

          

      Fix should be:

            

       

      CmakeVariable SG_VARIANT is  "2a" or "2b"

      Bug (current):

          

      Fix should be:

          

      To compare with visual studio:

      (in visual studio it is correct, when generating a sln solution)

      cmake -G "Visual Studio 17 2022" -D SG_VARIANT=1a ../bugreport
      cmake --open .
      

      Reference documentation:

      https://cmake.org/cmake/help/latest/command/source_group.html

        Attachments

        1. bug1a_s.png
          bug1a_s.png
          12 kB
        2. bug1a.png
          bug1a.png
          15 kB
        3. correct_2_s.png
          correct_2_s.png
          13 kB
        4. fix1a.png
          fix1a.png
          9 kB
        5. fix2.png
          fix2.png
          13 kB
        For Gerrit Dashboard: QTCREATORBUG-27432
        # Subject Branch Project Status CR V

          Activity

            People

            Assignee:
            madwinterin Marcus Tillmanns
            Reporter:
            coderabc a n
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Gerrit Reviews

                There are no open Gerrit changes