ROS下CMakelists.txt编写

ref:http://wiki.ros.org/rosbuild/CMakeLists


1.http://www.cmake.org/Wiki/CMake_2.4.6_Docs

2.http://blog.163.com/ji_wei8888/blog/static/486804462011991064371/

3.http://wiki.ros.org/rosbuild

4.http://www.cppblog.com/tx7do/archive/2010/08/19/124000.html

5.http://blog.csdn.net/panweiguozhou/article/details/6829085

自己的例子:

cmake_minimum_required(VERSION 2.4.6)
include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)

include_directories(/usr/local/include/triclops/include)
include_directories(/usr/local/include/dc1394)
include_directories(/usr/local/include/opencv)
include_directories(/usr/local/include/libraw1394)
include_directories(/usr/local/include)
include_directories(/usr/include)

# Set the build type.  Options are:
#  Coverage       : w/ debug symbols, w/o optimization, w/ code-coverage
#  Debug          : w/ debug symbols, w/o optimization
#  Release        : w/o debug symbols, w/ optimization
#  RelWithDebInfo : w/ debug symbols, w/ optimization
#  MinSizeRel     : w/o debug symbols, w/ optimization, stripped binaries
#set(ROS_BUILD_TYPE RelWithDebInfo)

rosbuild_init()

#set the default path for built executables to the "bin" directory
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
#set the default path for built libraries to the "lib" directory
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)

#uncomment if you have defined messages
rosbuild_genmsg()
#uncomment if you have defined services
#rosbuild_gensrv()

#common commands for building c++ executables and libraries
#rosbuild_add_library(${PROJECT_NAME} src/example.cpp)
#target_link_libraries(${PROJECT_NAME} another_library)
#rosbuild_add_boost_directories()
#rosbuild_link_boost(${PROJECT_NAME} thread)
#rosbuild_add_executable(example examples/example.cpp)
#target_link_libraries(example ${PROJECT_NAME})

#rosbuild_add_library(pgrlibdcstereo src/pgr-stereo/pgrlibdcstereo/pgr_conversions.cpp src/pgr-stereo/pgrlibdcstereo/pgr_stereocam.cpp src/pgr-stereo/pgrlibdcstereo/pgr_registers.cpp)
#rosbuild_add_library(/usr/local/lib/dc1394 /usr/local/lib/raw1394 /usr/local/lib/thread)
#rosbuild_add_library(triclops pnmutils pgrlibdcstereo)
#rosbuild_add_library(/usr/local/lib/opencv_core /usr/local/lib/opencv_imgproc /usr/local/lib/opencv_highgui)


rosbuild_add_executable(talker src/talker.cpp)
rosbuild_add_executable(listener src/listener.cpp)

rosbuild_add_executable(simplestereo src/pgr-stereo/simplestereo/simplestereo.cpp)
#target_link_libraries(simplestereo /usr/local/lib/libdc1394.a)

target_link_libraries(simplestereo /usr/local/lib/libdc1394.so)
target_link_libraries(simplestereo /usr/local/lib/libraw1394.a)
target_link_libraries(simplestereo /usr/local/include/triclops/lib/libtriclops.a)
target_link_libraries(simplestereo /usr/local/include/triclops/lib/libpgrlibdcstereo.a)
target_link_libraries(simplestereo /usr/local/include/triclops/lib/libpnmutils.a)
target_link_libraries(simplestereo /usr/local/lib/libopencv_core.so)
target_link_libraries(simplestereo /usr/local/lib/libopencv_imgproc.so)
target_link_libraries(simplestereo /usr/local/lib/libopencv_highgui.so)


rosbuild_add_executable(simplestereo-profile src/pgr-stereo/simplestereo/simplestereo-profile.cpp)
target_link_libraries(simplestereo-profile /usr/local/include/triclops/lib/libtriclops.a)
target_link_libraries(simplestereo-profile /usr/local/include/triclops/lib/libpgrlibdcstereo.a)
target_link_libraries(simplestereo-profile /usr/local/include/triclops/lib/libpnmutils.a)
target_link_libraries(simplestereo-profile /usr/local/lib/libdc1394.so)
target_link_libraries(simplestereo-profile /usr/local/lib/libraw1394.a)
target_link_libraries(simplestereo-profile /usr/local/lib/libopencv_core.so)
target_link_libraries(simplestereo-profile /usr/local/lib/libopencv_imgproc.so)
target_link_libraries(simplestereo-profile /usr/local/lib/libopencv_highgui.so)

其他人的例子:

 cmake_minimum_required(VERSION 2.4.6)

 include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)



 # Set the build type.  Options are:

 #  Coverage       : w/ debug symbols, w/o optimization, w/ code-coverage

 #  Debug          : w/ debug symbols, w/o optimization

 #  Release        : w/o debug symbols, w/ optimization

 #  RelWithDebInfo : w/ debug symbols, w/ optimization

 #  MinSizeRel     : w/o debug symbols, w/ optimization, stripped binaries

 #set(ROS_BUILD_TYPE RelWithDebInfo)



 rosbuild_init()



 #set the default path for built executables to the "bin" directory

 set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)

 #set the default path for built libraries to the "lib" directory

 set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)



 #uncomment if you have defined messages

 #rosbuild_genmsg()

 #uncomment if you have defined services

 #rosbuild_gensrv()



 #common commands for building c++ executables and libraries

 #rosbuild_add_library(${PROJECT_NAME} src/example.cpp)

 #target_link_libraries(${PROJECT_NAME} another_library)

 #rosbuild_add_boost_directories()

 #rosbuild_link_boost(${PROJECT_NAME} thread)

 #rosbuild_add_executable(example examples/example.cpp)

 #target_link_libraries(example ${PROJECT_NAME})

 rosbuild_add_executable(glut_test src/glut_test.cpp)

 target_link_libraries(glut_test /usr/lib/libglut.a)

 target_link_libraries(glut_test /usr/lib/libglut.so)

///

glut_test.cpp

 #include 



 void renderScene(void) {    

     glClear(GL_COLOR_BUFFER_BIT);

     glBegin(GL_TRIANGLES);

     glVertex3f(-0.5,-0.5,0.0);

     glVertex3f(0.5,0.0,0.0);

     glVertex3f(0.0,0.5,0.0);

     glEnd();

     glFlush();

 }



 int main(int argc, char **argv) {

     glutInit(&argc, argv);

     glutInitDisplayMode(GLUT_DEPTH | GLUT_SINGLE | GLUT_RGBA);

     glutInitWindowPosition(100,100);

     glutInitWindowSize(320,320);

     glutCreateWindow("3D Tech- GLUT Tutorial");

     glutDisplayFunc(renderScene);

     glutMainLoop();

     return 0;

 }


///

  • rosbuild
  • CMakeLists

Writing a ROS CMakeLists.txt file

This page documents the CMake API provided byrosbuild.

You might first want to see some examples.

We use CMake to build ROS packages. You need to install CMake on your system. Each package requires a file, called CMakeLists.txt to tell CMake how to build it. This file is analogous to a Makefile as used by make.

If you're unfamiliar with CMakeLists.txt, that's ok, because most ROS packages follow a very simple pattern that is described below. Of course, you can always use the full power of CMake, for which you may want to consult theCMake documentation.

NOTE: To support older platforms, we useonly features that are available in CMake 2.4.6. Check the2.4.6 docs to verify the availability of a feature you want to use.

目录

  1. Writing a ROS CMakeLists.txt file
  2. API documentation
    1. rosbuild.cmake
    2. Global variables
    3. rosbuild_init
    4. Build macros
      1. rosbuild_add_executable
      2. rosbuild_add_library
      3. rosbuild_add_swigpy_library
      4. rosbuild_add_compile_flags
      5. rosbuild_remove_compile_flags
      6. rosbuild_add_link_flags
      7. rosbuild_remove_link_flags
      8. rosbuild_add_boost_directories
      9. rosbuild_link_boost
      10. rosbuild_add_openmp_flags
      11. rosbuild_invoke_rospack
      12. rosbuild_find_ros_package
      13. rosbuild_find_ros_stack
      14. rosbuild_check_for_sse
      15. rosbuild_include
      16. rosbuild_add_lisp_executable
    5. Test macros
      1. rosbuild_add_gtest
      2. rosbuild_add_gtest_labeled
      3. rosbuild_add_gtest_future
      4. rosbuild_add_gtest_build_flags
      5. rosbuild_add_pyunit
      6. rosbuild_add_pyunit_labeled
      7. rosbuild_add_pyunit_future
      8. rosbuild_add_rostest
      9. rosbuild_add_rostest_labeled
      10. rosbuild_add_rostest_future
      11. rosbuild_add_roslaunch_check
      12. rosbuild_declare_test
      13. rosbuild_count_cores
      14. rosbuild_check_for_display
      15. rosbuild_check_for_vm
    6. Message / service macros
      1. rosbuild_gensrv
      2. rosbuild_genmsg
      3. rosbuild_add_generated_msgs
      4. rosbuild_add_generated_srvs
    7. Version macros
      1. rosbuild_get_stack_version
      2. rosbuild_get_package_version
    8. Downloading files during the build
      1. rosbuild_download_data
      2. rosbuild_download_test_data
      3. rosbuild_untar_file
    9. Special targets
      1. rosbuild_premsgsrvgen
      2. rosbuild_precompile
    10. Making stack distributions
      1. rosbuild_make_distribution

API documentation

rosbuild.cmake

To use any of the ROS macros, you must first do this:

include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)

This line brings in the rosbuild.cmake file, which defines the macros described below.

Global variables

Some variables can be set before callingrosbuild_init():

  • ROSBUILD_DONT_REDEFINE_PROJECT (new in 1.3.1): IfTRUE, don't infer the project name from the current working directory. Instead, inherit the existingPROJECT_NAME. Useful for complex projects in which a ROS package is just one part.

rosbuild_init

rosbuild_init()

This macro should be called first. It does the following (assume ${pkg} is the name of the package, and ${dir} is the package directory):

  • Configure default output locations:
    • executables go in ${dir}
    • libraries go in ${dir}/lib
  • Add ${dir}/include to the search path for include files
  • Invoke rospack to get compile and link flags, storing the result in several variables (but you don't need to access them directly if you're using throsbuild_add_executable anrosbuild_add_library macros):

    • -I compile flags go in ${pkg}_INCLUDE_DIRS
    • other compile flags go in ${pkg}_CFLAGS_OTHER
    • -L link flags go in ${pkg}_LIBRARY_DIRS
    • -l link flags go in ${pkg}_LIBRARIES
    • other link flags go in ${pkg}_LDFLAGS_OTHER

Note that you are free to override the default output locations after invokingrosbuild_init(). E.g., if you want your binaries in ${pkg}/bin, you might do this:

rosbuild_init()
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)

To put your libraries somewhere strange:

set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/libraries)

NOTE: the rosbuild_init() macro doesNOT bring in the compile or link flags that are exported by the package presently being built. ItONLY brings in the flags exported by the present package's dependencies. The flags in the export section of yourmanifest.xml are for use by others, not by you. If you need some of your package's exported flags when building the package itself, use the appropriate CMake calls in yourCMakeLists.txt, such as include_directories() andtarget_link_libraries().

But see Linking against libraries built by other ROS packages for when not to usetarget_link_libraries().

Build macros

rosbuild_add_executable

rosbuild_add_executable(exe src1 src2...)

This macro declares an executable that is to be built. It is a simple wrapper around the standard CMake command add_executable(), and takes exactly the same arguments. In addition to invoking add_executable(), this macro invokes set_target_properties() and target_link_libraries() to incorporate the compile and link flags found by throsbuild_init() macro.

NOTE: Do not call your executabletest. This target name is reserved for unit testing, and CMake will fail if you try it. If you really want your executable to be calledtest, you can do it like so:

rosbuild_add_executable(mytest src/test.cpp)
set_target_properties(mytest PROPERTIES OUTPUT_NAME test)

But if you're building test programs, you should do it withrosbuild_add_gtest(); see below.

If you're building an executable that shouldn't be built in themake all step (e.g., if you intend to userosbuild_add_gtest_build_flags()), then use CMake'sEXCLUDE_FROM_ALL option, e.g.:

rosbuild_add_executable(mytest EXCLUDE_FROM_ALL src/test.cpp)
rosbuild_add_gtest_build_flags(mytest)

rosbuild_add_library

rosbuild_add_library(lib src1 src2...)

This macro declares a library that is to be built. It is a simple wrapper around the standard CMake command add_library(), and takes exactly the same arguments. In addition to invoking add_library(), this macro invokes set_target_properties() to incorporate the compile flags found by the rosbuild_init() macro.

Example usage:

cmake_minimum_required(VERSION 2.4.6)
include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)
rosbuild_init()
rosbuild_add_library(XmlRpc src/XmlRpcClient.cpp
                   src/XmlRpcDispatch.cpp
                   src/XmlRpcServer.cpp
                   src/XmlRpcServerConnection.cpp
                   src/XmlRpcServerMethod.cpp
                   src/XmlRpcSocket.cpp
                   src/XmlRpcSource.cpp
                   src/XmlRpcUtil.cpp
                   src/XmlRpcValue.cpp)

NOTE: Do not call your librarytest. This target name is reserved for unit testing, and CMake will fail if you try it.

rosbuild_add_swigpy_library

New in 0.11

rosbuild_add_swigpy_library(target lib src1 src2...)

This macro is a variation o rosbuild_add_library() that should be used when building a SWIG-generated library that will be imported by Python. The first argument is a unique target name, which you can pass to things like target_link_libraries(). The rest of the arguments are the same as you would normally pass to rosbuild_add_library().

This macro will generate a library called_., where is what you passed in, and is the appropriate extension for a shared library. On OS X, the extension is forced to.so, to allow module imports to work with theMacPorts version of Python.

Example usage:

cmake_minimum_required(VERSION 2.4.6)
include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)
rosbuild_init()
find_package(PythonLibs REQUIRED)
rosbuild_add_swigpy_library(python_foo foo foo_swig_generated.cpp bar.cpp)
target_link_libraries(python_foo ${PYTHON_LIBRARIES})

This example will produce a library named_foo.so on most platforms.

NOTE: Do not call your targettest. This target name is reserved for unit testing, and CMake will fail if you try it.

rosbuild_add_compile_flags

rosbuild_add_compile_flags(target flags)

This macro adds compile flags for the given target. You can use it to add things like warning or optimization settings, but don't use it to add library/include search paths,-D definitions, or libraries to link against. Use CMake builtin commands (link_directories(),include_directories(),add_definitions(),target_link_libraries()) for those cases.

But see Linking against libraries built by other ROS packages for when not to usetarget_link_libraries().

rosbuild_remove_compile_flags

rosbuild_remove_compile_flags(target flags)

This macro removes compile flags for the given target.

rosbuild_add_link_flags(target flags)

This macro adds link flags for the given target. You can use it to add things like profiling settings, but don't use it to add library/include search paths,-D definitions, or libraries to link against. Use CMake builtin commands (link_directories() include_directories(), add_definitions(), target_link_libraries()) for those cases.

But see Linking against libraries built by other ROS packages for when not to usetarget_link_libraries().

rosbuild_remove_link_flags(target flags)

This macro removes link flags for the given target.

rosbuild_add_boost_directories

rosbuild_add_boost_directories()

This macro adds the boost include/library directories to your search paths. You must call this macro if any of your code includes boost headers.

rosbuild_link_boost(target lib1 lib2 lib3 ...)

This macro adds the boost link flags to a target, given some boost libraries you want to link against. You must call this macro for each of your library and executable that uses one or more libraries from boost. Example:

rosbuild_link_boost(my_exe thread regex)

rosbuild_add_openmp_flags

rosbuild_add_openmp_flags(target)

This macro adds the necessary compile and link flags to a target so that OpenMP can be used.

rosbuild_invoke_rospack

rosbuild_invoke_rospack(pkg prefix varname rospack_args)

This macro invokes rospack. Specifically, it invokes:

rospack ${rospack_args) ${pkg}

It stores the result in the variable ${prefix}_${varname}. Failure to invoke rospack is fatal.

rosbuild_find_ros_package

rosbuild_find_ros_package(pkg)

This macro searches for the given ROS package. If the package is found, then the variable ${pkg_PACKAGE_PATH} is set to the absolute path to the package. If the package is not found, the variable is not set.

rosbuild_find_ros_stack

(New in 1.6.0)

rosbuild_find_ros_stack(stack)

This macro searches for the given ROS stack. If the stack is found, then the variable ${stack_STACK_PATH} is set to the absolute path to the stack. If the stack is not found, the variable is not set.

rosbuild_check_for_sse

(New in 1.1.8)

rosbuild_check_for_sse()

This macro determines the level of SSE support in the compiler. If SSE support is found,HAS_SSE_EXTENSIONS is set to True. Similarly, SSE2 and SSE3 support causeHAS_SSE2_EXTENSIONS and HAS_SSE3_EXTENSIONS to be set to True, respectively. If any level of SSE support is found,SSE_FLAGS will contain the flags required to use the highest level available.

For example, to compile a library with the highest level of SSE available:

rosbuild_check_for_sse()
rosbuild_add_library(foo foo.cpp)
rosbuild_add_compile_flags(foo ${SSE_FLAGS})

To check for SSE2 specifically:

rosbuild_check_for_sse()
if(HAS_SSE2_EXTENSIONS)

endif(HAS_SSE2_EXTENSIONS)

rosbuild_include

(New in 1.1.8)

rosbuild_include(package module)

This macro includes CMake code exported by another package. Specifically, it includes a file calledmodule.cmake from a directory exported bypackage. This mechanism allows you to extend the build system by providing your own CMake code to be used in other packages.

The package calling rosbuild_include() must depend onpackage. That package must depend directly onrosbuild and must export a directory to search for CMake files.

E.g., if package dynamic_reconfigure wants to allow other packages to include the filedynamic_reconfigure/cmake/cfgbuild.cmake, then its manifest should contain:

...


  

...

Then package hokuyo_node, which depends ondynamic_reconfigure, can include that file like so:

rosbuild_include(dynamic_reconfigure cfgbuild)

rosbuild_add_lisp_executable

rosbuild_add_lisp_executable(output system_name entry_point)

Used to create a standalone Lisp executable. Your package must depend onroslisp_runtime. The executable will be calledoutput. Running it will start the SBCL runtime, load in the ASDF systemsystem_name, then call the function named byentry_point. See theroslisp documentation for more details.

Test macros

rosbuild provides a number macros to support testing. These macros allow you to define test programs that should be compiled (if necessary) and run duringmake test in your package. See UnitTesting for more information on testing.

rosbuild_add_gtest

(TIMEOUT option new in 1.1.8)

rosbuild_add_gtest(testexe src1 src2 ... [TIMEOUT timeout_secs])

This macro declares a Google Test (gtest) executable that is to be built. The arguments are the same arosbuild_add_executable (in fact this macro calls through torosbuild_add_executable). The named executable is built from the sources, and added as a dependency to thetest target. This macro invokesrosbuild_add_gtest_build_flags(), which adds the gtest build flags to the named executable. To build the executable, usemake tests.

If a test doesn't complete within a certain amount of time, it will be killed, and a test failure will be synthesized. By default, the time limit is 60 seconds. To set a different timeout, use theTIMEOUT option, e.g.:

# Give a slow test 3 minutes (180 seconds) to complete
rosbuild_add_gtest(myslowtest myslowtest.cpp TIMEOUT 180.0)

When make test is run, each gtest executable is run like so:

testexe --gtest_output=xml:${rosbuild_test_results_dir}/${PROJECT_NAME}/${_testname}.xml

The current working directory is the top of the package's source tree.

Test output is printed to the console, and also stored in XML format in $ROS_ROOT/test/test_results/${project}, where ${project} is the name of the ROS package.

Multiple tests may be declared.

NOTE: Do not call your testtest. This target name is reserved for unit testing, and CMake will fail if you try it.

rosbuild_add_gtest_labeled

(TIMEOUT option new in 1.1.8)

rosbuild_add_gtest_labeled(label testexe src1 src2 ... [TIMEOUT timeout_secs])

This macro is the same a rosbuild_add_gtest(), except that it only declares the test if EITHER:

  • the environment variable ROS_BUILD_TEST_LABEL is unset; OR

  • the label argument is equal to the environment variableROS_BUILD_TEST_LABEL.

Use this macro to declare tests that should not run in certain situations. Most commonly used with a continuous integration system.

rosbuild_add_gtest_future

DEPRECATED and rendered non-functional in 1.7. Instead of using this macro, simply comment out tests that don't yet pass.

rosbuild_add_gtest_future(testexe src1 src2 ... [TIMEOUT timeout_secs])

This macro is the same a rosbuild_add_gtest(), except that the resulting test will be only be run duringmake test-future. Use this macro to declare tests that fail now, but should pass in the future, after an existing bug is fixed or missing feature implemented.

We segregate future tests from current tests so that the automated build and test system can accurately report health of the system, including giving meaningful email notification on test failure.

rosbuild_add_gtest_build_flags

rosbuild_add_gtest_build_flags(testexe)

This macro adds the build flags necessary to compile and link an executable against gtest. Use this macro when you want to build a gtest exectuable, butnot declare it to be a test on its own. This commonly occurs when you're usingrostest and your test executable uses gtest. In this case you want the test executable to be run via rostest, not on its own.

This macro also invokes rosbuild_declare_test(), which adds a dependency from thetests target on the executable. To build the executable, usemake tests.

E.g., here we build an executable calledrtest that uses gtest, and declare arostest that uses it:

rosbuild_add_executable(rtest test/rtest.cpp test/test_constants.cpp)
rosbuild_add_gtest_build_flags(rtest)
rosbuild_add_rostest(test/rtest.xml)

The accompanying rostest XML file might look like this:


          args="$(find map_server)/test/testmap.bmp 0.1"/>
  
 

rosbuild_add_pyunit

(TIMEOUT option new 1.1.8)

rosbuild_add_pyunit(file [TIMEOUT timeout_secs])

This macro declares a Python unittest executable that is to be run. Make sure you consult the ROS unittest documentation as there are some additional items your unittest script needs to call.

If a test doesn't complete within a certain amount of time, it will be killed, and a test failure will be synthesized. By default, the time limit is 60 seconds. To set a different timeout, use theTIMEOUT option, e.g.:

# Give a slow test 3 minutes (180 seconds) to complete
rosbuild_add_pyunit(myslowtest.py TIMEOUT 180.0)

When make test is run, each Python unit test is run like so:

python file --gtest_output=xml:${rosbuild_test_results_dir}/${PROJECT_NAME}/${_testname}.xml

The current working directory is the top of the package's source tree.

rosbuild_add_pyunit_labeled

(TIMEOUT option new in 1.1.8.)

rosbuild_add_pyunit_labeled(label file [TIMEOUT timeout_secs])

This macro is the same a rosbuild_add_pyunit(), except that it only declares the test if EITHER:

  • the environment variable ROS_BUILD_TEST_LABEL is unset; OR

  • the label argument is equal to the environment variableROS_BUILD_TEST_LABEL.

Use this macro to declare tests that should not run in certain situations. Most commonly used with a continuous integration system.

rosbuild_add_pyunit_future

DEPRECATED and rendered non-functional in 1.7. Instead of using this macro, simply comment out tests that don't yet pass.(TIMEOUT option new in 1.1.8)

rosbuild_add_pyunit_future(file [TIMEOUT timeout_secs])

This macro is the same a rosbuild_add_pyunit(), except that the resulting test will be only be run duringmake test-future. Use this macro to declare tests that fail now, but should pass in the future, after an existing bug is fixed or missing feature implemented.

We segregate future tests from current tests so that the automated build and test system can accurately report health of the system, including giving meaningful email notification on test failure.

rosbuild_add_rostest

rosbuild_add_rostest(xmlfile)

This macro declares a rostest test that is to be run when testing the package. When make test is run on the package, the givenxmlfile will be passed torostest. Output goes in $ROS_ROOT/test/test_results/${project}, where ${project} is the name of the ROS package.

rosbuild_add_rostest_labeled

rosbuild_add_rostest_labeled(label file)

This macro is the same a rosbuild_add_rostest(), except that it only declares the test if EITHER:

  • the environment variable ROS_BUILD_TEST_LABEL is unset; OR

  • the label argument is equal to the environment variableROS_BUILD_TEST_LABEL.

Use this macro to declare tests that should not run in certain situations. Most commonly used with a continuous integration system.

rosbuild_add_rostest_future

DEPRECATED and rendered non-functional in 1.7. Instead of using this macro, simply comment out tests that don't yet pass.

rosbuild_add_rostest_future(xmlfile)

This macro is the same a rosbuild_add_rostest(), except that the resulting test will be only be run duringmake test-future. Use this macro to declare tests that fail now, but should pass in the future, after an existing bug is fixed or missing feature implemented.

We segregate future tests from current tests so that the automated build and test system can accurately report health of the system, including giving meaningful email notification on test failure.

rosbuild_add_roslaunch_check

(New in ROS 1.1.2)

rosbuild_add_roslaunch_check(file_or_directory [var1=val] [var2=val2] ...)

This macro declares as a unit test a parse check of one or moreroslaunchfiles. The parser (roslaunch/scripts/roslaunch-check) checks a number ofaspects of launch files, in a manner similar toroswtf.

The first argument should be either aroslaunch file, or a directory.If it's a directory, then all*.launch files in that directory arechecked.

Following the required first argument, you can optionally specifyenvironment variables that will be set before running the parser. Thisfeature is useful if you use $(env) in your roslaunch files. E.g., totest a roslaunch file with the environment variableROBOT set tosim:

rosbuild_add_roslaunch_check(foo.launch ROBOT=sim)

NOTE: Do not call your file or directorytest. This target name is reserved for unit testing, and CMake will fail if you try it. Instead, put your launch files into a directory with a different name, e.g.,tests.

rosbuild_declare_test

rosbuild_declare_test(exe)

This macro declares that an executable is a test harness, which adds it to themake tests build. Use this macro to declare that an executable is only used in testing. This macro is automatically invoked for any executable that is declared viarosbuild_add_gtest(),rosbuild_add_gtest_future(), orrosbuild_add_gtest_build_flags(). So you only need to use this macro for an executable that is used in testing, but isn't a test itself; e.g., a node that is used in setting up arostest.

This macro does not exclude building the executable from themake all build. To do this, you must supply theEXCLUDE_FROM_ALL option when callingrosbuild_add_executable().

rosbuild_count_cores

rosbuild_count_cores(num)

This macro calls out to Python to determine the number of physical cores on your machine, and writes this number intonum. It's intended for use in gating tests that require a lot of processing. E.g., if you want to run a test only when you have at least 4 cores:

rosbuild_count_cores(cores)
if(cores GREATER 4 OR cores EQUAL 4)
  rosbuild_add_rostest(my_crazy_test.xml)
endif(cores GREATER 4 OR cores EQUAL 4)

rosbuild_check_for_display

rosbuild_check_for_display(var)

This macro checks for the presence of an X display (currently by looking at the exit status from callingxdpyinfo). It setsvar to 1 if there is a display, and 0 otherwise. It's intended for us in gating tests that require an X display, e.g.:

rosbuild_check_for_display(disp)
if(disp)
  rosbuild_add_rostest(my_graphical_test.xml)
endif(disp)

rosbuild_check_for_vm

rosbuild_check_for_vm(result)

This macro determines whether the build is happening on a virtual machine. Currently, it just looks for "/proc/xen". The intended use is gating tests that have strict timing requirements. The assumption is that a non-VM will have low load.

E.g., to only run a test on a non-VM:

rosbuild_check_for_vm(vm)
if(NOT vm)
  rosbuild_add_rostest(my_strict_timing_test.xml)
endif(NOT vm)

Message / service macros

rosbuild_gensrv

rosbuild_gensrv()

This macro processes service specifications that defined locally in a package. It runsclient library-specific code generators over all*.srv files found in the srv subdirectory of the package.

Example usage:

cmake_minimum_required(VERSION 2.4.6)
include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)
rosbuild_init()
rosbuild_gensrv()
# the service provider
rosbuild_add_executable(deadreckon deadreckon.cpp)
# a dumb test client
rosbuild_add_executable(test_deadreckon_service test_deadreckon_service.cpp)

rosbuild_genmsg

rosbuild_genmsg()

This macro processes message specifications that defined locally in a package. It runsclient library-specific code generators over all*.msg files found in the msg subdirectory of the package.

rosbuild_add_generated_msgs

rosbuild_add_generated_msgs(AutoGen1.msg AutoGen2.msg)

This macro sets up for auto-generation of one or more messages. It creates an expectation that the message files passed as arguments will be created during the build. This macro may be called more than once. Through CTurtle, this macro must be called before rosbuild_init(). Starting with Diamondback, it must be calledbefore rosbuild_genmsg().

Auto-generating messages is an advanced topic; see the code inactionlib for an example.

rosbuild_add_generated_srvs

rosbuild_add_generated_srvs(AutoGen1.srv AutoGen2.srv)

This macro sets up for auto-generation of one or more services. It creates an expectation that the service files passed as arguments will be created during the build. This macro may be called more than once. Through CTurtle, this macro must be called before rosbuild_init(). Starting with Diamondback, it must be calledbefore rosbuild_gensrv().

Auto-generating services is an advanced topic; see the code inactionlib for an example.

Version macros

rosbuild_get_stack_version

(New in ROS 1.3.1)

rosbuild_get_stack_version(var stackname)

This macro fetches the name of the stackstackname and puts it intovar. If the version cannot be determined, it is a fatal error. This macro works by callingrosversion.

rosbuild_get_package_version

(New in ROS 1.3.1)

rosbuild_get_package_version(var pkgname)

This macro fetches the version of the stack that contains the packagepkgname, and puts it intovar. If the package is not in a stack, or if the stack's version cannot be determined, it is a fatal error. This macro works by callingrosbuild_get_stack_version(), with the output ofrosstack contains pkgname.

Downloading files during the build

It is sometimes necessary to download files during the build. This is usually done to avoid checking large, often binary, files into Subversion. Some macros are provided to help in these cases

rosbuild_download_data

(New in 0.8; 3-argument form new in 0.9)

rosbuild_download_data(url filename md5sum)

DEPRECATED 2-argument form, without an md5sum:

rosbuild_download_data(url filename)

This macro sets up a target for downloading a file fromurl and saving it locally with the namefilename, and checking the resulting file's md5 hash againstmd5sum. The target will fire on theall target, which means that it will happen during the main build of the package. There are no guarantees on ordering of steps within theall target (e.g., the download is not guaranteed to happen before a particular compilation step). Theurl should be fully-qualified (e.g., don't leave out the domain name), and thefilename should be relative to your package directory.

The md5 hash is checked on every build; if it doesn't match,filename is deleted, and one attempt is made to re-download the file; if it still doesn't match, the build is aborted with an error.

If you're pulling from a web-accessible Subversion repository and want a particular revision of a file, you can use the standard Subversion URL syntax,!svn/bc//. E.g., to download revision 6 of a map:

rosbuild_download_data(https://code.ros.org/svn/data/!svn/bc/6/trunk/willow_maps/willow-2010-02-18-0.025.pgm willow-2010-02-18-0.025.pgm b9c44f1d528c1ebd6a3f5b6720a5b8df)

Note for Willow Garage people: You should put your data at ipr:/var/www/pr.willowgarage.com/html/data, in a directory with the same name as your package.

rosbuild_download_test_data

(3-argument form new in 0.9)

rosbuild_download_test_data(url filename md5sum)

DEPRECATED 2-argument form, without an md5sum:

rosbuild_download_test_data(url filename)

This macro is the same as rosbuild_download_data(), except that it will fire on thetests target, which happens during the build of test programs, prior to running any tests.

Note for Willow Garage people: You should put your data atipr:/var/www/pr.willowgarage.com/html/data, in a directory with the same name as your package.

rosbuild_untar_file

(new in 1.1.8)

rosbuild_untar_file(tarfile unpacked_name [target])

This macro sets up rules to unpack the filetarfile, using the commandtar xf. The rule expects the file or directoryunpacked_name to exist after unpacking; you would normally set this equal to the name of the top-level directory contained intarfile. The optionaltarget is a target that should be made to depend on the unpacking oftarfile. Common values fortarget areALL (unpack duringmake) and tests (unpack duringmake test, prior to running any tests).

For example, to download a tar file of test data, and make sure that it's unpacked before running tests on it:

rosbuild_download_test_data(http://pr.willowgarage.com/data/${PROJECT_NAME}/test_session_results_fixture.tgz test_data/test_session_results_fixture.tgz a15e52b7b827ab7560bd42c98e7c5a93)
rosbuild_untar_file(test_data/test_session_results_fixture.tgz test_data/session_results_gold tests)

Special targets

rosbuild defines some special targets that you can use to encode dependencies in the build process.

rosbuild_premsgsrvgen

The rosbuild_premsgsrvgen target fires before doing message or service generation. By making this target depend on one of your targets, you can do work beforehand. A simple example, which will generate a file before message or service generation:

# Generate the file foo
add_custom_command(OUTPUT foo COMMAND touch foo)
# Create a target that depends on the generation of foo
add_custom_target(foo_target DEPENDS foo)
# Make message service generation depend on our target:
add_dependencies(rosbuild_premsgsrvgen foo)

rosbuild_precompile

The rosbuild_precompile target fires before compiling any C/C++ programs. By making this target depend on one of your targets, you can do work beforehand. A simple example, which will generate a file before compiling:

# Generate the file foo
add_custom_command(OUTPUT foo COMMAND touch foo)
# Create a target that depends on the generation of foo
add_custom_target(foo_target DEPENDS foo)
# Make compilation depend on our target:
add_dependencies(rosbuild_precompile foo)

Making stack distributions

The release unit in ROS is a stack. rosbuild offers support for making source distributions of stacks (more information).

rosbuild_make_distribution

rosbuild_make_distribution(version)
This macro performs the set up necessary to produce a source tarball of the stack, at the given version.

你可能感兴趣的:(ROS,Linux/Ubuntu,Ubuntu+ROS)