|
| 1 | + |
| 2 | +cmake_minimum_required(VERSION 3.0) |
| 3 | +project(libsigmf CXX) |
| 4 | + |
| 5 | +# c++14 used for auto return type for functions without having to do the -> declaration |
| 6 | +set(CMAKE_CXX_STANDARD 14) |
| 7 | +set(CMAKE_CXX_STANDARD_REQUIRED ON) |
| 8 | + |
| 9 | +list(APPEND CMAKE_MODULE_PATH cmake) |
| 10 | + |
| 11 | +add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/external/flatbuffers |
| 12 | + ${CMAKE_CURRENT_BINARY_DIR}/flatbuffers-build |
| 13 | + EXCLUDE_FROM_ALL) |
| 14 | + |
| 15 | +function(generate_sigmf_header generate_sigmf_target FBS_FILE OUTPUT_LOCATION) |
| 16 | + add_custom_target(generate_sigmf_target_${generate_sigmf_target} |
| 17 | + COMMAND flatc -c --reflect-types --reflect-names --gen-object-api -o "${OUTPUT_LOCATION}/" "${FBS_FILE}" |
| 18 | + COMMENT "Building C++ header for flatbuffers definition ${FBS_FILE}" |
| 19 | + WORKING_DIRECTORY .) |
| 20 | + add_library(${generate_sigmf_target} INTERFACE) |
| 21 | + add_dependencies(${generate_sigmf_target} generate_sigmf_target_${generate_sigmf_target} flatc) |
| 22 | + target_include_directories(${generate_sigmf_target} INTERFACE "${OUTPUT_LOCATION}/") |
| 23 | +endfunction(generate_sigmf_header) |
| 24 | + |
| 25 | + |
| 26 | +# TODO: check that these directories exist and submodule init them if not |
| 27 | +set(JSON_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/external/json/single_include") |
| 28 | +set(FLATBUFFERS_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/external/flatbuffers/include") |
| 29 | + |
| 30 | +# Create targets for generating the namespace definitions that we ship by default (using this requiers building flatc) |
| 31 | +generate_sigmf_header(generated_core_ns "${CMAKE_SOURCE_DIR}/sigmf_protocols/sigmf_core.fbs" "${CMAKE_CURRENT_BINARY_DIR}/include") |
| 32 | +generate_sigmf_header(generated_antenna_ns "${CMAKE_SOURCE_DIR}/sigmf_protocols/sigmf_antenna.fbs" "${CMAKE_CURRENT_BINARY_DIR}/include") |
| 33 | +generate_sigmf_header(generated_testing_ns "${CMAKE_SOURCE_DIR}/sigmf_protocols/testing_protocols.fbs" "${CMAKE_CURRENT_BINARY_DIR}/include") |
| 34 | +# We also carry around pre-generated headers so downstream doesn't need to build flatc |
| 35 | +set(SIGMF_GEN_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/sigmf_protocols") |
| 36 | + |
| 37 | +# Our interface target that downstream should ideally use target_link_libraries( ) with to get access to our include dirs |
| 38 | +add_library(libsigmf INTERFACE) |
| 39 | +target_include_directories(libsigmf INTERFACE ${JSON_INCLUDE_DIR} ${FLATBUFFERS_INCLUDE_DIR} ${SIGMF_GEN_HEADERS} ${CMAKE_CURRENT_SOURCE_DIR}/src) |
| 40 | + |
| 41 | +# Ensure that our protocol headers are generated before libsigmf dependency is satisfied (i.e. so examples have them) |
| 42 | +add_dependencies(libsigmf libsigmf_genheaders) |
| 43 | +add_custom_target(libsigmf_genheaders DEPENDS |
| 44 | + generate_sigmf_target_generated_core_ns |
| 45 | + generate_sigmf_target_generated_antenna_ns |
| 46 | + generate_sigmf_target_generated_testing_ns |
| 47 | + ) |
| 48 | + |
| 49 | +add_subdirectory(examples) |
| 50 | + |
| 51 | +add_custom_target(makedocs |
| 52 | + COMMAND mkdocs build |
| 53 | + COMMENT "Building documentation website" |
| 54 | + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) |
| 55 | + |
| 56 | +configure_file( |
| 57 | + ${CMAKE_SOURCE_DIR}/cmake/SigmfConfig.cmake.in |
| 58 | + ${CMAKE_BINARY_DIR}/cmake/SigmfConfig.cmake |
| 59 | + @ONLY |
| 60 | +) |
| 61 | + |
| 62 | +# TODO: can we install flatc with a different binary name? sigmf-flatc? |
| 63 | +install(TARGETS flatc DESTINATION bin) |
| 64 | +INSTALL( # install original headers |
| 65 | + DIRECTORY ${CMAKE_SOURCE_DIR}/src/ |
| 66 | + DESTINATION include/sigmf |
| 67 | + FILES_MATCHING PATTERN "*.h*") |
| 68 | +INSTALL( # install flatbuffers headers |
| 69 | + DIRECTORY ${CMAKE_SOURCE_DIR}/external/flatbuffers/include/flatbuffers/ |
| 70 | + DESTINATION include/sigmf/external/flatbuffers/ |
| 71 | + FILES_MATCHING PATTERN "*.h*") |
| 72 | +INSTALL( # install nlohmann headers |
| 73 | + DIRECTORY ${CMAKE_SOURCE_DIR}/external/json/include/nlohmann/ |
| 74 | + DESTINATION include/sigmf/external/nlohmann/ |
| 75 | + FILES_MATCHING PATTERN "*.hpp*") |
| 76 | +INSTALL( # install flatbuf proto defs |
| 77 | + DIRECTORY ${CMAKE_SOURCE_DIR}/sigmf_protocols/ |
| 78 | + DESTINATION include/sigmf/fbs |
| 79 | + FILES_MATCHING PATTERN "*.fbs*") |
| 80 | +INSTALL( # install generated headers |
| 81 | + DIRECTORY ${CMAKE_BINARY_DIR}/include/ |
| 82 | + DESTINATION include/sigmf/ |
| 83 | + FILES_MATCHING PATTERN "*.h*") |
| 84 | +INSTALL( |
| 85 | + FILES ${CMAKE_BINARY_DIR}/cmake/SigmfConfig.cmake |
| 86 | + DESTINATION cmake/sigmf |
| 87 | +) |
0 commit comments