CMakeLists.txt 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. # toplevel CMakeLists.txt for a catkin workspace
  2. # catkin/cmake/toplevel.cmake
  3. cmake_minimum_required(VERSION 2.8.3)
  4. set(CATKIN_TOPLEVEL TRUE)
  5. # search for catkin within the workspace
  6. set(_cmd "catkin_find_pkg" "catkin" "${CMAKE_SOURCE_DIR}")
  7. execute_process(COMMAND ${_cmd}
  8. RESULT_VARIABLE _res
  9. OUTPUT_VARIABLE _out
  10. ERROR_VARIABLE _err
  11. OUTPUT_STRIP_TRAILING_WHITESPACE
  12. ERROR_STRIP_TRAILING_WHITESPACE
  13. )
  14. if(NOT _res EQUAL 0 AND NOT _res EQUAL 2)
  15. # searching fot catkin resulted in an error
  16. string(REPLACE ";" " " _cmd_str "${_cmd}")
  17. message(FATAL_ERROR "Search for 'catkin' in workspace failed (${_cmd_str}): ${_err}")
  18. endif()
  19. # include catkin from workspace or via find_package()
  20. if(_res EQUAL 0)
  21. set(catkin_EXTRAS_DIR "${CMAKE_SOURCE_DIR}/${_out}/cmake")
  22. # include all.cmake without add_subdirectory to let it operate in same scope
  23. include(${catkin_EXTRAS_DIR}/all.cmake NO_POLICY_SCOPE)
  24. add_subdirectory("${_out}")
  25. else()
  26. # use either CMAKE_PREFIX_PATH explicitly passed to CMake as a command line argument
  27. # or CMAKE_PREFIX_PATH from the environment
  28. if(NOT DEFINED CMAKE_PREFIX_PATH)
  29. if(NOT "$ENV{CMAKE_PREFIX_PATH}" STREQUAL "")
  30. string(REPLACE ":" ";" CMAKE_PREFIX_PATH $ENV{CMAKE_PREFIX_PATH})
  31. endif()
  32. endif()
  33. # list of catkin workspaces
  34. set(catkin_search_path "")
  35. foreach(path ${CMAKE_PREFIX_PATH})
  36. if(EXISTS "${path}/.catkin")
  37. list(FIND catkin_search_path ${path} _index)
  38. if(_index EQUAL -1)
  39. list(APPEND catkin_search_path ${path})
  40. endif()
  41. endif()
  42. endforeach()
  43. # search for catkin in all workspaces
  44. set(CATKIN_TOPLEVEL_FIND_PACKAGE TRUE)
  45. find_package(catkin QUIET
  46. NO_POLICY_SCOPE
  47. PATHS ${catkin_search_path}
  48. NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
  49. unset(CATKIN_TOPLEVEL_FIND_PACKAGE)
  50. if(NOT catkin_FOUND)
  51. message(FATAL_ERROR "find_package(catkin) failed. catkin was neither found in the workspace nor in the CMAKE_PREFIX_PATH. One reason may be that no ROS setup.sh was sourced before.")
  52. endif()
  53. endif()
  54. catkin_workspace()