CMakeLists.txt 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. project(ubxproto C)
  2. cmake_minimum_required (VERSION 2.8)
  3. set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
  4. set(UBXPROTO_VERSION 14.0)
  5. set(INSTALL_LIB_DIR usr/lib CACHE PATH "Installation directory for libraries")
  6. set(INSTALL_INCLUDE_DIR usr/include CACHE PATH "Installation directory for headers")
  7. set(INSTALL_DATA_DIR usr/share/${PROJECT_NAME} CACHE PATH "Installation directory for data files")
  8. #Define include paths
  9. include_directories(SYSTEM ${CMAKE_CURRENT_SOURCE_DIR})
  10. #Set sources
  11. set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/ubx.c)
  12. #Compile object files for both shared and static libraries
  13. add_library(ubxprotoobjects OBJECT ${SOURCES})
  14. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
  15. set(PUBLIC_HEADER ${CMAKE_CURRENT_SOURCE_DIR}/ubxaid.h
  16. ${CMAKE_CURRENT_SOURCE_DIR}/ubxcfg.h
  17. ${CMAKE_CURRENT_SOURCE_DIR}/ubx.h
  18. ${CMAKE_CURRENT_SOURCE_DIR}/ubxlog.h
  19. ${CMAKE_CURRENT_SOURCE_DIR}/ubxmessage.h
  20. ${CMAKE_CURRENT_SOURCE_DIR}/ubxmon.h
  21. ${CMAKE_CURRENT_SOURCE_DIR}/ubxrxm.h
  22. ${CMAKE_CURRENT_SOURCE_DIR}/ubxutils.h)
  23. #Static library target
  24. add_library(ubxprotostatic STATIC $<TARGET_OBJECTS:ubxprotoobjects>)
  25. set_target_properties(ubxprotostatic PROPERTIES
  26. OUTPUT_NAME ubxproto
  27. LINKER_LANGUAGE C
  28. PUBLIC_HEADER "${PUBLIC_HEADER}")
  29. set(PROJECT_TARGETS ubxprotostatic)
  30. #Shared library target
  31. add_library(ubxprotoshared SHARED $<TARGET_OBJECTS:ubxprotoobjects>)
  32. set_target_properties(ubxprotoshared PROPERTIES
  33. OUTPUT_NAME ubxproto
  34. LINKER_LANGUAGE C
  35. SOVERSION ${UBXPROTO_VERSION})
  36. set(PROJECT_TARGETS ${PROJECT_TARGETS} ubxprotoshared)
  37. set(PROJECT_LIBS ubxproto)
  38. install(TARGETS ${PROJECT_TARGETS}
  39. EXPORT ${PROJECT_NAME}Targets
  40. ARCHIVE DESTINATION "/${INSTALL_LIB_DIR}" COMPONENT staticlib
  41. LIBRARY DESTINATION "/${INSTALL_LIB_DIR}" COMPONENT sharedlib
  42. PUBLIC_HEADER DESTINATION "/${INSTALL_INCLUDE_DIR}/ubxproto"
  43. COMPONENT dev
  44. )
  45. find_package(Doxygen)
  46. if(DOXYGEN_FOUND)
  47. set(DOXYGEN_INPUT ${CMAKE_SOURCE_DIR})
  48. set(DOXYGEN_OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/doc")
  49. add_custom_target(doc COMMAND ${DOXYGEN_EXECUTABLE} ubxproto.doxyconf
  50. WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
  51. COMMENT "Generating doxygen documenation")
  52. install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/doc" DESTINATION "/${INSTALL_DATA_DIR}" OPTIONAL)
  53. else(DOXYGEN_FOUND)
  54. message(STATUS "WARNING: Doxygen not found - Reference manual will not be created")
  55. endif(DOXYGEN_FOUND)
  56. #Generate cmake find library addtion
  57. include(CMakeGen)