From fb8608d24be20c1c74070d28780cd6b156c46668 Mon Sep 17 00:00:00 2001 From: otreblan Date: Fri, 4 Jun 2021 13:56:40 -0500 Subject: [PATCH 1/2] Add CMake --- .gitignore | 55 ++++++++++++++++++++++++++++ CMakeLists.txt | 63 ++++++++++++++++++++++++++++++++ config_scripts/battery_config.sh | 5 --- src/CMakeLists.txt | 4 ++ config.h => src/config.h | 2 + {logos => src/logos}/arch.h | 0 {logos => src/logos}/artix.h | 0 {logos => src/logos}/debian.h | 0 {logos => src/logos}/fedora.h | 0 {logos => src/logos}/gentoo.h | 0 {logos => src/logos}/manjaro.h | 0 {logos => src/logos}/ubuntu.h | 0 paleofetch.c => src/paleofetch.c | 0 paleofetch.h => src/paleofetch.h | 2 + 14 files changed, 126 insertions(+), 5 deletions(-) create mode 100644 CMakeLists.txt delete mode 100755 config_scripts/battery_config.sh create mode 100644 src/CMakeLists.txt rename config.h => src/config.h (99%) rename {logos => src/logos}/arch.h (100%) rename {logos => src/logos}/artix.h (100%) rename {logos => src/logos}/debian.h (100%) rename {logos => src/logos}/fedora.h (100%) rename {logos => src/logos}/gentoo.h (100%) rename {logos => src/logos}/manjaro.h (100%) rename {logos => src/logos}/ubuntu.h (100%) rename paleofetch.c => src/paleofetch.c (100%) rename paleofetch.h => src/paleofetch.h (98%) diff --git a/.gitignore b/.gitignore index e972a4b..760e2c5 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,56 @@ paleofetch + +# create by https://github.com/iamcco/coc-gitignore (Fri Jun 04 2021 13:56:04 GMT-0500 (hora estándar de Perú)) +# CMake.gitignore: +CMakeLists.txt.user +CMakeCache.txt +CMakeFiles +CMakeScripts +Testing +Makefile +cmake_install.cmake +install_manifest.txt +compile_commands.json +CTestTestfile.cmake +_deps + +# CMake.patch: +# External projects +*-prefix/ + +# create by https://github.com/iamcco/coc-gitignore (Fri Jun 04 2021 13:56:12 GMT-0500 (hora estándar de Perú)) +# C++.gitignore: +# Prerequisites +*.d + +# Compiled Object files +*.slo +*.lo +*.o +*.obj + +# Precompiled Headers +*.gch +*.pch + +# Compiled Dynamic libraries +*.so +*.dylib +*.dll + +# Fortran module files +*.mod +*.smod + +# Compiled Static libraries +*.lai +*.la +*.a +*.lib + +# Executables +*.exe +*.out +*.app + +build/ diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..858c6ad --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,63 @@ +cmake_minimum_required(VERSION 3.16.0) + +project(paleofetch + VERSION 0.0.0 + DESCRIPTION "Neofetch, but written in C" + HOMEPAGE_URL "https://github.com/JaGoLi/paleofetch" +) + +# Without this, paths are not relative in the sources list +cmake_policy(SET CMP0076 NEW) + +include(GNUInstallDirs) +include(FindPkgConfig) + +# The program itself +add_executable(${PROJECT_NAME}) + +add_subdirectory(src) # Sources list + +# Shared libraries +pkg_check_modules(libs + REQUIRED IMPORTED_TARGET + libpci + x11 +) + +# Linking +target_link_libraries(${PROJECT_NAME} + PRIVATE + PkgConfig::libs +) + +# Battery directory +execute_process(COMMAND + find + -L + /sys/class/power_supply/ + -maxdepth 1 + -iname "bat*" + -print0 + + OUTPUT_VARIABLE BATTERY_DIRECTORY +) + +target_compile_definitions(${PROJECT_NAME} + PRIVATE + "BATTERY_DIRECTORY=\"${BATTERY_DIRECTORY}\"" +) + +# Default flags +if(UNIX) + if(NOT (DEFINED ENV{CFLAGS} OR CMAKE_C_FLAGS)) + set(CMAKE_C_FLAGS "-Wall -Wextra -g") + endif() + if(NOT (DEFINED ENV{CXXFLAGS} OR CMAKE_CXX_FLAGS)) + set(CMAKE_CXX_FLAGS "-Wall -Wextra -g") + endif() +endif() + +# Install target +install(TARGETS ${PROJECT_NAME} + DESTINATION ${CMAKE_INSTALL_BINDIR} +) diff --git a/config_scripts/battery_config.sh b/config_scripts/battery_config.sh deleted file mode 100755 index 0a49740..0000000 --- a/config_scripts/battery_config.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh - -BATTERY_DIRECTORY=`ls /sys/class/power_supply | grep -i "^bat" | head -n 1` - -echo "BATTERY_DIRECTORY='\"/sys/class/power_supply/$BATTERY_DIRECTORY\"'" diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..938488c --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,4 @@ +target_sources(${PROJECT_NAME} + PRIVATE + paleofetch.c +) diff --git a/config.h b/src/config.h similarity index 99% rename from config.h rename to src/config.h index a4bd4af..23094f8 100644 --- a/config.h +++ b/src/config.h @@ -1,3 +1,5 @@ +#pragma once + #include "logos/arch.h" //define colors #define BLACK "\e[1;30m" diff --git a/logos/arch.h b/src/logos/arch.h similarity index 100% rename from logos/arch.h rename to src/logos/arch.h diff --git a/logos/artix.h b/src/logos/artix.h similarity index 100% rename from logos/artix.h rename to src/logos/artix.h diff --git a/logos/debian.h b/src/logos/debian.h similarity index 100% rename from logos/debian.h rename to src/logos/debian.h diff --git a/logos/fedora.h b/src/logos/fedora.h similarity index 100% rename from logos/fedora.h rename to src/logos/fedora.h diff --git a/logos/gentoo.h b/src/logos/gentoo.h similarity index 100% rename from logos/gentoo.h rename to src/logos/gentoo.h diff --git a/logos/manjaro.h b/src/logos/manjaro.h similarity index 100% rename from logos/manjaro.h rename to src/logos/manjaro.h diff --git a/logos/ubuntu.h b/src/logos/ubuntu.h similarity index 100% rename from logos/ubuntu.h rename to src/logos/ubuntu.h diff --git a/paleofetch.c b/src/paleofetch.c similarity index 100% rename from paleofetch.c rename to src/paleofetch.c diff --git a/paleofetch.h b/src/paleofetch.h similarity index 98% rename from paleofetch.h rename to src/paleofetch.h index 0e4578f..c9053d6 100644 --- a/paleofetch.h +++ b/src/paleofetch.h @@ -1,6 +1,8 @@ /* Forward-declare our functions so users can mention them in their * configs at the top of the file rather than near the bottom. */ +#pragma once + static char *get_title(), *get_bar(), *get_os(), From ae36be1350f0db4dfc42bad94f36f96a809fcb28 Mon Sep 17 00:00:00 2001 From: otreblan Date: Fri, 4 Jun 2021 14:17:03 -0500 Subject: [PATCH 2/2] Add DISTRO_LOGO CMake option --- CMakeLists.txt | 3 +++ Makefile | 17 ----------------- src/CMakeLists.txt | 8 ++++++++ src/{config.h => config.h.in} | 3 ++- 4 files changed, 13 insertions(+), 18 deletions(-) delete mode 100644 Makefile rename src/{config.h => config.h.in} (98%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 858c6ad..a438107 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,6 +15,9 @@ include(FindPkgConfig) # The program itself add_executable(${PROJECT_NAME}) +# Distro logo +set(DISTRO_LOGO "arch" CACHE STRING "The logo that will be displayed.") + add_subdirectory(src) # Sources list # Shared libraries diff --git a/Makefile b/Makefile deleted file mode 100644 index 0f79ef1..0000000 --- a/Makefile +++ /dev/null @@ -1,17 +0,0 @@ -CFLAGS=-O2 -Wall -Wextra -lX11 -lpci -PREFIX=$(HOME)/.local -CACHE=$(shell if [ "$$XDG_CACHE_HOME" ]; then echo "$$XDG_CACHE_HOME"; else echo "$$HOME"/.cache; fi) - -all: paleofetch - -clean: - rm -f paleofetch $(CACHE)/paleofetch - -paleofetch: paleofetch.c paleofetch.h config.h - $(eval battery_path := $(shell ./config_scripts/battery_config.sh)) - $(CC) paleofetch.c -o paleofetch $(CFLAGS) -D $(battery_path) - strip paleofetch - -install: paleofetch - mkdir -p $(PREFIX)/bin - install ./paleofetch $(PREFIX)/bin/paleofetch diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 938488c..43ba880 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -2,3 +2,11 @@ target_sources(${PROJECT_NAME} PRIVATE paleofetch.c ) + +# Fill @DISTRO_LOGO@ +configure_file(config.h.in config.h @ONLY) +target_include_directories(${PROJECT_NAME} + PRIVATE + "${CMAKE_CURRENT_BINARY_DIR}" + "${CMAKE_CURRENT_SOURCE_DIR}" +) diff --git a/src/config.h b/src/config.h.in similarity index 98% rename from src/config.h rename to src/config.h.in index 23094f8..eb032c4 100644 --- a/src/config.h +++ b/src/config.h.in @@ -1,6 +1,7 @@ #pragma once -#include "logos/arch.h" +#include "logos/@DISTRO_LOGO@.h" + //define colors #define BLACK "\e[1;30m" #define RED "\e[1;31m"