forked from nasa/astrobee
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCreateRosTestTargets.cmake
72 lines (63 loc) · 2.64 KB
/
CreateRosTestTargets.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# Copyright (c) 2017, United States Government, as represented by the
# Administrator of the National Aeronautics and Space Administration.
#
# All rights reserved.
#
# The Astrobee platform is licensed under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
# I made each test it's own executable. Alternatively, they could all
# be stuff in one large executable. I am unsure what is best. -Z
function(create_ros_test_targets)
cmake_parse_arguments(
test # Prefix of output variables
"" # List of Boolean Variables
"DIR" # List of mono valued arguments
"LIBS;INC;DEPS;EXCLUDE" # List of Multi Value Arguments
${ARGN}
)
# Search for all the tests in tool dir
file(GLOB TEST_SRC_FILES ${test_DIR}/*.cxx)
# Sift through tool sources and remove EXECLUDE
foreach(SRC ${TEST_SRC_FILES})
foreach(TEST_SRC ${test_EXCLUDE})
string(FIND ${SRC} ${TEST_SRC} POSITION)
if (${POSITION} GREATER -1)
list(REMOVE_ITEM TEST_SRC_FILES ${SRC})
endif()
endforeach()
endforeach()
foreach(filename ${TEST_SRC_FILES})
string(REPLACE ".cxx" "" execname ${filename})
string(REGEX REPLACE "^[^ ]*/" "" execname ${execname})
add_executable(${execname} ${filename})
target_link_libraries(${execname}
LINK_PUBLIC ${GTEST_LIBRARIES} ${test_LIBS})
target_include_directories(${execname} PUBLIC ${GTEST_INCLUDE_DIRS} ${test_INC})
# define TEST_DIR so that tests can find their test data
get_filename_component(ABSOLUTE_TEST_DIR ${test_DIR} ABSOLUTE)
add_definitions(-DTEST_DIR=\"${ABSOLUTE_TEST_DIR}\")
add_dependencies(${execname} ${test_DEPS} gtest_noros)
# install our tests to a new folder so we can check on robot that
# code is working.
install(TARGETS ${execname} DESTINATION test)
endforeach()
# Now search for all the launch files
file(GLOB TEST_LAUNCH_FILES ${test_DIR}/*.launch)
foreach(launch ${TEST_LAUNCH_FILES})
string(REGEX REPLACE "^[^ ]*/" "" execname ${launch})
add_test(
NAME ${execname}
COMMAND ${CMAKE_BINARY_DIR}/devel/env.sh rostest ${launch} --results-filename ${execname}.txt
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/Testing
)
endforeach()
endfunction()