1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- cmake_minimum_required(VERSION 2.8.12)
- project(cspot)
- # Configurable options
- set(CSPOT_EXTERNAL_BELL "" CACHE STRING "External bell library target name, optional")
- # CMake options
- set(CMAKE_CXX_STANDARD 17)
- # Main library sources
- file(GLOB SOURCES "src/*.cpp" "src/*.c")
- # Use externally specified bell library or the submodule
- if(CSPOT_EXTERNAL_BELL)
- list(APPEND EXTRA_LIBS ${CSPOT_EXTERNAL_BELL})
- else()
- add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/bell)
- list(APPEND EXTRA_LIBS bell)
- endif()
- # Add Apple Bonjour compatibility library for Linux
- if(UNIX AND NOT APPLE)
- list(APPEND EXTRA_LIBS dns_sd)
- # TODO: migrate from this to native linux mDNS
- endif()
- if (GENERATE_PROTOS)
- file(GLOB SOURCES "src/*.cpp" "src/*.c")
- set(NANOPB_OPTIONS "-I${CMAKE_CURRENT_SOURCE_DIR}")
- set(PROTOS protobuf/authentication.proto protobuf/mercury.proto protobuf/keyexchange.proto protobuf/spirc.proto protobuf/metadata.proto)
- message(${PROTOS})
- message("building protobuf")
- message(${CMAKE_CURRENT_SOURCE_DIR})
- nanopb_generate_cpp(PROTO_SRCS PROTO_HDRS RELPATH ${CMAKE_CURRENT_SOURCE_DIR} ${PROTOS})
- add_custom_target(generate_proto_sources DEPENDS ${PROTO_SRCS} ${PROTO_HDRS})
- set_source_files_properties(${PROTO_SRCS} ${PROTO_HDRS} PROPERTIES GENERATED TRUE)
- set(GENERATED_INCLUDES ${CMAKE_CURRENT_BINARY_DIR})
- else()
- file(GLOB SOURCES "src/*.cpp" "src/*.c" "protobuf/*.c")
- message("BEWARE => NOT GENERATING PROTOBUF")
- set(GENERATED_INCLUDES ".")
- endif()
- add_library(cspot STATIC ${SOURCES} ${PROTO_SRCS})
- # PUBLIC to propagate includes from bell to cspot dependents
- target_compile_definitions(bell PUBLIC PB_ENABLE_MALLOC)
- target_compile_definitions(bell PUBLIC PB_FIELD_32BIT)
- target_link_libraries(cspot PUBLIC ${EXTRA_LIBS})
- target_include_directories(cspot PUBLIC "include" ${GENERATED_INCLUDES} ${NANOPB_INCLUDE_DIRS})
|