CMakeLists.txt 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 20)
  7. if(MSVC)
  8. add_compile_definitions(NOMINMAX _WINSOCK_DEPRECATED_NO_WARNINGS _CRT_SECURE_NO_WARNINGS)
  9. add_definitions(/wd4068 /wd4244 /wd4018 /wd4101 /wd4102 /wd4142 /wd4996)
  10. endif()
  11. # Main library sources
  12. file(GLOB SOURCES "src/*.cpp" "src/*.c")
  13. if(WIN32)
  14. list(APPEND SOURCES "mdnssvc/mdns.c" "mdnssvc/mdnsd.c")
  15. list(APPEND EXTRA_INCLUDES "mdnssvc")
  16. endif()
  17. # Use externally specified bell library or the submodule
  18. if(CSPOT_EXTERNAL_BELL)
  19. list(APPEND EXTRA_LIBS ${CSPOT_EXTERNAL_BELL})
  20. else()
  21. add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/bell)
  22. list(APPEND EXTRA_LIBS bell)
  23. endif()
  24. # Add Apple Bonjour compatibility library for Linux
  25. if(UNIX AND NOT APPLE)
  26. list(APPEND EXTRA_LIBS dns_sd)
  27. # TODO: migrate from this to native linux mDNS
  28. endif()
  29. # Build protobuf code
  30. if(0)
  31. set(NANOPB_OPTIONS "-I${CMAKE_CURRENT_SOURCE_DIR}")
  32. file(GLOB PROTOS protobuf/*.proto)
  33. nanopb_generate_cpp(PROTO_SRCS PROTO_HDRS RELPATH ${CMAKE_CURRENT_SOURCE_DIR} ${PROTOS})
  34. add_custom_target(generate_proto_sources DEPENDS ${PROTO_SRCS} ${PROTO_HDRS})
  35. set_source_files_properties(${PROTO_SRCS} ${PROTO_HDRS} PROPERTIES GENERATED TRUE)
  36. else()
  37. list(APPEND SOURCES "protobuf/authentication.pb.c" "protobuf/keyexchange.pb.c" "protobuf/mercury.pb.c" "protobuf/metadata.pb.c" "protobuf/spirc.pb.c")
  38. list(APPEND EXTRA_INCLUDES ".")
  39. message(WARNING "NOT GENERATING PROTOBUF")
  40. endif()
  41. add_library(cspot STATIC ${SOURCES} ${PROTO_SRCS})
  42. # PUBLIC to propagate includes from bell to cspot dependents
  43. target_compile_definitions(bell PUBLIC PB_ENABLE_MALLOC)
  44. target_compile_definitions(bell PUBLIC PB_FIELD_32BIT)
  45. target_link_libraries(cspot PUBLIC ${EXTRA_LIBS})
  46. target_include_directories(cspot PUBLIC "include" ${CMAKE_CURRENT_BINARY_DIR} ${NANOPB_INCLUDE_DIRS} ${EXTRA_INCLUDES})