Closed elfring closed 5 years ago
I've added CMakeLists.txt in the staging branch
I noticed that using the old Makefile, the compiled binary is only 92 KB in size, while using CMake the binary is 668 KB in size.
Using old Makefile (92 KB):
$ g++ -std=c++14 -flto -Os -Wall -lpthread -lX11 -lglog -o Wmderland src/*.cpp
$ size Wmderland
text data bss dec hex filename
55235 2056 384 57675 e14b Wmderland
Using CMake (668 KB):
$ cmake .
$ make
$ size Wmderland
text data bss dec hex filename
442400 2096 368 444864 6c9c0 Wmderland
So I think perhaps the .text section has included lots of unused symbols for debugging? But even if I set this in CMakeLists.txt, the binary size is still over 600 KB.
set(CMAKE_CXX_FLAGS "-std=c++14 -flto -Os -Wall -lpthread")
Any idea?
Problem solved in 2880b55c68d4755b16eda07664d75a00e8b00428
First I moved the line project(Wmderland)
to the first line of CMakeLists.txt, and then the compiled executable size drops from 668 KB to 143 KB miraculously :confused:
Then I made the following changes:
cmake_minimum_required(VERSION 3.0)
-> cmake_minimum_required(VERSION 3.9)
set(CMAKE_BUILD_TYPE Release)
-> set(CMAKE_BUILD_TYPE MinSizeRel)
and the size drops to 92 KB!
Note: a CMake cheatsheet I've found http://www.brianlheim.com/2018/04/09/cmake-cheat-sheet.html
I suggest to reuse a higher level build system than your current make script so that powerful checks for software features will become easier.