-
Notifications
You must be signed in to change notification settings - Fork 101
/
CMakeLists.txt
198 lines (165 loc) · 5.42 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
cmake_minimum_required(VERSION 3.15 FATAL_ERROR)
project(efsw)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_CXX_STANDARD 11)
set(ESFW_MAIN_PROJECT OFF)
if((CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) AND(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME))
set(ESFW_MAIN_PROJECT ON)
endif()
include(GNUInstallDirs)
find_package(Threads REQUIRED)
option(VERBOSE "Build efsw with verbose mode.")
option(BUILD_SHARED_LIBS "Build efsw as a shared library" ON)
option(BUILD_STATIC_LIBS "Build efsw as a static library" ON)
option(BUILD_TEST_APP "Build the test app" ${ESFW_MAIN_PROJECT})
option(EFSW_INSTALL "Add efsw install targets" ${ESFW_MAIN_PROJECT})
add_library(efsw)
if(BUILD_STATIC_LIBS)
add_library(efsw-static STATIC)
target_include_directories(efsw-static
PRIVATE src/
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
endif()
set(EFSW_CPP_SOURCE
src/efsw/Debug.cpp
src/efsw/DirectorySnapshot.cpp
src/efsw/DirectorySnapshotDiff.cpp
src/efsw/DirWatcherGeneric.cpp
src/efsw/FileInfo.cpp
src/efsw/FileSystem.cpp
src/efsw/FileWatcher.cpp
src/efsw/FileWatcherCWrapper.cpp
src/efsw/FileWatcherGeneric.cpp
src/efsw/FileWatcherImpl.cpp
src/efsw/Log.cpp
src/efsw/Mutex.cpp
src/efsw/String.cpp
src/efsw/System.cpp
src/efsw/Thread.cpp
src/efsw/Watcher.cpp
src/efsw/WatcherGeneric.cpp
)
target_include_directories(efsw
PRIVATE src/
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
if(VERBOSE)
target_compile_definitions(efsw PRIVATE EFSW_VERBOSE)
endif()
target_compile_features(efsw PRIVATE cxx_std_11)
if(BUILD_SHARED_LIBS)
target_compile_definitions(efsw PRIVATE EFSW_DYNAMIC EFSW_EXPORTS)
endif()
# platforms
if(WIN32)
list(APPEND EFSW_CPP_SOURCE
src/efsw/platform/win/FileSystemImpl.cpp
src/efsw/platform/win/MutexImpl.cpp
src/efsw/platform/win/SystemImpl.cpp
src/efsw/platform/win/ThreadImpl.cpp
)
else()
list(APPEND EFSW_CPP_SOURCE
src/efsw/platform/posix/FileSystemImpl.cpp
src/efsw/platform/posix/MutexImpl.cpp
src/efsw/platform/posix/SystemImpl.cpp
src/efsw/platform/posix/ThreadImpl.cpp
)
endif()
# watcher implementations
if(APPLE)
list(APPEND EFSW_CPP_SOURCE
src/efsw/FileWatcherFSEvents.cpp
src/efsw/FileWatcherKqueue.cpp
src/efsw/WatcherFSEvents.cpp
src/efsw/WatcherKqueue.cpp
)
elseif(WIN32)
list(APPEND EFSW_CPP_SOURCE
src/efsw/FileWatcherWin32.cpp
src/efsw/WatcherWin32.cpp
)
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
list(APPEND EFSW_CPP_SOURCE
src/efsw/FileWatcherInotify.cpp
src/efsw/WatcherInotify.cpp
)
find_path(EFSW_INOTIFY_H NAMES sys/inotify.h NO_CACHE)
if(EFSW_INOTIFY_H STREQUAL "EFSW_INOTIFY_H-NOTFOUND")
target_compile_definitions(efsw PRIVATE EFSW_INOTIFY_NOSYS)
endif()
elseif(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
list(APPEND EFSW_CPP_SOURCE
src/efsw/FileWatcherKqueue.cpp
src/efsw/WatcherKqueue.cpp
)
endif()
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" OR
(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC"))
target_compile_definitions(efsw PRIVATE _SCL_SECURE_NO_WARNINGS)
else()
target_compile_options(efsw PRIVATE -Wall -Wno-long-long -fPIC)
endif()
target_compile_definitions(efsw PRIVATE $<IF:$<CONFIG:Debug>,DEBUG,NDEBUG>)
if(APPLE)
set(MAC_LIBS "-framework CoreFoundation" "-framework CoreServices")
target_link_libraries(efsw PRIVATE ${MAC_LIBS})
if(BUILD_STATIC_LIBS)
target_link_libraries(efsw-static PRIVATE ${MAC_LIBS})
endif()
elseif(NOT(${CMAKE_SYSTEM_NAME} MATCHES "Haiku") AND NOT WIN32)
target_link_libraries(efsw PRIVATE Threads::Threads)
endif()
target_sources(efsw PRIVATE ${EFSW_CPP_SOURCE})
if(BUILD_STATIC_LIBS)
target_sources(efsw-static PRIVATE ${EFSW_CPP_SOURCE})
endif()
include(CMakePackageConfigHelpers)
set(packageDestDir "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
configure_package_config_file(
${CMAKE_CURRENT_SOURCE_DIR}/efswConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/cmake/efswConfig.cmake
INSTALL_DESTINATION "${packageDestDir}"
NO_SET_AND_CHECK_MACRO
NO_CHECK_REQUIRED_COMPONENTS_MACRO
)
export(TARGETS efsw NAMESPACE efsw:: FILE ${CMAKE_CURRENT_BINARY_DIR}/cmake/${PROJECT_NAME}Targets.cmake)
if(BUILD_STATIC_LIBS)
export(TARGETS efsw-static NAMESPACE efsw:: APPEND FILE ${CMAKE_CURRENT_BINARY_DIR}/cmake/${PROJECT_NAME}Targets.cmake)
endif()
if(EFSW_INSTALL)
install(TARGETS efsw EXPORT efswExport
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
install(
FILES
include/efsw/efsw.h include/efsw/efsw.hpp
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/efsw
)
if(BUILD_STATIC_LIBS)
install(TARGETS efsw-static EXPORT efswExport
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
endif()
install(EXPORT efswExport NAMESPACE efsw:: DESTINATION "${packageDestDir}" FILE ${PROJECT_NAME}Targets.cmake)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/cmake/efswConfig.cmake DESTINATION "${packageDestDir}")
endif()
if(BUILD_TEST_APP)
# C++ test application
add_executable(efsw-test src/test/efsw-test.cpp)
target_link_libraries(efsw-test efsw-static)
# C test application
add_executable(efsw-test-stdc src/test/efsw-test.c)
target_link_libraries(efsw-test-stdc efsw-static)
endif()