CMakeLists.txt 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #
  2. # Copyright (c) 2016-2017 UAVCAN Team
  3. #
  4. cmake_minimum_required(VERSION 3.1)
  5. project(libcanard)
  6. # Catch library for unit testing
  7. include_directories(catch)
  8. # Libcanard
  9. include_directories(..)
  10. include_directories(../drivers/socketcan)
  11. # Compiler configuration - supporting only Clang and GCC
  12. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wextra -Werror -m32")
  13. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -Wall -Wextra -Werror -m32 -pedantic")
  14. # C warnings
  15. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wdouble-promotion -Wswitch-enum -Wfloat-equal -Wundef")
  16. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wconversion -Wtype-limits")
  17. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wsign-conversion -Wcast-align -Wmissing-declarations")
  18. # C++ warnings
  19. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wdouble-promotion -Wswitch-enum -Wfloat-equal -Wundef")
  20. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wconversion -Wsign-promo")
  21. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wsign-conversion -Wcast-align -Wmissing-declarations")
  22. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wtype-limits -Wzero-as-null-pointer-constant -Wnon-virtual-dtor")
  23. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Woverloaded-virtual -Wsign-promo -Wold-style-cast")
  24. # We allow the following warnings for compatibility with the C codebase:
  25. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=old-style-cast -Wno-error=zero-as-null-pointer-constant")
  26. # Expose internal API for unit testing
  27. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DCANARD_INTERNAL=''")
  28. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DCANARD_INTERNAL=''")
  29. # Unit tests
  30. file(GLOB tests_src
  31. RELATIVE "${CMAKE_SOURCE_DIR}"
  32. "*.cpp"
  33. "catch/*.cpp"
  34. "stm32/*.cpp")
  35. message(STATUS "Unit test source files: ${tests_src}")
  36. add_executable(run_tests
  37. ${tests_src}
  38. ../canard.c)
  39. target_link_libraries(run_tests
  40. pthread)
  41. # Demo application
  42. exec_program("git"
  43. ${CMAKE_CURRENT_SOURCE_DIR}
  44. ARGS "rev-parse --short=8 HEAD"
  45. OUTPUT_VARIABLE GIT_HASH)
  46. add_executable(demo
  47. demo.c
  48. ../canard.c
  49. ../drivers/socketcan/socketcan.c)
  50. target_compile_definitions(demo
  51. PUBLIC GIT_HASH=0x${GIT_HASH})