CMakeLists.txt 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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. # Use externally specified bell library or the submodule
  14. if(CSPOT_EXTERNAL_BELL)
  15. list(APPEND EXTRA_LIBS ${CSPOT_EXTERNAL_BELL})
  16. else()
  17. add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/bell)
  18. list(APPEND EXTRA_LIBS bell)
  19. endif()
  20. # Build protobuf code
  21. set(NANOPB_OPTIONS "-I${CMAKE_CURRENT_SOURCE_DIR}")
  22. file(GLOB PROTOS protobuf/*.proto)
  23. nanopb_generate_cpp(PROTO_SRCS PROTO_HDRS RELPATH ${CMAKE_CURRENT_SOURCE_DIR} ${PROTOS})
  24. add_custom_target(generate_proto_sources DEPENDS ${PROTO_SRCS} ${PROTO_HDRS})
  25. set_source_files_properties(${PROTO_SRCS} ${PROTO_HDRS} PROPERTIES GENERATED TRUE)
  26. add_library(cspot STATIC ${SOURCES} ${PROTO_SRCS})
  27. # PUBLIC to propagate includes from bell to cspot dependents
  28. target_compile_definitions(bell PUBLIC PB_ENABLE_MALLOC)
  29. target_compile_definitions(bell PUBLIC PB_FIELD_32BIT)
  30. target_link_libraries(cspot PUBLIC ${EXTRA_LIBS})
  31. target_include_directories(cspot PUBLIC "include" ${CMAKE_CURRENT_BINARY_DIR} ${NANOPB_INCLUDE_DIRS} ${EXTRA_INCLUDES})