forked from ThePhD/infoware
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
217 lines (167 loc) · 8.89 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# infoware - C++ System information Library
#
# Written in 2016-2019 by nabijaczleweli <[email protected]> and ThePhD <[email protected]>
#
# 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/>
cmake_minimum_required(VERSION 3.6.0)
find_package(Git)
execute_process(COMMAND ${GIT_EXECUTABLE} describe --tags --abbrev=0 OUTPUT_VARIABLE infoware_version ERROR_QUIET)
string(STRIP "${infoware_version}" infoware_version)
if(infoware_version STREQUAL "")
set(infoware_version "0.1.0")
else()
string(REPLACE "v" "" infoware_version "${infoware_version}")
endif()
project(infoware VERSION ${infoware_version} LANGUAGES CXX)
option(INFOWARE_USE_D3D "Add public, transitive define to infoware to use Direct 3D for GPU detection." OFF)
option(INFOWARE_USE_OPENGL "Add public, transitive define to infoware to use Open Graphics Language (OpenGL) for GPU detection." OFF)
option(INFOWARE_USE_OPENCL "Add public, transitive define to infoware to use Open Compute Language (OpenCL) for GPU detection." OFF)
option(INFOWARE_USE_X11 "Add public, transitive define to infoware to use X11 for display detection." OFF)
option(INFOWARE_EXAMPLES "Add infoware examples to the build." OFF)
option(INFOWARE_TESTS "Input tests for infoware." OFF)
if(INFOWARE_USE_D3D)
if(INFOWARE_USE_OPENCL)
message(WARNING "INFOWARE_USE_OPENCL specified, but the higher-priority INFOWARE_USE_D3D was specified, too, and will be used instead.")
elseif(INFOWARE_USE_OPENGL)
message(WARNING "INFOWARE_USE_OPENGL specified, but the higher-priority INFOWARE_USE_D3D was specified, too, and will be used instead.")
endif()
endif()
if(INFOWARE_USE_OPENCL)
if(INFOWARE_USE_OPENGL)
message(WARNING "INFOWARE_USE_OPENGL specified, but the higher-priority INFOWARE_USE_OPENCL was specified, too, and will be used instead.")
endif()
endif()
if(INFOWARE_USE_X11 AND WIN32)
message(WARNING "INFOWARE_USE_X11 specified, but compiling for Win32, WinAPI will be used instead.")
endif()
file(GLOB_RECURSE infoware_source_files LIST_DIRECTORIES false CONFIGURE_DEPENDS src/*.cpp)
file(GLOB_RECURSE infoware_private_headers LIST_DIRECTORIES false CONFIGURE_DEPENDS include/infoware/detail/*.hpp)
file(GLOB infoware_public_headers LIST_DIRECTORIES false CONFIGURE_DEPENDS include/infoware/*.hpp)
add_library(infoware ${infoware_source_files} ${infoware_public_headers} ${infoware_private_headers})
add_library(iware::infoware ALIAS infoware)
target_include_directories(infoware PRIVATE "${CMAKE_CURRENT_BINARY_DIR}")
set_target_properties(infoware PROPERTIES CXX_STANDARD 14
CXX_STANDARD_REQUIRED ON
CXX_EXTENSIONS OFF
PUBLIC_HEADER "${infoware_public_headers}"
RUNTIME_OUTPUT_DIRECTORY "bin"
LIBRARY_OUTPUT_DIRECTORY "bin"
ARCHIVE_OUTPUT_DIRECTORY "lib"
DEBUG_POSTFIX "d"
MINSIZEREL_POSTFIX "msr"
RELWITHDEBINFO_POSTFIX "rwdi")
target_compile_definitions(infoware PRIVATE INFOWARE_VERSION="${infoware_version}")
# Thanks, @griwes
if(EXISTS "${CMAKE_CURRENT_BINARY_DIR}/pciids/pci.ids")
execute_process(COMMAND ${GIT_EXECUTABLE} pull
WORKING_DIRECTORY pciids)
else()
execute_process(COMMAND ${GIT_EXECUTABLE} clone https://github.com/pciutils/pciids)
endif()
add_executable(infoware_pci_generator tools/pci_generator.cpp)
set_target_properties(infoware_pci_generator PROPERTIES CXX_STANDARD 14
CXX_STANDARD_REQUIRED ON
CXX_EXTENSIONS OFF)
add_custom_target(infoware_generate_pcis
COMMAND ${CMAKE_COMMAND} -E make_directory infoware_generated/
COMMAND $<TARGET_FILE:infoware_pci_generator> "${CMAKE_CURRENT_BINARY_DIR}/pciids/pci.ids" > "infoware_generated/pci_data.hpp"
DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/pciids/pci.ids"
BYPRODUCTS "infoware_generated/pci_data.hpp")
add_dependencies(infoware infoware_generate_pcis)
if(MSVC)
# Only CMake 3.15.0 makes this stuff not necessary, but we have a shitty
# minimum required version :/
string(REGEX REPLACE "/W[0-4]" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
target_compile_options(infoware PRIVATE /EHsc /W4)
target_compile_definitions(infoware PRIVATE UNICODE _UNICODE)
else()
target_compile_options(infoware PRIVATE -pedantic -Wall -Wextra -pipe)
endif()
if(WIN32 AND NOT MSVC)
target_compile_options(infoware PRIVATE -march=native)
endif()
if(WIN32)
target_link_libraries(infoware PRIVATE gdi32 version Ole32 OleAut32 wbemuuid)
endif()
if(APPLE)
target_link_libraries(infoware PRIVATE "-framework CoreFoundation" "-framework CoreGraphics")
endif()
if(INFOWARE_USE_D3D)
target_compile_definitions(infoware PUBLIC INFOWARE_USE_D3D)
if (WIN32)
target_link_libraries(infoware PUBLIC dxgi)
endif()
elseif(INFOWARE_USE_OPENCL)
target_compile_definitions(infoware PUBLIC INFOWARE_USE_OPENCL)
target_link_libraries(infoware PUBLIC OpenCL)
elseif(INFOWARE_USE_OPENGL)
target_compile_definitions(infoware PUBLIC INFOWARE_USE_OPENGL)
if(WIN32)
target_link_libraries(infoware PUBLIC opengl32)
elseif(NOT DARWIN)
target_link_libraries(infoware PUBLIC GL)
else()
target_link_libraries(infoware PUBLIC "-framework OpenGL")
endif()
endif()
if(NOT DARWIN AND INFOWARE_USE_X11)
include(FindX11)
target_compile_definitions(infoware PUBLIC INFOWARE_USE_X11)
target_include_directories(infoware PUBLIC ${X11_INCLUDE_DIR})
target_link_libraries(infoware PUBLIC ${X11_LIBRARIES})
if(X11_Xrandr_FOUND)
target_link_libraries(infoware PUBLIC ${X11_Xrandr_LIB})
else()
message(FATAL_ERROR "Xrandr is required for infoware")
endif()
endif()
if(INFOWARE_EXAMPLES)
file(GLOB infoware_example_sources LIST_DIRECTORIES false examples/*.cpp)
foreach(infoware_example_source IN LISTS infoware_example_sources)
string(REGEX REPLACE "([^/\\]+[/\\])*([^/\\]+)\\.cpp" "\\2" infoware_example_name "${infoware_example_source}")
string(REPLACE "/" "" infoware_example_name "${infoware_example_name}")
add_executable(infoware_${infoware_example_name}_example "${infoware_example_source}")
add_executable(iware::${infoware_example_name}_example ALIAS infoware_${infoware_example_name}_example)
target_link_libraries(infoware_${infoware_example_name}_example PUBLIC infoware)
set_target_properties(infoware_${infoware_example_name}_example PROPERTIES CXX_STANDARD 14
CXX_STANDARD_REQUIRED ON
CXX_EXTENSIONS OFF
RUNTIME_OUTPUT_DIRECTORY "bin"
LIBRARY_OUTPUT_DIRECTORY "bin"
ARCHIVE_OUTPUT_DIRECTORY "lib")
if(INFOWARE_TESTS)
add_test(NAME example_${infoware_example_name} COMMAND infoware_${infoware_example_name}_example)
endif()
endforeach()
endif()
if(INFOWARE_TESTS)
enable_testing()
endif()
# Use GNU install directories if CMAKE_INSTALL_PREFIX not specified
include(GNUInstallDirs)
# Specify where library and headers will be installed
install(TARGETS infoware
EXPORT infowareTargets
ARCHIVE 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}>)
# Create infowareConfigVersion package used to specify installed package version
include(CMakePackageConfigHelpers)
write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/cmake/infowareConfigVersion.cmake"
VERSION ${VERSION}
COMPATIBILITY AnyNewerVersion)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/cmake/infowareConfigVersion.cmake
DESTINATION ${CMAKE_INSTALL_PREFIX}/share/infoware
COMPONENT devel)
# Specifying config file that will be used to find a library using find_package().
export(TARGETS ${PROJECT_NAME}
FILE infowareConfig.cmake)
install(EXPORT infowareTargets
FILE infowareConfig.cmake
DESTINATION ${CMAKE_INSTALL_PREFIX}/share/infoware)