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. Different files are generated with cmake and with qmake
Forum Updated to NodeBB v4.3 + New Features

Different files are generated with cmake and with qmake

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 5 Posters 959 Views 3 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.
  • posktomtenP Offline
    posktomtenP Offline
    posktomten
    wrote on last edited by posktomten
    #3

    No, then the files will be much larger.
    (I'm using MinGW GCC 11.2.0, haven't tested with MSVC)

    posktomten

    1 Reply Last reply
    0
    • posktomtenP Offline
      posktomtenP Offline
      posktomten
      wrote on last edited by
      #4

      Now I have tested with MSVC. The files don't get bigger.

      posktomten

      JoeCFDJ 1 Reply Last reply
      0
      • Chris KawaC Online
        Chris KawaC Online
        Chris Kawa
        Lifetime Qt Champion
        wrote on last edited by
        #5

        CMake and qmake don't compile or link your app. All they do is set up parameters for the compiler/linker, and those are the same in both cases, so you can set both build tools to produce exactly the same outputs.
        Don't guess. Just pick one file and look at the compilation log from both build tools. Compare what options go directly into compiling/linking. Some default is probably different, that's all. Maybe one sets optimizer for size and the other for speed or something like that.

        1 Reply Last reply
        0
        • C Offline
          C Offline
          ChrisW67
          wrote on last edited by
          #6

          On my Linux box with GCC the qmake generated Makefile builds with the -O2 compiler flag.

          ...
          g++ -c -pipe -O2 -std=gnu++1z -Wall -Wextra -D_REENTRANT -fPIC -DQT_DISABLE_DEPRECATED_BEFORE=0x060000 -DABOUT_LIBRARY -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I. -I/usr/include/x86_64-linux-gnu/qt5 -I/usr/include/x86_64-linux-gnu/qt5/QtWidgets -I/usr/include/x86_64-linux-gnu/qt5/QtGui -I/usr/include/x86_64-linux-gnu/qt5/QtCore -I. -I/usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++ -o about.o about.cpp
          ...
          
          chrisw@newton:/tmp/libabout/code$ ls -l ../code-lib/
          total 44
          lrwxrwxrwx 1 chrisw chrisw    17 Dec  4 11:05 libabout.so -> libabout.so.1.0.0
          lrwxrwxrwx 1 chrisw chrisw    17 Dec  4 11:05 libabout.so.1 -> libabout.so.1.0.0
          lrwxrwxrwx 1 chrisw chrisw    17 Dec  4 11:05 libabout.so.1.0 -> libabout.so.1.0.0
          -rwxrwxr-x 1 chrisw chrisw 43616 Dec  4 11:05 libabout.so.1.0.0
          

          The CMake generated Makefile does not seem to specify optimization options

          ...
          [75%] Building CXX object CMakeFiles/about.dir/about.cpp.o
          /usr/bin/c++ -DABOUT_LIBRARY -DQT_CORE_LIB -DQT_DISABLE_DEPRECATED_BEFORE=0x060000 -DQT_GUI_LIB -DQT_NO_DEBUG -DQT_WIDGETS_LIB -Dabout_EXPORTS -I/tmp/libabout/code -I/tmp/libabout/code/about_autogen/include -isystem /home/chrisw/Qt/6.4.0/gcc_64/include/QtWidgets -isystem /home/chrisw/Qt/6.4.0/gcc_64/include -isystem /home/chrisw/Qt/6.4.0/gcc_64/include/QtCore -isystem /home/chrisw/Qt/6.4.0/gcc_64/mkspecs/linux-g++ -isystem /home/chrisw/Qt/6.4.0/gcc_64/include/QtGui -fPIC -fPIC -std=gnu++17 -MD -MT CMakeFiles/about.dir/about.cpp.o -MF CMakeFiles/about.dir/about.cpp.o.d -o CMakeFiles/about.dir/about.cpp.o -c /tmp/libabout/code/about.cpp
          ...
          
          chrisw@newton:/tmp/libabout/code$ ls -l ../code-lib/
          total 56
          -rwxrwxr-x 1 chrisw chrisw 56512 Dec  4 11:01 libabout.so
          
          1 Reply Last reply
          1
          • posktomtenP posktomten

            Now I have tested with MSVC. The files don't get bigger.

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

            @posktomten you can check if the default flags are the same in both builds.

            1 Reply Last reply
            0
            • posktomtenP Offline
              posktomtenP Offline
              posktomten
              wrote on last edited by posktomten
              #8

              Fixed a typo
              And a big thank you for the help and all the points of view!

              Been doing this all day. Something I don't understand.
              Same inputs to the compiler? But different results when using cmake and when using qmake.

              // cmake
              // Changes -O3 to -O2
              macro(remove_cxx_flag flag)
                 string(REPLACE "${flag}" "" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
              endmacro()
              remove_cxx_flag("-O3")
              set(CMAKE_CXX_FLAGS_RELEASE "-O2${CMAKE_CXX_FLAGS_RELEASE}")
              
              message(${CMAKE_CXX_FLAGS_RELEASE}) // -O2 -DNDEBUG
              // size: 84 KB
              
              // qmake
              QMAKE_CXXFLAGS_RELEASE += -DNDEBUG
              message($$QMAKE_CXXFLAGS_RELEASE)  // -O2 -DNDEBUG
              // size: 35 KB
              
              
              // Compiled using the command prompt
              
              qmake -project ../code/about.pro
              qmake ../code/about.pro
              mingw32-make
              
              // size 38 KB
                message($$QMAKE_CXXFLAGS_RELEASE)  // -O2 -DNDEBUGG
              
              
              cmake -G "MinGW Makefiles"
              cmake --build .
              mingw32-make
              
              // size 94 KB
                message(${CMAKE_CXX_FLAGS_RELEASE}) // -O2 -DNDEBUG
              

              posktomten

              1 Reply Last reply
              0
              • Chris KawaC Online
                Chris KawaC Online
                Chris Kawa
                Lifetime Qt Champion
                wrote on last edited by
                #9

                @posktomten I rather meant to put CMake into verbose mode, to see something like what @ChrisW67 posted, not just look at one variable.
                QMAKE_CXXFLAGS_RELEASE might not contain everything that is passed. At least look at the linker flags too, QMAKE_LFLAGS_RELEASE, but better would be to look at the actual commands executed.

                1 Reply Last reply
                0
                • posktomtenP Offline
                  posktomtenP Offline
                  posktomten
                  wrote on last edited by posktomten
                  #10

                  Hey!
                  Thanks for all the suggestions.
                  @Chris-Kawa probably has the best solution. I haven't succeeded yet.
                  I can state:
                  The difference in the created file size (*.dll, *.so) depending on whether cmake or qmake is used:
                  Linux, GCC: insignificant
                  Windows, MSVC: insignificant
                  Windows, MinGW GCC: significant

                  posktomten

                  1 Reply Last reply
                  0
                  • C Offline
                    C Offline
                    ChrisW67
                    wrote on last edited by ChrisW67
                    #11

                    The qmake-generated Makefile is verbose enough. You can get the verbose form from the CMake generated Makefile:

                    mingw32-make VERBOSE=1
                    

                    I see that CMake does not specify -D_REENTRANT which could change code inclusions. It also calls the C++ compiler via c++ which, even if symlinked to g++, might trigger g++ to use different defaults. Lots of possibilities.

                    1 Reply Last reply
                    0
                    • posktomtenP Offline
                      posktomtenP Offline
                      posktomten
                      wrote on last edited by
                      #12

                      Thanks!
                      I'll have to test that

                      posktomten

                      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