-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
65 lines (57 loc) · 2.12 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
cmake_minimum_required(VERSION 3.10.2)
project(powerboard-driver)
#- Use the module that provides GNU standard installation directories
include(GNUInstallDirs)
#-[] Set project specific options
#-> Library build options
option(BUILD_PYTHON "Build Python 3 bindings of the driver." ON)
option(BUILD_ROS "Build ROS 1 wrapper alongside the library." OFF)
option(BUILD_EXAMPLES "Build examples alongside the library." ON)
#-> Tell the linker where to look for an external library
link_directories(thirdparty/libi2c/)
#-[] Set project specific files paths
#-> Where to look for ".h" files with "#include"
SET(INCLUDE_PATHS
include/
thirdparty/libi2c/include
)
#-> Where to pick library source files
SET(LIBRARY_SOURCE_FILES
src/board.cpp
)
#-> Files used as library headers but future devs
SET(LIBRARY_HEADERS_FILES
include/board.h
include/commands.h
)
#-> Library compilation output path
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib)
#-[] Build project's library
#-> Create a shared library (a .so file) with given source files
add_library(powerboard-driver SHARED ${LIBRARY_SOURCE_FILES})
#-> Give library paths for external libraries' header files
target_include_directories(powerboard-driver PUBLIC ${INCLUDE_PATHS})
#-> Indicate which files are library's headers
set_target_properties(powerboard-driver PROPERTIES PUBLIC_HEADER "${LIBRARY_HEADERS_FILES}")
#-> Link external libraries used by this library
target_link_libraries(powerboard-driver libi2c.so)
#-[] Generate project installation rules
install(TARGETS powerboard-driver
LIBRARY
DESTINATION ${CMAKE_INSTALL_LIBDIR}/powerboard-driver
PUBLIC_HEADER
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/powerboard-driver)
#-[] Library's python bindings
if (BUILD_PYTHON)
message(STATUS "Building Python 3 bindings...")
add_subdirectory(thirdparty/pybind11)
add_subdirectory(python)
endif(BUILD_PYTHON)
if (BUILD_ROS)
message(STATUS "Building ROS 1 wrapper...")
endif(BUILD_ROS)
#-[] Library's CXX examples
if (BUILD_EXAMPLES)
message(STATUS "Building examples..")
add_subdirectory(examples)
endif(BUILD_EXAMPLES)