Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[build] allow using find_package instead of vendored submodules #46

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,4 @@ doc
__pycache__/
venv/
*.py[cod]
/_build/
35 changes: 30 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@
cmake_minimum_required(VERSION 3.13.1)
project(ot-commissioner VERSION 1.0.0)

option(OT_COMM_COVERAGE "Enable coverage reporting" OFF)
option(OT_COMM_TEST "Build tests" ON)
option(OT_COMM_APP "Build the CLI App" ON)
option(OT_COMM_COVERAGE "Enable coverage reporting" OFF)
option(OT_COMM_TEST "Build tests" ON)
option(OT_COMM_APP "Build the CLI App" ON)
option(OT_COMM_USE_VENDORED_LIBS "Build using submodules instead of using find_package" ON)

if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug)
Expand All @@ -41,13 +42,37 @@ if(NOT "${CMAKE_CXX_STANDARD}")
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
endif()

set(CMAKE_CXX_EXTENSIONS OFF)

list(APPEND CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR})
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_BINARY_DIR})

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wfatal-errors -Wno-missing-braces")

if(OT_COMM_USE_VENDORED_LIBS)
# Defines for mbedtls
set(MBEDTLS_USER_CONFIG ${PROJECT_SOURCE_DIR}/third_party/mbedtls/mbedtls_user_config.h)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMBEDTLS_USER_CONFIG_FILE='<${MBEDTLS_USER_CONFIG}>'")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DMBEDTLS_USER_CONFIG_FILE='<${MBEDTLS_USER_CONFIG}>'")
add_subdirectory(third_party EXCLUDE_FROM_ALL)
else()
find_package(fmt REQUIRED)
find_package(nlohmann_json REQUIRED)
find_package(mdns REQUIRED)
find_package(MbedTLS REQUIRED)
find_package(Libevent REQUIRED)
find_package(cose-c REQUIRED)
find_package(cn-cbor REQUIRED)
if (OT_COMM_TEST)
find_package(Catch2 REQUIRED)
endif()
endif()

add_subdirectory(src)

if (OT_COMM_TEST)
add_subdirectory(tests)
endif()
add_subdirectory(tools)
add_subdirectory(third_party EXCLUDE_FROM_ALL)

21 changes: 21 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# build with docker:
# docker build -t builder .

FROM ubuntu:19.10

# install build tools and libreadline
RUN apt update -y && apt install -y python3 python3-pip cmake make gcc g++ libreadline-dev
RUN pip3 install conan

# copy source
COPY . /tmp/.
WORKDIR /tmp/

# make sure build dir is there and is clean
RUN mkdir build || true && rm -rf build/* || true

# install conan dependencies
RUN cd build && conan remote add gocarlos "https://api.bintray.com/conan/gocarlos/public-conan" && conan install .. --build missing

# build using cmake and find package
RUN cd build && cmake .. -DOT_COMM_USE_VENDORED_LIBS=OFF && cmake --build . -j
9 changes: 9 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh

rm -rf _build
mkdir _build
cd _build

conan install .. --build missing
cmake .. -DOT_COMM_USE_VENDORED_LIBS=OFF
cmake --build . -j
53 changes: 53 additions & 0 deletions cmake/FindLibevent.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# * Find Libevent (a cross event library) This module defines
# LIBEVENT_INCLUDE_DIR, where to find Libevent headers LIBEVENT_LIB, Libevent
# libraries Libevent_FOUND, If false, do not try to use libevent

set(Libevent_EXTRA_PREFIXES /usr/local /opt/local "$ENV{HOME}")
foreach(prefix ${Libevent_EXTRA_PREFIXES})
list(APPEND Libevent_INCLUDE_PATHS "${prefix}/include")
list(APPEND Libevent_LIB_PATHS "${prefix}/lib")
endforeach()

find_path(LIBEVENT_INCLUDE_DIR event.h PATHS ${Libevent_INCLUDE_PATHS})
find_library(
LIBEVENT_LIB
NAMES event
PATHS ${Libevent_LIB_PATHS})
find_library(
LIBEVENT_PTHREAD_LIB
NAMES event_pthreads
PATHS ${Libevent_LIB_PATHS})

if(LIBEVENT_LIB
AND LIBEVENT_INCLUDE_DIR
AND LIBEVENT_PTHREAD_LIB)
set(Libevent_FOUND TRUE)
set(LIBEVENT_LIB ${LIBEVENT_LIB} ${LIBEVENT_PTHREAD_LIB})
else()
set(Libevent_FOUND FALSE)
endif()

if(Libevent_FOUND)
if(NOT Libevent_FIND_QUIETLY)
message(STATUS "Found libevent: ${LIBEVENT_LIB}")
endif()
else()
if(Libevent_FIND_REQUIRED)
message(FATAL_ERROR "Could NOT find libevent and libevent_pthread.")
endif()
message(STATUS "libevent and libevent_pthread NOT found.")
endif()

mark_as_advanced(LIBEVENT_LIB LIBEVENT_INCLUDE_DIR)

add_library(event_pthreads IMPORTED UNKNOWN)
set_target_properties(event_pthreads PROPERTIES IMPORTED_LOCATION
${LIBEVENT_INCLUDE_DIR})
set_target_properties(event_pthreads PROPERTIES INTERFACE_INCLUDE_DIRECTORIES
"${LIBEVENT_PTHREAD_LIB}")

add_library(event_core IMPORTED UNKNOWN)
set_target_properties(event_core PROPERTIES IMPORTED_LOCATION
${LIBEVENT_INCLUDE_DIR})
set_target_properties(event_core PROPERTIES INTERFACE_INCLUDE_DIRECTORIES
"${LIBEVENT_LIB}")
23 changes: 23 additions & 0 deletions cmake/FindMbedTLS.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
find_path(MBEDTLS_INCLUDE_DIRS mbedtls/ssl.h)

find_library(MBEDTLS_LIBRARY mbedtls)
find_library(MBEDX509_LIBRARY mbedx509)
find_library(MBEDCRYPTO_LIBRARY mbedcrypto)

set(MBEDTLS_LIBRARIES "${MBEDTLS_LIBRARY}" "${MBEDX509_LIBRARY}" "${MBEDCRYPTO_LIBRARY}")

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(MBEDTLS DEFAULT_MSG
MBEDTLS_INCLUDE_DIRS MBEDTLS_LIBRARY MBEDX509_LIBRARY MBEDCRYPTO_LIBRARY)

mark_as_advanced(MBEDTLS_INCLUDE_DIRS MBEDTLS_LIBRARY MBEDX509_LIBRARY MBEDCRYPTO_LIBRARY)

add_library(mbedtls
IMPORTED
UNKNOWN)
set_target_properties(mbedtls
PROPERTIES IMPORTED_LOCATION
${MBEDTLS_LIBRARIES})
set_target_properties(mbedtls
PROPERTIES INTERFACE_INCLUDE_DIRECTORIES
"${MBEDTLS_INCLUDE_DIRS}")
21 changes: 21 additions & 0 deletions conanfile.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# TODO: remove this and next line
# conan remote add gocarlos "https://api.bintray.com/conan/gocarlos/public-conan"

[requires]
fmt/6.1.2
libevent/2.1.11
nlohmann_json/3.7.3
mbedtls/2.16.3-gpl
mdns/20200331

cose-c/20200225@gocarlos/testing
cn-cbor/1.0.0

# testing
catch2/2.11.3

[generators]
cmake_find_package
cmake_paths

[options]
4 changes: 4 additions & 0 deletions src/library/multicast_dns.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@

#include <functional>

#if __has_include("mdns/mdns.h")
#include <mdns/mdns.h>
#else
#include <mdns.h>
#endif

#include <commissioner/commissioner.hpp>

Expand Down
10 changes: 7 additions & 3 deletions third_party/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,19 @@
# POSSIBILITY OF SUCH DAMAGE.
#

add_subdirectory(Catch2/repo)
if (OT_COMM_TEST)
add_subdirectory(Catch2/repo)
endif()

set(coveralls OFF CACHE BOOL "Disbale generating coveralls data")
add_subdirectory(cn-cbor/repo)
add_subdirectory(COSE-C)
add_subdirectory(fmtlib/repo)
add_subdirectory(json/repo)

add_subdirectory(libevent)

add_subdirectory(mbedtls)
add_subdirectory(mdns/repo)

if(NOT TARGET mdns::mdns)
add_library(mdns::mdns ALIAS mdns)
endif()
2 changes: 1 addition & 1 deletion third_party/mdns/repo
Submodule repo updated 1 files
+1 −1 src/CMakeLists.txt