Projektarbeit Line Following Robot bei Prof. Chowanetz im WS22/23
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CMakeLists.txt 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. # ----------------------------------------------------------------------------
  2. # Basic Configuration
  3. # ----------------------------------------------------------------------------
  4. CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
  5. if (POLICY CMP0048)
  6. cmake_policy(SET CMP0048 NEW)
  7. endif (POLICY CMP0048)
  8. PROJECT(raspicam)
  9. set(PROJECT_VERSION "0.1.2")
  10. string(REGEX MATCHALL "[0-9]" PROJECT_VERSION_PARTS "${PROJECT_VERSION}")
  11. list(GET PROJECT_VERSION_PARTS 0 PROJECT_VERSION_MAJOR)
  12. list(GET PROJECT_VERSION_PARTS 1 PROJECT_VERSION_MINOR)
  13. list(GET PROJECT_VERSION_PARTS 2 PROJECT_VERSION_PATCH)
  14. set(PROJECT_SOVERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}")
  15. #------------------------------------------------------
  16. # Build type
  17. #------------------------------------------------------
  18. IF(NOT CMAKE_BUILD_TYPE )
  19. SET( CMAKE_BUILD_TYPE "Release" )
  20. ENDIF()
  21. #------------------------------------------------------
  22. # Lib Names and Dirs
  23. #------------------------------------------------------
  24. # Postfix of so's:
  25. set(PROJECT_DLLVERSION)
  26. SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_INSTALL_PREFIX}/lib/cmake/ /usr/lib/cmake)
  27. OPTION(BUILD_SHARED_LIBS "Set to OFF to build static libraries" ON)
  28. OPTION(BUILD_UTILS "Acitvates/Deactivates building utils libraries" ON)
  29. # ----------------------------------------------------------------------------
  30. # Find Dependencies
  31. # ----------------------------------------------------------------------------
  32. #Add include to dependencies dir
  33. include_directories(${PROJECT_SOURCE_DIR}/dependencies ${PROJECT_SOURCE_DIR}/dependencies/mmal ${PROJECT_SOURCE_DIR}/dependencies/vcos)
  34. #find the mmal libraries(I use conditional because I normally comile in pc)
  35. if(${CMAKE_SYSTEM_PROCESSOR} MATCHES arm*)
  36. FIND_LIBRARY(mmalcore_LIBS NAMES mmal_core PATHS /opt/vc/lib)
  37. FIND_LIBRARY(mmalutil_LIBS NAMES mmal_util PATHS /opt/vc/lib)
  38. FIND_LIBRARY(mmal_LIBS NAMES mmal PATHS /opt/vc/lib)
  39. IF( (NOT mmal_LIBS ) OR (NOT mmalutil_LIBS) OR (NOT mmalcore_LIBS) )
  40. MESSAGE(FATAL_ERROR "Could not find mmal libraries")
  41. ENDIF()
  42. set(REQUIRED_LIBRARIES ${REQUIRED_LIBRARIES} ${mmalcore_LIBS} ${mmalutil_LIBS} ${mmal_LIBS} )
  43. ENDIF()
  44. #If opencv installed, creates the libraspicam_cv library module
  45. FIND_PACKAGE(OpenCV)
  46. IF(OpenCV_FOUND)
  47. include_directories(${OpenCV_INCLUDE_DIRS})
  48. SET(LIB_COMPONENTS ${LIB_COMPONENTS} ${PROJECT_NAME}_cv)
  49. SET(PROJECT_CV_CREATED_FLAG "YES")
  50. ENDIF()
  51. # ----------------------------------------------------------------------------
  52. # PROJECT CONFIGURATION
  53. # force some variables that could be defined in the command line to be written to cache
  54. # ----------------------------------------------------------------------------
  55. OPTION(INSTALL_DOC "Set to ON to build/install Documentation" OFF)
  56. IF (INSTALL_DOC)
  57. FIND_PACKAGE(Doxygen REQUIRED)
  58. MESSAGE( STATUS "INSTALL_DOC: ${INSTALL_DOC} ")
  59. INCLUDE("${PROJECT_SOURCE_DIR}/generateDoc.cmake")
  60. GENERATE_DOCUMENTATION(${PROJECT_SOURCE_DIR}/dox.in)
  61. ENDIF()
  62. # ----------------------------------------------------------------------------
  63. # Uninstall target, for "make uninstall"
  64. # ----------------------------------------------------------------------------
  65. CONFIGURE_FILE( "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" IMMEDIATE @ONLY)
  66. ADD_CUSTOM_TARGET(uninstall "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")
  67. # ----------------------------------------------------------------------------
  68. # create configuration file from .in file (If you use windows take care with paths)
  69. # ----------------------------------------------------------------------------
  70. CONFIGURE_FILE("${PROJECT_SOURCE_DIR}/config.cmake.in" "${PROJECT_BINARY_DIR}/Find${PROJECT_NAME}.cmake")
  71. CONFIGURE_FILE("${PROJECT_SOURCE_DIR}/config.cmake.in" "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake")
  72. INSTALL(FILES "${PROJECT_BINARY_DIR}/Find${PROJECT_NAME}.cmake" DESTINATION lib/cmake/ )
  73. INSTALL(FILES "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" DESTINATION lib/cmake/ )
  74. # ----------------------------------------------------------------------------
  75. # Program Optimization and debug (Extracted from OpenCV)
  76. # ----------------------------------------------------------------------------
  77. set(WARNINGS_ARE_ERRORS OFF CACHE BOOL "Treat warnings as errors")
  78. set(WHOLE_PROGRAM_OPTIMIZATION OFF CACHE BOOL "Flags for whole program optimization.")
  79. set(EXTRA_C_FLAGS "")
  80. set(EXTRA_C_FLAGS_RELEASE "")
  81. set(EXTRA_C_FLAGS_DEBUG "")
  82. set(EXTRA_EXE_LINKER_FLAGS "")
  83. set(EXTRA_EXE_LINKER_FLAGS_RELEASE "")
  84. set(EXTRA_EXE_LINKER_FLAGS_DEBUG "")
  85. IF(CMAKE_COMPILER_IS_GNUCXX OR MINGW)
  86. set(ENABLE_PROFILING OFF CACHE BOOL "Enable profiling in the GCC compiler (Add flags: -g -pg)")
  87. set(USE_OMIT_FRAME_POINTER ON CACHE BOOL "Enable -fomit-frame-pointer for GCC")
  88. if(${CMAKE_SYSTEM_PROCESSOR} MATCHES arm*) # We can use only -O2 because the -O3 causes gcc crash
  89. set(USE_O2 ON CACHE BOOL "Enable -O2 for GCC")
  90. set(USE_FAST_MATH ON CACHE BOOL "Enable -ffast-math for GCC")
  91. endif()
  92. if(${CMAKE_SYSTEM_PROCESSOR} MATCHES powerpc*)
  93. set(USE_O3 ON CACHE BOOL "Enable -O3 for GCC")
  94. set(USE_POWERPC ON CACHE BOOL "Enable PowerPC for GCC")
  95. endif ()
  96. if(${CMAKE_SYSTEM_PROCESSOR} MATCHES amd64* OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES x86_64*)
  97. set(USE_O3 ON CACHE BOOL "Enable -O3 for GCC")
  98. set(USE_FAST_MATH ON CACHE BOOL "Enable -ffast-math for GCC")
  99. set(USE_MMX ON CACHE BOOL "Enable MMX for GCC")
  100. set(USE_SSE ON CACHE BOOL "Enable SSE for GCC")
  101. set(USE_SSE2 ON CACHE BOOL "Enable SSE2 for GCC")
  102. set(USE_SSE3 ON CACHE BOOL "Enable SSE3 for GCC")
  103. endif()
  104. if(${CMAKE_SYSTEM_PROCESSOR} MATCHES i686* OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES x86)
  105. set(USE_O3 ON CACHE BOOL "Enable -O3 for GCC")
  106. set(USE_FAST_MATH ON CACHE BOOL "Enable -ffast-math for GCC")
  107. set(USE_MMX ON CACHE BOOL "Enable MMX for GCC")
  108. set(USE_SSE OFF CACHE BOOL "Enable SSE for GCC")
  109. set(USE_SSE2 OFF CACHE BOOL "Enable SSE2 for GCC")
  110. set(USE_SSE3 OFF CACHE BOOL "Enable SSE3 for GCC")
  111. endif ()
  112. set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -Wall")
  113. if(WARNINGS_ARE_ERRORS)
  114. set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -Werror")
  115. endif()
  116. # The -Wno-long-long is required in 64bit systems when including sytem headers.
  117. if(${CMAKE_SYSTEM_PROCESSOR} MATCHES x86_64* OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES amd64*)
  118. set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -Wno-long-long")
  119. endif()
  120. # Whole program optimization
  121. if(WHOLE_PROGRAM_OPTIMIZATION)
  122. set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} -fwhole-program --combine")
  123. endif()
  124. # Other optimizations
  125. if(USE_OMIT_FRAME_POINTER)
  126. set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} -fomit-frame-pointer")
  127. endif()
  128. if(USE_O2)
  129. set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} -O2")
  130. endif()
  131. if(USE_O3)
  132. set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} -O3")
  133. endif()
  134. if(USE_FAST_MATH)
  135. set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} -ffast-math")
  136. endif()
  137. if(USE_POWERPC)
  138. set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} -mcpu=G3 -mtune=G5")
  139. endif()
  140. if(USE_MMX)
  141. set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} -mmmx")
  142. endif()
  143. if(USE_SSE)
  144. set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} -msse")
  145. endif()
  146. if(USE_SSE2)
  147. set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} -msse2")
  148. endif()
  149. if(USE_SSE3 AND NOT MINGW) # SSE3 should be disabled under MingW because it generates compiler errors
  150. set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} -msse3")
  151. endif()
  152. if(ENABLE_PROFILING)
  153. set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} -pg -g")
  154. else()
  155. if(NOT APPLE)
  156. set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -ffunction-sections")
  157. endif()
  158. endif()
  159. # Parallel mode
  160. if(ENABLE_OPENMP)
  161. set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -fopenmp")
  162. set(LINKER_LIBS ${LINKER_LIBS} gomp)
  163. endif()
  164. set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} -DNDEBUG")
  165. set(EXTRA_C_FLAGS_DEBUG "-g3 -O0 -DDEBUG -D_DEBUG -W -Wextra -Wno-return-type")
  166. MESSAGE( STATUS "-------------------------------------------------------------------------------" )
  167. message( STATUS "GNU COMPILER")
  168. MESSAGE( STATUS "-------------------------------------------------------------------------------" )
  169. ENDIF ()
  170. IF(${CMAKE_SYSTEM_PROCESSOR} MATCHES armv6l ) ##BEAGLE BOARD
  171. SET(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} -mcpu=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard -ftree-vectorize")
  172. ENDIF()
  173. SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-pedantic -Wall -Wno-variadic-macros -std=c++0x -Wl,--no-as-needed")#for using condition variables
  174. SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_C_FLAGS} ")
  175. SET(CMAKE_CXX_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} -lpthread")
  176. SET(CMAKE_CXX_FLAGS_DEBUG "${EXTRA_C_FLAGS_DEBUG} -lpthread")
  177. SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${EXTRA_EXE_LINKER_FLAGS}")
  178. SET(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} ${EXTRA_EXE_LINKER_FLAGS_RELEASE}")
  179. SET(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} ${EXTRA_EXE_LINKER_FLAGS_DEBUG}")
  180. #------------------------------------------------
  181. # DIRS
  182. #------------------------------------------------
  183. ADD_SUBDIRECTORY(src)
  184. IF(BUILD_UTILS)
  185. ADD_SUBDIRECTORY(utils)
  186. ENDIF()
  187. # ----------------------------------------------------------------------------
  188. # display status message for important variables
  189. # ----------------------------------------------------------------------------
  190. message( STATUS )
  191. MESSAGE( STATUS "-------------------------------------------------------------------------------" )
  192. message( STATUS "General configuration for ${PROJECT_NAME} ${PROJECT_VERSION}")
  193. MESSAGE( STATUS "-------------------------------------------------------------------------------" )
  194. message( STATUS )
  195. message(" Built as dynamic libs?:" ${BUILD_SHARED_LIBS})
  196. message(" Compiler:" "${CMAKE_COMPILER}" "${CMAKE_CXX_COMPILER}")
  197. message( STATUS "C++ flags (Release): ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELEASE}")
  198. message( STATUS "C++ flags (Debug): ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_DEBUG}")
  199. message( STATUS "CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
  200. message( STATUS "CMAKE_BINARY_DIR: ${CMAKE_BINARY_DIR}")
  201. MESSAGE( STATUS )
  202. MESSAGE( STATUS "CMAKE_SYSTEM_PROCESSOR = ${CMAKE_SYSTEM_PROCESSOR}" )
  203. MESSAGE( STATUS "BUILD_SHARED_LIBS = ${BUILD_SHARED_LIBS}" )
  204. MESSAGE( STATUS "BUILD_UTILS = ${BUILD_UTILS}" )
  205. MESSAGE( STATUS "CMAKE_INSTALL_PREFIX = ${CMAKE_INSTALL_PREFIX}" )
  206. MESSAGE( STATUS "CMAKE_BUILD_TYPE = ${CMAKE_BUILD_TYPE}" )
  207. MESSAGE( STATUS "CMAKE_MODULE_PATH = ${CMAKE_MODULE_PATH}" )
  208. MESSAGE( STATUS )
  209. MESSAGE( STATUS "CREATE OPENCV MODULE=${OpenCV_FOUND}")
  210. MESSAGE( STATUS "CMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}")
  211. MESSAGE( STATUS "REQUIRED_LIBRARIES=${REQUIRED_LIBRARIES}")
  212. MESSAGE( STATUS )
  213. MESSAGE( STATUS )
  214. MESSAGE( STATUS "Change a value with: cmake -D<Variable>=<Value>" )
  215. MESSAGE( STATUS )