This repository has been archived by the owner on Mar 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.cmake
56 lines (54 loc) · 2.35 KB
/
functions.cmake
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
# Create module library
function(make_lib module srcs link_libs inc_dirs compile_defs)
add_library(${module} ${srcs})
ament_target_dependencies(${module} PUBLIC ${ROS_DEPS})
target_compile_definitions(${module} PUBLIC ${compile_defs})
target_link_libraries(${module} PUBLIC ${link_libs})
target_include_directories(
${module} PUBLIC
${CMAKE_CURRENT_LIST_DIR}/inc
${CMAKE_SOURCE_DIR}/lib
${inc_dirs}
)
add_dependencies(${module} ${AUTOGEN_TARGETS})
set(${module}_inc_dir ${CMAKE_CURRENT_LIST_DIR}/inc CACHE INTERNAL "${module} header include directory")
endfunction()
# Create project module ROS executable
function(make_exe module srcs link_libs inc_dirs compile_defs)
set(bin_module bin_${module})
add_executable(${bin_module} ${srcs})
target_compile_definitions(${bin_module} PUBLIC ${compile_defs})
ament_target_dependencies(${bin_module} PUBLIC ${ROS_DEPS})
target_link_libraries(${bin_module} PUBLIC ${link_libs} boost_program_options net_node)
target_include_directories(
${bin_module} PUBLIC
${CMAKE_CURRENT_LIST_DIR}/inc
${CMAKE_SOURCE_DIR}/lib
${inc_dirs}
${net_node_inc_dir}
)
add_dependencies(${bin_module} ${AUTOGEN_TARGETS})
install(TARGETS ${bin_module} DESTINATION lib/${PROJECT_NAME})
# Rename the output binary to just be the module name
set_target_properties(${bin_module} PROPERTIES OUTPUT_NAME ${module})
endfunction()
# Create unit test
function(make_unit_test module srcs link_libs inc_dirs compile_defs)
if(UNIT_TEST)
set(test_module test_${module})
add_executable(${test_module} ${srcs})
target_compile_definitions(${test_module} PUBLIC ${compile_defs})
ament_target_dependencies(${test_module} PUBLIC ${ROS_DEPS})
target_include_directories(
${test_module} PRIVATE
${CMAKE_CURRENT_LIST_DIR}/inc
${CMAKE_SOURCE_DIR}/lib
${inc_dirs}
)
target_link_libraries(${test_module} PUBLIC ${GTEST_LINK_LIBS} ${link_libs})
add_dependencies(${test_module} ${AUTOGEN_TARGETS})
# Make the unit test runnable with CTest (invoked via test.sh)
add_test(NAME ${test_module} COMMAND ${test_module})
set_tests_properties(${test_module} PROPERTIES TIMEOUT 60) # 1 minute per test timeout
endif()
endfunction()