-
Notifications
You must be signed in to change notification settings - Fork 128
/
CMakeLists.txt
56 lines (44 loc) · 1.54 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
# We need this directory to build the examples
include_directories(${PROJECT_SOURCE_DIR}/src)
include_directories(${PROJECT_SOURCE_DIR}/examples)
if(NATS_BUILD_LIBUV_EXAMPLE)
include_directories(${LIBUV_DIR}/include)
endif()
if(NATS_BUILD_LIBEVENT_EXAMPLE)
include_directories(${LIBEVENT_DIR}/include)
endif()
if(WIN32)
set(LIB_SUFFIX ${CMAKE_STATIC_LIBRARY_SUFFIX})
else()
set(LIB_SUFFIX ${CMAKE_SHARED_LIBRARY_SUFFIX})
endif()
# Get all the .c files in the examples directory
file(GLOB EXAMPLES_SOURCES RELATIVE ${PROJECT_SOURCE_DIR}/examples *.c)
add_definitions(-Dnats_IMPORTS)
# For each file...
foreach(examples_src ${EXAMPLES_SOURCES})
# Remove the suffix so that it becomes the executable name
string(REPLACE ".c" "" examplename ${examples_src})
set(exampleexe "nats-${examplename}")
set(buildExample OFF)
set(NATS_ASYNC_IO_LIB "")
if(examplename MATCHES "libuv")
if(NATS_BUILD_LIBUV_EXAMPLE)
set(buildExample ON)
set(NATS_ASYNC_IO_LIB ${LIBUV_DIR}/lib/libuv${LIB_SUFFIX})
endif()
elseif(examplename MATCHES "libevent")
if(NATS_BUILD_LIBEVENT_EXAMPLE)
set(buildExample ON)
set(NATS_ASYNC_IO_LIB ${LIBEVENT_DIR}/lib/libevent${LIB_SUFFIX})
endif()
else()
set(buildExample ON)
endif()
if(buildExample)
# Build the executable
add_executable(${exampleexe} ${PROJECT_SOURCE_DIR}/examples/${examples_src})
# Link dynamically
target_link_libraries(${exampleexe} nats ${NATS_EXTRA_LIB} ${NATS_ASYNC_IO_LIB})
endif()
endforeach()