CMakeLists.txt 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. cmake_minimum_required(VERSION 2.8.12)
  2. project(cspot)
  3. # Configurable options
  4. set(CSPOT_EXTERNAL_BELL "" CACHE STRING "External bell library target name, optional")
  5. # CMake options
  6. set(CMAKE_CXX_STANDARD 17)
  7. # Main library sources
  8. file(GLOB SOURCES "src/*.cpp" "src/*.c")
  9. # Use externally specified bell library or the submodule
  10. if(CSPOT_EXTERNAL_BELL)
  11. list(APPEND EXTRA_LIBS ${CSPOT_EXTERNAL_BELL})
  12. else()
  13. add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/bell)
  14. list(APPEND EXTRA_LIBS bell)
  15. endif()
  16. # Add Apple Bonjour compatibility library for Linux
  17. if(UNIX AND NOT APPLE)
  18. list(APPEND EXTRA_LIBS dns_sd)
  19. # TODO: migrate from this to native linux mDNS
  20. endif()
  21. if (GENERATE_PROTOS)
  22. file(GLOB SOURCES "src/*.cpp" "src/*.c")
  23. set(NANOPB_OPTIONS "-I${CMAKE_CURRENT_SOURCE_DIR}")
  24. set(PROTOS protobuf/authentication.proto protobuf/mercury.proto protobuf/keyexchange.proto protobuf/spirc.proto protobuf/metadata.proto)
  25. message(${PROTOS})
  26. message("building protobuf")
  27. message(${CMAKE_CURRENT_SOURCE_DIR})
  28. nanopb_generate_cpp(PROTO_SRCS PROTO_HDRS RELPATH ${CMAKE_CURRENT_SOURCE_DIR} ${PROTOS})
  29. add_custom_target(generate_proto_sources DEPENDS ${PROTO_SRCS} ${PROTO_HDRS})
  30. set_source_files_properties(${PROTO_SRCS} ${PROTO_HDRS} PROPERTIES GENERATED TRUE)
  31. set(GENERATED_INCLUDES ${CMAKE_CURRENT_BINARY_DIR})
  32. else()
  33. file(GLOB SOURCES "src/*.cpp" "src/*.c" "protobuf/*.c")
  34. message("BEWARE => NOT GENERATING PROTOBUF")
  35. set(GENERATED_INCLUDES ".")
  36. endif()
  37. add_library(cspot STATIC ${SOURCES} ${PROTO_SRCS})
  38. # PUBLIC to propagate includes from bell to cspot dependents
  39. target_compile_definitions(bell PUBLIC PB_ENABLE_MALLOC)
  40. target_compile_definitions(bell PUBLIC PB_FIELD_32BIT)
  41. target_link_libraries(cspot PUBLIC ${EXTRA_LIBS})
  42. target_include_directories(cspot PUBLIC "include" ${GENERATED_INCLUDES} ${NANOPB_INCLUDE_DIRS})