From bc8887fb42d18efef8a4ca4d5cc2f72a41c5abeb Mon Sep 17 00:00:00 2001 From: Linus Dierheimer Date: Wed, 9 Feb 2022 15:20:07 +0100 Subject: [PATCH] Improved compile time by compiling common sources as a static lib --- CMakeLists.txt | 289 ++++++++++++++++++++++++---------------------- DEVELOPMENT.md | 1 - src/common/logo.c | 4 - src/fastfetch.c | 1 - src/fastfetch.h | 9 +- 5 files changed, 152 insertions(+), 152 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 05ca503d6..e87fe7b1a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,6 +2,18 @@ cmake_minimum_required(VERSION 3.1.0) # Threads::Threads project(fastfetch LANGUAGES C) +OPTION(ENABLE_LIBPCI "Enable libpci" ON) +OPTION(ENABLE_VULKAN "Enable vulkan" ON) +OPTION(ENABLE_WAYLAND "Enable wayland-client" ON) +OPTION(ENABLE_XCB_RANDR "Enable xcb-randr" ON) +OPTION(ENABLE_XCB "Enable xcb" ON) +OPTION(ENABLE_XRANDR "Enable xrandr" ON) +OPTION(ENABLE_X11 "Enable x11" ON) +OPTION(ENABLE_GIO "Enable gio-2.0" ON) +OPTION(ENABLE_DCONF "Enable dconf" ON) +OPTION(ENABLE_XFCONF "Enable libxfconf-0" ON) +OPTION(ENABLE_RPM "Enable rpm" ON) + if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Release) endif() @@ -48,141 +60,10 @@ find_package(Threads REQUIRED) find_package(PkgConfig REQUIRED) -OPTION(ENABLE_LIBPCI "Enable libpci" ON) -OPTION(ENABLE_VULKAN "Enable vulkan" ON) -OPTION(ENABLE_WAYLAND "Enable wayland-client" ON) -OPTION(ENABLE_XCB_RANDR "Enable xcb-randr" ON) -OPTION(ENABLE_XCB "Enable xcb" ON) -OPTION(ENABLE_XRANDR "Enable xrandr" ON) -OPTION(ENABLE_X11 "Enable x11" ON) -OPTION(ENABLE_GIO "Enable gio-2.0" ON) -OPTION(ENABLE_DCONF "Enable dconf" ON) -OPTION(ENABLE_XFCONF "Enable libxfconf-0" ON) -OPTION(ENABLE_RPM "Enable rpm" ON) - -if(ENABLE_LIBPCI) - pkg_check_modules (LIBPCI libpci) - if(LIBPCI_FOUND) - add_compile_definitions(FF_HAVE_LIBPCI=1) - else(LIBPCI_FOUND) - message(WARNING "Package libpci not found. Building without support.") - endif(LIBPCI_FOUND) -endif(ENABLE_LIBPCI) - -if(ENABLE_VULKAN) - pkg_check_modules (VULKAN vulkan) - if(VULKAN_FOUND) - add_compile_definitions(FF_HAVE_VULKAN=1) - else(VULKAN_FOUND) - message(WARNING "Package vulkan not found. Building without support.") - endif(VULKAN_FOUND) -endif(ENABLE_VULKAN) - -if(ENABLE_WAYLAND) - pkg_check_modules (WAYLAND wayland-client) - if(WAYLAND_FOUND) - add_compile_definitions(FF_HAVE_WAYLAND=1) - else(WAYLAND_FOUND) - message(WARNING "Package wayland-client not found. Building without support.") - endif(WAYLAND_FOUND) -endif(ENABLE_WAYLAND) - -if(ENABLE_XCB_RANDR) - pkg_check_modules (XCB_RANDR xcb-randr) - if(XCB_RANDR_FOUND) - add_compile_definitions(FF_HAVE_XCB_RANDR=1) - else(XCB_RANDR_FOUND) - message(WARNING "Package xcb-randr not found. Building without support.") - endif(XCB_RANDR_FOUND) -endif(ENABLE_XCB_RANDR) - -if(ENABLE_XCB) - pkg_check_modules (XCB xcb) - if(XCB_FOUND) - add_compile_definitions(FF_HAVE_XCB=1) - else(XCB_FOUND) - message(WARNING "Package xcb not found. Building without support.") - endif(XCB_FOUND) -endif(ENABLE_XCB) - -if(ENABLE_XRANDR) - pkg_check_modules (XRANDR xrandr) - if(XRANDR_FOUND) - add_compile_definitions(FF_HAVE_XRANDR=1) - else(XRANDR_FOUND) - message(WARNING "Package xrandr not found. Building without support.") - endif(XRANDR_FOUND) -endif(ENABLE_XRANDR) - -if(ENABLE_X11) - pkg_check_modules (X11 x11) - if(X11_FOUND) - add_compile_definitions(FF_HAVE_X11=1) - else(X11_FOUND) - message(WARNING "Package x11 not found. Building without support.") - endif(X11_FOUND) -endif(ENABLE_X11) - -if(ENABLE_GIO) - pkg_check_modules (GIO gio-2.0) - if(GIO_FOUND) - add_compile_definitions(FF_HAVE_GIO=1) - else(GIO_FOUND) - message(WARNING "Package gio-2.0 not found. Building without support.") - endif(GIO_FOUND) -endif(ENABLE_GIO) - -if(ENABLE_DCONF) - pkg_check_modules (DCONF dconf) - if(DCONF_FOUND) - add_compile_definitions(FF_HAVE_DCONF=1) - else(DCONF_FOUND) - message(WARNING "Package dconf not found. Building without support.") - endif(DCONF_FOUND) -endif(ENABLE_DCONF) - -if(ENABLE_XFCONF) - pkg_check_modules (XFCONF libxfconf-0) - if(XFCONF_FOUND) - add_compile_definitions(FF_HAVE_XFCONF=1) - else(XFCONF_FOUND) - message(WARNING "Package libxfconf-0 not found. Building without support.") - endif(XFCONF_FOUND) -endif(ENABLE_XFCONF) - -if(ENABLE_RPM) - pkg_check_modules (RPM rpm) - if(RPM_FOUND) - add_compile_definitions(FF_HAVE_RPM=1) - else(RPM_FOUND) - message(WARNING "Package librpm not found. Building without support.") - endif(RPM_FOUND) -endif(ENABLE_RPM) - -include_directories( - ${PROJECT_BINARY_DIR} - ${PROJECT_SOURCE_DIR}/src - ${LIBPCI_INCLUDE_DIRS} - ${VULKAN_INCLUDE_DIRS} - ${WAYLAND_INCLUDE_DIRS} - ${XCB_RANDR_INCLUDE_DIRS} - ${XCB_INCLUDE_DIRS} - ${XRANDR_INCLUDE_DIRS} - ${X11_INCLUDE_DIRS} - ${GIO_INCLUDE_DIRS} - ${DCONF_INCLUDE_DIRS} - ${XFCONF_INCLUDE_DIRS} - ${RPM_INCLUDE_DIRS} -) - -link_libraries( - ${CMAKE_DL_LIBS} - Threads::Threads -) - -set(SRCS +add_library(libfastfetch STATIC src/util/FFstrbuf.c src/util/FFlist.c + src/util/FFvaluestore.c src/common/init.c src/common/threading.c src/common/io.c @@ -235,27 +116,153 @@ set(SRCS src/modules/colors.c ) +if(ENABLE_LIBPCI) + pkg_check_modules (LIBPCI libpci) + if(LIBPCI_FOUND) + target_compile_definitions(libfastfetch PRIVATE FF_HAVE_LIBPCI=1) + else(LIBPCI_FOUND) + message(WARNING "Package libpci not found. Building without support.") + endif(LIBPCI_FOUND) +endif(ENABLE_LIBPCI) + +if(ENABLE_VULKAN) + pkg_check_modules (VULKAN vulkan) + if(VULKAN_FOUND) + target_compile_definitions(libfastfetch PRIVATE FF_HAVE_VULKAN=1) + else(VULKAN_FOUND) + message(WARNING "Package vulkan not found. Building without support.") + endif(VULKAN_FOUND) +endif(ENABLE_VULKAN) + +if(ENABLE_WAYLAND) + pkg_check_modules (WAYLAND wayland-client) + if(WAYLAND_FOUND) + target_compile_definitions(libfastfetch PRIVATE FF_HAVE_WAYLAND=1) + else(WAYLAND_FOUND) + message(WARNING "Package wayland-client not found. Building without support.") + endif(WAYLAND_FOUND) +endif(ENABLE_WAYLAND) + +if(ENABLE_XCB_RANDR) + pkg_check_modules (XCB_RANDR xcb-randr) + if(XCB_RANDR_FOUND) + target_compile_definitions(libfastfetch PRIVATE FF_HAVE_XCB_RANDR=1) + else(XCB_RANDR_FOUND) + message(WARNING "Package xcb-randr not found. Building without support.") + endif(XCB_RANDR_FOUND) +endif(ENABLE_XCB_RANDR) + +if(ENABLE_XCB) + pkg_check_modules (XCB xcb) + if(XCB_FOUND) + target_compile_definitions(libfastfetch PRIVATE FF_HAVE_XCB=1) + else(XCB_FOUND) + message(WARNING "Package xcb not found. Building without support.") + endif(XCB_FOUND) +endif(ENABLE_XCB) + +if(ENABLE_XRANDR) + pkg_check_modules (XRANDR xrandr) + if(XRANDR_FOUND) + target_compile_definitions(libfastfetch PRIVATE FF_HAVE_XRANDR=1) + else(XRANDR_FOUND) + message(WARNING "Package xrandr not found. Building without support.") + endif(XRANDR_FOUND) +endif(ENABLE_XRANDR) + +if(ENABLE_X11) + pkg_check_modules (X11 x11) + if(X11_FOUND) + target_compile_definitions(libfastfetch PRIVATE FF_HAVE_X11=1) + else(X11_FOUND) + message(WARNING "Package x11 not found. Building without support.") + endif(X11_FOUND) +endif(ENABLE_X11) + +if(ENABLE_GIO) + pkg_check_modules (GIO gio-2.0) + if(GIO_FOUND) + target_compile_definitions(libfastfetch PRIVATE FF_HAVE_GIO=1) + else(GIO_FOUND) + message(WARNING "Package gio-2.0 not found. Building without support.") + endif(GIO_FOUND) +endif(ENABLE_GIO) + +if(ENABLE_DCONF) + pkg_check_modules (DCONF dconf) + if(DCONF_FOUND) + target_compile_definitions(libfastfetch PRIVATE FF_HAVE_DCONF=1) + else(DCONF_FOUND) + message(WARNING "Package dconf not found. Building without support.") + endif(DCONF_FOUND) +endif(ENABLE_DCONF) + +if(ENABLE_XFCONF) + pkg_check_modules (XFCONF libxfconf-0) + if(XFCONF_FOUND) + target_compile_definitions(libfastfetch PRIVATE FF_HAVE_XFCONF=1) + else(XFCONF_FOUND) + message(WARNING "Package libxfconf-0 not found. Building without support.") + endif(XFCONF_FOUND) +endif(ENABLE_XFCONF) + +if(ENABLE_RPM) + pkg_check_modules (RPM rpm) + if(RPM_FOUND) + target_compile_definitions(libfastfetch PRIVATE FF_HAVE_RPM=1) + else(RPM_FOUND) + message(WARNING "Package librpm not found. Building without support.") + endif(RPM_FOUND) +endif(ENABLE_RPM) + +target_include_directories(libfastfetch + PUBLIC ${PROJECT_BINARY_DIR} + PUBLIC ${PROJECT_SOURCE_DIR}/src + + PRIVATE ${LIBPCI_INCLUDE_DIRS} + PRIVATE ${VULKAN_INCLUDE_DIRS} + PRIVATE ${WAYLAND_INCLUDE_DIRS} + PRIVATE ${XCB_RANDR_INCLUDE_DIRS} + PRIVATE ${XCB_INCLUDE_DIRS} + PRIVATE ${XRANDR_INCLUDE_DIRS} + PRIVATE ${X11_INCLUDE_DIRS} + PRIVATE ${GIO_INCLUDE_DIRS} + PRIVATE ${DCONF_INCLUDE_DIRS} + PRIVATE ${XFCONF_INCLUDE_DIRS} + PRIVATE ${RPM_INCLUDE_DIRS} +) + +target_link_libraries(libfastfetch + PRIVATE ${CMAKE_DL_LIBS} + PRIVATE Threads::Threads +) + +set_target_properties(libfastfetch PROPERTIES OUTPUT_NAME "fastfetch") + add_executable(fastfetch src/fastfetch.c - src/util/FFvaluestore.c - ${SRCS} +) +target_link_libraries(fastfetch + PRIVATE libfastfetch ) add_executable(flashfetch src/flashfetch.c - ${SRCS} ) - -target_compile_definitions(flashfetch PUBLIC - FASTFETCH_BUILD_FLASHFETCH +target_link_libraries(flashfetch + PRIVATE libfastfetch ) add_executable(fastfetch-test-performance tests/performance.c - ${SRCS} +) +target_link_libraries(fastfetch-test-performance + PRIVATE libfastfetch ) add_executable(fastfetch-test-strbuf tests/strbuf.c - ${SRCS} +) +target_link_libraries(fastfetch-test-strbuf + PRIVATE libfastfetch ) diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index 3dd43813d..bd6a49e35 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -20,7 +20,6 @@ Here i just add things that are easy to forget. - [ ] Fish completions - [ ] Make CPU usage detection much faster and more accurate - [ ] Detect CPU usage in a common detection methode and expose it both to the cpuUsage module and the cpu format string -- [ ] Build fastfetch as a **static** lib and link `fastfetch`, `flashfetch` and the tests against it, to reduce build time - [ ] Per session caching ### General diff --git a/src/common/logo.c b/src/common/logo.c index c4d8be2b1..71344e9af 100644 --- a/src/common/logo.c +++ b/src/common/logo.c @@ -1199,8 +1199,6 @@ void ffPrintRemainingLogo(FFinstance* instance) } } -#ifndef FASTFETCH_BUILD_FLASHFETCH - void ffPrintLogos(FFinstance* instance) { GetLogoMethod* methods = getLogoMethods(); @@ -1252,5 +1250,3 @@ void ffListLogosForAutocompletion() ++methods; } } - -#endif diff --git a/src/fastfetch.c b/src/fastfetch.c index e883dc961..bd2a5682c 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -1,5 +1,4 @@ #include "fastfetch.h" -#include "util/FFvaluestore.h" #include #include diff --git a/src/fastfetch.h b/src/fastfetch.h index c8995aeac..8b47f3b8f 100644 --- a/src/fastfetch.h +++ b/src/fastfetch.h @@ -18,6 +18,7 @@ #include "util/FFstrbuf.h" #include "util/FFlist.h" +#include "util/FFvaluestore.h" static inline void ffUnused(int dummy, ...) { (void) dummy; } #define FF_UNUSED(...) ffUnused(0, __VA_ARGS__); @@ -389,11 +390,9 @@ void ffLoadLogo(FFinstance* instance); void ffPrintLogoLine(FFinstance* instance); void ffPrintRemainingLogo(FFinstance* instance); -#ifndef FASTFETCH_BUILD_FLASHFATCH - void ffPrintLogos(FFinstance* instance); - void ffListLogos(); - void ffListLogosForAutocompletion(); -#endif +void ffPrintLogos(FFinstance* instance); +void ffListLogos(); +void ffListLogosForAutocompletion(); //common/format.c void ffFormatAppendFormatArg(FFstrbuf* buffer, const FFformatarg* formatarg);