-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
90 lines (67 loc) · 3.11 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
cmake_minimum_required(VERSION 3.5)
project(snip)
set(SNIP_VERSION 0.1)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} "/usr/lib/" "/usr/local/lib/")
set(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "/usr/include/" "/usr/local/include/")
set(CMAKE_C_STANDARD 99)
find_package( Threads )
option(SNIP__DOWNLOAD_AND_BUILD_DEPENDENCIES
"Download and build dependencies files." OFF)
if(SNIP__DOWNLOAD_AND_BUILD_DEPENDENCIES)
if(NOT EXISTS "${CMAKE_SOURCE_DIR}/third_party/libevent/include/event2/event.h")
execute_process(COMMAND "git" "clone" "-b" "patches-2.1" "https://github.com/libevent/libevent.git" "${CMAKE_SOURCE_DIR}/third_party/libevent")
endif()
set(EVENT__DISABLE_OPENSSL ON)
set(EVENT__DISABLE_TESTS ON)
add_subdirectory("third_party/libevent")
# set(LIBEVENT_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/third_party/libevent/include")
if(NOT EXISTS "${CMAKE_SOURCE_DIR}/third_party/libyaml/include/yaml.h")
execute_process(COMMAND "git" "clone" "https://github.com/yaml/libyaml.git" "${CMAKE_SOURCE_DIR}/third_party/libyaml")
endif()
add_subdirectory("third_party/libyaml")
set(LibYAML_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/third_party/libyaml/include")
set(LIBS ${LIBS} event yaml)
else ()
find_package(LibYAML)
include_directories(${LibYAML_INCLUDE_DIRS})
if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
find_package(Libevent 2.1 REQUIRED libevent windows)
else()
find_package(Libevent 2.1 REQUIRED libevent pthreads)
endif()
set(LIBS ${LIBS} ${LIBEVENT_LIBRARIES} ${LibYAML_LIBRARIES})
endif()
include_directories(${LIBEVENT_INCLUDE_DIRS})
include_directories(${LibYAML_INCLUDE_DIRS})
#find_package(OpenSSL REQUIRED)
#include_directories(${OPENSSL_INCLUDE_DIR})
#set(LIBS ${LIBS} ${OPENSSL_LIBRARIES})
set(SOURCE_FILES snip.c snip.h tls.h compat.h config.c config.h log.c log.h net_util.c net_util.h sys_util.c sys_util.h tls.c)
add_executable(snip main.c ${SOURCE_FILES})
target_link_libraries(snip ${CMAKE_THREAD_LIBS_INIT} )
target_compile_definitions(snip
PUBLIC SNIP_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
PUBLIC SNIP_INSTALL_CONF_DIR="${CMAKE_INSTALL_PREFIX}etc/"
PUBLIC SNIP_INSTALL_CONF_PATH="${CMAKE_INSTALL_CONF_DIR}snip.yml"
PUBLIC SNIP_VERSION="${SNIP_VERSION}"
)
add_subdirectory(tests)
target_link_libraries(snip ${LIBS})
# We build this as a library so we can test with it. May eventually make it available this way also though.
add_library(snip_lib ${SOURCE_FILES})
target_compile_definitions(snip_lib
PUBLIC SNIP_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
PUBLIC SNIP_INSTALL_CONF_DIR="${CMAKE_INSTALL_PREFIX}etc/"
PUBLIC SNIP_INSTALL_CONF_PATH="${CMAKE_INSTALL_CONF_DIR}snip.yml"
PUBLIC SNIP_VERSION="${SNIP_VERSION}"
)
target_link_libraries(snip_lib ${LIBS})
target_link_libraries(snip_lib ${CMAKE_THREAD_LIBS_INIT} )
if(SNIP__DOWNLOAD_AND_BUILD_DEPENDENCIES)
# If we downloaded dependencies, we should build, require, and use them.
add_dependencies(snip event)
add_dependencies(snip_lib event)
add_dependencies(snip yaml)
add_dependencies(snip_lib yaml)
endif()