-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
75 lines (61 loc) · 1.74 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
cmake_minimum_required(VERSION 3.11)
project(rfcomm)
# optimization for dev environments
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# project version
set(MAJOR 0)
set(MINOR 1)
set(REMAP_VERSION ${MAJOR}.${MINOR})
# flags
set(CMAKE_CXX_FLAGS "-pthread")
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
# set cmake modules path
list(APPEND CMAKE_MODULE_PATH "$ENV{CMAKE_MODULE_PATH}")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
# link bluetooth dependencies
set(EXTRA_LIBS ${YARP_LIBRARIES})
list(APPEND EXTRA_LIBS "bluetooth")
# set path variables
set(PROJECT_DIR ${CMAKE_CURRENT_LIST_DIR})
set(BIN_DIR ${PROJECT_BINARY_DIR}/bin)
set(SRC_DIR ${PROJECT_DIR}/src)
set(INCLUDE_DIR ${PROJECT_DIR}/include)
option(BUILD_SHARED_LIBS "Build Shared Library" ON) # default ON
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${BIN_DIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${BIN_DIR})
# find header files
set (INCLUDE_DIRS "")
file(GLOB_RECURSE HEADERS
${INCLUDE_DIR}/*.h
${INCLUDE_DIR}/*.hpp
)
foreach (HEADER ${HEADERS})
get_filename_component(DIR ${HEADER} PATH)
list (APPEND INCLUDE_DIRS ${DIR})
endforeach()
list(REMOVE_DUPLICATES INCLUDE_DIRS)
# find source files
file(GLOB_RECURSE SRC_DIR
${SRC_DIR}/*.c
)
# setup target
add_executable(rfcomm
${PROJECT_DIR}/main.c
${SRC_DIR}
)
# include directories
target_include_directories(rfcomm PRIVATE
${INCLUDE_DIRS}
)
# link bluetooth dependencies
target_link_libraries(rfcomm ${EXTRA_LIBS})
# execute target
option(EXECUTE_TARGET "Execute Project Target" ON) # default OFF
if(EXECUTE_TARGET)
add_custom_command(TARGET rfcomm
POST_BUILD
COMMAND ./build/bin/rfcomm
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR})
endif()