Skip to content

Commit 63041aa

Browse files
Enable link time optimization
1 parent 242df5f commit 63041aa

File tree

1 file changed

+68
-41
lines changed

1 file changed

+68
-41
lines changed

CMakeLists.txt

Lines changed: 68 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
1-
cmake_minimum_required(VERSION 3.1.0) # Threads::Threads and CMAKE_C_STANDARD
1+
cmake_minimum_required(VERSION 3.9.0) # CMAKE_INTERPROCEDURAL_OPTIMIZATION
22

33
project(fastfetch
44
VERSION 1.5.2
55
LANGUAGES C
66
)
77

8-
set(THREADS_PREFER_PTHREAD_FLAG ON)
9-
find_package(Threads REQUIRED)
10-
11-
find_package(PkgConfig REQUIRED)
12-
13-
# This is set to off by github actions for release builds
14-
OPTION(SET_TWEAK "Add tweak to project version" ON)
15-
16-
# Also create test executables
17-
OPTION(BUILD_TESTS "Build tests" OFF)
8+
#####################
9+
# Configure options #
10+
#####################
1811

1912
OPTION(ENABLE_LIBPCI "Enable libpci" ON)
2013
OPTION(ENABLE_VULKAN "Enable vulkan" ON)
@@ -38,15 +31,39 @@ OPTION(ENABLE_GLX "Enable glx" ON)
3831
OPTION(ENABLE_OSMESA "Enable osmesa" ON)
3932
OPTION(ENABLE_OPENCL "Enable opencl" ON)
4033

34+
OPTION(BUILD_TESTS "Build tests" OFF) # Also create test executables
35+
OPTION(SET_TWEAK "Add tweak to project version" ON) # This is set to off by github actions for release builds
36+
37+
#############################
38+
# Compile time dependencies #
39+
#############################
40+
41+
set(THREADS_PREFER_PTHREAD_FLAG ON)
42+
find_package(Threads REQUIRED)
43+
44+
find_package(PkgConfig REQUIRED)
45+
46+
####################
47+
# Compiler options #
48+
####################
49+
4150
if(NOT CMAKE_BUILD_TYPE)
4251
set(CMAKE_BUILD_TYPE Release)
4352
endif()
4453

4554
set(CMAKE_C_STANDARD 11)
4655
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wconversion")
47-
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "-Wl,-O3")
4856

49-
# These variables are mainly here for android, which has a different root fs structure.
57+
include(CheckIPOSupported)
58+
check_ipo_supported(RESULT IPO_SUPPORTED)
59+
if(IPO_SUPPORTED)
60+
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
61+
endif()
62+
63+
#######################
64+
# Target FS structure #
65+
#######################
66+
5067
if(NOT TARGET_DIR_ROOT)
5168
if(NOT ANDROID)
5269
set(TARGET_DIR_ROOT "")
@@ -71,15 +88,10 @@ if(NOT TARGET_DIR_HOME)
7188
endif()
7289
endif()
7390

74-
function(fastfetch_load_text FILENAME OUTVAR)
75-
file(READ "${FILENAME}" TEMP)
76-
string(REPLACE "\n" "\\n" TEMP "${TEMP}")
77-
string(REPLACE "\"" "\\\"" TEMP "${TEMP}")
78-
string(REPLACE "$\\" "" TEMP "${TEMP}")
79-
set("${OUTVAR}" "${TEMP}" PARENT_SCOPE)
80-
endfunction(fastfetch_load_text)
91+
#################
92+
# Tweak version #
93+
#################
8194

82-
# Track commits between version bumps for output in --version
8395
if (SET_TWEAK AND EXISTS "${CMAKE_SOURCE_DIR}/.git")
8496
execute_process(
8597
COMMAND git describe --tags
@@ -90,6 +102,18 @@ if (SET_TWEAK AND EXISTS "${CMAKE_SOURCE_DIR}/.git")
90102
string(REGEX MATCH "-[0-9]+" PROJECT_VERSION_TWEAK "${PROJECT_VERSION_TWEAK}")
91103
endif()
92104

105+
#############
106+
# Text data #
107+
#############
108+
109+
function(fastfetch_load_text FILENAME OUTVAR)
110+
file(READ "${FILENAME}" TEMP)
111+
string(REPLACE "\n" "\\n" TEMP "${TEMP}")
112+
string(REPLACE "\"" "\\\"" TEMP "${TEMP}")
113+
string(REPLACE "$\\" "" TEMP "${TEMP}")
114+
set("${OUTVAR}" "${TEMP}" PARENT_SCOPE)
115+
endfunction(fastfetch_load_text)
116+
93117
fastfetch_load_text(src/data/structure.txt DATATEXT_STRUCTURE)
94118
fastfetch_load_text(src/data/config.txt DATATEXT_CONFIG)
95119
fastfetch_load_text(src/data/modules.txt DATATEXT_MODULES)
@@ -98,9 +122,15 @@ fastfetch_load_text(src/data/help_color.txt DATATEXT_HELP_COLOR)
98122
fastfetch_load_text(src/data/help_format.txt DATATEXT_HELP_FORMAT)
99123
fastfetch_load_text(src/data/help_config.txt DATATEXT_HELP_CONFIG)
100124

125+
######################
126+
# Configure config.h #
127+
######################
128+
101129
configure_file(src/fastfetch_config.h.in fastfetch_config.h)
102130

103-
# Init CMake targets
131+
#######################
132+
# libfastfetch target #
133+
#######################
104134

105135
add_library(libfastfetch STATIC
106136
src/util/FFstrbuf.c
@@ -423,7 +453,13 @@ target_link_libraries(libfastfetch
423453
PRIVATE Threads::Threads
424454
)
425455

426-
set_target_properties(libfastfetch PROPERTIES OUTPUT_NAME "fastfetch")
456+
set_target_properties(libfastfetch PROPERTIES
457+
OUTPUT_NAME "fastfetch"
458+
)
459+
460+
######################
461+
# Executable targets #
462+
######################
427463

428464
add_executable(fastfetch
429465
src/fastfetch.c
@@ -439,7 +475,9 @@ target_link_libraries(flashfetch
439475
PRIVATE libfastfetch
440476
)
441477

442-
# Testing
478+
###################
479+
# Testing targets #
480+
###################
443481

444482
if (BUILD_TESTS)
445483
add_executable(fastfetch-test-performance
@@ -460,7 +498,9 @@ if (BUILD_TESTS)
460498
add_test(NAME test-strbuf COMMAND fastfetch-test-strbuf)
461499
endif()
462500

463-
# Installation
501+
##################
502+
# install target #
503+
##################
464504

465505
include(GNUInstallDirs)
466506

@@ -490,7 +530,9 @@ install(
490530
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/licenses/${CMAKE_PROJECT_NAME}
491531
)
492532

493-
# Packaging
533+
##################
534+
# package target #
535+
##################
494536

495537
set(CPACK_GENERATOR "DEB;RPM;TGZ;ZIP")
496538

@@ -505,21 +547,6 @@ set(CPACK_PACKAGE_HOMEPAGE_URL "https://github.com/LinusDierheimer")
505547
set(CPACK_DEBIAN_PACKAGE_SECTION, "utils")
506548
set(CPACK_DEBIAN_PACKAGE_PRIORITY "optional")
507549
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6")
508-
set(CPACK_DEBIAN_PACKAGE_RECOMMENDS "\
509-
libpci3, \
510-
libvulkan1, \
511-
libwayland-client0, \
512-
libxcb-randr0, \
513-
xcb, \
514-
libxrandr2, \
515-
libx11-6, \
516-
libdconf1, \
517-
libglib2.0-0, \
518-
libdbus-1-3, \
519-
libxfconf-0-3, \
520-
libmagickcore-6.q16hdri-6, \
521-
zlib1g \
522-
")
523550

524551
set(CPACK_RPM_PACKAGE_LICENSE "MIT")
525552

0 commit comments

Comments
 (0)