1# Copyright 2022 Google LLC 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15cmake_minimum_required(VERSION 3.14) 16 17project(NearbyPresenceProtocol) 18 19set(CMAKE_CXX_STANDARD 20) 20 21set(BETO_CORE_ROOT ${CMAKE_SOURCE_DIR}/../..) 22set(NEARBY_ROOT ${CMAKE_SOURCE_DIR}/..) 23set(THIRD_PARTY_DIR ${BETO_CORE_ROOT}/third_party) 24 25set(CMAKE_C_FLAGS_DEBUG "-DDEBUG") 26set(CMAKE_CXX_FLAGS_DEBUG "-DDEBUG") 27if (UNIX) 28 set(CMAKE_C_FLAGS_DEBUG "-g ${CMAKE_C_FLAGS_DEBUG}") 29 set(CMAKE_CXX_FLAGS_DEBUG "-g ${CMAKE_C_FLAGS_DEBUG}") 30endif () 31 32if (MSVC) 33 add_compile_options(-W4 -O1 -MD) 34endif () 35 36if (ENABLE_TESTS) 37 message(STATUS "Enabling workspace wide tests") 38 39 # We want to suppress warnings coming from external libraries as they just 40 # pollute the build output 41 add_compile_options(-w) 42 43 # Setup GoogleTest 44 include(FetchContent) 45 FetchContent_Declare( 46 googletest 47 GIT_REPOSITORY https://github.com/google/googletest.git 48 GIT_TAG v1.14.0 49 ) 50 FetchContent_MakeAvailable(googletest) 51 enable_testing() 52 include(GoogleTest) 53 54 # Include google benchmark 55 add_subdirectory(${THIRD_PARTY_DIR}/benchmark ${THIRD_PARTY_DIR}/benchmark/build) 56 57 # Setup jsoncpp 58 set(JSONCPP_DIR ${THIRD_PARTY_DIR}/jsoncpp) 59 include_directories(${JSONCPP_DIR}) 60 add_library( 61 jsoncpp 62 ${JSONCPP_DIR}/jsoncpp.cpp 63 ) 64endif () 65 66set(ABSL_PROPAGATE_CXX_STD ON) 67if (ENABLE_FUZZ) 68 if (NOT "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") 69 MESSAGE(FATAL_ERROR "fuzzing is only enabed when building with Clang, please set CC and CXX to use clang instead of ${CMAKE_CXX_COMPILER_ID}") 70 endif () 71 72 add_subdirectory(${THIRD_PARTY_DIR}/boringssl boringssl-build) 73 add_subdirectory(${THIRD_PARTY_DIR}/fuzztest fuzztest-build) 74 enable_testing() 75 include(GoogleTest) 76else () 77 # fuzztest handles pulling in absl, so we if we are not building fuzzers we need 78 # to include it ourselves via third_party. 79 add_subdirectory(${THIRD_PARTY_DIR}/abseil-cpp ${THIRD_PARTY_DIR}/abseil-cpp/build) 80endif () 81 82if (UNIX) 83 set_directory_properties( 84 PROPERTIES 85 COMPILE_OPTIONS 86 -Werror 87 -Wall 88 -Wextra 89 -Wimplicit-fallthrough 90 -Wextra-semi 91 -Wshadow 92 -Wsign-compare 93 ) 94endif () 95 96# rust std lib requires linking against these 97if (UNIX) 98 link_libraries( 99 dl pthread -fsanitize=address 100 ) 101elseif (MSVC) 102 link_libraries( 103 bcrypt ntdll userenv ws2_32 104 ) 105endif () 106 107add_subdirectory(np_cpp_ffi) 108add_subdirectory(ldt_np_adv_ffi/c) 109