Skip to content

Commit

Permalink
initialize
Browse files Browse the repository at this point in the history
  • Loading branch information
holmes1412 committed Aug 9, 2020
1 parent 2d4124e commit 7114f18
Show file tree
Hide file tree
Showing 104 changed files with 16,333 additions and 52 deletions.
7 changes: 7 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# top-most EditorConfig file
root = true

# all files
[*]
indent_style = tab
indent_size = 4
62 changes: 36 additions & 26 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,32 +1,42 @@
# Prerequisites
*.d

# Compiled Object files
*.slo
*.a
*.bak
*.gz
*.zip
*.tar
*.la
*.lo
*.o
*.obj

# Precompiled Headers
*.gch
*.pch

# Compiled Dynamic libraries
*.rpm
*.so
*.dylib
*.dll
*.so.*
*.cmake
*.vcxproj
*.filters
*.sln
*.pb.h
*.pb.cc
*.log
*.srpc.h
*.thrift.h
*.pb_skeleton.h
*.pb_skeleton.cc
*.thrift_skeleton.h
*.thrift_skeleton.cc

# Fortran module files
*.mod
*.smod
_bin/
_include/
_lib/
.deps/
build/
build_pkg/
CMakeFiles/
Debug/
Release/

# Compiled Static libraries
*.lai
*.la
*.a
*.lib
missing
SRCINFO
SRCNUMVER
SRCVERSION
CMakeCache.txt
Makefile

# Executables
*.exe
*.out
*.app
138 changes: 138 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
cmake_minimum_required(VERSION 3.6)

set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "build type")
set(CMAKE_INSTALL_PREFIX /opt/sogou CACHE PATH "install prefix")

project(srpc
VERSION 1.0.3
LANGUAGES C CXX)

set(INC_DIR ${PROJECT_SOURCE_DIR}/_include CACHE PATH "srpc inc")
set(LIB_DIR ${PROJECT_SOURCE_DIR}/_lib CACHE PATH "srpc lib")
set(BIN_DIR ${PROJECT_SOURCE_DIR}/_bin CACHE PATH "srpc bin")

include(GNUInstallDirs)

set(CMAKE_CONFIG_INSTALL_FILE ${PROJECT_BINARY_DIR}/config.toinstall.cmake)
set(CMAKE_CONFIG_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LIB_DIR})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIB_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${BIN_DIR})

add_custom_target(
LINK_HEADERS ALL
COMMENT "link headers..."
)

INCLUDE(CMakeLists_Headers.txt)

macro(makeLink src dest target)
add_custom_command(
TARGET ${target} PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E create_symlink ${src} ${dest}
DEPENDS ${dest}
)
endmacro()

add_custom_command(
TARGET LINK_HEADERS PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory ${INC_DIR}/${PROJECT_NAME}
)

foreach(header_file ${INCLUDE_HEADERS})
string(REPLACE "/" ";" arr ${header_file})
list(GET arr -1 file_name)
makeLink(${PROJECT_SOURCE_DIR}/${header_file} ${INC_DIR}/${PROJECT_NAME}/${file_name} LINK_HEADERS)
endforeach()

add_subdirectory(src)

####CONFIG

include(CMakePackageConfigHelpers)
set(CONFIG_INC_DIR ${INC_DIR})
set(CONFIG_LIB_DIR ${LIB_DIR})
set(CONFIG_BIN_DIR ${BIN_DIR})
configure_package_config_file(
${PROJECT_NAME}-config.cmake.in
${PROJECT_SOURCE_DIR}/${PROJECT_NAME}-config.cmake
INSTALL_DESTINATION ${CMAKE_CONFIG_INSTALL_DIR}
PATH_VARS CONFIG_INC_DIR CONFIG_LIB_DIR CONFIG_BIN_DIR
)

set(CONFIG_INC_DIR ${CMAKE_INSTALL_INCLUDEDIR})
set(CONFIG_LIB_DIR ${CMAKE_INSTALL_LIBDIR})
set(CONFIG_BIN_DIR ${CMAKE_INSTALL_BINDIR})
configure_package_config_file(
${PROJECT_NAME}-config.cmake.in
${CMAKE_CONFIG_INSTALL_FILE}
INSTALL_DESTINATION ${CMAKE_CONFIG_INSTALL_DIR}
PATH_VARS CONFIG_INC_DIR CONFIG_LIB_DIR CONFIG_BIN_DIR
)

install(
FILES ${CMAKE_CONFIG_INSTALL_FILE}
DESTINATION ${CMAKE_CONFIG_INSTALL_DIR}
COMPONENT devel
RENAME ${PROJECT_NAME}-config.cmake
)

#### PACK

set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Sogou RPC")
set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})

# set(CPACK_RPM_PRE_INSTALL_SCRIPT_FILE ${CMAKE_CURRENT_SOURCE_DIR}/pre_script.sh)
# set(CPACK_RPM_POST_INSTALL_SCRIPT_FILE ${CMAKE_CURRENT_SOURCE_DIR}/post_script.sh)

execute_process(
COMMAND git log -n1 --format=%ad --date=short
RESULT_VARIABLE GIT_LOG_RET
OUTPUT_VARIABLE GIT_YMD
OUTPUT_STRIP_TRAILING_WHITESPACE
)

if (NOT GIT_LOG_RET EQUAL 0)
set(GIT_YMD 0)
endif()

string(REPLACE "-" "" RELEASE_LABEL ${GIT_YMD})
set(CPACK_RPM_PACKAGE_RELEASE ${RELEASE_LABEL})

set(CPACK_RPM_COMPONENT_INSTALL ON)
set(CPACK_COMPONENTS_ALL devel)
set(CPACK_RPM_FILE_NAME RPM-DEFAULT)
set(CPACK_RPM_PACKAGE_RELEASE_DIST ON)

set(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION /usr/lib64/cmake)

set(PB_PACKAGE_REQUIRED "protobuf-devel")
execute_process(COMMAND
grep VERSION /etc/os-release
OUTPUT_VARIABLE OS_RELEASE_CORE OUTPUT_STRIP_TRAILING_WHITESPACE)
if (NOT ${OS_RELEASE_CORE} EQUAL "")
string(SUBSTRING ${OS_RELEASE_CORE} 9 1 OS_RELEASE_CORE_NUMBER)
if (${OS_RELEASE_CORE_NUMBER} EQUAL "7")
set(PB_PACKAGE_REQUIRED "protobuf3-devel")
endif()
endif()

set(CPACK_RPM_DEVEL_PACKAGE_REQUIRES "workflow-devel >= 1.12.3, ${PB_PACKAGE_REQUIRED}")

install(
FILES ${INCLUDE_HEADERS}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}
COMPONENT devel
)

install(
FILES README.md
DESTINATION "${CMAKE_INSTALL_DOCDIR}-${PROJECT_VERSION}"
COMPONENT devel
)

set(CPACK_RPM_SPEC_MORE_DEFINE "%define __spec_install_post /bin/true") # disable strip
set(CPACK_GENERATOR "RPM")

include(CPack)

28 changes: 28 additions & 0 deletions CMakeLists_Headers.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
cmake_minimum_required(VERSION 3.6)

set(INCLUDE_HEADERS
src/compress/rpc_compress.h
src/compress/rpc_compress_gzip.h
src/message/rpc_message.h
src/message/rpc_message_srpc.h
src/message/rpc_message_thrift.h
src/message/rpc_message_brpc.h
src/thrift/rpc_thrift_buffer.h
src/thrift/rpc_thrift_enum.h
src/thrift/rpc_thrift_idl.h
src/thrift/rpc_thrift_idl.inl
src/rpc_basic.h
src/rpc_buffer.h
src/rpc_client.h
src/rpc_context.h
src/rpc_context.inl
src/rpc_global.h
src/rpc_options.h
src/rpc_server.h
src/rpc_service.h
src/rpc_task.inl
src/rpc_types.h
src/rpc_zero_copy_stream.h
src/sogou_rpc.h
)

60 changes: 60 additions & 0 deletions GNUmakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
ROOT_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
ALL_TARGETS := all base check install preinstall package rpm clean tutorial example
MAKE_FILE := Makefile

DEFAULT_BUILD_DIR := build
BUILD_DIR := $(shell if [ -f $(MAKE_FILE) ]; then echo "."; else echo $(DEFAULT_BUILD_DIR); fi)
CMAKE3 := $(shell if which cmake3>/dev/null ; then echo cmake3; else echo cmake; fi;)

.PHONY: $(ALL_TARGETS)

all: base
make -C $(BUILD_DIR) -f Makefile

base:
mkdir -p $(BUILD_DIR)
ifeq ($(DEBUG),y)
cd $(BUILD_DIR) && $(CMAKE3) -D CMAKE_BUILD_TYPE=Debug $(ROOT_DIR)
else
cd $(BUILD_DIR) && $(CMAKE3) $(ROOT_DIR)
endif

tutorial: all
make -C tutorial

example: all
make -C example

check: all
make -C test check

install preinstall package: base
mkdir -p $(BUILD_DIR)
cd $(BUILD_DIR) && $(CMAKE3) $(ROOT_DIR)
make -C $(BUILD_DIR) -f Makefile $@

rpm: package
ifneq ($(BUILD_DIR),.)
mv $(BUILD_DIR)/*.rpm ./
endif

clean:
ifeq (build, $(wildcard build))
-make -C build clean
endif
-make -C test clean
-make -C benchmark clean
-make -C example clean
-make -C tutorial clean
rm -rf $(DEFAULT_BUILD_DIR)
rm -rf _include
rm -rf _lib
rm -rf _bin
rm -f SRCINFO SRCNUMVER SRCVERSION
rm -f ./*.rpm
rm -f src/message/*.pb.h src/message/*.pb.cc
find . -name CMakeCache.txt | xargs rm -f
find . -name Makefile | xargs rm -f
find . -name "*.cmake" | xargs rm -f
find . -name CMakeFiles | xargs rm -rf

26 changes: 1 addition & 25 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
Expand Down Expand Up @@ -174,28 +175,3 @@
of your accepting any such warranty or additional liability.

END OF TERMS AND CONDITIONS

APPENDIX: How to apply the Apache License to your work.

To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright [yyyy] [name of copyright owner]

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Loading

0 comments on commit 7114f18

Please sign in to comment.