This repository has been archived by the owner on Sep 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 66
/
CMakeLists.txt
121 lines (103 loc) · 3.76 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
cmake_minimum_required(VERSION 3.20.2)
project(ViGEmClient VERSION 1.21.222.0)
# Install directory setup
include(GNUInstallDirs)
set(VIGEM_INC_DIR ${CMAKE_INSTALL_INCLUDEDIR})
option(ViGEmClient_DLL "Generate a dynamic library instead of a static library" OFF)
set(VIGEM_HEADERS
${CMAKE_CURRENT_SOURCE_DIR}/include/ViGEm/km/BusShared.h
${CMAKE_CURRENT_SOURCE_DIR}/include/ViGEm/Client.h
${CMAKE_CURRENT_SOURCE_DIR}/include/ViGEm/Common.h
${CMAKE_CURRENT_SOURCE_DIR}/include/ViGEm/Util.h
)
set(VIGEM_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/Internal.h
${CMAKE_CURRENT_SOURCE_DIR}/src/resource.h
${CMAKE_CURRENT_SOURCE_DIR}/src/ViGEmClient.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/ViGEmClient.rc
)
function(setup_include_directories target_name)
target_include_directories(
${target_name}
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src
${CMAKE_CURRENT_SOURCE_DIR}/include
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${VIGEM_INC_DIR}>
)
endfunction()
add_library(ViGEmClient STATIC
${VIGEM_HEADERS}
${VIGEM_SOURCES}
)
setup_include_directories(ViGEmClient)
add_library(ViGEmClient::ViGEmClient ALIAS ViGEmClient)
# Setup dynamic library if requested and set output name to ViGEmClient.dll
if (ViGEmClient_DLL)
add_library(ViGEmClientShared SHARED
${VIGEM_HEADERS}
${VIGEM_SOURCES}
)
set_target_properties(ViGEmClientShared PROPERTIES
OUTPUT_NAME ViGEmClient
SUFFIX .dll
)
target_link_libraries(ViGEmClientShared PRIVATE setupapi.lib)
setup_include_directories(ViGEmClientShared)
add_library(ViGEmClient::ViGEmClientShared ALIAS ViGEmClientShared)
endif()
# Setup install targets
include(CMakePackageConfigHelpers)
set(VIGEM_CMAKE_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/ViGEmClient)
set(version_config "${PROJECT_BINARY_DIR}/ViGEmClientConfigVersion.cmake")
set(project_config "${PROJECT_BINARY_DIR}/ViGEmClientConfig.cmake")
set(pkgconfig ${PROJECT_BINARY_DIR}/ViGEmClient.pc)
set(targets_export_name ViGEmClientTargets)
set(VIGEMCLIENT_LIB_NAME ViGEmClient)
write_basic_package_version_file(
${version_config}
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)
set(VIGEM_LIB_DIR ${CMAKE_INSTALL_LIBDIR})
set(VIGEM_PKGCONFIG_DIR ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
# Create path
string(CONCAT libdir_for_pc_file "\${exec_prefix}" "/" "${VIGEM_LIB_DIR}")
string(CONCAT includedir_for_pc_file "\${prefix}" "/" "${VIGEM_INC_DIR}")
# pkg-config support
configure_file(
${PROJECT_SOURCE_DIR}/cmake/ViGEmClient.pc.in # Input file
${pkgconfig}
@ONLY
)
# CMake package config
configure_package_config_file(
${CMAKE_CURRENT_SOURCE_DIR}/cmake/ViGEmClientConfig.cmake.in
${project_config}
INSTALL_DESTINATION ${VIGEM_CMAKE_DIR}
)
# Setup install targets
set(INSTALL_TARGETS ViGEmClient)
if (ViGEmClient_DLL)
list(APPEND INSTALL_TARGETS ViGEmClientShared)
endif()
# Install library and headers
install(TARGETS ${INSTALL_TARGETS} EXPORT ${targets_export_name}
LIBRARY DESTINATION ${VIGEM_LIB_DIR}
ARCHIVE DESTINATION ${VIGEM_LIB_DIR}
PUBLIC_HEADER DESTINATION "${VIGEM_INC_DIR}/ViGEm"
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
install(FILES ${VIGEM_HEADERS} DESTINATION "${VIGEM_INC_DIR}/ViGEm")
export(TARGETS ${INSTALL_TARGETS} NAMESPACE ViGEmClient::
FILE ${PROJECT_BINARY_DIR}/${targets_export_name}.cmake)
# Install version, config and target files.
install(
FILES ${project_config} ${version_config}
DESTINATION ${VIGEM_CMAKE_DIR}
)
install(EXPORT ${targets_export_name} DESTINATION ${VIGEM_CMAKE_DIR}
NAMESPACE ViGEmClient::)
# TODO: pkg-config doesn't work as expected on Windows
install(FILES "${pkgconfig}" DESTINATION "${VIGEM_PKGCONFIG_DIR}")