Skip to content

Commit

Permalink
restructure; add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
scivey committed Oct 1, 2015
1 parent 32e0607 commit 23195ec
Show file tree
Hide file tree
Showing 57 changed files with 3,177 additions and 619 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ gen-py
data
relevanced
unit_test_runner
build

36 changes: 36 additions & 0 deletions CMakeLibs/AddCXXCompilerFlag.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# - Adds a compiler flag if it is supported by the compiler
#
# This function checks that the supplied compiler flag is supported and then
# adds it to the corresponding compiler flags
#
# add_cxx_compiler_flag(<FLAG> [<VARIANT>])
#
# - Example
#
# include(AddCXXCompilerFlag)
# add_cxx_compiler_flag(-Wall)
# add_cxx_compiler_flag(-no-strict-aliasing RELEASE)
# Requires CMake 2.6+

if(__add_cxx_compiler_flag)
return()
endif()
set(__add_cxx_compiler_flag INCLUDED)

include(CheckCXXCompilerFlag)

function(add_cxx_compiler_flag FLAG)
string(TOUPPER "HAVE_CXX_FLAG_${FLAG}" SANITIZED_FLAG)
string(REPLACE "+" "X" SANITIZED_FLAG ${SANITIZED_FLAG})
string(REGEX REPLACE "[^A-Za-z_0-9]" "_" SANITIZED_FLAG ${SANITIZED_FLAG})
string(REGEX REPLACE "_+" "_" SANITIZED_FLAG ${SANITIZED_FLAG})
set(CMAKE_REQUIRED_FLAGS "${FLAG}")
check_cxx_compiler_flag("" ${SANITIZED_FLAG})
if(${SANITIZED_FLAG})
set(VARIANT ${ARGV1})
if(ARGV1)
string(TOUPPER "_${VARIANT}" VARIANT)
endif()
set(CMAKE_CXX_FLAGS${VARIANT} "${CMAKE_CXX_FLAGS${VARIANT}} ${FLAG}" PARENT_SCOPE)
endif()
endfunction()
38 changes: 38 additions & 0 deletions CMakeLibs/CXXFeatureCheck.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# - Compile and run code to check for C++ features
#
# This functions compiles a source file under the `cmake` folder
# and adds the corresponding `HAVE_[FILENAME]` flag to the CMake
# environment
#
# cxx_feature_check(<FLAG> [<VARIANT>])
#
# - Example
#
# include(CXXFeatureCheck)
# cxx_feature_check(STD_REGEX)
# Requires CMake 2.6+

if(__cxx_feature_check)
return()
endif()
set(__cxx_feature_check INCLUDED)

function(cxx_feature_check FILE)
string(TOLOWER ${FILE} FILE)
string(TOUPPER ${FILE} VAR)
string(TOUPPER "HAVE_${VAR}" FEATURE)
message("-- Performing Test ${FEATURE}")
try_run(RUN_${FEATURE} COMPILE_${FEATURE}
${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/${FILE}.cpp)
if(RUN_${FEATURE} EQUAL 0)
message("-- Performing Test ${FEATURE} -- success")
set(HAVE_${VAR} 1 PARENT_SCOPE)
add_definitions(-DHAVE_${VAR})
else()
if(NOT COMPILE_${FEATURE})
message("-- Performing Test ${FEATURE} -- failed to compile")
else()
message("-- Performing Test ${FEATURE} -- compiled but failed to run")
endif()
endif()
endfunction()
45 changes: 45 additions & 0 deletions CMakeLibs/GetGitVersion.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# - Returns a version string from Git tags
#
# This function inspects the annotated git tags for the project and returns a string
# into a CMake variable
#
# get_git_version(<var>)
#
# - Example
#
# include(GetGitVersion)
# get_git_version(GIT_VERSION)
#
# Requires CMake 2.6+

if(__get_git_version)
return()
endif()
set(__get_git_version INCLUDED)

function(get_git_version var)
execute_process(COMMAND git describe --match "v[0-9]*.[0-9]*.[0-9]*" --abbrev=8
RESULT_VARIABLE status
OUTPUT_VARIABLE GIT_VERSION
ERROR_QUIET)
if(${status})
set(GIT_VERSION "v0.0.0")
else()
string(STRIP ${GIT_VERSION} GIT_VERSION)
string(REGEX REPLACE "-[0-9]+-g" "-" GIT_VERSION ${GIT_VERSION})
endif()

# Work out if the repository is dirty
execute_process(COMMAND git update-index -q --refresh
OUTPUT_QUIET
ERROR_QUIET)
execute_process(COMMAND git diff-index --name-only HEAD --
OUTPUT_VARIABLE GIT_DIFF_INDEX
ERROR_QUIET)
string(COMPARE NOTEQUAL "${GIT_DIFF_INDEX}" "" GIT_DIRTY)
if (${GIT_DIRTY})
set(GIT_VERSION "${GIT_VERSION}-dirty")
endif()
message("-- git Version: ${GIT_VERSION}")
set(${var} ${GIT_VERSION} PARENT_SCOPE)
endfunction()
134 changes: 134 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
cmake_minimum_required(VERSION 2.8.12)
project(relevanced)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMakeLibs")

string(ASCII 27 ESC)
macro(WARNING_LOG MESSAGE)
message("-- ${ESC}[31m${MESSAGE}${ESC}[m")
endmacro(WARNING_LOG)

macro(LOG MESSAGE)
message("-- ${MESSAGE}")
endmacro(LOG)

# If no explicit compiler override and clang++ exists, prefer clang.
# find_file(CLANGCXX_3_5_EXISTS, "clang++-3.5")
# find_file(CLANGXX_EXISTS "clang++")
# if(DEFINED ENV{CC})
# set(CMAKE_C_COMPILER "$ENV{CC}")
# LOG("Overriding C compiler from clang to $ENV{CC}")
# elseif(CLANGCXX_3_5_EXISTS)
# LOG(${CMAKE_CXX_COMPILER})
# set(CMAKE_C_COMPILER "clang-3.5")
# elseif(CLANGXX_EXISTS)
# set(CMAKE_C_COMPILER "clang")
# endif()
# if(DEFINED ENV{CXX})
# set(CMAKE_CXX_COMPILER "$ENV{CXX}")
# LOG("Overriding CXX compiler from clang++ to $ENV{CXX}")
# elseif(CLANGCXX_3_5_EXISTS)
# set(USING_CLANG true)
# set(CMAKE_CXX_COMPILER "clang++-3.5")
# elseif(CLANGXX_EXISTS)
# set(USING_CLANG true)
# set(CMAKE_CXX_COMPILER "clang++")
# endif()

set(CMAKE_CXX_COMPILER "clang++-3.5")
set(CMAKE_C_COMPILER "clang")


LOG(${CMAKE_CXX_COMPILER})

include("${CMAKE_SOURCE_DIR}/CMakeLibs")
include(GetGitVersion)
include(CheckCXXCompilerFlag)
include(CXXFeatureCheck)
include(AddCXXCompilerFlag)
include_directories("${CMAKE_SOURCE_DIR}/src")

add_cxx_compiler_flag(--std=c++14)
if(DEFINED USING_CLANG)
add_cxx_compiler_flag(-stdlib=libstdc++)
endif()

# make debug (environment variable from Makefile)
if(DEFINED ENV{DEBUG})
set(DEBUG TRUE)
set(CMAKE_BUILD_TYPE "Debug")
add_compile_options(-g -O0)
add_definitions(-DDEBUG)
WARNING_LOG("Setting DEBUG build")
else()
set(DEBUG FALSE)
add_compile_options(-Os)
add_definitions(-DNDEBUG)
endif()

if(NOT DEFINED ENV{OPTIMIZED})
add_compile_options(-march=x86-64 -mno-avx)
endif()

# make analyze (environment variable from Makefile)
if(DEFINED ENV{ANALYZE})
set(CMAKE_CXX_COMPILER "${CMAKE_SOURCE_DIR}/tools/analysis/clang-analyze.sh")
endif()

include(CMakeLibs)

# Discover build version from an environment variable or from the git checkout.
if(DEFINED ENV{RELEVANCED_BUILD_VERSION})
set(RELEVANCED_BUILD_VERSION "$ENV{RELEVANCED_BUILD_VERSION}")
else()
# Generate version from git
execute_process(
COMMAND git describe --tags HEAD --always
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
OUTPUT_VARIABLE RELEVANCED_BUILD_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE
)
endif()

# We need to link some packages as dynamic/dependent.
set(CMAKE_FIND_LIBRARY_SUFFIXES .dylib .so .a)

find_library(wangle REQUIRED)
find_library(folly REQUIRED)
find_library(mitie REQUIRED)
find_library(thrift REQUIRED)
find_library(thriftcpp2 REQUIRED)
find_library(thriftz REQUIRED)
find_library(rocksdb REQUIRED)
find_library(glog REQUIRED)
find_library(gflags REQUIRED)
find_library(bz2 REQUIRED)
find_library(lz REQUIRED)
find_library(lz4 REQUIRED)
find_library(boost_thread REQUIRED)
find_library(boost_system REQUIRED)
find_library(jemalloc REQUIRED)
find_library(atomic REQUIRED)
find_library(pthread REQUIRED)
find_library(double-conversion REQUIRED)
find_library(snappy REQUIRED)


# enable_testing()

include_directories("/usr/local/include")
link_directories("/usr/local/lib")

add_subdirectory(src)
add_subdirectory(src/test)


# make format-all
add_custom_target(
format-all
find src \( -name "*.h" -o -name "*.cpp" -o -name "*.mm" \)
-exec clang-format -i {} +
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
COMMENT "Format all code with clang-format" VERBATIM
)

Loading

0 comments on commit 23195ec

Please sign in to comment.