-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
181 lines (143 loc) · 4.89 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# https://github.com/mauriciopoppe/cmake-starter/blob/master/CMakeLists.txt
########## Compiler Setup ##########
# 1. Setup: Declare min CMake version, name of the project, and compiler settings
cmake_minimum_required( VERSION 3.0 )
project( isaac_ros_service )
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -Wall -lboost_system -pthread" ) # Use C++17
# NOTE: CMake function calls do NOT have commas between arguments!
########## Project Setup ##########
# 2. Set paths to look for headers and sources in the project
set( CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}/out" )
set( EXM_DIR ${PROJECT_SOURCE_DIR}/example )
set( SRC_DIR ${PROJECT_SOURCE_DIR}/src )
set( TST_DIR ${PROJECT_SOURCE_DIR}/test )
set( HLP_DIR ${PROJECT_SOURCE_DIR}/helpers )
set( FUL_DIR ${PROJECT_SOURCE_DIR}/full_server )
# NOTE: Use ${VAR_NAME} to substitute the value of `VAR_NAME` in that place
# the -I flag in gcc
include_directories(
${EXM_DIR}
${SRC_DIR}
${TST_DIR}
${HLP_DIR}
${FUL_DIR}
)
# 3. Shortcuts
# set( HELP_CPP ${SRC_DIR}/demo2400_helpers.cpp )
########## Libraries ##########
set( THREADS_PREFER_PTHREAD_FLAG ON )
find_package( Threads REQUIRED )
set( BOOST_VRSN_MIN 1.65.1 )
set( Boost_USE_STATIC_LIBS OFF )
set( Boost_USE_MULTITHREADED ON )
set( Boost_USE_STATIC_RUNTIME OFF )
set( ASIO_HDR_DIR ${PROJECT_SOURCE_DIR}/boost_asio/include/boost )
# set( BOOST_ROOT /usr/lib/x86_64-linux-gnu/ )
set( BOOST_LIBRARYDIR /usr/lib/x86_64-linux-gnu )
find_package( Boost ${BOOST_VRSN_MIN} REQUIRED COMPONENTS
system
filesystem
thread
chrono
)
if( Boost_FOUND )
include_directories(
${Boost_INCLUDE_DIRS}
${ASIO_HDR_DIR}
)
link_directories( ${Boost_LIBRARY_DIRS} )
else()
message( FATAL_ERROR "Fatal error: Boost (version >= ${BOOST_VRSN_MIN}) required.\n")
endif()
########## Build Info ##########
# 4. Some messages to the user to let them know how things are going
message( "Project Name: ${PROJECT_NAME}" )
message( "~~ Directories ~~" )
message( "Examples: ${EXM_DIR}" )
message( "Sources: ${SRC_DIR}" )
message( "Programs: ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}" )
########## Programs & Libraries ##########
# 5. Add executable programs to the project
message( "\n\nWriting build scripts..." )
##### Examples #####
set( EXEC_NAME server_blk )
add_executable( ${EXEC_NAME} ${EXM_DIR}/${EXEC_NAME}.cpp )
target_link_libraries( ${EXEC_NAME}
${Boost_LIBRARIES}
)
message( "${EXEC_NAME} ready!" )
set( EXEC_NAME client_blk )
add_executable( ${EXEC_NAME} ${EXM_DIR}/${EXEC_NAME}.cpp )
target_link_libraries( ${EXEC_NAME}
${Boost_LIBRARIES}
)
message( "${EXEC_NAME} ready!" )
set( EXEC_NAME thread_pool )
add_executable( ${EXEC_NAME} ${EXM_DIR}/${EXEC_NAME}.cpp )
target_link_libraries( ${EXEC_NAME}
${Boost_LIBRARIES}
)
message( "${EXEC_NAME} ready!" )
set( EXEC_NAME lockfree_queue )
add_executable( ${EXEC_NAME} ${EXM_DIR}/${EXEC_NAME}.cpp )
target_link_libraries( ${EXEC_NAME}
${Boost_LIBRARIES}
)
message( "${EXEC_NAME} ready!" )
set( EXEC_NAME lock_guard )
add_executable( ${EXEC_NAME} ${EXM_DIR}/${EXEC_NAME}.cpp )
target_link_libraries( ${EXEC_NAME}
${Boost_LIBRARIES}
)
message( "${EXEC_NAME} ready!" )
set( EXEC_NAME posix_main )
add_executable( ${EXEC_NAME} ${FUL_DIR}/${EXEC_NAME}.cpp
${FUL_DIR}/connection.cpp
${FUL_DIR}/mime_types.cpp
${FUL_DIR}/reply.cpp
${FUL_DIR}/request_handler.cpp
${FUL_DIR}/request_parser.cpp
${FUL_DIR}/server.cpp
)
target_link_libraries( ${EXEC_NAME}
${Boost_LIBRARIES}
)
message( "${EXEC_NAME} ready!" )
##### Tests #####
set( EXEC_NAME shared )
add_executable( ${EXEC_NAME} ${TST_DIR}/${EXEC_NAME}.cpp ${HLP_DIR}/helper.cpp )
target_link_libraries( ${EXEC_NAME}
${Boost_LIBRARIES}
)
message( "${EXEC_NAME} ready!" )
set( EXEC_NAME test01_server )
add_executable( ${EXEC_NAME} ${TST_DIR}/${EXEC_NAME}.cpp ${HLP_DIR}/helper.cpp ${SRC_DIR}/Connection.cpp ${SRC_DIR}/IP.cpp )
target_link_libraries( ${EXEC_NAME}
${Boost_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
)
message( "${EXEC_NAME} ready!" )
# set( EXEC_NAME test02_server )
# add_executable( ${EXEC_NAME} ${TST_DIR}/${EXEC_NAME}.cpp ${HLP_DIR}/helper.cpp ${SRC_DIR}/Connection.cpp ${SRC_DIR}/IP.cpp )
# target_link_libraries( ${EXEC_NAME}
# ${Boost_LIBRARIES}
# ${CMAKE_THREAD_LIBS_INIT}
# )
# message( "${EXEC_NAME} ready!" )
set( EXEC_NAME srl_client )
add_executable( ${EXEC_NAME} ${TST_DIR}/${EXEC_NAME}.cpp )
target_link_libraries( ${EXEC_NAME}
${Boost_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
)
message( "${EXEC_NAME} ready!" )
set( EXEC_NAME srl_server )
add_executable( ${EXEC_NAME} ${TST_DIR}/${EXEC_NAME}.cpp )
target_link_libraries( ${EXEC_NAME}
${Boost_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
)
message( "${EXEC_NAME} ready!" )
# https://stackoverflow.com/questions/14077611/how-do-i-tell-cmake-to-link-in-a-static-library-in-the-source-directory
# https://stackoverflow.com/a/14078232
message( "\n\n Cmake setup COMPLETED" )