Different files are generated with cmake and with qmake
-
Hey!
Windows 10, MinGW GCC 11.2.0
When I use cmake:
"about.dll" size 85 KB
"abouttest.exe" 593 KBWhen I use qmake:
"about.dll" size 38 KB
"abouttest.exe" 524 KBLinux Ubuntu 22.04
The size varies slightlyldd (linux) indicates that "abouttest" knows where "about.so" is. Remembers the location from the compilation.
I thought the methods were different, but the result was the same. Is there a reason to start using cmake?
https://gitlab.com/posktomten/libabout
Sincerely
Ingemar Ceicer -
Hey!
Windows 10, MinGW GCC 11.2.0
When I use cmake:
"about.dll" size 85 KB
"abouttest.exe" 593 KBWhen I use qmake:
"about.dll" size 38 KB
"abouttest.exe" 524 KBLinux Ubuntu 22.04
The size varies slightlyldd (linux) indicates that "abouttest" knows where "about.so" is. Remembers the location from the compilation.
I thought the methods were different, but the result was the same. Is there a reason to start using cmake?
https://gitlab.com/posktomten/libabout
Sincerely
Ingemar Ceicer@posktomten maybe you are building cmake in debug mode and qmake in release?
-
No, then the files will be much larger.
(I'm using MinGW GCC 11.2.0, haven't tested with MSVC) -
Now I have tested with MSVC. The files don't get bigger.
-
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. -
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
-
Now I have tested with MSVC. The files don't get bigger.
@posktomten you can check if the default flags are the same in both builds.
-
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 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. -
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 -
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 viac++
which, even if symlinked tog++
, might triggerg++
to use different defaults. Lots of possibilities. -
Thanks!
I'll have to test that