-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
130 lines (110 loc) · 4.14 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
project(dpm C)
include(UsePkgConfig)
# Cmake < 2.4.6 does not have FindPkgConfig
include(FindPkgConfig OPTIONAL)
cmake_minimum_required(VERSION 2.4.5)
option(DEBUG "Compile DPM in DEBUG mode")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wno-unused-parameter")
#
# TODO: Also make this pass -DDEBUG to the compilation phase.
#
if(DEBUG)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g")
message("Compiling in debug mode")
else(DEBUG)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2")
message("Compiling in optimized mode")
endif(DEBUG)
#
# locate pkgconfig - only verify if pkgconfig exists
# This is an extra verification step if FindPkgConfig exists.
# We use the variables exposed by UsePkgConfig instead.
#
if(PKG_CONFIG_FOUND)
message(STATUS "Using pkg-config")
pkg_check_modules(LUA lua>=5.1)
if(NOT LUA_VERSION)
pkg_check_modules(LUA lua51>=5.1)
if (NOT LUA_VERSION)
message(SEND_ERROR "lua 5.1 was not found (via find pkgconfig)")
endif(NOT LUA_VERSION)
endif(NOT LUA_VERSION)
endif(PKG_CONFIG_FOUND)
#
# locate lua via pkgconfig. debian uses versioned lua${ver}.pc files.
#
if(PKGCONFIG_EXECUTABLE)
pkgconfig("lua5.1" LUA_INCLUDE_DIR LUA_LINK_DIR LUA_LDFLAGS LUA_CFLAGS)
if(NOT LUA_INCLUDE_DIR)
pkgconfig("lua" LUA_INCLUDE_DIR LUA_LINK_DIR LUA_LDFLAGS LUA_CFLAGS)
if(NOT LUA_INCLUDE_DIR)
message(SEND_ERROR "lua 5.1 was not found (via use pkgconfig)")
endif(NOT LUA_INCLUDE_DIR)
endif(NOT LUA_INCLUDE_DIR)
endif(PKGCONFIG_EXECUTABLE)
#
# If there is no pkg-config, emulate FIND_PACKAGE behavior to locate lua.
#
if(NOT LUA_INCLUDE_DIR)
find_path(LUA_INCLUDE_DIR NAMES lua.h PATHS /usr/local/include PATH_SUFFIXES lua51)
find_library(LUA_LIBRARY NAMES lua PATHS /usr/local/lib PATH_SUFFIXES lua51)
if(LUA_INCLUDE_DIR AND LUA_LIBRARY)
set(LUA_MANUALLY_FOUND TRUE)
# Lua's always bound to -lm so far as I know...
set(LUA_LDFLAGS "-lm")
endif(LUA_INCLUDE_DIR AND LUA_LIBRARY)
if(NOT LUA_MANUALLY_FOUND)
message(FATAL_ERROR "Lua 5.1 was not found (via scanning)")
endif(NOT LUA_MANUALLY_FOUND)
endif(NOT LUA_INCLUDE_DIR)
if(VERBOSE)
message("${LUA_INCLUDE_DIR} ${LUA_LINK_DIR} ${LUA_LDFLAGS} ${LUA_CFLAGS}")
endif(VERBOSE)
#
# libevent doesn't have a pkgconfig file,
# so we have to make some assumptions (user can override)
#
if(NOT LIBEVENT_PREFIX)
find_path(LIBEVENT_INCLUDE_DIR NAMES event.h)
find_library(LIBEVENT_LIBRARY NAMES event)
if(LIBEVENT_INCLUDE_DIR AND LIBEVENT_LIBRARY)
set(LIBEVENT_FOUND TRUE)
endif(LIBEVENT_INCLUDE_DIR AND LIBEVENT_LIBRARY)
if(NOT LIBEVENT_FOUND AND NOT LIBEVENT_PREFIX)
message(FATAL_ERROR "libevent library or header not found. Retry with -DLIBEVENT_PREFIX='/path/to/your/libevent'")
endif(NOT LIBEVENT_FOUND AND NOT LIBEVENT_PREFIX)
endif(NOT LIBEVENT_PREFIX)
if(LIBEVENT_PREFIX)
set(LIBEVENT_INCLUDE_DIR "${LIBEVENT_PREFIX}/include")
set(LIBEVENT_LINK_DIR "${LIBEVENT_PREFIX}/lib")
set(LIBEVENT_LDFLAGS "-levent")
if(NOT EXISTS "${LIBEVENT_INCLUDE_DIR}/event.h")
message(FATAL_ERROR "libevent's event.h header not found. Retry with -DLIBEVENT_PREFIX='/path/to/your/libevent'")
endif(NOT EXISTS "${LIBEVENT_INCLUDE_DIR}/event.h")
endif(LIBEVENT_PREFIX)
#
# all files compiled in this directory get these additional paths
#
include_directories(${LUA_INCLUDE_DIR} ${LIBEVENT_INCLUDE_DIR})
link_directories(${LUA_LINK_DIR} ${LIBEVENT_LINK_DIR})
#
# compile to 'dpm'
#
add_executable(dpm sha1.c luaobj.c dpm.c)
set_target_properties(dpm PROPERTIES
COMPILE_FLAGS "${LUA_CFLAGS} ${LIBEVENT_CFLAGS}"
LINK_FLAGS "${LUA_LDFLAGS} ${LIBEVENT_LDFLAGS}")
add_definitions(-DDPMLIBDIR="\\"${CMAKE_INSTALL_PREFIX}/dpm\\"")
if(LUA_MANUALLY_FOUND)
message(STATUS "Linking with manually detected lua")
target_link_libraries(dpm ${LUA_LIBRARY})
endif(LUA_MANUALLY_FOUND)
if(LIBEVENT_FOUND)
message(STATUS "Linking with manually detected libevent")
target_link_libraries(dpm ${LIBEVENT_LIBRARY})
endif(LIBEVENT_FOUND)
#
# install phase - we have the proxy binary and lua libraries.
#
install(TARGETS dpm RUNTIME DESTINATION bin)
install(DIRECTORY lua DESTINATION dpm)