-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
96 lines (81 loc) · 3.07 KB
/
Copy pathCMakeLists.txt
File metadata and controls
96 lines (81 loc) · 3.07 KB
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
#--------------------------------------
# Global compilation directives
#--------------------------------------
cmake_minimum_required(VERSION 3.1)
#----------------------------------------------------------------------------
# Project options
#----------------------------------------------------------------------------
# Overload option() to display currently selected options and automatically add compiler definitions
# Add a debug dump to the option() function
function(option name)
_option(${name} ${ARGN})
message("-- ${name} is set to ${${name}}")
if(${name})
add_definitions(-D${name})
endif(${name})
endfunction(option)
#----------------------------------------------------------------------------
# Compiler flags
#----------------------------------------------------------------------------
# GCC specific flags
if(CMAKE_COMPILER_IS_GNUCXX)
# Enable C++11
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
# Enable all warnings
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
# Treat all warnings as errors
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
# Disable "statement has no effect" warnings
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-value")
endif(CMAKE_COMPILER_IS_GNUCXX)
#----------------------------------------------------------------------------
# External libraries
#----------------------------------------------------------------------------
# TClap
find_path(TCLAP_INCLUDE_DIR tclap/CmdLine.h)
# hidapi
find_path(HIDAPI_INCLUDE_DIR hidapi/hidapi.h)
find_library(HIDAPI_LIBRARY hidapi-libusb)
#----------------------------------------------------------------------------
# Overriding functions & setting up global macros
#----------------------------------------------------------------------------
# add_library
function(ADD_LIBRARY name)
_add_library(${name} ${ARGN})
# CMake >= 3.1.0 does not allow to set the INSTALL_RPATH property on INTERFACE_LIBRARY target type
get_target_property(TARGET_TYPE ${name} TYPE)
if(NOT "${TARGET_TYPE}" STREQUAL "INTERFACE_LIBRARY")
set_target_properties(${name} PROPERTIES INSTALL_RPATH "$ORIGIN")
endif(NOT "${TARGET_TYPE}" STREQUAL "INTERFACE_LIBRARY")
endfunction(ADD_LIBRARY)
# add_executable
function(ADD_EXECUTABLE name)
_add_executable(${name} ${ARGN})
set_target_properties(${name} PROPERTIES INSTALL_RPATH "$ORIGIN/../lib")
endfunction(ADD_EXECUTABLE)
#----------------------------------------------------------------------------
# Installation directories
#----------------------------------------------------------------------------
set(BINARY_INSTALL_DIR bin)
set(LIBRARY_INSTALL_DIR lib)
set(INCLUDE_INSTALL_DIR include)
set(SHARED_INSTALL_DIR share)
#--------------------------------------
# Main target
#--------------------------------------
include_directories(
${TCLAP_INCLUDE_DIR}
${HIDAPI_INCLUDE_DIR}
)
add_executable(kbd-light
main.cpp
msi_keyboard.cpp
)
target_link_libraries(kbd-light
${HIDAPI_LIBRARY}
)
install(TARGETS kbd-light
RUNTIME DESTINATION ${BINARY_INSTALL_DIR}
LIBRARY DESTINATION ${LIBRARY_INSTALL_DIR}
ARCHIVE DESTINATION ${LIBRARY_INSTALL_DIR}
)