forked from acdemiralp/hid.hpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
86 lines (75 loc) · 4.19 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
################################################## Project ##################################################
cmake_minimum_required(VERSION 3.12 FATAL_ERROR)
project (hid VERSION 1.0 LANGUAGES CXX)
list (APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
set_property (GLOBAL PROPERTY USE_FOLDERS ON)
set (CMAKE_BUILD_TYPE Release)
set (CMAKE_CXX_STANDARD 23)
if (MSVC)
add_compile_options (/W4)
else ()
add_compile_options (-Wall -Wextra -pedantic)
endif()
################################################## Options ##################################################
option(BUILD_TESTS "Build tests." OFF)
################################################## Sources ##################################################
file(GLOB_RECURSE PROJECT_HEADERS include/*.h include/*.hpp include/*.ipp)
file(GLOB_RECURSE PROJECT_CMAKE_UTILS cmake/*.cmake)
file(GLOB_RECURSE PROJECT_MISC *.bat *.gitignore *.md *.py *.sh *.txt)
set (PROJECT_FILES
${PROJECT_HEADERS}
${PROJECT_CMAKE_UTILS}
${PROJECT_MISC})
include (assign_source_group)
assign_source_group(${PROJECT_FILES})
################################################## Dependencies ##################################################
if (BUILD_TESTS)
find_package(doctest CONFIG REQUIRED)
list (APPEND PROJECT_LIBRARIES doctest::doctest)
find_package(hidapi CONFIG REQUIRED)
list (APPEND PROJECT_LIBRARIES hidapi::hidapi hidapi::winapi hidapi::include)
endif()
################################################## Targets ##################################################
add_library(${PROJECT_NAME} INTERFACE)
target_include_directories(${PROJECT_NAME} INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
$<INSTALL_INTERFACE:include>)
target_include_directories(${PROJECT_NAME} INTERFACE ${PROJECT_INCLUDE_DIRS})
target_link_libraries (${PROJECT_NAME} INTERFACE ${PROJECT_LIBRARIES})
target_compile_definitions(${PROJECT_NAME} INTERFACE ${PROJECT_COMPILE_DEFINITIONS})
target_compile_options (${PROJECT_NAME} INTERFACE ${PROJECT_COMPILE_OPTIONS})
# Hack for header-only project to appear in the IDEs.
add_library(${PROJECT_NAME}_ STATIC ${PROJECT_FILES})
target_include_directories(${PROJECT_NAME}_ PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_BINARY_DIR})
target_include_directories(${PROJECT_NAME}_ PUBLIC ${PROJECT_INCLUDE_DIRS})
target_link_libraries (${PROJECT_NAME}_ PUBLIC ${PROJECT_LIBRARIES})
target_compile_definitions(${PROJECT_NAME}_ PUBLIC ${PROJECT_COMPILE_DEFINITIONS})
target_compile_options (${PROJECT_NAME}_ PUBLIC ${PROJECT_COMPILE_OPTIONS})
set_target_properties (${PROJECT_NAME}_ PROPERTIES LINKER_LANGUAGE CXX)
################################################## Testing ##################################################
if(BUILD_TESTS)
enable_testing ()
set (TEST_MAIN_NAME test_main)
set (TEST_MAIN_SOURCES tests/internal/main.cpp)
add_library (${TEST_MAIN_NAME} OBJECT ${TEST_MAIN_SOURCES})
target_link_libraries(${TEST_MAIN_NAME} ${PROJECT_NAME})
set_property (TARGET ${TEST_MAIN_NAME} PROPERTY FOLDER tests)
assign_source_group (${TEST_MAIN_SOURCES})
file(GLOB PROJECT_TEST_CPPS tests/*.c tests/*.cpp tests/*.cu)
foreach(_SOURCE ${PROJECT_TEST_CPPS})
get_filename_component(_NAME ${_SOURCE} NAME_WE)
add_executable (${_NAME} ${_SOURCE} $<TARGET_OBJECTS:${TEST_MAIN_NAME}>)
target_link_libraries (${_NAME} ${PROJECT_NAME} ${PROJECT_LIBRARIES})
add_test (${_NAME} ${_NAME})
set_property (TARGET ${_NAME} PROPERTY FOLDER tests)
assign_source_group (${_SOURCE})
endforeach()
endif()
################################################## Installation ##################################################
install(TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME}-config)
install(DIRECTORY include/ DESTINATION include)
install(EXPORT ${PROJECT_NAME}-config NAMESPACE ${PROJECT_NAME}:: DESTINATION cmake)
export (TARGETS ${PROJECT_NAME} NAMESPACE ${PROJECT_NAME}:: FILE ${PROJECT_NAME}-config.cmake)