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

Cmake cleanup #187

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
12 changes: 12 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Defines the Chromium style for automatic reformatting.
# http://clang.llvm.org/docs/ClangFormatStyleOptions.html
BasedOnStyle: Chromium
# This defaults to 'Auto'. Explicitly set it for a while, so that
# 'vector<vector<int> >' in existing files gets formatted to
# 'vector<vector<int>>'. ('Auto' means that clang-format will only use
# 'int>>' if the file already contains at least one such instance.)
Standard: Cpp11
SortIncludes: true
---
Language: ObjC
ColumnLimit: 100
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
*.project
*.workspace
.idea/
CMakeLists.txt
cmake-build-debug/
mazda/installer/config/androidauto/data_persist/dev/bin/headunit
*.creator.user
bin/
*/version\.h
.vscode
.vscode
build
third_party
79 changes: 66 additions & 13 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,70 @@
dist: trusty
dist: focal

addons:
apt:
packages:
- libdbus-c++-bin
- libssl-dev
- libusb-1.0-0-dev
- libgstreamer1.0-dev
- gstreamer1.0-gl
- libgstreamer-plugins-base1.0-dev
- libgstreamer-plugins-bad1.0-dev
- protobuf-compiler
- libprotobuf-dev
- libsdl1.2-dev
- libsdl2-dev
- libgtk-3-dev
- libudev-dev
- libunwind-dev
- libtool-bin
- libefl-all-dev

language: cpp
before_script: cd mazda
script: make clean release
deploy:
- provider: releases
api_key: $GITHUB_TOKEN
file: AndroidAuto_*.zip
file_glob: true
overwrite: true
skip_cleanup: true
on:
tags: true

compiler:
- gcc
- clang

arch:
- amd64
- arm64

env:
jobs:
- BUILD_TYPE=Debug CMAKE_ARGS="-DCMAKE_STAGING_PREFIX=`pwd`/staging/usr/local"
- BUILD_TYPE=Release CMAKE_ARGS="-DCMAKE_STAGING_PREFIX=`pwd`/staging/usr/local"
- BUILD_TYPE=MinSizeRel CMAKE_ARGS="-DCMAKE_STAGING_PREFIX=`pwd`/staging/usr/local"
- BUILD_TYPE=Debug
CMAKE_ARGS="-DCMAKE_TOOLCHAIN_FILE=${TRAVIS_BUILD_DIR}/cmake/gcc-toolchain.cmake
-DBUILD_MAZDA=ON -DCMAKE_STAGING_PREFIX=`pwd`/staging/usr/local
-DOPENSSL_CRYPTO_LIBRARY=${TRAVIS_BUILD_DIR}/mazda/m3-toolchain/arm-cortexa9_neon-linux-gnueabi/sysroot/usr/lib/libcrypto.a
-DOPENSSL_INCLUDE_DIR=${TRAVIS_BUILD_DIR}/mazda/m3-toolchain/arm-cortexa9_neon-linux-gnueabi/sysroot/usr/include
-DProtobuf_LIBRARIES=${TRAVIS_BUILD_DIR}/mazda/protobuf-2.6.1-arm/lib/libprotobuf-lite.a
-DProtobuf_INCLUDE_DIR=${TRAVIS_BUILD_DIR}/mazda/protobuf-2.6.1-arm/include"
export PKG_CONFIG_PATH=${TRAVIS_BUILD_DIR}/mazda/m3-toolchain/arm-cortexa9_neon-linux-gnueabi/sysroot/usr/lib/pkgconfig:${TRAVIS_BUILD_DIR}/mazda/protobuf-2.6.1-arm/lib/pkgconfig
export PATH=${TRAVIS_BUILD_DIR}/mazda/m3-toolchain/bin:$PATH
- BUILD_TYPE=Release
CMAKE_ARGS="-DCMAKE_TOOLCHAIN_FILE=${TRAVIS_BUILD_DIR}/cmake/gcc-toolchain.cmake
-DBUILD_MAZDA=ON -DCMAKE_STAGING_PREFIX=`pwd`/staging/usr/local
-DOPENSSL_CRYPTO_LIBRARY=${TRAVIS_BUILD_DIR}/mazda/m3-toolchain/arm-cortexa9_neon-linux-gnueabi/sysroot/usr/lib/libcrypto.a
-DOPENSSL_INCLUDE_DIR=${TRAVIS_BUILD_DIR}/mazda/m3-toolchain/arm-cortexa9_neon-linux-gnueabi/sysroot/usr/include
-DProtobuf_LIBRARIES=${TRAVIS_BUILD_DIR}/mazda/protobuf-2.6.1-arm/lib/libprotobuf-lite.a
-DProtobuf_INCLUDE_DIR=${TRAVIS_BUILD_DIR}/mazda/protobuf-2.6.1-arm/include"
export PKG_CONFIG_PATH=${TRAVIS_BUILD_DIR}/mazda/m3-toolchain/arm-cortexa9_neon-linux-gnueabi/sysroot/usr/lib/pkgconfig:${TRAVIS_BUILD_DIR}/mazda/protobuf-2.6.1-arm/lib/pkgconfig
export PATH=${TRAVIS_BUILD_DIR}/mazda/m3-toolchain/bin:$PATH
- BUILD_TYPE=MinSizeRel
CMAKE_ARGS="-DCMAKE_TOOLCHAIN_FILE=${TRAVIS_BUILD_DIR}/cmake/gcc-toolchain.cmake
-DBUILD_MAZDA=ON -DCMAKE_STAGING_PREFIX=`pwd`/staging/usr/local
-DOPENSSL_CRYPTO_LIBRARY=${TRAVIS_BUILD_DIR}/mazda/m3-toolchain/arm-cortexa9_neon-linux-gnueabi/sysroot/usr/lib/libcrypto.a
-DOPENSSL_INCLUDE_DIR=${TRAVIS_BUILD_DIR}/mazda/m3-toolchain/arm-cortexa9_neon-linux-gnueabi/sysroot/usr/include
-DProtobuf_LIBRARIES=${TRAVIS_BUILD_DIR}/mazda/protobuf-2.6.1-arm/lib/libprotobuf-lite.a
-DProtobuf_INCLUDE_DIR=${TRAVIS_BUILD_DIR}/mazda/protobuf-2.6.1-arm/include"
export PKG_CONFIG_PATH=${TRAVIS_BUILD_DIR}/mazda/m3-toolchain/arm-cortexa9_neon-linux-gnueabi/sysroot/usr/lib/pkgconfig:${TRAVIS_BUILD_DIR}/mazda/protobuf-2.6.1-arm/lib/pkgconfig
export PATH=${TRAVIS_BUILD_DIR}/mazda/m3-toolchain/bin:$PATH

script:
- env
- cd ${TRAVIS_BUILD_DIR}
- mkdir build && cd build
- cmake .. -DCMAKE_BUILD_TYPE=${BUILD_TYPE} ${CMAKE_ARGS}
- make install -j
116 changes: 116 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
cmake_minimum_required(VERSION 3.10.2)

if(NOT CMAKE_MODULE_PATH)
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
elseif()
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
endif()

project(AAHU LANGUAGES CXX)

option(BUILD_MAZDA "Builds Mazda version of Android Auto" OFF)
option(BUILD_UBUNTU "Builds Ubuntu version of Android Auto" ON)
if(BUILD_MAZDA)
set(BUILD_UBUNTU OFF)
elseif(BUILD_UBUNTU)
set(BUILD_MAZDA OFF)
endif()

include(deps)

set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_EXTENSIONS OFF)

protobuf_generate_cpp(PROTO_SRC PROTO_HEADER hu/hu.proto)

set(SRC_FILES
hu/hu_aap.cpp
hu/hu_aad.cpp
hu/hu_ssl.cpp
hu/hu_usb.cpp
hu/hu_uti.cpp
hu/hu_tcp.cpp
${PROTO_HEADER} ${PROTO_SRC}

common/audio.cpp
common/command_server.cpp
common/config.cpp
common/glib_utils.cpp
common/web++/web++.cpp
)

set(MAZDA_SRC
mazda/bt/mzd_bluetooth.cpp
mazda/gps/mzd_gps.cpp
mazda/hud/hud.cpp
mazda/nm/mzd_nightmode.cpp
mazda/callbacks.cpp
mazda/outputs.cpp
mazda/main.cpp
)

set(UBUNTU_SRC
ubuntu/bt/ub_bluetooth.cpp
ubuntu/main.cpp
ubuntu/outputs.cpp
ubuntu/callbacks.cpp
)

if(BUILD_MAZDA)
list(APPEND SRC_FILES ${MAZDA_SRC})
endif()

if(BUILD_UBUNTU)
list(APPEND SRC_FILES ${UBUNTU_SRC})
endif()

add_executable(headunit ${SRC_FILES})

target_include_directories(headunit PUBLIC
hu common
${GTK3_INCLUDE_DIRS}
${USB_INCLUDE_DIRS}
${GST_INCLUDE_DIRS}
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_SYSROOT}/usr/include/SDL2
)

target_compile_options(headunit PUBLIC
-Wno-narrowing
-D__STDC_FORMAT_MACROS
-DDBUS_API_SUBJECT_TO_CHANGE
)

target_link_libraries(headunit PUBLIC
${GST_LIBRARIES}
${GTK3_LIBRARIES}
${X11_LIBRARIES}
${ALSA_LIBRARIES}
${Protobuf_LIBRARY}
${GLFW_STATIC_LIBRARY}
${SDL2_LIBRARIES}
${UDEV_LIBRARIES}
${USB_LIBRARIES}
${UNWIND_LIBRARIES}
OpenSSL::Crypto
OpenSSL::SSL
Threads::Threads
-v
)

if(BUILD_MAZDA)
target_compile_options(headunit PUBLIC -static-libstdc++ -DCMU=1)

target_include_directories(headunit PUBLIC
${CMAKE_STAGING_PREFIX}/include
${THIRD_PARTY_DIR}/dbus-cplusplus
${CMAKE_STAGING_PREFIX}/include/dbus-c++-1)

target_link_libraries(headunit PUBLIC
${CMAKE_STAGING_PREFIX}/lib/libdbus-c++-1.a
${CMAKE_STAGING_PREFIX}/lib/libdbus-c++-glib-1.a
${DBUS_LIBRARIES})
endif()

install(TARGETS headunit RUNTIME DESTINATION bin)
59 changes: 59 additions & 0 deletions cmake/FindDBus.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# - Try to find DBus
# Once done, this will define
#
# DBUS_FOUND - system has DBus
# DBUS_INCLUDE_DIRS - the DBus include directories
# DBUS_LIBRARIES - link these to use DBus
#
# Copyright (C) 2012 Raphael Kubo da Costa <rakuco@webkit.org>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND ITS CONTRIBUTORS ``AS
# IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR ITS
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

FIND_PACKAGE(PkgConfig)
PKG_CHECK_MODULES(PC_DBUS QUIET dbus-1)

FIND_LIBRARY(DBUS_LIBRARIES
NAMES dbus-1
HINTS ${PC_DBUS_LIBDIR}
${PC_DBUS_LIBRARY_DIRS}
)

FIND_PATH(DBUS_INCLUDE_DIR
NAMES dbus/dbus.h
HINTS ${PC_DBUS_INCLUDEDIR}
${PC_DBUS_INCLUDE_DIRS}
)

GET_FILENAME_COMPONENT(_DBUS_LIBRARY_DIR ${DBUS_LIBRARIES} PATH)
FIND_PATH(DBUS_ARCH_INCLUDE_DIR
NAMES dbus/dbus-arch-deps.h
HINTS ${PC_DBUS_INCLUDEDIR}
${PC_DBUS_INCLUDE_DIRS}
${_DBUS_LIBRARY_DIR}
${DBUS_INCLUDE_DIR}
PATH_SUFFIXES include
)

SET(DBUS_INCLUDE_DIRS ${DBUS_INCLUDE_DIR} ${DBUS_ARCH_INCLUDE_DIR})

INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(DBUS REQUIRED_VARS DBUS_INCLUDE_DIRS DBUS_LIBRARIES)
54 changes: 54 additions & 0 deletions cmake/dbus.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
diff --git a/include/dbus-c++/dispatcher.h b/include/dbus-c++/dispatcher.h
index b5b5536..b7a4534 100644
--- a/include/dbus-c++/dispatcher.h
+++ b/include/dbus-c++/dispatcher.h
@@ -267,6 +267,18 @@ struct Threading
return new Mx;
}

+#ifndef DBUS_HAS_RECURSIVE_MUTEX
+ static bool mutex_free(Mutex *mx)
+ {
+ delete mx;
+ return false;
+ }
+ static bool mutex_lock(Mutex *mx)
+ {
+ mx->lock();
+ return false;
+ }
+#else
static void mutex_free(Mutex *mx)
{
delete mx;
@@ -276,6 +288,7 @@ struct Threading
{
mx->lock();
}
+#endif//DBUS_HAS_RECURSIVE_MUTEX

static void mutex_unlock(Mutex *mx)
{
diff --git a/src/eventloop-integration.cpp b/src/eventloop-integration.cpp
index 0cc65c3..5776971 100644
--- a/src/eventloop-integration.cpp
+++ b/src/eventloop-integration.cpp
@@ -38,6 +38,7 @@
#include <cassert>
#include <sys/poll.h>
#include <fcntl.h>
+#include <unistd.h>

using namespace DBus;
using namespace std;
diff --git a/src/pipe.cpp b/src/pipe.cpp
index 01211b3..d0572c7 100644
--- a/src/pipe.cpp
+++ b/src/pipe.cpp
@@ -83,5 +83,5 @@ ssize_t Pipe::read(void *buffer, unsigned int &nbytes)
void Pipe::signal()
{
// TODO: ignoring return of read/write generates warning; maybe relevant for eventloop work...
- ::write(_fd_write, '\0', 1);
+ ::write(_fd_write, "\0", 1);
}
Loading