-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy pathCMakeLists.txt
74 lines (65 loc) · 2.47 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
cmake_minimum_required (VERSION 2.8.12)
project(Levent)
set(levent_cmake "config.cmake")
if (EXISTS $ENV{LEVENT_CMAKE})
set(levent_cmake $ENV{LEVENT_CMAKE})
endif()
include(${levent_cmake})
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -ggdb")
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -save-temps")
#message("name:${CMAKE_SYSTEM_NAME}")
#message("linker flags:${CMAKE_SHARED_LINKER_FLAGS}")
#message("compiler: ${CMAKE_C_COMPILER}")
include_directories(${LUA_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/deps/http-parser)
include_directories(${LUA_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/deps/libev)
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/deps/libev/.libs/)
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set(CMAKE_SHARED_LINKER_FLAGS "-undefined dynamic_lookup")
endif()
add_definitions(-DHTTP_PARSER_STRICT=0)
if(WIN32)
set(suffix ".dll")
add_definitions(-DLUA_BUILD_AS_DLL -DLUA_LIB -DHTTP_PARSER_STRICT=0)
else()
set(suffix ".so")
endif()
if(APPLE)
include_directories(${LUA_INCLUDE_DIR} /usr/local/opt/openssl/include)
set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH};/usr/local/opt/openssl/lib)
endif()
macro (add_lua_library lname)
add_library(${lname} SHARED ${ARGN})
if(WIN32)
target_link_libraries(${lname} ${LUA_LIBRARIES})
endif()
set_target_properties(${lname} PROPERTIES PREFIX "")
set_target_properties(${lname} PROPERTIES SUFFIX ${suffix})
endmacro()
# levent.module
set(CSOURCE src/lua-socket.c src/lua-errno.c src/lua-levent.c src/lua-ev.c src/lua-http-parser.c deps/http-parser/http_parser.c)
set(CMONGO cext/lua-mongo.c)
set(CBSON cext/lua-bson.c)
set(CRYPTO cext/luacrypto/lcrypto.c)
find_library(CRYPTOLIB NAMES crypto)
IF(NOT WIN32)
add_lua_library(levent ${CSOURCE})
# ignore compile warning: incompatible-pointer-types
target_compile_options(levent PRIVATE -Wno-incompatible-pointer-types)
target_link_libraries(levent ev)
add_custom_command(TARGET levent
PRE_BUILD
COMMAND CFLAGS=-fPIC ./configure --enable-shared=no
COMMAND make
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/deps/libev)
add_lua_library(mongo ${CMONGO})
add_lua_library(bson ${CBSON})
add_lua_library(crypto ${CRYPTO})
target_link_libraries(crypto ${CRYPTOLIB})
ELSE()
set(CSOURCE ${CSOURCE} src/evwrap.c)
add_lua_library(levent ${CSOURCE})
add_lua_library(mongo ${CMONGO})
add_lua_library(bson ${CBSON})
add_lua_library(crypto ${CRYPTO})
target_link_libraries(crypto ${CRYPTOLIB})
ENDIF()