Skip to content

Commit

Permalink
cmakeify
Browse files Browse the repository at this point in the history
  • Loading branch information
terjeros committed May 28, 2019
1 parent 6cc0581 commit c8a08cc
Show file tree
Hide file tree
Showing 19 changed files with 327 additions and 415 deletions.
43 changes: 43 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
cmake_minimum_required(VERSION 3.0)

project(lshw)
set(VERSION "B.02.18")

find_package(Git)

if(EXISTS "${PROJECT_SOURCE_DIR}/.git" AND "${MAKE_RELEASE}" STREQUAL "")
if(GIT_FOUND)
execute_process(
COMMAND ${GIT_EXECUTABLE} describe --tags
OUTPUT_VARIABLE DESCRIBE_TAG
OUTPUT_STRIP_TRAILING_WHITESPACE)
string(REGEX MATCH "B.[0-9]+.[0-9]+[-][0-9]+" VERSION ${DESCRIBE_TAG})
string(REPLACE "-" "." VERSION ${VERSION})
endif()
endif()

message("-- lshw: ${VERSION}")

option(GUI "Enable GUI application (${PROJECT_NAME}-gtk)" ON)
option(HWDATA "Install hwdata files" ON)
option(SQLITE "Enable SQLite support" OFF)
option(ZLIB "Enable zlib support" OFF)
option(NOLOGO "Don't install vendor logos" OFF)
option(STATIC "Do a static (will disable other features)" OFF)
option(POLICYKIT "Install PolicyKit file and pfexec wrapper" OFF)

include(GNUInstallDirs)
set(CMAKE_INSTALL_PREFIX "/usr/local" CACHE STRING "Install prefix")
set(DATADIR "${CMAKE_INSTALL_FULL_DATADIR}")
set(PROJECT_DATADIR "${CMAKE_INSTALL_FULL_DATADIR}/${PROJECT_NAME}")
set(SBINDIR "${CMAKE_INSTALL_FULL_SBINDIR}")
set(MANDIR "${CMAKE_INSTALL_FULL_MANDIR}")
set(LOCALEDIR "${CMAKE_INSTALL_FULL_LOCALEDIR}")

configure_file(
"${PROJECT_SOURCE_DIR}/lshw.spec.in"
"${PROJECT_BINARY_DIR}/lshw.spec")

add_subdirectory(src)
add_subdirectory(src/po)
add_subdirectory(src/gui)
20 changes: 0 additions & 20 deletions Makefile

This file was deleted.

51 changes: 34 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,29 @@ Installation
1. Requirements
- Linux 2.4.x, 2.6.x, 3.x or 4.x (2.2.x might work, though)
- a PA-RISC-, Alpha-, IA-64- (Itanium-), PowerPC-, ARM- or x86- based machine
- cmake, GNU make or Ninja
- an ANSI (or close enough to ANSI compliance) C++ compiler (tested with g++ 2.95.4 and 3.x)
- for the (optional) GTK+ graphical user interface, you will need a
complete GTK+ development environment (gtk2-devel on RedHat/Fedora derivatives)
- for optional SQLite feature install SQLite
- for optional zlib feature install zlib and gzip

2. To compile it, just use:
2. Use cmake options to decide feature set:
- -DGUI=OFF - disable graphical user interface version og lshw
- -DZLIB=ON - enable reading of gzipped datafiles
- -DSQLITE=ON - enable SQLite support
- -DPOLICYKIT=ON - enable PolicyKit integration
- -DNOLOGO=ON - don't install logos with copyright

$ make
3. Do configuration and build by

To compile with zlib support (see below), use:

$ make ZLIB=1

3. If you want to build the optional GUI, do:

$ make
$ make gui
$ mkdir build && cd build
$ cmake .. -GNinja <options>
$ ninja-build

4. If you want to install the result, do:

$ make install
$ make install-gui
$ ninja-build install

Getting help
------------
Expand All @@ -61,12 +63,27 @@ If compiled with zlib support, lshw will look for `file`.gz first, then for `fil

Statically-linked and/or compressed binaries can be built by using

$ make static

$ mkdir build && cd build
$ cmake .. -DSTATIC=ON
$ ninja
or
$ mkdir build && cd build
$ cmake .. -GNinja
$ ninja compressed

$ make compressed
Building compressed binaries requires `upx` (cf. https://upx.github.io/).

in the `src/` directory
Release management and data files maintenance
---------------------------------------------

Building compressed binaries requires `upx` (cf. https://upx.github.io/).
Create release tarball,

1. Edit CMakeLists.txt to set version
2. Run
$ mkdir build && cd build
$ cmake .. -DMAKE_RELEASE=ON
$ make release

Update hwdata files:

$ make refresh_hwdata
62 changes: 17 additions & 45 deletions lshw.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ Version: @VERSION@
Release: 2
Source: http://www.ezix.org/software/files/%{name}-%{version}.tar.gz
URL: http://lshw.ezix.org/
License: GPL
License: GPLv2
Group: Applications/System
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
BuildRequires: gcc
BuildRequires: gcc-c++
BuildRequires: cmake

%description
lshw (Hardware Lister) is a small tool to provide detailed information on
Expand Down Expand Up @@ -37,7 +39,7 @@ lshw (Hardware Lister) is a small tool to provide detailed informaton on
the hardware configuration of the machine. It can report exact memory
configuration, firmware version, mainboard configuration, CPU version
and speed, cache configuration, bus speed, etc. on DMI-capable x86s
systems and on some PowerPC machines (PowerMac G4 is known to work).
systems and on some PowerPC machines (PowerMac G4 is known to work).

This package provides a graphical user interface to display hardware
information.
Expand All @@ -52,59 +54,29 @@ http://lshw.ezix.org/
%setup -q

%build
%{__make} %{?_smp_mflags} \
PREFIX="%{_prefix}" \
SBINDIR="%{_sbindir}" \
MANDIR="%{_mandir}" \
DATADIR="%{_datadir}" \
all
%if %{!?_without_gui:1}0
%{__make} %{?_smp_mflags} \
PREFIX="%{_prefix}" \
SBINDIR="%{_sbindir}" \
MANDIR="%{_mandir}" \
DATADIR="%{_datadir}" \
gui
%endif
mkdir build && cd build
%cmake .. %{?_without_gui:-DGUI=OFF}
make %{?_smp_mflags} VERBOSE=1

%install
%{__rm} -rf "%{buildroot}"

%{__make} \
DESTDIR="%{buildroot}" \
PREFIX="%{_prefix}" \
SBINDIR="%{_sbindir}" \
MANDIR="%{_mandir}" \
DATADIR="%{_datadir}" \
INSTALL="%{__install} -p" \
install
%if %{!?_without_gui:1}0
%{__make} \
DESTDIR="%{buildroot}" \
PREFIX="%{_prefix}" \
SBINDIR="%{_sbindir}" \
MANDIR="%{_mandir}" \
DATADIR="%{_datadir}" \
INSTALL="%{__install} -p" \
install-gui
%endif

%clean
%{__rm} -rf %{buildroot}
cd build
make install DESTDIR=%{buildroot}

%files
%defattr(-,root,root, 0555)
%doc README.md COPYING docs/TODO docs/Changelog docs/lshw.xsd
%license COPYING
%doc docs/TODO docs/Changelog docs/lshw.xsd
%{_sbindir}/lshw
%doc %{_mandir}/man?/*
%{_mandir}/man?/*
%{_datadir}/lshw/
%{_datadir}/locale/*/*/*

%if %{!?_without_gui:1}0
%files gui
%defattr(-,root,root, 0555)
%doc COPYING
%license COPYING
%{_sbindir}/gtk-lshw
%{_datadir}/appdata/gtk-lshw.appdata.xml
%{_datadir}/applications/gtk-lshw.desktop
%{_datadir}/pixmaps/gtk-lshw.svg
%endif

%changelog
Expand Down
102 changes: 102 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
if(STATIC)
set(ZLIB OFF)
set(SQLITE OFF)
endif()

# SQLite support
if(SQLITE)
pkg_check_modules(SQLITE3 sqlite3)
if(SQLITE3_FOUND)
message("-- Enabling SQLite support")
else()
message(FATAL_ERROR "SQLite not found, install lib or disable feature: -DSQLITE=OFF")
endif()
else()
message("-- SQLite support disabled")
endif()

# zlib support
if(ZLIB)
find_program(GZIP gzip "Path to gzip application")
if(NOT GZIP)
message(FATAL_ERROR "gzip program not found, install gzip or disable zlib support: -DZLIB=OFF")
endif()
pkg_check_modules(Z zlib)
if(Z_FOUND)
message("-- Enabling zlib support")
else()
message(FATAL_ERROR "zlib not found, install lib or disable feature: -DZLIB=OFF")
endif()
else()
message("-- zlib support disabled")
endif()

if(ERROR)
message(FATAL_ERROR "Configuration failed")
endif()

# Some special targets, compress, refresh_hwdata and release
add_custom_target(compressed
COMMAND upx -9 -o lshw-compress lshw
COMMENT "Creating upx compressed binary")
add_dependencies(compressed lshw)

add_custom_target(refresh_hwdata
COMMAND wget -N http://pciids.sourceforge.net/pci.ids
COMMAND wget -N http://www.linux-usb.org/usb.ids
COMMAND wget -N http://standards-oui.ieee.org/oui/oui.txt
COMMAND wget -O manuf.txt http://anonsvn.wireshark.org/wireshark/trunk/manuf
COMMAND wget -N https://git.fedorahosted.org/cgit/hwdata.git/plain/pnp.ids
COMMAND wget -N http://www-pc.uni-regensburg.de/hardware/TECHNIK/PCI_PNP/pnpid.txt
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/src"
COMMENT "Updating hwdata files from upstream location")

set(TARNAME ${PROJECT_NAME}-${VERSION})
add_custom_target(release
COMMAND ${GIT_EXECUTABLE} archive --prefix=${TARNAME}/
-o ${PROJECT_BINARY_DIR}/${TARNAME}.tar HEAD
COMMAND mv ${PROJECT_BINARY_DIR}/lshw.spec ${PROJECT_SOURCE_DIR}/lshw.spec
COMMAND tar --owner=0 --group=0
--transform s,lshw.spec,${TARNAME}/lshw.spec,
-rf ${PROJECT_BINARY_DIR}/${TARNAME}.tar lshw.spec
COMMAND gzip ${PROJECT_BINARY_DIR}/${TARNAME}.tar
COMMAND rm ${PROJECT_SOURCE_DIR}/lshw.spec
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
COMMENT "Creating release tarball")

configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/core/config.h.in"
"${PROJECT_BINARY_DIR}/config.h")

include_directories("${PROJECT_BINARY_DIR}")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/core")

file(GLOB DATAFILES "pci.ids" "pnp.ids" "usb.ids" "manuf.txt" "oui.txt" "pnpid.txt")

file(GLOB SOURCES "core/*.cc")
add_library(core ${SOURCES})
add_executable(lshw lshw.cc)

if(STATIC)
set_target_properties(lshw PROPERTIES LINK_FLAGS "-static" )
endif()

target_link_libraries(lshw ${SQLITE3_LIBRARIES} ${Z_LIBRARIES} core resolv)

if(NOT ZLIB)
if(HWDATA)
install(FILES ${DATAFILES} DESTINATION ${PROJECT_DATADIR})
endif()
else()
foreach(DATAFILE ${DATAFILES})
get_filename_component(FILE ${DATAFILE} NAME)
add_custom_command(
OUTPUT ${FILE}.gz
COMMAND ${GZIP} -c ${DATAFILE} > ${FILE}.gz)
add_custom_target(${FILE} ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${FILE}.gz)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${FILE}.gz DESTINATION ${PROJECT_DATADIR})
endforeach()
endif()

install(FILES lshw.1 DESTINATION ${MANDIR}/man1 COMPONENT doc)
install(TARGETS lshw DESTINATION sbin)
Loading

0 comments on commit c8a08cc

Please sign in to comment.