Skip to content

Commit

Permalink
Add new vcpkg distribution files, and enable being built as a shared …
Browse files Browse the repository at this point in the history
…library. Adds to #41
  • Loading branch information
ThePhD committed May 16, 2020
1 parent 3c9a288 commit 8b56770
Show file tree
Hide file tree
Showing 14 changed files with 170 additions and 44 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
!examples/**
!include
!include/**
!distribution
!distribution/**
!tools
!tools/**
!.git*
Expand Down
24 changes: 10 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,10 @@ cmake_minimum_required(VERSION 3.6.0)

set(infoware_version "0.5.2")

find_package(Git)
# check if we pre-injected the Git_FOUND value
if(NOT Git_FOUND)
# fall back to using find_program as well
# should prevent vcpkg failures from destroying us...
find_program(GIT_EXECUTABLE
NAMES git git.exe)
message(STATUS "${GIT_EXECUTABLE}")
if (${GIT_EXECUTABLE})
set(Git_FOUND true)
else()
set(Git_FOUND false)
endif()
# if not, do the find_package
find_package(Git)
endif()
if(Git_FOUND)
execute_process(COMMAND "${GIT_EXECUTABLE}" describe --tags
Expand Down Expand Up @@ -102,7 +94,9 @@ set_target_properties(infoware PROPERTIES CXX_STANDARD 14
MINSIZEREL_POSTFIX "msr"
RELWITHDEBINFO_POSTFIX "rwdi")

target_compile_definitions(infoware PRIVATE INFOWARE_VERSION="${infoware_version}")
target_compile_definitions(infoware PRIVATE INFOWARE_VERSION="${infoware_version}"
INFOWARE_BUILDING=1
PUBLIC $<$<STREQUAL:$<TARGET_PROPERTY:infoware,TYPE>,SHARED_LIBRARY>:INFOWARE_DLL=1>)


set(infoware_pci_ids_error "\
Expand Down Expand Up @@ -206,7 +200,7 @@ if(NOT DARWIN AND INFOWARE_USE_X11)
if(X11_Xrandr_FOUND)
target_link_libraries(infoware PUBLIC ${X11_Xrandr_LIB})
else()
message(FATAL_ERROR "Xrandr is required for infoware")
message(FATAL_ERROR "Xrandr is required for infoware")
endif()
endif()

Expand Down Expand Up @@ -248,7 +242,9 @@ include(GNUInstallDirs)
# Specify where library and headers will be installed
install(TARGETS infoware
EXPORT infowareTargets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/infoware)
target_include_directories(infoware PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
Expand Down
27 changes: 27 additions & 0 deletions distribution/vcpkg/CONTROL
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# infoware - C++ System information Library
#
# Written in 2016-2020 by nabijaczleweli <nabijaczleweli@gmail.com> and ThePhD <phdofthehouse@gmail.com>
#
# To the extent possible under law, the author(s) have dedicated all copyright and related
# and neighboring rights to this software to the public domain worldwide. This software is
# distributed without any warranty.
#
# You should have received a copy of the CC0 Public Domain Dedication along with this software.
# If not, see <http://creativecommons.org/publicdomain/zero/1.0/>

# vcpkg CONTROL file for infoware
Source: infoware
Version: v0.5.2
Description: C++ Library for pulling system and hardware information, without hitting the command line.

Feature: x11
Description: Prefer usage of X11 to find graphical capabilities.

Feature: d3d
Description: Prefer usage of Direct3D to find graphical capabilities (typically only works on Windows systems).

Feature: opencl
Description: Prefer usage of OpenCL to find graphical capabilities of the system.

Feature: opengl
Description: Prefer usage of OpenGL to find graphical capabilities (may require additional libraries to be available for linking depending on the system).
52 changes: 52 additions & 0 deletions distribution/vcpkg/portfile.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# infoware - C++ System information Library
#
# Written in 2016-2020 by nabijaczleweli <nabijaczleweli@gmail.com> and ThePhD <phdofthehouse@gmail.com>
#
# To the extent possible under law, the author(s) have dedicated all copyright and related
# and neighboring rights to this software to the public domain worldwide. This software is
# distributed without any warranty.
#
# You should have received a copy of the CC0 Public Domain Dedication along with this software.
# If not, see <http://creativecommons.org/publicdomain/zero/1.0/>

# vcpkg portfile.cmake file for infoware

include(vcpkg_common_functions)

vcpkg_from_github(
OUT_SOURCE_PATH SOURCE_PATH
REPO ThePhD/infoware
REF v0.5.2
SHA512 ed3b4384c135ebdcead21afc3b5ccb790d7058f5dadfb31a5be52e10078d9140851e2971f3e974a9915dd8a5d2615be3bcee2270baf145b921f46b27c8182cd7
HEAD_REF master
)

vcpkg_check_features(
OUT_FEATURE_OPTIONS FEATURE_OPTIONS
x11 INFOWARE_USE_X11
d3d INFOWARE_USE_D3D
opencl INFOWARE_USE_OPENCL
opengl INFOWARE_USE_OPENGL
)

vcpkg_find_acquire_program(GIT)

vcpkg_configure_cmake(
SOURCE_PATH ${SOURCE_PATH}
PREFER_NINJA
OPTIONS
${FEATURE_OPTIONS}
-DINFOWARE_EXAMPLES=OFF
-DINFOWARE_TESTS=OFF
-DGIT_EXECUTABLE=${GIT}
-DGIT_FOUND=true
)

vcpkg_install_cmake()

# make sure the LICENSE file is present as the copyright file
file(INSTALL ${SOURCE_PATH}/LICENSE DESTINATION ${CURRENT_PACKAGES_DIR}/share/infoware RENAME copyright)
# remove things for debug version of how vcpkg does stuff...?
# they also handle share stuff and configuration for debug vs. release, so not our responsibility
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include")
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/share")
21 changes: 11 additions & 10 deletions include/infoware/cpu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#pragma once

#include <infoware/detail/linkage.hpp>

#include <cstdint>
#include <string>
Expand Down Expand Up @@ -107,37 +108,37 @@ namespace iware {


/// Returns the quantity of CPU at various gradation.
quantities_t quantities();
INFOWARE_API_LINKAGE quantities_t quantities();

/// Get CPU's cache properties.
///
/// `level` is the cache level (3 -> L3 cache).
cache_t cache(unsigned int level);
INFOWARE_API_LINKAGE cache_t cache(unsigned int level);

/// Returns the architecture of the current CPU.
architecture_t architecture() noexcept;
INFOWARE_API_LINKAGE architecture_t architecture() noexcept;

/// Returns the current frequency of the current CPU in Hz.
std::uint64_t frequency() noexcept;
INFOWARE_API_LINKAGE std::uint64_t frequency() noexcept;

/// Returns the current endianness of the current CPU.
endianness_t endianness() noexcept;
INFOWARE_API_LINKAGE endianness_t endianness() noexcept;

/// Returns the CPU's vendor.
std::string vendor();
INFOWARE_API_LINKAGE std::string vendor();

/// Returns the CPU's vendor according to the CPUID instruction
std::string vendor_id();
INFOWARE_API_LINKAGE std::string vendor_id();

/// Returns the CPU's model name.
std::string model_name();
INFOWARE_API_LINKAGE std::string model_name();

/// Returns whether an instruction set is supported by the current CPU.
///
/// `noexcept` on Windows
bool instruction_set_supported(instruction_set_t set);
INFOWARE_API_LINKAGE bool instruction_set_supported(instruction_set_t set);

/// Retrieve all of the instruction sets this hardware supports
std::vector<instruction_set_t> supported_instruction_sets();
INFOWARE_API_LINKAGE std::vector<instruction_set_t> supported_instruction_sets();
} // namespace cpu
} // namespace iware
6 changes: 4 additions & 2 deletions include/infoware/detail/cpuid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@
#pragma once


#include <infoware/detail/linkage.hpp>

#include <cstdint>


namespace iware {
namespace detail {
void cpuid(std::int32_t (&out)[4], std::int32_t x);
INFOWARE_API_LINKAGE_INTERNAL void cpuid(std::int32_t (&out)[4], std::int32_t x);

std::uint64_t xgetbv(std::uint32_t x);
INFOWARE_API_LINKAGE_INTERNAL std::uint64_t xgetbv(std::uint32_t x);
} // namespace detail
} // namespace iware
32 changes: 32 additions & 0 deletions include/infoware/detail/linkage.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// infoware - C++ System information Library
//
// Written in 2016-2020 by nabijaczleweli <nabijaczleweli@gmail.com> and ThePhD <phdofthehouse@gmail.com>
//
// To the extent possible under law, the author(s) have dedicated all copyright and related
// and neighboring rights to this software to the public domain worldwide. This software is
// distributed without any warranty.
//
// You should have received a copy of the CC0 Public Domain Dedication along with this software.
// If not, see <http://creativecommons.org/publicdomain/zero/1.0/>


#pragma once

#if defined _MSC_VER
#if defined INFOWARE_DLL
#if defined INFOWARE_BUILDING
#define INFOWARE_API_LINKAGE __declspec(dllexport)
#define INFOWARE_API_LINKAGE_INTERNAL
#else
#define INFOWARE_API_LINKAGE __declspec(dllimport)
#define INFOWARE_API_LINKAGE_INTERNAL
#endif // FICAPI_BUILD - Building the Library vs. Using the Library
#else
#define INFOWARE_API_LINKAGE
#define INFOWARE_API_LINKAGE_INTERNAL
#endif // Building a DLL vs. Static Library
#else // g++ / clang++
#define INFOWARE_API_LINKAGE __attribute__((visibility("default")))
#define INFOWARE_API_LINKAGE_INTERNAL __attribute__((visibility("hidden")))
#endif // MSVC vs. other shared object / dll attributes

4 changes: 3 additions & 1 deletion include/infoware/detail/scope.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#pragma once


#include <infoware/detail/linkage.hpp>

#include <functional>


Expand All @@ -22,7 +24,7 @@ namespace iware {
std::function<void()> func;

quickscope_wrapper(const quickscope_wrapper&) = delete;
~quickscope_wrapper();
INFOWARE_API_LINKAGE_INTERNAL ~quickscope_wrapper();
};
} // namespace detail
} // namespace iware
8 changes: 5 additions & 3 deletions include/infoware/detail/sysctl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#pragma once


#include <infoware/detail/linkage.hpp>

#include <cstdint>
#include <utility>
#include <vector>
Expand All @@ -21,9 +23,9 @@
namespace iware {
namespace detail {
/// https://github.com/ThePhD/infoware/issues/13
std::vector<char> sysctl(const char* name);
std::vector<char> sysctl(int mib_0, int mib_1);
INFOWARE_API_LINKAGE_INTERNAL std::vector<char> sysctl(const char* name);
INFOWARE_API_LINKAGE_INTERNAL std::vector<char> sysctl(int mib_0, int mib_1);

std::pair<bool, std::uint64_t> deconstruct_sysctl_int(const std::vector<char>& data);
INFOWARE_API_LINKAGE_INTERNAL std::pair<bool, std::uint64_t> deconstruct_sysctl_int(const std::vector<char>& data);
} // namespace detail
} // namespace iware
6 changes: 4 additions & 2 deletions include/infoware/detail/winstring.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@
#pragma once


#include <infoware/detail/linkage.hpp>

#include <string>


namespace iware {
namespace detail {
std::string narrowen_bstring(const wchar_t* wstr);
std::string narrowen_winstring(const wchar_t* wstr);
INFOWARE_API_LINKAGE_INTERNAL std::string narrowen_bstring(const wchar_t* wstr);
INFOWARE_API_LINKAGE_INTERNAL std::string narrowen_winstring(const wchar_t* wstr);
} // namespace detail
} // namespace iware
4 changes: 3 additions & 1 deletion include/infoware/gpu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#pragma once


#include <infoware/detail/linkage.hpp>

#include <cstdint>
#include <string>
#include <vector>
Expand All @@ -39,6 +41,6 @@ namespace iware {


/// Returns all GPU's properties.
std::vector<device_properties_t> device_properties();
INFOWARE_API_LINKAGE std::vector<device_properties_t> device_properties();
} // namespace gpu
} // namespace iware
6 changes: 4 additions & 2 deletions include/infoware/pci.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#pragma once


#include <infoware/detail/linkage.hpp>

#include <cstdint>
#include <string>

Expand All @@ -29,9 +31,9 @@ namespace iware {
///
/// If the vendor was not found, both names are nullptr.
/// If the vendor was found, but the device wasn't, the device name is nullptr;
device identify_device(std::uint64_t vendor_id, std::uint64_t device_id) noexcept;
INFOWARE_API_LINKAGE device identify_device(std::uint64_t vendor_id, std::uint64_t device_id) noexcept;

/// Get the name the vendor with the specified PCI ID, or nullptr if not found.
const char* identify_vendor(std::uint64_t vendor_id) noexcept;
INFOWARE_API_LINKAGE const char* identify_vendor(std::uint64_t vendor_id) noexcept;
} // namespace pci
} // namespace iware
18 changes: 10 additions & 8 deletions include/infoware/system.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#pragma once


#include <infoware/detail/linkage.hpp>

#include <cstdint>
#include <string>
#include <vector>
Expand Down Expand Up @@ -72,31 +74,31 @@ namespace iware {
};

/// Get amount of connected mice.
std::size_t mouse_amount() noexcept;
INFOWARE_API_LINKAGE std::size_t mouse_amount() noexcept;

/// Get amount of connected keyboards.
///
/// Always returns 0 on Linuxish kernels, as it can not be detected there.
std::size_t keyboard_amount() noexcept;
INFOWARE_API_LINKAGE std::size_t keyboard_amount() noexcept;

/// Get amount of other connected HIDs.
///
/// Always returns 0 on Linuxish kernels, as it can not be detected there.
std::size_t other_HID_amount() noexcept;
INFOWARE_API_LINKAGE std::size_t other_HID_amount() noexcept;

/// Get RAM statistics.
memory_t memory() noexcept;
INFOWARE_API_LINKAGE memory_t memory() noexcept;

/// Get kernel information.
kernel_info_t kernel_info();
INFOWARE_API_LINKAGE kernel_info_t kernel_info();

/// Get system information.
OS_info_t OS_info();
INFOWARE_API_LINKAGE OS_info_t OS_info();

/// Get information about displays.
std::vector<display_t> displays();
INFOWARE_API_LINKAGE std::vector<display_t> displays();

/// Get information about available configurations for each display.
std::vector<std::vector<display_config_t>> available_display_configurations();
INFOWARE_API_LINKAGE std::vector<std::vector<display_config_t>> available_display_configurations();
} // namespace system
} // namespace iware
Loading

0 comments on commit 8b56770

Please sign in to comment.