-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathCMakeLists.txt
115 lines (86 loc) · 2.99 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
cmake_minimum_required (VERSION 3.10.0)
# Fix behavior of CMAKE_CXX_STANDARD when targeting macOS.
if (POLICY CMP0025)
cmake_policy(SET CMP0025 NEW)
endif ()
# Fix a warning on macOS.
if (POLICY CMP0042)
cmake_policy(SET CMP0042 NEW)
endif ()
# Don't use -rdynamic since it breaks causes musl static linking.
if (POLICY CMP0065)
cmake_policy(SET CMP0065 NEW)
endif ()
project (libusbp)
set (LIBUSBP_VERSION_MAJOR 1)
set (LIBUSBP_VERSION_MINOR 3)
set (LIBUSBP_VERSION_PATCH 1)
# Make 'Release' be the default build type, since the debug builds
# include exported symbols that might cause name conflicts.
if (NOT CMAKE_BUILD_TYPE)
set (CMAKE_BUILD_TYPE "Release" CACHE STRING
"Options are Debug Release RelWithDebInfo MinSizeRel" FORCE)
endif ()
option (BUILD_SHARED_LIBS "Build as shared library" TRUE)
if (NOT BUILD_SHARED_LIBS)
add_definitions (-DLIBUSBP_STATIC)
set (PC_MORE_CFLAGS "-DLIBUSBP_STATIC")
endif ()
set(ENABLE_EXAMPLES FALSE CACHE BOOL
"True if you want to build the examples.")
set(ENABLE_TESTS FALSE CACHE BOOL
"True if you want to build the tests.")
set(LIBUSBP_LOG FALSE CACHE BOOL
"Output log messages to stderr for debugging.")
set(VBOX_LINUX_ON_WINDOWS FALSE CACHE BOOL
"Skip tests known to cause problems on a Linux VirtualBox guest on Windows.")
set(ENABLE_GCOV FALSE CACHE BOOL
"Compile with special options needed for gcov.")
set (CMAKE_C_STANDARD 99)
set (CMAKE_CXX_STANDARD 11)
set (LIBUSBP_VERSION ${LIBUSBP_VERSION_MAJOR}.${LIBUSBP_VERSION_MINOR}.${LIBUSBP_VERSION_PATCH})
if (CMAKE_VERSION VERSION_GREATER "2.8.10")
string(TIMESTAMP YEAR "%Y")
endif ()
find_package(PkgConfig)
# Put libraries and executables in the top level of the build directory
# so that the executables can find the libraries and it is easy to run
# everything.
set (CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
# Warn about everything.
if (MSVC)
set (CMAKE_C_FLAGS "/Wall ${CMAKE_C_FLAGS}")
set (CMAKE_CXX_FLAGS "/Wall ${CMAKE_CXX_FLAGS}")
else()
set (CMAKE_C_FLAGS "-Wall -Wextra -pedantic ${CMAKE_C_FLAGS}")
set (CMAKE_CXX_FLAGS "-Wall -Wextra -pedantic ${CMAKE_CXX_FLAGS}")
endif()
if (ENABLE_GCOV)
set (CMAKE_C_FLAGS "-fprofile-arcs -ftest-coverage ${CMAKE_C_FLAGS}")
endif ()
if (WIN32)
# Enable correct behavior for the return value of vsnprintf.
add_definitions (-D__USE_MINGW_ANSI_STDIO=1)
# Enable functions only available in Windows Vista and later,
# such as StringCompareEx.
add_definitions (-D_WIN32_WINNT=0x0600 -DNTDDI_VERSION=0x06000000)
endif ()
# Detect Linux.
if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
set (LINUX 1)
endif ()
# Install the header files into include/
install(FILES include/libusbp.h include/libusbp.hpp
DESTINATION "include/libusbp-${LIBUSBP_VERSION_MAJOR}")
add_subdirectory (src)
if (ENABLE_TESTS)
add_subdirectory (test)
add_subdirectory (manual_tests)
endif ()
if (ENABLE_EXAMPLES)
add_subdirectory (examples)
endif ()
if (WIN32)
add_subdirectory (install_helper)
endif ()