Add CMake support

Change-Id: I716e1fa3ec43bfe57326f5a691131505f84b7832
This commit is contained in:
Alexey Polyudov
2020-04-04 12:55:01 -07:00
parent b0730bb8c9
commit 7466db88c0
17 changed files with 614 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
build/**
+48
View File
@@ -0,0 +1,48 @@
cmake_minimum_required(VERSION 3.13)
project(nearby CXX)
option(nearby_USE_LOCAL_PROTOBUF
"Use local copy of protobuf library and compiler" OFF)
option(nearby_USE_LOCAL_ABSL
"Use local copy of abseil-cpp library" OFF)
# target_sources() may convert relative paths to absolute
cmake_policy(SET CMP0076 NEW)
set (CMAKE_CXX_STANDARD 17)
set (CMAKE_CXX_STANDARD_REQUIRED ON)
include(cmake/proto_defs.cmake)
include(cmake/local_build_setup.cmake)
if (nearby_USE_LOCAL_PROTOBUF)
include(cmake/local_build_protobuf.cmake)
endif()
include(cmake/local_setup_smhasher.cmake)
find_package(Protobuf REQUIRED)
enable_testing()
if (NOT TARGET ukey2)
add_subdirectory(third_party/ukey2)
endif()
if (NOT TARGET gtest)
add_subdirectory(third_party/gtest)
endif()
if (nearby_USE_LOCAL_ABSL)
if (NOT TARGET absl::base)
add_subdirectory(third_party/absl)
endif()
else()
find_package(absl REQUIRED)
endif()
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/cpp)
add_subdirectory(cpp/core)
add_subdirectory(cpp/platform)
add_subdirectory(proto)
+14
View File
@@ -0,0 +1,14 @@
project(smhasher CXX)
cmake_minimum_required(VERSION 3.13)
add_library(smhasher_murmur3 STATIC
cpp/src/smhasher/MurmurHash3.cpp
)
target_include_directories(smhasher_murmur3
PUBLIC
cpp/include
PRIVATE
cpp/include/smhasher
)
+28
View File
@@ -0,0 +1,28 @@
if (NOT EXISTS ${TOOLS_INSTALL_PREFIX}/bin/protoc)
set(PKG_BUILD_ROOT ${TOOLS_BUILD_ROOT}/protobuf)
set(PKG_SRC_ROOT ${CMAKE_SOURCE_DIR}/third_party/protobuf)
execute_process(
COMMAND mkdir -p ${PKG_BUILD_ROOT}
)
execute_process(
COMMAND cmake ${PKG_SRC_ROOT}/cmake
WORKING_DIRECTORY ${PKG_BUILD_ROOT}
)
execute_process(
COMMAND make -j${N_CPUS}
WORKING_DIRECTORY ${PKG_BUILD_ROOT}
)
execute_process(
COMMAND make check
WORKING_DIRECTORY ${PKG_BUILD_ROOT}
RESULT_VARIABLE test_exit_code
ERROR_QUIET
)
if (NOT ${test_exit_code} EQUAL "0")
message(FATAL_ERROR "Protobuf tests failed; can't use this protobuf")
endif()
execute_process(
COMMAND /bin/bash -c "DESTDIR=${TOOLS_INSTALL_ROOT} make install"
WORKING_DIRECTORY ${PKG_BUILD_ROOT}
)
endif()
+12
View File
@@ -0,0 +1,12 @@
include(ProcessorCount)
ProcessorCount(N_CPUS)
if (N_CPUS EQUAL 0)
set (N_CPUS 1)
endif()
set (TOOLS_ROOT ${CMAKE_BINARY_DIR}/stage)
set (TOOLS_BUILD_ROOT ${TOOLS_ROOT}/build)
set (TOOLS_INSTALL_ROOT ${TOOLS_ROOT}/install)
set (TOOLS_INSTALL_PREFIX ${TOOLS_INSTALL_ROOT}/usr/local)
set (CMAKE_FIND_ROOT_PATH ${TOOLS_INSTALL_ROOT})
+22
View File
@@ -0,0 +1,22 @@
set(PKG_STAGE_SRC_ROOT ${TOOLS_ROOT}/src/smhasher)
if (NOT EXISTS ${PKG_STAGE_SRC_ROOT}/CMakeLists.txt)
set(PKG_SRC_ROOT ${PROJECT_SOURCE_DIR}/third_party/smhasher)
execute_process(
COMMAND mkdir -p ${PKG_STAGE_SRC_ROOT}/cpp/src/smhasher
)
execute_process(
COMMAND mkdir -p ${PKG_STAGE_SRC_ROOT}/cpp/include/smhasher
)
execute_process(
COMMAND cp ${PKG_SRC_ROOT}/src/MurmurHash3.cpp ${PKG_STAGE_SRC_ROOT}/cpp/src/smhasher
)
execute_process(
COMMAND cp ${PKG_SRC_ROOT}/src/MurmurHash3.h ${PKG_STAGE_SRC_ROOT}/cpp/include/smhasher
)
execute_process(
COMMAND cp cmake/CMakeLists-smhasher.txt ${PKG_STAGE_SRC_ROOT}/CMakeLists.txt
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
)
endif()
add_subdirectory(${PKG_STAGE_SRC_ROOT})
+28
View File
@@ -0,0 +1,28 @@
function(add_cc_proto_library NAME)
set(single)
set(multi_args PROTOS INCS DEPS)
cmake_parse_arguments(PARSE_ARGV 1 args "" "${single}" "${multi_args}")
protobuf_generate(
PROTOS ${args_PROTOS}
LANGUAGE cpp
OUT_VAR ${NAME}_var
)
add_library(${NAME}
${${NAME}_var}
)
target_link_libraries(${NAME}
PUBLIC
${Protobuf_LIBRARIES}
${args_DEPS}
)
target_include_directories(${NAME}
PUBLIC
${Protobuf_INCLUDE_DIRS}
${args_INCS}
${CMAKE_CURRENT_BINARY_DIR}
)
endfunction()
+58
View File
@@ -0,0 +1,58 @@
add_library(core STATIC)
target_sources(core
PUBLIC
core.h
)
target_include_directories(core
PUBLIC
${PROJECT_SOURCE_DIR}/cpp
)
target_link_libraries(core
PUBLIC
core_internal
platform_types
)
add_library(core_types STATIC)
target_sources(core_types
PRIVATE
payload.cc
strategy.cc
PUBLIC
listeners.h
options.h
params.h
payload.h
status.h
strategy.h
)
target_link_libraries(core_types
PUBLIC
platform_api
platform_port_string
platform_types
platform_utils
)
add_executable(core_build_test
check_compilation.cc
)
target_link_libraries(core_build_test
PUBLIC
absl::strings
core
core_types
platform_impl_default_lock
platform_impl_sample
platform_port_string
platform_types
platform_utils
)
add_subdirectory(internal)
+80
View File
@@ -0,0 +1,80 @@
add_library(core_internal STATIC)
target_sources(core_internal
PRIVATE
ble_advertisement.cc
bluetooth_device_name.cc
internal_payload.cc
internal_payload.h
loop_runner.cc
loop_runner.h
offline_frames.cc
offline_frames.h
PUBLIC
bandwidth_upgrade_handler.h
bandwidth_upgrade_manager.h
base_bandwidth_upgrade_handler.h
base_endpoint_channel.h
base_pcp_handler.h
ble_advertisement.h
ble_compat.h
ble_endpoint_channel.h
bluetooth_device_name.h
bluetooth_endpoint_channel.h
client_proxy.h
encryption_runner.h
endpoint_channel.h
endpoint_channel_manager.h
endpoint_manager.h
internal_payload_factory.h
medium_manager.h
offline_service_controller.h
p2p_cluster_pcp_handler.h
p2p_point_to_point_pcp_handler.h
p2p_star_pcp_handler.h
payload_manager.h
pcp.h
pcp_handler.h
pcp_manager.h
service_controller.h
service_controller_router.h
wifi_lan_upgrade_handler.h
)
target_link_libraries(core_internal
PUBLIC
absl::strings
core_internal_mediums
core_types
platform_api
platform_port_down_cast
platform_port_string
platform_types
platform_utils
proto_connections_enums_cc_proto
proto_offline_wire_formats_cc_proto
ukey2
)
add_executable(core_internal_test
bluetooth_device_name_test.cc
ble_advertisement_test.cc
)
add_test(
NAME core_internal_test
COMMAND core_internal_test
)
target_link_libraries(core_internal_test
PUBLIC
core_internal
gtest
gtest_main
platform_impl_default_cond_var
platform_impl_default_lock
platform_port_string
platform_utils
)
add_subdirectory(mediums)
+57
View File
@@ -0,0 +1,57 @@
add_library(core_internal_mediums STATIC)
target_sources(core_internal_mediums
PRIVATE
ble_advertisement.cc
ble_advertisement_header.cc
ble_packet.cc
ble_peripheral.cc
utils.cc
utils.h
PUBLIC
advertisement_read_result.h
ble.h
ble_advertisement.h
ble_advertisement_header.h
ble_packet.h
ble_peripheral.h
ble_v2.h
bloom_filter.h
bluetooth_classic.h
bluetooth_radio.h
discovered_peripheral_callback.h
discovered_peripheral_tracker.h
lost_entity_tracker.h
mediums.h
uuid.h
)
target_link_libraries(core_internal_mediums
PUBLIC
absl::numeric
absl::strings
platform_api
platform_port_string
platform_types
platform_utils
smhasher_murmur3
)
add_executable(core_internal_mediums_test
advertisement_read_result_test.cc
ble_advertisement_header_test.cc
ble_advertisement_test.cc
ble_packet_test.cc
bloom_filter_test.cc
lost_entity_tracker_test.cc
)
target_link_libraries(core_internal_mediums_test
PUBLIC
absl::time
core_internal_mediums
gtest
gtest_main
platform_impl_default
platform_utils
)
+79
View File
@@ -0,0 +1,79 @@
add_library(platform_utils STATIC
base64_utils.cc
file_impl.cc
prng.cc
reliability_utils.cc
)
target_sources(platform_utils
PUBLIC
base64_utils.h
cancelable_alarm.h
file_impl.h
pipe.h
prng.h
reliability_utils.h
synchronized.h
)
target_link_libraries(platform_utils
PUBLIC
platform_types
platform_api
absl::strings
)
add_library(platform_types STATIC
ptr.cc
)
target_sources(platform_types
PUBLIC
byte_array.h
callable.h
cancelable.h
container_of.h
exception.h
logging.h
ptr.h
runnable.h
)
target_link_libraries(platform_types
PUBLIC
absl::base
absl::strings
)
add_executable(platform_test
byte_array_test.cc
container_of_test.cc
file_impl_test.cc
pipe_test.cc
prng_test.cc
ptr_test.cc
)
target_link_libraries(platform_test
PUBLIC
absl::base
absl::strings
absl::time
gtest
gtest_main
platform_api
platform_impl_default_cond_var
platform_impl_default_lock
platform_types
platform_utils
)
add_test(
NAME platform_test
COMMAND platform_test
)
add_subdirectory(api)
add_subdirectory(impl/sample)
add_subdirectory(impl/default)
add_subdirectory(port)
+32
View File
@@ -0,0 +1,32 @@
add_library(platform_api STATIC
atomic_boolean.h
atomic_reference.h
ble.h
ble_v2.h
bluetooth_adapter.h
bluetooth_classic.h
condition_variable.h
count_down_latch.h
executor.h
future.h
hash_utils.h
input_file.h
input_stream.h
lock.h
multi_thread_executor.h
output_file.h
output_stream.h
scheduled_executor.h
settable_future.h
single_thread_executor.h
socket.h
submittable_executor.h
system_clock.h
thread_utils.h
wifi.h
)
target_link_libraries(platform_api
PUBLIC
platform_types
)
+53
View File
@@ -0,0 +1,53 @@
add_library(platform_impl_default STATIC)
target_sources(platform_impl_default
PRIVATE
default_condition_variable.cc
default_lock.cc
default_platform.cc
PUBLIC
default_condition_variable.h
default_lock.h
default_platform.h
)
target_include_directories(platform_impl_default
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
)
target_link_libraries(platform_impl_default
PUBLIC
platform_api
platform_types
)
add_library(platform_impl_default_lock STATIC)
target_sources(platform_impl_default_lock
PRIVATE
default_lock.cc
PUBLIC
default_lock.h
)
target_link_libraries(platform_impl_default_lock
PUBLIC
platform_api
)
add_library(platform_impl_default_cond_var STATIC)
target_sources(platform_impl_default_cond_var
PRIVATE
default_condition_variable.cc
PUBLIC
default_condition_variable.h
)
target_link_libraries(platform_impl_default_cond_var
PUBLIC
platform_api
platform_impl_default_lock
platform_types
)
+18
View File
@@ -0,0 +1,18 @@
add_library(platform_impl_sample STATIC)
target_sources(platform_impl_sample
PRIVATE
sample_wifi_medium.cc
PUBLIC
sample_platform.h
sample_wifi_medium.h
)
target_link_libraries(platform_impl_sample
PUBLIC
absl::time
platform_api
platform_port_string
platform_types
platform_utils
)
+30
View File
@@ -0,0 +1,30 @@
add_library(platform_port_config_private INTERFACE)
target_sources(platform_port_config_private
INTERFACE
config.h
)
add_library(platform_port_string INTERFACE)
target_sources(platform_port_string
INTERFACE
string.h
)
target_link_libraries(platform_port_string
INTERFACE
platform_port_config_private
)
add_library(platform_port_down_cast INTERFACE)
target_sources(platform_port_down_cast
INTERFACE
down_cast.h
)
target_link_libraries(platform_port_down_cast
INTERFACE
platform_port_config_private
)
+49
View File
@@ -0,0 +1,49 @@
add_cc_proto_library(
proto_bootstrap_enums_cc_proto
PROTOS bootstrap_enums.proto
INCS ${CMAKE_CURRENT_BINARY_DIR}/..
)
add_cc_proto_library(
proto_connections_enums_cc_proto
PROTOS connections_enums.proto
INCS ${CMAKE_CURRENT_BINARY_DIR}/..
)
add_cc_proto_library(
proto_discovery_enums_cc_proto
PROTOS discovery_enums.proto
INCS ${CMAKE_CURRENT_BINARY_DIR}/..
)
add_cc_proto_library(
proto_magic_pair_enums_cc_proto
PROTOS magic_pair_enums.proto
INCS ${CMAKE_CURRENT_BINARY_DIR}/..
)
add_cc_proto_library(
proto_nearby_client_enums_cc_proto
PROTOS nearby_client_enums.proto
INCS ${CMAKE_CURRENT_BINARY_DIR}/..
)
add_cc_proto_library(
proto_nearby_event_codes_cc_proto
PROTOS nearby_event_codes.proto
INCS ${CMAKE_CURRENT_BINARY_DIR}/..
)
add_cc_proto_library(
proto_setup_enums_cc_proto
PROTOS setup_enums.proto
INCS ${CMAKE_CURRENT_BINARY_DIR}/..
)
add_cc_proto_library(
proto_sharing_enums_cc_proto
PROTOS sharing_enums.proto
INCS ${CMAKE_CURRENT_BINARY_DIR}/..
)
add_subdirectory(connections)
+5
View File
@@ -0,0 +1,5 @@
add_cc_proto_library(
proto_offline_wire_formats_cc_proto
PROTOS offline_wire_formats.proto
INCS ${CMAKE_CURRENT_BINARY_DIR}/../..
)