This repository has been archived by the owner on Aug 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 35
/
CMakeLists.txt
177 lines (156 loc) · 5.44 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
#
# Copyright (c) 2011 Marius Zwicker <[email protected]>
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
cmake_minimum_required(VERSION 3.4.3)
cmake_policy(SET CMP0063 OLD)
project(pthread_workqueue VERSION 0.9.4 LANGUAGES C)
enable_testing()
set(CMAKE_C_VISIBILITY_PRESET hidden)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_STANDARD 99)
option(STATIC_WORKQUEUE "build libpthread_workqueue as static library" OFF)
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
find_package(Threads REQUIRED)
include(CheckIncludeFiles)
include(GNUInstallDirs)
if(ENABLE_TESTING)
check_include_files(err.h HAVE_ERR_H)
# HACK: Avoid generating a config.h for just a single definition
if(HAVE_ERR_H)
add_definitions(-DHAVE_ERR_H=1)
else()
add_definitions(-DHAVE_ERR_H=0)
endif()
add_definitions(-DNO_CONFIG_H)
endif()
set(PTHREAD_WORKQUEUE_HEADERS
include/pthread_workqueue.h)
set(PTHREAD_WORKQUEUE_SOURCES
src/api.c
src/debug.h
src/private.h
src/thread_info.h
src/thread_rt.h
src/witem_cache.c)
if(CMAKE_SYSTEM_NAME MATCHES Windows)
list(APPEND PTHREAD_WORKQUEUE_SOURCES
src/windows/manager.c
src/windows/platform.c
src/windows/platform.h
src/windows/posix_semaphore.h
src/windows/pthread_cond.h
src/windows/pthread_cond_variables.h
src/windows/pthread_create.h
src/windows/pthread_mutex.h
src/windows/pthread_rw_lock.h
src/windows/pthread_tls.h
src/windows/queue.h
src/windows/stdint.h
src/windows/thread_info.c
src/windows/thread_rt.c
src/windows/threads.h
src/windows/times.h)
elseif(CMAKE_SYSTEM_NAME MATCHES "(Solaris|SunOS)")
list(APPEND PTHREAD_WORKQUEUE_SOURCES
src/posix/manager.c
src/posix/platform.h
src/posix/thread_info.c
src/posix/thread_rt.c
src/solaris/load.c
src/solaris/thread_info.c
src/solaris/thread_rt.c)
elseif(CMAKE_SYSTEM_NAME STREQUAL Linux)
list(APPEND PTHREAD_WORKQUEUE_SOURCES
src/posix/manager.c
src/posix/platform.h
src/posix/thread_info.c
src/posix/thread_rt.c
src/linux/load.c
src/linux/thread_info.c
src/linux/thread_rt.c)
elseif(CMAKE_SYSTEM_NAME STREQUAL Android)
list(APPEND PTHREAD_WORKQUEUE_SOURCES
src/posix/manager.c
src/posix/platform.h
src/posix/thread_info.c
src/posix/thread_rt.c
src/linux/load.c
src/linux/thread_info.c
src/linux/thread_rt.c)
else()
message(FATAL_ERROR "unsupported host os")
endif()
source_group(includes
FILES
${PTHREAD_WORKQUEUE_HEADERS})
source_group(src
FILES
${PTHREAD_WORKQUEUE_SOURCES})
if(STATIC_WORKQUEUE)
set(LIBRARY_TYPE STATIC)
else()
set(LIBRARY_TYPE SHARED)
endif()
add_library(pthread_workqueue
${LIBRARY_TYPE}
${PTHREAD_WORKQUEUE_SOURCES}
${PTHREAD_WORKQUEUE_HEADERS})
set_target_properties(pthread_workqueue PROPERTIES DEBUG_POSTFIX "d")
if(WIN32)
target_compile_definitions(pthread_workqueue PRIVATE
LIBPTHREAD_WORKQUEUE_EXPORTS;_USRDLL;_WINDLL)
target_compile_definitions(pthread_workqueue
PRIVATE
_CRT_SECURE_NO_WARNINGS
_CRT_SECURE_NO_WARNINGS_GLOBALS)
else()
target_compile_definitions(pthread_workqueue PRIVATE
_XOPEN_SOURCE=600;_GNU_SOURCE)
endif()
if(STATIC_WORKQUEUE)
target_compile_definitions(pthread_workqueue PRIVATE MAKE_STATIC)
endif()
target_include_directories(pthread_workqueue PRIVATE include)
if(NOT WIN32)
target_include_directories(pthread_workqueue PRIVATE src)
endif()
target_link_libraries(pthread_workqueue PUBLIC Threads::Threads)
if(ENABLE_TESTING)
add_subdirectory(testing)
endif()
configure_file("${PROJECT_SOURCE_DIR}/libpthread_workqueue.pc.in"
"${CMAKE_BINARY_DIR}/libpthread_workqueue.pc")
install(TARGETS
pthread_workqueue
DESTINATION
${CMAKE_INSTALL_FULL_LIBDIR})
install(FILES
${PTHREAD_WORKQUEUE_HEADERS}
DESTINATION
${CMAKE_INSTALL_FULL_INCLUDEDIR})
install(FILES
${PROJECT_SOURCE_DIR}/pthread_workqueue.3
DESTINATION
${CMAKE_INSTALL_FULL_MANDIR})
install(FILES
${CMAKE_BINARY_DIR}/libpthread_workqueue.pc
DESTINATION
${CMAKE_INSTALL_FULL_LIBDIR}/pkgconfig)
set(CPACK_PACKAGE_NAME ${PACKAGE_NAME})
set(CPACK_PACKAGE_VERSION ${PACKAGE_VERSION})
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Mark Heily <[email protected]>")
include(CPack)