Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. CMake building precompiled headers can't find Qt stuff
Forum Updated to NodeBB v4.3 + New Features

CMake building precompiled headers can't find Qt stuff

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 2 Posters 438 Views 2 Watching
  • 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.
  • PerdrixP Offline
    PerdrixP Offline
    Perdrix
    wrote on last edited by
    #1
    2>1>
    2>Building Custom Rule C:/Users/amonra/Documents/GitHub/DSS/DeepSkyStacker/CMakeLists.txt
    2>cmake_pch.cxx
    2>C:\Users\amonra\Documents\GitHub\DSS\DeepSkyStacker\stdafx.h(3,10): error C1083: Cannot open include file: 'QtWidgets': No such file or directory
    2>(compiling source file 'CMakeFiles/DeepSkyStacker.dir/cmake_pch.cxx')
    2>Done building project "DeepSkyStacker.vcxproj" -- FAILED.
    

    I did:

    find_package(Qt6 6.8 REQUIRED COMPONENTS Gui Widgets Network Charts)
    qt_standard_project_setup()
    

    So thought that the Qt include dirs would be searched.

    What have I missed?

    Christian EhrlicherC 1 Reply Last reply
    0
    • PerdrixP Offline
      PerdrixP Offline
      Perdrix
      wrote on last edited by Perdrix
      #6

      I finally discovered that the includes for Qt are added when you do (for example):

      target_link_libraries(DeepSkyStacker PRIVATE
          Qt6::Widgets
          Qt6::Network
         :
      

      which is not at all obvious - once I added that, it worked.

      Christian EhrlicherC 1 Reply Last reply
      0
      • PerdrixP Perdrix
        2>1>
        2>Building Custom Rule C:/Users/amonra/Documents/GitHub/DSS/DeepSkyStacker/CMakeLists.txt
        2>cmake_pch.cxx
        2>C:\Users\amonra\Documents\GitHub\DSS\DeepSkyStacker\stdafx.h(3,10): error C1083: Cannot open include file: 'QtWidgets': No such file or directory
        2>(compiling source file 'CMakeFiles/DeepSkyStacker.dir/cmake_pch.cxx')
        2>Done building project "DeepSkyStacker.vcxproj" -- FAILED.
        

        I did:

        find_package(Qt6 6.8 REQUIRED COMPONENTS Gui Widgets Network Charts)
        qt_standard_project_setup()
        

        So thought that the Qt include dirs would be searched.

        What have I missed?

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

        @Perdrix said in CMake building precompiled headers can't find Qt stuff:

        What have I missed?

        At least the part on where you create the pch in the CMakeLists.txt

        https://cmake.org/cmake/help/latest/command/target_precompile_headers.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
        0
        • PerdrixP Offline
          PerdrixP Offline
          Perdrix
          wrote on last edited by Perdrix
          #3

          Err no that was in the CMakeLists.txt file otherwise CMake would not have created the cmake_pch.cxx file:

          target_precompile_headers(DeepSkyStacker PRIVATE
          	stdafx.h
          	)
          

          It's the failure to find the Qt headers I am concerned about.

          1 Reply Last reply
          0
          • Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #4

            Since you as always fail to provide a minimal, compilable example - this works fine for me:

            find_package(Qt6 COMPONENTS Widgets REQUIRED)
            add_executable(TestApp
                main.cpp
            )
            target_link_libraries(TestApp PRIVATE Qt6::Widgets)
            target_precompile_headers(TestApp PRIVATE pre.h)
            

            pre.h contains

            #include <QDialog>
            

            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
            • PerdrixP Offline
              PerdrixP Offline
              Perdrix
              wrote on last edited by
              #5

              If I knew how to create a minimal example in this case I would have done so - its not for lack of trying.
              I have specified:

              ################################################################################
              # Include directories
              ################################################################################
              target_include_directories(DeepSkyStacker PUBLIC
                  ${CMAKE_CURRENT_SOURCE_DIR}/.
                  ${CMAKE_CURRENT_SOURCE_DIR}/../DeepSkyStackerKernel
                  ${CMAKE_CURRENT_SOURCE_DIR}/GeneratedFiles/$<CONFIG>
                  ${CMAKE_CURRENT_SOURCE_DIR}/GeneratedFiles
                  ${CMAKE_CURRENT_SOURCE_DIR}/../LibRaw
                  ${CMAKE_CURRENT_SOURCE_DIR}/../ZCLass
                  ${CMAKE_CURRENT_SOURCE_DIR}/../Tools
                  ${CMAKE_CURRENT_SOURCE_DIR}/../LibTiff
                  ${CMAKE_CURRENT_SOURCE_DIR}/../CFitsIO
                  ${CMAKE_CURRENT_SOURCE_DIR}/../Zlib
                  $ENV{Boost_1_80_0}
              	"$<$<CONFIG:Debug>:C:/Program Files (x86)/Visual Leak Detector/include>"
              )
              

              to pick up my own include directories. If by doing that I have wiped out the ones set by:

              find_package(Qt6 6.8 REQUIRED COMPONENTS Gui Widgets Network Charts)
              qt_standard_project_setup()
              

              then I may have done that wrong - I thought target_include_directories appended to the ones already set, if not, how do I change that to append to the ones set by the Qt stuff.

              D.

              1 Reply Last reply
              0
              • PerdrixP Offline
                PerdrixP Offline
                Perdrix
                wrote on last edited by Perdrix
                #6

                I finally discovered that the includes for Qt are added when you do (for example):

                target_link_libraries(DeepSkyStacker PRIVATE
                    Qt6::Widgets
                    Qt6::Network
                   :
                

                which is not at all obvious - once I added that, it worked.

                Christian EhrlicherC 1 Reply Last reply
                0
                • PerdrixP Perdrix has marked this topic as solved on
                • PerdrixP Perdrix

                  I finally discovered that the includes for Qt are added when you do (for example):

                  target_link_libraries(DeepSkyStacker PRIVATE
                      Qt6::Widgets
                      Qt6::Network
                     :
                  

                  which is not at all obvious - once I added that, it worked.

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

                  @Perdrix said in CMake building precompiled headers can't find Qt stuff:

                  I finally discovered that the includes for Qt

                  That's not related to Qt but how imported targets in usually cmake work.

                  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
                  • PerdrixP Offline
                    PerdrixP Offline
                    Perdrix
                    wrote on last edited by
                    #8

                    YOU may know that, but a new user of CMake wouldn't be expected to.

                    1 Reply Last reply
                    0
                    • Christian EhrlicherC Offline
                      Christian EhrlicherC Offline
                      Christian Ehrlicher
                      Lifetime Qt Champion
                      wrote on last edited by
                      #9

                      Not that in the Qt documentation of every class is written on how to use the Qt libs...
                      https://doc.qt.io/qt-6/qwidget.html

                      CMake:	find_package(Qt6 REQUIRED COMPONENTS Widgets)
                      target_link_libraries(mytarget PRIVATE Qt6::Widgets)
                      

                      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
                      • PerdrixP Offline
                        PerdrixP Offline
                        Perdrix
                        wrote on last edited by
                        #10

                        I fail to see the relevance of that remark - the point I was making is that it is totally counter-intuitive that target_link_libraries(Qt6::Widgets) should add include directories for the compilation.

                        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