Add target main and build

This commit is contained in:
John Zhao 2018-03-12 00:15:30 +08:00
parent d165b1a734
commit c3f3784c11
11 changed files with 399 additions and 8 deletions

7
.gitignore vendored
View File

@ -1,5 +1,12 @@
.DS_Store
_build/
_output/
/doc/output/
/get-pip.py
/*INFO*
/*WARNING*
/*ERROR*

57
CMakeLists.txt Normal file
View File

@ -0,0 +1,57 @@
cmake_minimum_required(VERSION 3.0)
project(mynteye VERSION 2.0.0 LANGUAGES C CXX)
# options
# flags
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
include(cmake/DetectCXX11.cmake)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=native")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native")
string(STRIP "${CMAKE_C_FLAGS}" CMAKE_C_FLAGS)
string(STRIP "${CMAKE_CXX_FLAGS}" CMAKE_CXX_FLAGS)
message(STATUS "C_FLAGS: ${CMAKE_C_FLAGS}")
message(STATUS "CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
# packages
LIST(APPEND CMAKE_PREFIX_PATH third_party/glog/_build)
find_package(glog REQUIRED)
message(STATUS "Found glog: ${glog_VERSION}")
LIST(APPEND CMAKE_MODULE_PATH cmake)
# config
set(MYNTEYE_NAMESPACE "mynteye")
message(STATUS "Namespace: ${MYNTEYE_NAMESPACE}")
configure_file(
include/mynteye/mynteye.h.in
include/mynteye/mynteye.h @ONLY
)
# targets
include(cmake/Common.cmake)
set(OUT_DIR "${PROJECT_SOURCE_DIR}/_output")
set_outdir(
"${OUT_DIR}/lib"
"${OUT_DIR}/lib"
"${OUT_DIR}/bin"
)
include_directories(
include
${CMAKE_BINARY_DIR}/include
)
add_executable(main src/main.cc)
target_link_libraries(main glog::glog)

View File

@ -130,7 +130,9 @@ endif
# CMake
CMAKE := cmake -DCMAKE_BUILD_TYPE=Release
CMAKE := cmake
# CMAKE := $(CMAKE) -DCMAKE_BUILD_TYPE=Debug
CMAKE := $(CMAKE) -DCMAKE_BUILD_TYPE=Release
ifneq ($(CC),)
CMAKE := $(CMAKE) -DCMAKE_C_COMPILER=$(CC)
endif
@ -148,7 +150,6 @@ ifneq ($(MAKE),)
endif
CMAKE_OPTIONS :=
#CMAKE_OPTIONS += -DDEBUG=ON -DTIMECOST=ON
# CMAKE_OPTIONS += -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON
CMAKE_OPTIONS_AFTER :=
@ -191,7 +192,7 @@ define echo
endef
define rm
[ ! -e "$1" ] || (rm -rf "$1" && $(ECHO) "RM: $1")
[ ! -h "$1" ] && [ ! -e "$1" ] || (rm -rf "$1" && $(ECHO) "RM: $1")
endef
define rm_f

View File

@ -8,6 +8,7 @@ help:
@echo " make apidoc make api doc"
@echo " make opendoc open api doc (html)"
@echo " make init init project"
@echo " make build build project"
@echo " make test build test and run"
@echo " make clean|cleanall clean generated or useless things"
@ -49,6 +50,14 @@ third_party: submodules
.PHONY: submodules third_party
# build
build: third_party
@$(call echo,Make $@)
@$(call cmake_build,./_build)
.PHONY: build
# test
test: submodules
@ -62,14 +71,22 @@ test: submodules
clean:
@$(call echo,Make $@)
@$(call rm,./tests/gtest/_build/)
@$(call rm,./third_party/glog/_build/)
@$(call rm,./_build/)
@$(call rm,./_output/)
@$(MAKE) cleanlog
cleanall: clean
@$(call rm,./doc/output/)
@$(call rm,./tests/gtest/_build/)
@$(call rm,./third_party/glog/_build/)
@$(FIND) . -type f -name ".DS_Store" -print0 | xargs -0 rm -f
.PHONY: clean cleanall
cleanlog:
@$(call rm_f,*INFO*)
@$(call rm_f,*WARNING*)
@$(call rm_f,*ERROR*)
.PHONY: clean cleanall cleanlog
# others
@ -89,3 +106,9 @@ host:
@echo CMAKE: $(CMAKE)
.PHONY: host
cpplint:
@$(call echo,Make $@)
@$(SH) ./scripts/$@.sh
.PHONY: cpplint

16
cmake/Common.cmake Executable file
View File

@ -0,0 +1,16 @@
include(CMakeParseArguments)
# set_outdir(ARCHIVE_OUTPUT_DIRECTORY
# LIBRARY_OUTPUT_DIRECTORY
# RUNTIME_OUTPUT_DIRECTORY)
macro(set_outdir ARCHIVE_OUTPUT_DIRECTORY LIBRARY_OUTPUT_DIRECTORY RUNTIME_OUTPUT_DIRECTORY)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${ARCHIVE_OUTPUT_DIRECTORY})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_DIRECTORY})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${RUNTIME_OUTPUT_DIRECTORY})
foreach(CONFIG ${CMAKE_CONFIGURATION_TYPES})
string(TOUPPER ${CONFIG} CONFIG)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${CONFIG} ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_${CONFIG} ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_${CONFIG} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
endforeach()
endmacro()

37
cmake/DetectCXX11.cmake Normal file
View File

@ -0,0 +1,37 @@
if(MSVC)
# Support For C++11/14/17 Features (Modern C++)
# https://msdn.microsoft.com/en-us/library/hh567368.aspx
# MSVC_VERSION:
# https://cmake.org/cmake/help/latest/variable/MSVC_VERSION.html
if(NOT (MSVC_VERSION LESS 1600))
message(STATUS "Visual Studio >= 2010, MSVC >= 10.0")
else()
message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
endif()
else()
set(CXX_FLAGS_EXTRA "")
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag("-std=c++11" COMPILER_SUPPORTS_CXX11)
check_cxx_compiler_flag("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
if(COMPILER_SUPPORTS_CXX11)
set(CXX_FLAGS_EXTRA "-std=c++11")
message(STATUS "Using flag -std=c++11")
elseif(COMPILER_SUPPORTS_CXX0X)
set(CXX_FLAGS_EXTRA "-std=c++0x")
message(STATUS "Using flag -std=c++0x")
else()
message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX_FLAGS_EXTRA}")
# Ensure access this in sub directories
set(CXX_FLAGS_EXTRA "${CXX_FLAGS_EXTRA}" CACHE STRING "Value of the extra cxx flags.")
endif()

72
include/mynteye/global.h Normal file
View File

@ -0,0 +1,72 @@
#ifndef MYNTEYE_GLOBAL_H_
#define MYNTEYE_GLOBAL_H_
#pragma once
#ifdef _WIN32
#define OS_WIN
#ifdef _WIN64
#define OS_WIN64
#else
#define OS_WIN32
#endif
#if defined(__MINGW32__) || defined(__MINGW64__)
#define OS_MINGW
#ifdef __MINGW64__
#define OS_MINGW64
#else
#define OS_MINGW32
#endif
#elif defined(__CYGWIN__) || defined(__CYGWIN32__)
#define OS_CYGWIN
#endif
#elif __APPLE__
#include "TargetConditionals.h"
#if TARGET_IPHONE_SIMULATOR
#define OS_IPHONE
#define OS_IPHONE_SIMULATOR
#elif TARGET_OS_IPHONE
#define OS_IPHONE
#elif TARGET_OS_MAC
#define OS_MAC
#else
#error "Unknown Apple platform"
#endif
#elif __ANDROID__
#define OS_ANDROID
#elif __linux__
#define OS_LINUX
#elif __unix__
#define OS_UNIX
#elif defined(_POSIX_VERSION)
#define OS_POSIX
#else
#error "Unknown compiler"
#endif
#ifdef OS_WIN
#define DECL_EXPORT __declspec(dllexport)
#define DECL_IMPORT __declspec(dllimport)
#define DECL_HIDDEN
#else
#define DECL_EXPORT __attribute__((visibility("default")))
#define DECL_IMPORT __attribute__((visibility("default")))
#define DECL_HIDDEN __attribute__((visibility("hidden")))
#endif
#if defined(OS_WIN) && !defined(OS_MINGW) && !defined(OS_CYGWIN)
#define OS_SEP "\\"
#else
#define OS_SEP "/"
#endif
#define STRINGIFY_HELPER(X) #X
#define STRINGIFY(X) STRINGIFY_HELPER(X)
#define DISABLE_COPY(Class) \
Class(const Class &) = delete; \
Class &operator=(const Class &) = delete;
template <typename... T>
void unused(T &&...) {}
#endif // MYNTEYE_GLOBAL_H_

View File

@ -0,0 +1,48 @@
#ifndef MYNTEYE_MYNTEYE_H_
#define MYNTEYE_MYNTEYE_H_
#pragma once
#include "mynteye/global.h"
#ifdef DOXYGEN_WORKING
# define MYNTEYE_API
#else
# ifdef MYNTEYE_EXPORTS
# define MYNTEYE_API DECL_EXPORT
# else
# define MYNTEYE_API DECL_IMPORT
# endif
#endif
#define MYNTEYE_API_VERSION_MAJOR @PROJECT_VERSION_MAJOR@
#define MYNTEYE_API_VERSION_MINOR @PROJECT_VERSION_MINOR@
#define MYNTEYE_API_VERSION_PATCH @PROJECT_VERSION_PATCH@
/* MYNTEYE_API_VERSION is (major << 16) + (minor << 8) + patch */
#define MYNTEYE_API_VERSION \
MYNTEYE_API_VERSION_CHECK( \
MYNTEYE_API_VERSION_MAJOR, \
MYNTEYE_API_VERSION_MINOR, \
MYNTEYE_API_VERSION_PATCH \
)
/* Can be used like
* #if (MYNTEYE_API_VERSION >= MYNTEYE_API_VERSION_CHECK(2, 0, 0)) */
#define MYNTEYE_API_VERSION_CHECK(major, minor, patch) \
((major<<16)|(minor<<8)|(patch)) // NOLINT
/* MYNTEYE_API_VERSION in "X.Y.Z" format */
#define MYNTEYE_API_VERSION_STR (STRINGIFY(MYNTEYE_API_VERSION_MAJOR.MYNTEYE_API_VERSION_MINOR.MYNTEYE_API_VERSION_PATCH)) // NOLINT
#cmakedefine MYNTEYE_NAMESPACE @MYNTEYE_NAMESPACE@
#if defined(MYNTEYE_NAMESPACE)
# define MYNTEYE_BEGIN_NAMESPACE namespace MYNTEYE_NAMESPACE {
# define MYNTEYE_END_NAMESPACE }
# define MYNTEYE_USE_NAMESPACE using namespace ::MYNTEYE_NAMESPACE; // NOLINT
#else
# define MYNTEYE_BEGIN_NAMESPACE
# define MYNTEYE_END_NAMESPACE
# define MYNTEYE_USE_NAMESPACE
#endif
#endif // MYNTEYE_MYNTEYE_H_

60
scripts/cpplint.sh Executable file
View File

@ -0,0 +1,60 @@
#!/usr/bin/env bash
BASE_DIR=$(cd "$(dirname "$0")" && pwd)
ROOT_DIR=$(realpath "$BASE_DIR/..")
source "$BASE_DIR/common/echo.sh"
source "$BASE_DIR/common/detect.sh"
source "$BASE_DIR/common/host.sh"
PYTHON="python"
if [ "$HOST_OS" = "Win" ]; then
# default python on MSYS
PYTHON="python2"
fi
CPPLINT="$PYTHON $ROOT_DIR/tools/linter/cpplint.py"
# CPPLINT="cpplint"
_detect $PYTHON
DIRS=(
_build/include
include
src
)
FIND="$($BASE_DIR/getfind.sh)"
PATT="-name *.cc -o -name *.h"
PATT="$PATT -o -name *.cpp -o -name *.hpp"
# PATT="$PATT -o -name *.cu -o -name *.cuh"
# _echo "PATT: $PATT"
ret=0
_echo_s "WorkDir: $ROOT_DIR"
for dir in "${DIRS[@]}"; do
if [ -d "$ROOT_DIR/$dir" ]; then
_echo_i "WorkDir: $dir"
for f in `$FIND "$ROOT_DIR/$dir" -type f \( ${PATT} \)`; do
_echo_in "cpplint $f"
$CPPLINT "--verbose=1" \
"--filter=-legal/copyright,-build/c++11" \
"--root=$ROOT_DIR/$dir" "$f"
if [ $? -eq 0 ]; then
_echo_dn "cpplint success"
else
_echo_en "cpplint failed"
ret=1
fi
done
else
_echo_i "WorkDir: $dir - not found"
fi
done
if [ $ret -eq 0 ]; then
_echo_d "Well done"
else
_echo_e "There are cpplint errors"
fi

70
src/main.cc Normal file
View File

@ -0,0 +1,70 @@
// #define GOOGLE_STRIP_LOG 1
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
#define GLOG_NO_ABBREVIATED_SEVERITIES
#endif
#include <glog/logging.h>
#ifdef HAVE_LIB_GFLAGS
#include <gflags/gflags.h>
#endif
#include "mynteye/mynteye.h"
int main(int /*argc*/, char *argv[]) {
// Set whether log messages go to stderr instead of logfiles
// FLAGS_logtostderr = true;
// Set whether log messages go to stderr in addition to logfiles.
FLAGS_alsologtostderr = true;
// Set color messages logged to stderr (if supported by terminal).
FLAGS_colorlogtostderr = true;
// If specified, logfiles are written into this directory instead of the
// default logging directory.
FLAGS_log_dir = ".";
// Sets the maximum log file size (in MB).
FLAGS_max_log_size = 1024;
// Sets whether to avoid logging to the disk if the disk is full.
FLAGS_stop_logging_if_full_disk = true;
// Show all VLOG(m) messages for m <= this.
FLAGS_v = 2;
// Initialize google's logging library.
google::InitGoogleLogging(argv[0]);
#ifdef HAVE_LIB_GFLAGS
// Optional: parse command line flags
gflags::ParseCommandLineFlags(&argc, &argv, true);
#endif
if (VLOG_IS_ON(2)) {
VLOG(2) << "do some logging preparation and logging";
}
VLOG(2) << "verbose msg";
VLOG(1) << "debug msg";
LOG(INFO) << "info msg";
LOG(WARNING) << "warning msg";
LOG(ERROR) << "error msg";
// LOG(FATAL) << "fatal msg";
LOG(INFO) << "MYNTEYE API version is " << MYNTEYE_API_VERSION_STR;
if (MYNTEYE_API_VERSION >= MYNTEYE_API_VERSION_CHECK(2, 0, 0)) {
LOG(INFO) << "MYNTEYE API version is greater than or equal to 2.0.0";
} else {
LOG(INFO) << "MYNTEYE API version is less than 2.0.0";
}
// Shutdown google's logging library.
google::ShutdownGoogleLogging();
return 0;
}
// miniglog: https://github.com/tzutalin/miniglog
/*
ANDROID_LOG_FATAL, // LOG(FATAL)
ANDROID_LOG_ERROR, // LOG(ERROR)
ANDROID_LOG_WARN, // LOG(WARNING)
ANDROID_LOG_INFO, // LOG(INFO), LG, VLOG(0)
ANDROID_LOG_DEBUG, // VLOG(1)
ANDROID_LOG_VERBOSE, // VLOG(2) .. VLOG(N)
*/

@ -1 +1 @@
Subproject commit be4da30f2cd0dcfeb99b5f9703662b33fed5d9a7
Subproject commit 22352c93bef7af9e65df6e2c65fff64350033263