forked from loentar/ngrest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
125 lines (103 loc) · 3.85 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
cmake_minimum_required (VERSION 2.8.4)
project (ngrest)
set(NGREST_VERSION "0.2.0")
include(CheckCXXCompilerFlag)
include(CheckLibraryExists)
include(CheckIncludeFileCXX)
include(GNUInstallDirs)
check_cxx_compiler_flag(-std=gnu++11 HAS_CXX11)
if (HAS_CXX11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
endif()
if (NOT APPLE)
check_cxx_compiler_flag(-Wl,--no-undefined HAS_NO_UNDEFINED)
if (HAS_NO_UNDEFINED)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--no-undefined")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined")
endif()
endif()
check_cxx_compiler_flag(-pedantic HAS_PEDANTIC)
if (HAS_PEDANTIC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic")
endif()
check_cxx_compiler_flag(-Wall HAS_WALL)
if (HAS_WALL)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
endif()
check_library_exists(dl dlopen "" HAS_DL)
if (NOT APPLE)
check_include_file_cxx(sys/epoll.h HAS_EPOLL)
if (HAS_EPOLL)
add_definitions(-DHAS_EPOLL)
endif()
endif()
if (MINGW)
add_definitions(-D_WIN32_WINNT=0x0501)
set(CMAKE_SHARED_LIBRARY_PREFIX "")
set(CMAKE_SHARED_MODULE_PREFIX "")
set(CMAKE_SHARED_LIBRARY_SUFFIX ".dll")
set(CMAKE_SHARED_MODULE_SUFFIX ".dll")
endif()
check_library_exists(pthread pthread_create "" HAS_PTHREAD)
if ("$ENV{WITH_THREAD_LOCK}" STREQUAL "1")
add_definitions(-DNGREST_THREAD_LOCK)
set(LINK_PTHREAD "${HAS_PTHREAD}")
endif()
if (CMAKE_BUILD_TYPE MATCHES "DEBUG")
add_definitions(-DDEBUG)
# link pthread in debug/single thread version
# to detect incorrect posting to event loop from non-main thread
set(LINK_PTHREAD "${HAS_PTHREAD}")
endif()
set(PROJECT_DEPLOY_DIR ${PROJECT_BINARY_DIR}/deploy)
set(PROJECT_INCLUDE_DIR ${PROJECT_DEPLOY_DIR}/include)
set(PROJECT_SHARE_DIR ${PROJECT_DEPLOY_DIR}/share/ngrest)
set(PROJECT_SERVICES_DIR ${PROJECT_SHARE_DIR}/services)
set(PROJECT_FILTERS_DIR ${PROJECT_SHARE_DIR}/filters)
set(PROJECT_CODEGEN_DIR ${PROJECT_SHARE_DIR}/codegen)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_DEPLOY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_DEPLOY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_DEPLOY_DIR}/bin)
set(TESTS_OUTPUT_DIRECTORY ${PROJECT_DEPLOY_DIR}/tests)
set(EXAMPLES_OUTPUT_DIRECTORY ${PROJECT_DEPLOY_DIR}/examples)
FUNCTION(PREPEND var prefix)
SET(listVar "")
FOREACH(f ${ARGN})
LIST(APPEND listVar "${prefix}/${f}")
ENDFOREACH(f)
SET(${var} "${listVar}" PARENT_SCOPE)
ENDFUNCTION(PREPEND)
FUNCTION(CODEGEN_FILES outVar prefix)
SET(listVar "${prefix}/ServiceGroupImpl.h" "${prefix}/ServiceGroupImpl.cpp")
FOREACH(file ${ARGN})
get_filename_component(fileBase "${file}" NAME_WE)
LIST(APPEND listVar "${prefix}/${fileBase}Wrapper.h")
LIST(APPEND listVar "${prefix}/${fileBase}Wrapper.cpp")
ENDFOREACH(file)
SET(${outVar} "${listVar}" PARENT_SCOPE)
ENDFUNCTION(CODEGEN_FILES)
include_directories("${PROJECT_INCLUDE_DIR}")
add_subdirectory(core)
add_subdirectory(tools)
add_subdirectory(services)
add_subdirectory(modules)
if ("${WITH_TESTS}" STREQUAL "1")
add_subdirectory(tests)
endif()
if ("${WITH_EXAMPLES}" STREQUAL "1")
add_subdirectory(examples)
endif()
install(DIRECTORY ${PROJECT_DEPLOY_DIR}/bin DESTINATION ${CMAKE_INSTALL_PREFIX}
PATTERN "bin/*"
PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ
GROUP_EXECUTE GROUP_READ
)
install(DIRECTORY
${PROJECT_DEPLOY_DIR}/lib
${PROJECT_DEPLOY_DIR}/include
${PROJECT_DEPLOY_DIR}/share
DESTINATION ${CMAKE_INSTALL_PREFIX})
enable_testing()
add_test(NAME json COMMAND ./ngrestjsontest WORKING_DIRECTORY ${TESTS_OUTPUT_DIRECTORY})
add_test(NAME server_client COMMAND ./test_server_client WORKING_DIRECTORY ${TESTS_OUTPUT_DIRECTORY})