-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCMakeLists.txt
130 lines (112 loc) · 3.28 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
130
cmake_minimum_required(VERSION 3.17)
project(zero)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
set(ZERO_VERSION 1.0.9)
option(BUILD_SHARED_LIBS "Build using shared libraries" OFF)
if (BUILD_SHARED_LIBS AND MSVC)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
endif ()
include(CTest)
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
find_package(Iconv REQUIRED)
find_package(Threads REQUIRED)
find_package(fmt CONFIG REQUIRED)
add_library(
zero
src/log.cpp
src/env.cpp
src/cmdline.cpp
src/os/os.cpp
src/os/net.cpp
src/os/stat.cpp
src/os/process.cpp
src/atomic/event.cpp
src/concurrent/channel.cpp
src/encoding/hex.cpp
src/encoding/base64.cpp
src/strings/strings.cpp
src/filesystem/fs.cpp
$<$<PLATFORM_ID:Windows>:src/os/windows/error.cpp src/os/windows/process.cpp>
$<$<PLATFORM_ID:Darwin>:src/os/macos/error.cpp src/os/macos/process.cpp>
$<$<PLATFORM_ID:Linux,Android>:src/os/linux/process.cpp src/os/linux/procfs/procfs.cpp src/os/linux/procfs/process.cpp>
)
target_include_directories(
zero
PUBLIC
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
)
target_link_libraries(
zero
PRIVATE
Iconv::Iconv
Threads::Threads
$<$<PLATFORM_ID:Windows>:Ws2_32>
$<$<PLATFORM_ID:Windows>:Iphlpapi>
PUBLIC
fmt::fmt
)
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
set(
EXCLUDE_HEADERS
${EXCLUDE_HEADERS}
PATTERN "os/unix" EXCLUDE
PATTERN "os/macos" EXCLUDE
PATTERN "os/linux" EXCLUDE
)
endif ()
if (CMAKE_SYSTEM_NAME MATCHES "Linux|Android")
set(
EXCLUDE_HEADERS
${EXCLUDE_HEADERS}
PATTERN "os/windows" EXCLUDE
PATTERN "os/macos" EXCLUDE
)
endif ()
if (CMAKE_SYSTEM_NAME MATCHES "Darwin")
set(
EXCLUDE_HEADERS
${EXCLUDE_HEADERS}
PATTERN "os/windows" EXCLUDE
PATTERN "os/linux" EXCLUDE
)
endif ()
install(
DIRECTORY
include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
${EXCLUDE_HEADERS}
)
install(
TARGETS zero
EXPORT ${PROJECT_NAME}Targets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
install(
EXPORT ${PROJECT_NAME}Targets
NAMESPACE zero::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
)
configure_package_config_file(
cmake/${PROJECT_NAME}-config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
)
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
VERSION ${ZERO_VERSION}
COMPATIBILITY SameMajorVersion
)
install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
)
if (BUILD_TESTING)
add_subdirectory(test)
endif ()