-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
129 lines (102 loc) · 3.17 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
cmake_policy(SET CMP0091 NEW)
project(OpenXinput)
cmake_minimum_required(VERSION 3.15)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
option(OPENXINPUT_STATIC_GUIDS "Static GUIDs instead. (Uses less dependencies)" ON)
option(OPENXINPUT_DISABLE_COM "Disable COM calls." ON)
set(OPENXINPUT_XUSER_MAX_COUNT 8 CACHE STRING "Max controller count supported by OpenXinput. (Can't be less than 4 because of Xinput compatibility)")
option(OPENXINPUT_BUILD_EXAMPLE "Build OpenXinput example." OFF)
option(BUILD_SHARED_LIBS "Build OpenXinput as a Xinput replacement. If set to no, all exported library functions will be prepended with 'Open', like 'OpenXinputGetState'." ON)
##################
## DEVOBJ
add_library(devobj SHARED
DEVOBJ/DEVOBJ.c
DEVOBJ/DEVOBJ.h
DEVOBJ/DEVOBJ.def
)
set_target_properties(devobj
PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/dustbin/bin"
)
##################
## OpenXinput
set(LIBRARY_NAME Xinput1_4)
set(OPENXINPUT_SOURCES
src/OpenXinput.cpp
)
set(OPENXINPUT_HEADERS
src/OpenXinput.h
src/OpenXinputInternal.h
)
add_library(${LIBRARY_NAME}
$<$<BOOL:${BUILD_SHARED_LIBS}>:src/OpenXinput.def>
${OPENXINPUT_SOURCES}
${OPENXINPUT_HEADERS}
)
set_target_properties(${LIBRARY_NAME} PROPERTIES
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>"
POSITION_INDEPENDENT_CODE ON
C_VISIBILITY_PRESET hidden
CXX_VISIBILITY_PRESET hidden
VISIBILITY_INLINES_HIDDEN ON
)
target_include_directories(${LIBRARY_NAME}
PRIVATE
DEVOBJ
)
target_link_libraries(${LIBRARY_NAME}
PUBLIC
devobj
mincore
WindowsApp
)
target_compile_definitions(${LIBRARY_NAME}
PRIVATE
$<$<BOOL:${OPENXINPUT_STATIC_GUIDS}>:OPENXINPUT_STATIC_GUIDS>
$<$<BOOL:${OPENXINPUT_DISABLE_COM}>:OPENXINPUT_DISABLE_COM>
$<$<BOOL:${OPENXINPUT_XUSER_MAX_COUNT}>:OPENXINPUT_XUSER_MAX_COUNT=${OPENXINPUT_XUSER_MAX_COUNT}>
PUBLIC
$<$<BOOL:${BUILD_SHARED_LIBS}>:OPENXINPUT_BUILD_SHARED>
)
set_target_properties(${LIBRARY_NAME}
PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
)
##################
## Examples
if(${OPENXINPUT_BUILD_EXAMPLE})
add_executable(openxinput_example
example/main.cpp
)
target_link_libraries(openxinput_example
PRIVATE
${LIBRARY_NAME}
)
target_include_directories(openxinput_example
PRIVATE
src/
)
set_target_properties(openxinput_example
PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
)
endif()
##################
## Install rules
set(CMAKE_INSTALL_PREFIX ${CMAKE_CURRENT_BINARY_DIR})
install(
TARGETS ${LIBRARY_NAME}
RUNTIME DESTINATION "output/bin"
LIBRARY DESTINATION "output/lib"
)
install(FILES
$<$<AND:$<BOOL:${BUILD_SHARED_LIBS}>,$<BOOL:${MSVC}>>:$<TARGET_PDB_FILE:${LIBRARY_NAME}>> DESTINATION "output/pdb" OPTIONAL
)