forked from Lupus/libevfibers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
177 lines (158 loc) · 5.43 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
cmake_minimum_required(VERSION 2.8.7)
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
# We are building as stand-alone project
project(libevfibers C)
else()
# We are building as part of other project
set(EVFIBERS_EMBED TRUE)
endif()
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
if(NOT CMAKE_BUILD_TYPE)
message(STATUS "No build type selected, defaulting to RelWithDebInfo")
set(CMAKE_BUILD_TYPE "RelWithDebInfo")
endif(NOT CMAKE_BUILD_TYPE)
set(VERSION_MAJOR 0)
set(VERSION_MINOR 4)
set(VERSION_PATCH 1)
set(VERSION_STRING "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
include(CheckIncludeFiles)
if(NOT DEFINED WANT_EIO)
message(STATUS "WANT_EIO flag not specified, defaulting to TRUE")
set(WANT_EIO TRUE)
endif(NOT DEFINED WANT_EIO)
aux_source_directory("${CMAKE_CURRENT_SOURCE_DIR}/src" EVFIBERS_SOURCES)
aux_source_directory("${CMAKE_CURRENT_SOURCE_DIR}/coro" CORO_SOURCES)
find_package(LibEv REQUIRED)
if(WANT_EIO)
find_package(Threads)
if(WANT_EMBEDDED_EIO)
include(ExternalProject)
ExternalProject_Add(
libeio
PREFIX "${CMAKE_CURRENT_BINARY_DIR}/eio"
CVS_REPOSITORY :pserver:[email protected]/schmorpforge
CVS_MODULE libeio
CVS_TAG -r rel-4_32
UPDATE_COMMAND ""
CONFIGURE_COMMAND CFLAGS=-fpic ./configure --enable-static --disable-shared --prefix=${CMAKE_CURRENT_BINARY_DIR}/eio
BUILD_IN_SOURCE 1
)
ExternalProject_Add_Step(libeio autogen
COMMAND "./autogen.sh"
DEPENDEES update
DEPENDERS configure
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/eio/src/libeio"
)
ExternalProject_Add_Step(libeio autoconf
COMMAND "autoconf"
DEPENDEES autogen
DEPENDERS configure
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/eio/src/libeio"
)
ExternalProject_Add_Step(libeio mvembedheader
COMMAND mv ${CMAKE_CURRENT_BINARY_DIR}/eio/include/eio.h ${CMAKE_CURRENT_BINARY_DIR}/include/evfibers/libeio_embedded.h
DEPENDEES install
)
set(LIBEIO_INCLUDE_DIR "${CMAKE_CURRENT_BINARY_DIR}/eio/include")
set(LIBEIO_LIBRARY "-L${CMAKE_CURRENT_BINARY_DIR}/eio/lib -Wl,-whole-archive -leio -Wl,-no-whole-archive ${CMAKE_THREAD_LIBS_INIT}")
set(LIBEIO_FOUND TRUE)
set(FBR_USE_EMBEDDED_EIO TRUE)
else(WANT_EMBEDDED_EIO)
find_package(LibEio)
endif(WANT_EMBEDDED_EIO)
endif(WANT_EIO)
if(WANT_ASAN)
# Force ucontext.h as libcoro backend so as to better interact with ASan
add_definitions(-DCORO_UCONTEXT)
endif(WANT_ASAN)
if(WANT_VALGRIND)
check_include_files(valgrind/valgrind.h HAVE_VALGRIND_H)
if (NOT HAVE_VALGRIND_H)
message(FATAL_ERROR "cannot find valgrind.h")
endif(NOT HAVE_VALGRIND_H)
endif(WANT_VALGRIND)
include_directories(
"${CMAKE_CURRENT_SOURCE_DIR}/include"
"${CMAKE_CURRENT_BINARY_DIR}/include"
"${CMAKE_CURRENT_SOURCE_DIR}/coro"
${LIBEV_INCLUDE_DIR}
${LIBEIO_INCLUDE_DIR}
)
if(WANT_LTO)
set(LTO_FLAGS "-flto")
endif(WANT_LTO)
if(WANT_ASAN)
set(ASAN_FLAGS "-fsanitize=address")
endif(WANT_ASAN)
set(CMAKE_C_FLAGS "-W -Wall -Werror -fno-strict-aliasing ${LTO_FLAGS} ${ASAN_FLAGS} ${CMAKE_C_FLAGS}")
set(SOURCES ${EVFIBERS_SOURCES} ${CORO_SOURCES})
add_library(evfibers SHARED ${SOURCES})
set_target_properties(evfibers
PROPERTIES
SOVERSION ${VERSION_MAJOR}
VERSION ${VERSION_STRING}
)
target_link_libraries(evfibers
${LIBEV_LIBRARY}
${LIBEIO_LIBRARY}
${CMAKE_THREAD_LIBS_INIT})
if(WANT_EIO AND WANT_EMBEDDED_EIO)
add_dependencies(evfibers libeio)
endif(WANT_EIO AND WANT_EMBEDDED_EIO)
add_library(evfibers_static STATIC ${SOURCES})
set_target_properties(evfibers_static PROPERTIES
OUTPUT_NAME evfibers
COMPILE_FLAGS "-fPIC")
if(EVFIBERS_EMBED)
set(EVFIBERS_EMBED_LIBS evfibers_static
${LIBEV_LIBRARY}
${LIBEIO_LIBRARY}
${CMAKE_THREAD_LIBS_INIT}
PARENT_SCOPE)
endif(EVFIBERS_EMBED)
add_executable(fiber_bench_buffer "${CMAKE_CURRENT_SOURCE_DIR}/bench/buffer.c")
target_link_libraries(fiber_bench_buffer evfibers ${CMAKE_THREAD_LIBS_INIT})
add_executable(fiber_bench_condvar "${CMAKE_CURRENT_SOURCE_DIR}/bench/condvar.c")
target_link_libraries(fiber_bench_condvar evfibers ${CMAKE_THREAD_LIBS_INIT})
# Variables for config.h
if(WANT_EIO AND THREADS_FOUND AND LIBEIO_FOUND)
set(FBR_EIO_ENABLED TRUE)
message(STATUS "libeio support has been ENABLED")
else(WANT_EIO AND THREADS_FOUND AND LIBEIO_FOUND)
message(STATUS "libeio support has been DISABLED")
endif(WANT_EIO AND THREADS_FOUND AND LIBEIO_FOUND)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/include/evfibers/config.h.in"
"${CMAKE_CURRENT_BINARY_DIR}/include/evfibers/config.h")
# provide pkg-config file
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/libevfibers.pc.in
${CMAKE_CURRENT_BINARY_DIR}/libevfibers.pc @ONLY
)
install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/libevfibers.pc
DESTINATION
"lib/pkgconfig"
)
subdirs(test)
if(NOT EVFIBERS_EMBED)
install(TARGETS evfibers
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
)
install(TARGETS evfibers_static
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
)
file(GLOB DEV_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/include/evfibers/*.h")
file(GLOB DEV_HEADERS2 "${CMAKE_CURRENT_BINARY_DIR}/include/evfibers/*.h")
install(FILES ${DEV_HEADERS} ${DEV_HEADERS2}
DESTINATION "include/evfibers")
if(WANT_EMBEDDED_EIO)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/include/evfibers/libeio_embedded.h
DESTINATION "include/evfibers")
endif(WANT_EMBEDDED_EIO)
endif(NOT EVFIBERS_EMBED)