Skip to content

Commit 79f0aa5

Browse files
pavel_anabijaczleweli
authored andcommitted
CMakeLists.txt - add config option to exclude whole pci stuff
1 parent c8da4c2 commit 79f0aa5

File tree

3 files changed

+73
-57
lines changed

3 files changed

+73
-57
lines changed

CMakeLists.txt

Lines changed: 63 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ option(INFOWARE_USE_OPENCL "Add public, transitive define to infoware to use Ope
1717

1818
option(INFOWARE_USE_X11 "Add public, transitive define to infoware to use X11 for display detection." OFF)
1919

20+
option(INFOWARE_USE_PCIIDS "Want PCI IDs. If disabled, the PCI ID database will not be compiled, and the pci.hpp API will be unimplemented." ON)
21+
2022
option(INFOWARE_EXAMPLES "Add infoware examples to the build." OFF)
2123
option(INFOWARE_TESTS "Input tests for infoware." OFF)
2224

@@ -91,67 +93,71 @@ if(BUILD_SHARED_LIBS) # Controls add_library() w/o explicit mode
9193
target_compile_definitions(infoware PUBLIC INFOWARE_DLL=1)
9294
endif()
9395

94-
if(NOT Git_FOUND) # Could be pre-injected
95-
find_package(Git)
96-
endif()
96+
if(INFOWARE_USE_PCIIDS)
97+
target_compile_definitions(infoware PRIVATE INFOWARE_USE_PCIIDS)
9798

98-
set(INFOWARE_PCI_DATA_DIR infoware_generated CACHE PATH "Output directory for the PCI ids generator")
99-
set(INFOWARE_PCI_DATA_HPP pci_data.hpp)
100-
set(INFOWARE_PCI_DATA_GEN "${INFOWARE_PCI_DATA_DIR}/${INFOWARE_PCI_DATA_HPP}")
101-
set(infoware_pci_ids_error "\
102-
The pci.ids file, downloadable from https://github.com/pciutils/pciids or http://pci-ids.ucw.cz, is required for building infoware, \
103-
and cloned automatically from that GitHub repository by default.\n\
104-
To use a local copy, set INFOWARE_PCI_IDS_PATH to its location.")
105-
if(NOT CMAKE_CROSSCOMPILING)
106-
if(INFOWARE_PCI_IDS_PATH)
107-
if(NOT EXISTS "${INFOWARE_PCI_IDS_PATH}")
108-
message(WARNING "The specified pci.ids file INFOWARE_PCI_IDS_PATH=${INFOWARE_PCI_IDS_PATH} doesn't seem to exist.")
109-
endif()
110-
set(infoware_pci_ids_file "${INFOWARE_PCI_IDS_PATH}")
111-
elseif(NOT Git_FOUND)
112-
message(SEND_ERROR "Couldn't find a usable git executable in the environment, and the CMake variable INFOWARE_PCI_IDS_PATH is empty.\n${infoware_pci_ids_error}")
113-
else()
114-
# Thanks, @griwes
115-
set(infoware_pci_ids_file "${CMAKE_CURRENT_BINARY_DIR}/pciids/pci.ids")
116-
if(EXISTS "${infoware_pci_ids_file}")
117-
execute_process(COMMAND "${GIT_EXECUTABLE}" remote set-url origin "${INFOWARE_PCI_IDS_REPOSITORY}"
118-
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/pciids")
119-
execute_process(COMMAND "${GIT_EXECUTABLE}" pull
120-
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/pciids"
121-
RESULT_VARIABLE infoware_git_pciids_clone_err)
99+
if(NOT Git_FOUND) # Could be pre-injected
100+
find_package(Git)
101+
endif()
102+
103+
set(INFOWARE_PCI_DATA_DIR infoware_generated CACHE PATH "Output directory for the PCI ids generator")
104+
set(INFOWARE_PCI_DATA_HPP pci_data.hpp)
105+
set(INFOWARE_PCI_DATA_GEN "${INFOWARE_PCI_DATA_DIR}/${INFOWARE_PCI_DATA_HPP}")
106+
set(infoware_pci_ids_error "\
107+
The pci.ids file, downloadable from https://github.com/pciutils/pciids or http://pci-ids.ucw.cz, is required for building infoware, \
108+
and cloned automatically from that GitHub repository by default.\n\
109+
To use a local copy, set INFOWARE_PCI_IDS_PATH to its location.")
110+
if(NOT CMAKE_CROSSCOMPILING)
111+
if(INFOWARE_PCI_IDS_PATH)
112+
if(NOT EXISTS "${INFOWARE_PCI_IDS_PATH}")
113+
message(WARNING "The specified pci.ids file INFOWARE_PCI_IDS_PATH=${INFOWARE_PCI_IDS_PATH} doesn't seem to exist.")
114+
endif()
115+
set(infoware_pci_ids_file "${INFOWARE_PCI_IDS_PATH}")
116+
elseif(NOT Git_FOUND)
117+
message(SEND_ERROR "Couldn't find a usable git executable in the environment, and the CMake variable INFOWARE_PCI_IDS_PATH is empty.\n${infoware_pci_ids_error}")
122118
else()
123-
execute_process(COMMAND "${GIT_EXECUTABLE}" clone "${INFOWARE_PCI_IDS_REPOSITORY}" -- pciids
124-
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
125-
RESULT_VARIABLE infoware_git_pciids_clone_err)
119+
# Thanks, @griwes
120+
set(infoware_pci_ids_file "${CMAKE_CURRENT_BINARY_DIR}/pciids/pci.ids")
121+
if(EXISTS "${infoware_pci_ids_file}")
122+
execute_process(COMMAND "${GIT_EXECUTABLE}" remote set-url origin "${INFOWARE_PCI_IDS_REPOSITORY}"
123+
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/pciids")
124+
execute_process(COMMAND "${GIT_EXECUTABLE}" pull
125+
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/pciids"
126+
RESULT_VARIABLE infoware_git_pciids_clone_err)
127+
else()
128+
execute_process(COMMAND "${GIT_EXECUTABLE}" clone "${INFOWARE_PCI_IDS_REPOSITORY}" -- pciids
129+
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
130+
RESULT_VARIABLE infoware_git_pciids_clone_err)
131+
endif()
132+
if(infoware_git_pciids_clone_err)
133+
message(SEND_ERROR "Cloning/pulling pciids repository from ${INFOWARE_PCI_IDS_REPOSITORY} failed with ${infoware_git_pciids_clone_err}.\n${infoware_pci_ids_error}")
134+
endif()
126135
endif()
127-
if(infoware_git_pciids_clone_err)
128-
message(SEND_ERROR "Cloning/pulling pciids repository from ${INFOWARE_PCI_IDS_REPOSITORY} failed with ${infoware_git_pciids_clone_err}.\n${infoware_pci_ids_error}")
129-
endif()
130-
endif()
131136

132-
add_executable(infoware_pci_generator tools/pci_generator.cpp)
133-
set_target_properties(infoware_pci_generator PROPERTIES CXX_STANDARD 14
134-
CXX_STANDARD_REQUIRED ON
135-
CXX_EXTENSIONS OFF)
136-
137-
add_custom_command(OUTPUT ${INFOWARE_PCI_DATA_GEN}
138-
COMMAND ${CMAKE_COMMAND} -E make_directory "${INFOWARE_PCI_DATA_DIR}"
139-
COMMAND $<TARGET_FILE:infoware_pci_generator> "${infoware_pci_ids_file}" > "${INFOWARE_PCI_DATA_GEN}"
140-
DEPENDS "${infoware_pci_ids_file}"
141-
COMMENT "Generating ${INFOWARE_PCI_DATA_HPP}")
142-
add_custom_target(infoware_generate_pcis DEPENDS "${INFOWARE_PCI_DATA_GEN}")
143-
else()
144-
include(ExternalProject)
145-
ExternalProject_Add(infoware_generate_pcis
146-
SOURCE_DIR ${CMAKE_SOURCE_DIR}
147-
PREFIX ${CMAKE_BINARY_DIR}/pci_generator
148-
BINARY_DIR ${CMAKE_BINARY_DIR}/pci_generator
149-
BUILD_COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR> --target infoware_generate_pcis
150-
INSTALL_COMMAND ""
151-
BUILD_ALWAYS ON
152-
CMAKE_ARGS -DINFOWARE_PCI_DATA_DIR:PATH=${CMAKE_BINARY_DIR}/${INFOWARE_PCI_DATA_DIR})
153-
endif()
154-
add_dependencies(infoware infoware_generate_pcis)
137+
add_executable(infoware_pci_generator tools/pci_generator.cpp)
138+
set_target_properties(infoware_pci_generator PROPERTIES CXX_STANDARD 14
139+
CXX_STANDARD_REQUIRED ON
140+
CXX_EXTENSIONS OFF)
141+
142+
add_custom_command(OUTPUT ${INFOWARE_PCI_DATA_GEN}
143+
COMMAND ${CMAKE_COMMAND} -E make_directory "${INFOWARE_PCI_DATA_DIR}"
144+
COMMAND $<TARGET_FILE:infoware_pci_generator> "${infoware_pci_ids_file}" > "${INFOWARE_PCI_DATA_GEN}"
145+
DEPENDS "${infoware_pci_ids_file}"
146+
COMMENT "Generating ${INFOWARE_PCI_DATA_HPP}")
147+
add_custom_target(infoware_generate_pcis DEPENDS "${INFOWARE_PCI_DATA_GEN}")
148+
else()
149+
include(ExternalProject)
150+
ExternalProject_Add(infoware_generate_pcis
151+
SOURCE_DIR ${CMAKE_SOURCE_DIR}
152+
PREFIX ${CMAKE_BINARY_DIR}/pci_generator
153+
BINARY_DIR ${CMAKE_BINARY_DIR}/pci_generator
154+
BUILD_COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR> --target infoware_generate_pcis
155+
INSTALL_COMMAND ""
156+
BUILD_ALWAYS ON
157+
CMAKE_ARGS -DINFOWARE_PCI_DATA_DIR:PATH=${CMAKE_BINARY_DIR}/${INFOWARE_PCI_DATA_DIR})
158+
endif()
159+
add_dependencies(infoware infoware_generate_pcis)
160+
endif(INFOWARE_USE_PCIIDS)
155161

156162

157163
if(MSVC)

examples/pci.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ static bool print_vendor(std::uint64_t vendor_id, const char* vendor_name);
2828
int main(int, const char** argv) {
2929
std::cout << "Infoware version " << iware::version << '\n';
3030

31+
#ifdef INFOWARE_USE_PCIIDS
3132
if(argv[1] == nullptr)
3233
std::cout << "Usage: " << argv[0] << " <vendor_id> [device_id]" << '\n';
3334
else {
@@ -51,6 +52,9 @@ int main(int, const char** argv) {
5152
return (vendor_ok ? 0 : 1) | (device.device_name ? 0 : 2);
5253
}
5354
}
55+
#else
56+
std::cout << "Compiled without PCI ID support\n";
57+
#endif
5458
}
5559

5660

src/pci.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
// infoware - C++ System information Library
33

44

5+
#ifdef INFOWARE_USE_PCIIDS
6+
7+
58
#include "infoware/pci.hpp"
69
#include "infoware_generated/pci_data.hpp"
710
#include <algorithm>
@@ -62,3 +65,6 @@ const char* iware::pci::identify_vendor(std::uint64_t pci_id) noexcept {
6265
else
6366
return nullptr;
6467
}
68+
69+
70+
#endif

0 commit comments

Comments
 (0)