CMakeLists.txt 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. project (mavlink)
  2. if (NOT DEFINED MAVLINK_SOURCE_DIR)
  3. set(MAVLINK_SOURCE_DIR ${CMAKE_SOURCE_DIR})
  4. endif ()
  5. # settings
  6. cmake_minimum_required (VERSION 2.8.2)
  7. set(PROJECT_VERSION_MAJOR "1")
  8. set(PROJECT_VERSION_MINOR "0")
  9. set(PROJECT_VERSION_PATCH "9")
  10. set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")
  11. set(PROJECT_CONTACT_EMAIL http://groups.google.com/group/mavlink)
  12. set(PROJECT_CONTACT_VENDOR mavlink)
  13. set(LIBRARY_VERSION ${PROJECT_VERSION})
  14. set(LIBRARY_SOVERSION "0.0.0")
  15. # third party
  16. # none required
  17. # options
  18. option(WITH_TESTS "Build test programs." OFF)
  19. option(WITH_BUILD_DEPS "Build dependencies." OFF) # no deps currently to build
  20. option(WITH_BUILD_STATIC "Build preferring static linking." ON)
  21. # variables
  22. set(ROOT_THREAD TRUE CACHE INTERNAL "Is this the top level of the recursion?")
  23. # modules
  24. list(APPEND CMAKE_MODULE_PATH ${MAVLINK_SOURCE_DIR}/cmake ${MAVLINK_SOURCE_DIR}/cmake/arkcmake)
  25. include(DefineCMakeDefaults)
  26. include(CheckIncludeFiles)
  27. include(CheckFunctionExists)
  28. include(CheckSymbolExists)
  29. include(CheckLibraryExists)
  30. #include(CheckTypeSize)
  31. #include(CheckPrototypeExists)
  32. #include(CheckCXXSourceCompiles)
  33. #include(CheckCSourceCompiles)
  34. include(ExternalProjectWithFilename)
  35. if (UNIX)
  36. include(GNUInstallDirs)
  37. set(LIB_INSTALL_DIR "lib${LIB_SUFFIX}" CACHE PATH "Installation path for libraries")
  38. endif ()
  39. # spawn new cmake to build deps
  40. if (WITH_BUILD_DEPS AND ROOT_THREAD)
  41. execute_process(COMMAND ${CMAKE_COMMAND} "${MAVLINK_SOURCE_DIR}"
  42. "-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}"
  43. "-DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}"
  44. "-DWITH_BUILD_DEPS=${WITH_BUILD_DEPS}"
  45. "-DWITH_BUILD_STATIC=${WITH_BUILD_STATIC}"
  46. "-DWITH_TESTS=${WITH_TESTS}"
  47. "-DROOT_THREAD=FALSE"
  48. RESULT_VARIABLE ERROR)
  49. if (ERROR)
  50. message(FATAL_ERROR "error, recursing loop returned error code: ${ERROR}")
  51. endif()
  52. message("** Making dependencies")
  53. execute_process(COMMAND ${CMAKE_MAKE_PROGRAM} "-j4" "-f${CMAKE_BINARY_DIR}/Makefile")
  54. message("** Configuring ${PROJECT_NAME}")
  55. endif()
  56. # external projects find path
  57. if(NOT EP_BASE_DIR)
  58. set(EP_BASE_DIR "${CMAKE_BINARY_DIR}/CMakeExternals")
  59. endif()
  60. set_property(DIRECTORY PROPERTY EP_BASE ${EP_BASE_DIR})
  61. set(EP_INSTALL_DIR "${EP_BASE_DIR}/Install")
  62. list(APPEND CMAKE_FIND_ROOT_PATH ${EP_BASE_DIR})
  63. # prefer static packages if building static library
  64. message("** Finding libraries")
  65. if (WITH_BUILD_STATIC)
  66. # prefer static libs
  67. if(WIN32)
  68. set(CMAKE_FIND_LIBRARY_SUFFIXES .lib .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
  69. else()
  70. set(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
  71. endif()
  72. endif()
  73. # find libraries with cmake modules
  74. find_package(PythonInterp)
  75. # enable languages
  76. if (WITH_TESTS)
  77. enable_language(C)
  78. enable_language(CXX)
  79. include(DefineCompilerFlags)
  80. endif()
  81. # build dependencies
  82. if (WITH_BUILD_DEPS AND (NOT ROOT_THREAD) )
  83. message("** Configuring dependencies")
  84. # add external projects
  85. # none required currently
  86. set(CMAKE_DEFAULT_ARGS
  87. -DEP_BASE_DIR=${EP_BASE_DIR}
  88. -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
  89. -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
  90. )
  91. # terminate non root cmake thread
  92. return()
  93. endif()
  94. # configure
  95. #check_include_files(string.h HAVE_STRING_H)
  96. #check_function_exists(memcopy HAVE_MEMCOPY)
  97. #check_symbol_exists(LC_MESSAGES "locale.h" HAVE_LC_MESSAGES)
  98. #check_library_exists(pthread attachNode "" HAVE_PTHREAD)
  99. # config files
  100. configure_file(config.h.in config.h)
  101. install(FILES ${CMAKE_BINARY_DIR}/config.h DESTINATION include/${PROJECT_NAME} COMPONENT Dev)
  102. # mavlink generation
  103. macro(generateMavlink version definitions)
  104. foreach(definition ${definitions})
  105. set(targetName ${definition}-v${version})
  106. set(definitionAbsPath ${MAVLINK_SOURCE_DIR}/message_definitions/v${version}/${definition})
  107. message(STATUS "processing: ${definitionAbsPath}")
  108. add_custom_command(
  109. OUTPUT ${targetName}-stamp
  110. COMMAND PYTHONPATH=$ENV{PYTHONPATH}:${CMAKE_CURRENT_SOURCE_DIR} ${PYTHON_EXECUTABLE} -m pymavlink.tools.mavgen --lang=C --wire-protocol=${version}
  111. --output=include/v${version} ${definitionAbsPath}
  112. COMMAND touch ${targetName}-stamp
  113. )
  114. add_custom_target(${targetName} ALL DEPENDS ${targetName}-stamp)
  115. endforeach()
  116. endmacro()
  117. # build
  118. set(mavgen -m pymavlink.tools.mavgen)
  119. set(v0.9Definitions
  120. ardupilotmega.xml
  121. common.xml
  122. minimal.xml
  123. slugs.xml
  124. test.xml
  125. ualberta.xml
  126. )
  127. generateMavlink("0.9" "${v0.9Definitions}")
  128. set(v1.0Definitions
  129. ASLUAV.xml
  130. ardupilotmega.xml
  131. autoquad.xml
  132. common.xml
  133. matrixpilot.xml
  134. minimal.xml
  135. paparazzi.xml
  136. python_array_test.xml
  137. slugs.xml
  138. test.xml
  139. ualberta.xml
  140. )
  141. generateMavlink("1.0" "${v1.0Definitions}")
  142. # testing
  143. if (BUILD_TEST)
  144. if (UNIX)
  145. include_directories(${CMAKE_BINARY_DIR}/include/v0.9/common)
  146. # TODO fix udp example
  147. #add_executable(mavlink_udp examples/linux/mavlink_udp.c)
  148. endif()
  149. endif()
  150. # install files
  151. install(DIRECTORY ${CMAKE_BINARY_DIR}/include/ DESTINATION include/${PROJECT_NAME} COMPONENT Dev FILES_MATCHING PATTERN "*.h*")
  152. install(DIRECTORY ${CMAKE_BINARY_DIR}/src/ DESTINATION share/${PROJECT_NAME} COMPONENT Dev FILES_MATCHING PATTERN "*.c*")
  153. install(DIRECTORY ${MAVLINK_SOURCE_DIR}/share/${PROJECT_NAME} DESTINATION share COMPONENT Dev FILES_MATCHING PATTERN "*.c*")
  154. if (UNIX)
  155. install(DIRECTORY ${MAVLINK_SOURCE_DIR}/pymavlink DESTINATION ${CMAKE_INSTALL_LIBDIR}/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/site-packages COMPONENT Dev)
  156. else ()
  157. install(DIRECTORY ${MAVLINK_SOURCE_DIR}/pymavlink DESTINATION "share/pyshared" COMPONENT Dev)
  158. endif ()
  159. configure_file(pc.in ${PROJECT_NAME}.pc)
  160. install(FILES
  161. ${PROJECT_BINARY_DIR}/${PROJECT_NAME}.pc
  162. DESTINATION lib${LIB_SUFFIX}/pkgconfig COMPONENT Dev
  163. )
  164. ### packaging
  165. # apple bundle icon
  166. if (APPLE)
  167. # set how it shows up in Info.plist
  168. set(MACOSX_BUNDLE_ICON_FILE mavlink.icns)
  169. # set where in the bundle to put the icns file
  170. set_source_files_properties(cmake/mavlink.icns PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
  171. # include the icns file in the target
  172. #list(APPEND MAVLINKGUI_SRCS cmake/mavlink.icns)
  173. endif()
  174. # set NSIS image
  175. if (WIN32)
  176. set(CPACK_PACKAGE_ICON "${MAVLINK_SOURCE_DIR}/cmake/mavlink.bmp")
  177. endif()
  178. # add file extensions and set resource files
  179. configure_file("COPYING" "COPYING.txt" COPYONLY)
  180. configure_file("README.md" "README.md" COPYONLY)
  181. set(CPACK_RESOURCE_FILE_LICENSE "${MAVLINK_SOURCE_DIR}/COPYING")
  182. set(CPACK_RESOURCE_FILE_README "${MAVLINK_SOURCE_DIR}/README.md")
  183. set(CPACK_PACKAGE_DESCRIPTION_FILE "${CPACK_RESOURCE_FILE_README}")
  184. set(CPACK_RESOURCE_FILE_WELCOME "${MAVLINK_SOURCE_DIR}/cmake/WELCOME.txt")
  185. set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "mavlink message marshalling library")
  186. set(CPACK_PACKAGE_VENDOR ${PROJECT_CONTACT_VENDOR})
  187. set(CPACK_PACKAGE_CONTACT "${PROJECT_CONTACT_EMAIL}")
  188. set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
  189. set(CPACK_SET_DESTDIR TRUE)
  190. set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${PROJECT_VERSION}")
  191. set(CPACK_COMPONENTS_GROUPING "ALL_COMPONENTS_IN_ONE")
  192. include(CPack)
  193. # vim:sw=4:ts=4:expandtab