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 #81

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
10 changes: 6 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,14 @@
# specific language governing permissions and limitations
# under the License.

project(pegasus)
cmake_minimum_required(VERSION 3.11.0)

project(pegasus)

if(NOT UNIX)
message(FATAL_ERROR "It's not supported yet to build Pegasus on non-UNIX or non-UNIX-like system!")
endif()

if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
# require at least gcc 5.4.0
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.4.0)
Expand All @@ -39,9 +44,6 @@ set(THIRDPARTY_ROOT ${PROJECT_ROOT}/thirdparty)
set(THIRDPARTY_INSTALL_DIR ${PROJECT_ROOT}/thirdparty/output)
message(STATUS "THIRDPARTY_INSTALL_DIR = ${THIRDPARTY_INSTALL_DIR}")

set(BUILD_DIR ${PROJECT_ROOT}/src/builder)
message(STATUS "BUILD_DIR = ${BUILD_DIR}")

option(BUILD_TEST "build unit test" ON)
message(STATUS "BUILD_TEST = ${BUILD_TEST}")

Expand Down
104 changes: 51 additions & 53 deletions cmake_modules/BaseFunctions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function(dsn_install_library)
install(TARGETS ${MY_PROJ_NAME} DESTINATION "lib")
endfunction()

# Install this target into ${CMAKE_INSTALL_PREFIX}/bin/${PROJ_NAME}
# Install this target into ${CMAKE_INSTALL_PREFIX}/bin/${MY_PROJ_NAME}
function(dsn_install_executable)
set(MY_PROJ_TYPE "EXECUTABLE")
set(INSTALL_DIR "bin/${MY_PROJ_NAME}")
Expand All @@ -67,58 +67,43 @@ function(dsn_install_executable)
endif()
endfunction()

function(ms_add_project PROJ_TYPE PROJ_NAME PROJ_SRC PROJ_LIBS PROJ_BINPLACES)
if(NOT((PROJ_TYPE STREQUAL "STATIC") OR (PROJ_TYPE STREQUAL "SHARED") OR
(PROJ_TYPE STREQUAL "EXECUTABLE") OR (PROJ_TYPE STREQUAL "OBJECT")))
message(FATAL_ERROR "Invalid project type.")
endif()

if(PROJ_SRC STREQUAL "")
message(FATAL_ERROR "No source files.")
endif()

if((PROJ_TYPE STREQUAL "STATIC") OR (PROJ_TYPE STREQUAL "OBJECT"))
add_library(${PROJ_NAME} ${PROJ_TYPE} ${PROJ_SRC})
elseif(PROJ_TYPE STREQUAL "SHARED")
add_library(${PROJ_NAME} ${PROJ_TYPE} ${PROJ_SRC})
elseif(PROJ_TYPE STREQUAL "EXECUTABLE")
add_executable(${PROJ_NAME} ${PROJ_SRC})
endif()

if((PROJ_TYPE STREQUAL "SHARED") OR (PROJ_TYPE STREQUAL "EXECUTABLE"))
if(PROJ_TYPE STREQUAL "SHARED")
set(LINK_MODE PRIVATE)
else()
set(LINK_MODE PUBLIC)
endif()
target_link_libraries(${PROJ_NAME} "${LINK_MODE}" ${PROJ_LIBS})
endif()
endfunction(ms_add_project)


# Parameters:
# - MY_PROJ_TYPE
# - MY_PROJ_NAME
# - MY_SRC_SEARCH_MODE
# - MY_PROJ_TYPE: required: STATIC, SHARED, EXECUTABLE or OBJECT
# - MY_PROJ_NAME: required: <string>
# - MY_SRC_SEARCH_MODE: optional: GLOB_RECURSE or GLOB, default is GLOB
# Search mode for source files under current project directory
# "GLOB_RECURSE" for recursive search
# "GLOB" for non-recursive search
# - MY_PROJ_SRC
# - MY_PROJ_LIBS
# - MY_BINPLACES
# GLOB_RECURSE: for recursive search
# GLOB: for non-recursive search
# - MY_PROJ_SRC: optional: default is ""
# <empty>: includes all source files from the project directory
# <non-empty>: appends the specified files to all the source files from the project directory
# - MY_PROJ_LIBS: optional: default is ""
# The libraries to link
# - MY_BOOST_LIBS: optional: default is ""
# The boost libraries to link
# - MY_BINPLACES: optional: default is ""
# Extra files that will be installed
# - MY_BOOST_LIBS
function(dsn_add_project)
# 1. validate MY_PROJ_TYPE
if((NOT DEFINED MY_PROJ_TYPE) OR (MY_PROJ_TYPE STREQUAL ""))
message(FATAL_ERROR "MY_PROJ_TYPE is empty.")
endif()
if(NOT((MY_PROJ_TYPE STREQUAL "STATIC") OR (MY_PROJ_TYPE STREQUAL "SHARED") OR
(MY_PROJ_TYPE STREQUAL "EXECUTABLE") OR (MY_PROJ_TYPE STREQUAL "OBJECT")))
message(FATAL_ERROR "Invalid project type.")
endif()

# 2. validate MY_PROJ_NAME
if((NOT DEFINED MY_PROJ_NAME) OR (MY_PROJ_NAME STREQUAL ""))
message(FATAL_ERROR "MY_PROJ_NAME is empty.")
endif()

# 3. update MY_SRC_SEARCH_MODE
if(NOT DEFINED MY_SRC_SEARCH_MODE)
set(MY_SRC_SEARCH_MODE "GLOB")
endif()

# 4. update and validate MY_PROJ_SRC
# find source files from current directory
if(NOT DEFINED MY_PROJ_SRC)
set(MY_PROJ_SRC "")
Expand All @@ -127,25 +112,47 @@ function(dsn_add_project)
# We restrict the file suffix to keep our codes consistent.
file(${MY_SRC_SEARCH_MODE} TEMP_SRC
"${CMAKE_CURRENT_SOURCE_DIR}/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/*.c"
)
set(MY_PROJ_SRC ${TEMP_SRC} ${MY_PROJ_SRC})
if(MY_PROJ_SRC STREQUAL "")
message(FATAL_ERROR "No source files.")
endif()

# 5. update MY_BOOST_LIBS and MY_PROJ_LIBS
if(NOT DEFINED MY_BOOST_LIBS)
set(MY_BOOST_LIBS "")
endif()
if(NOT DEFINED MY_PROJ_LIBS)
set(MY_PROJ_LIBS "")
endif()
# TODO(yingchun): Link the libs explicitly in each projects.
if((MY_PROJ_TYPE STREQUAL "SHARED") OR (MY_PROJ_TYPE STREQUAL "EXECUTABLE"))
set(MY_PROJ_LIBS ${MY_PROJ_LIBS} ${DEFAULT_THIRDPARTY_LIBS} ${MY_BOOST_LIBS} ${DSN_SYSTEM_LIBS})
endif()

# 6. update MY_BINPLACES
if(NOT DEFINED MY_BINPLACES)
set(MY_BINPLACES "")
endif()

if(NOT DEFINED MY_BOOST_LIBS)
set(MY_BOOST_LIBS "")
# 7. add executable or library
if(MY_PROJ_TYPE STREQUAL "EXECUTABLE")
add_executable(${MY_PROJ_NAME} ${MY_PROJ_SRC})
else()
add_library(${MY_PROJ_NAME} ${MY_PROJ_TYPE} ${MY_PROJ_SRC})
endif()

# 8. link the libraries
if((MY_PROJ_TYPE STREQUAL "SHARED") OR (MY_PROJ_TYPE STREQUAL "EXECUTABLE"))
set(MY_PROJ_LIBS ${MY_PROJ_LIBS} ${DEFAULT_THIRDPARTY_LIBS} ${MY_BOOST_LIBS} ${DSN_SYSTEM_LIBS})
if(MY_PROJ_TYPE STREQUAL "SHARED")
set(LINK_MODE PRIVATE)
else()
set(LINK_MODE PUBLIC)
endif()
target_link_libraries(${MY_PROJ_NAME} "${LINK_MODE}" ${MY_PROJ_LIBS})
endif()
ms_add_project("${MY_PROJ_TYPE}" "${MY_PROJ_NAME}" "${MY_PROJ_SRC}" "${MY_PROJ_LIBS}" "${MY_BINPLACES}")

# 9. add -DFILE_BASENAME="filename"
define_file_basename_for_sources(${MY_PROJ_NAME})
endfunction(dsn_add_project)

Expand Down Expand Up @@ -174,7 +181,6 @@ endfunction(dsn_add_object)
function(dsn_add_test)
if(${BUILD_TEST})
add_definitions(-DGTEST_HAS_TR1_TUPLE=0 -DGTEST_USE_OWN_TR1_TUPLE=0)
set(MY_EXECUTABLE_IS_TEST TRUE)
dsn_add_executable()

file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
Expand Down Expand Up @@ -363,10 +369,6 @@ function(dsn_setup_thirdparty_libs)
endfunction(dsn_setup_thirdparty_libs)

function(dsn_common_setup)
if(NOT (UNIX))
message(FATAL_ERROR "Only Unix are supported.")
endif()

if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
message(FATAL_ERROR "In-source builds are not allowed.")
endif()
Expand All @@ -382,10 +384,6 @@ function(dsn_common_setup)
set(ENV{CCACHE_MAXSIZE} "1024M")
endif(CCACHE)

if(NOT DEFINED DSN_BUILD_RUNTIME)
set(DSN_BUILD_RUNTIME FALSE)
endif()

set(BUILD_SHARED_LIBS OFF)

include(CheckCXXCompilerFlag)
Expand Down
18 changes: 5 additions & 13 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,14 @@
# specific language governing permissions and limitations
# under the License.

project(pegasus C CXX)

set(PEGASUS_PROJECT_DIR ${CMAKE_CURRENT_SOURCE_DIR})

set(DSN_BUILD_RUNTIME TRUE)
add_compile_options(-fPIC)

dsn_common_setup()

if(UNIX)
add_compile_options(-fPIC)
endif()

include_directories(${PEGASUS_PROJECT_DIR})
include_directories(${PEGASUS_PROJECT_DIR}/common/serialization_helper)
include_directories(${PEGASUS_PROJECT_DIR}/include)
include_directories(${PEGASUS_PROJECT_DIR}/builder/output/include)
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/common/serialization_helper)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/builder/output/include)

add_subdirectory(aio)
add_subdirectory(base)
Expand Down
4 changes: 0 additions & 4 deletions src/base/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@

set(MY_PROJ_NAME "pegasus_base")

if(UNIX)
add_compile_options(-fPIC)
endif()

# Search mode for source files under CURRENT project directory?
# "GLOB_RECURSE" for recursive search
# "GLOB" for non-recursive search
Expand Down
1 change: 1 addition & 0 deletions src/meta/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,5 @@ add_definitions(-DDSN_MOCK_TEST)

dsn_add_shared_library()

add_subdirectory(meta_test_utils)
add_subdirectory(test)
37 changes: 37 additions & 0 deletions src/meta/meta_test_utils/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# The MIT License (MIT)
#
# Copyright (c) 2015 Microsoft Corporation
#
# -=- Robust Distributed System Nucleus (rDSN) -=-
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

set(MY_PROJ_NAME meta_test_utils)
set(MY_PROJ_SRC "")
set(MY_SRC_SEARCH_MODE "GLOB")
set(MY_PROJ_LIBS
dsn_meta_server
dsn_replica_server
dsn_replication_common
dsn_runtime
hashtable
gtest)
set(MY_BOOST_LIBS Boost::system Boost::filesystem Boost::regex)
set(MY_BINPLACES "")
dsn_add_static_library()
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@
#include "meta/meta_service.h"
#include "meta/meta_split_service.h"
#include "meta/meta_state_service_utils.h"
#include "meta/meta_test_utils/misc.h"
#include "meta/partition_guardian.h"
#include "meta/server_load_balancer.h"
#include "meta/server_state.h"
#include "meta/test/misc/misc.h"
#include "meta_service_test_app.h"
#include "meta/test/meta_service_test_app.h"
#include "runtime/rpc/rpc_address.h"
#include "runtime/rpc/rpc_message.h"
#include "runtime/task/task_tracker.h"
Expand Down
File renamed without changes.
File renamed without changes.
23 changes: 5 additions & 18 deletions src/meta/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,10 @@
# THE SOFTWARE.

set(MY_PROJ_NAME dsn.meta.test)

# Source files under CURRENT project directory will be automatically included.
# You can manually set MY_PROJ_SRC to include source files under other directories.
file(GLOB MY_PROJ_SRC
${PROJECT_SOURCE_DIR}/src/meta/*.cpp
${PROJECT_SOURCE_DIR}/src/meta/duplication/*.cpp
)
set(MY_PROJ_SRC ${MY_PROJ_SRC} misc/misc.cpp)

# Search mode for source files under CURRENT project directory?
# "GLOB_RECURSE" for recursive search
# "GLOB" for non-recursive search
set(MY_SRC_SEARCH_MODE "GLOB")

set(MY_PROJ_SRC "")
set(MY_PROJ_LIBS
dsn.replication.zookeeper_provider
dsn_replica_server
dsn_replication_common
dsn.block_service
dsn.block_service.local
Expand All @@ -60,14 +48,13 @@ set(MY_PROJ_LIBS
crypto
gtest
ssl
hdfs)

hdfs
meta_test_utils)
set(MY_BOOST_LIBS Boost::system Boost::filesystem Boost::regex)

# Extra files that will be installed
set(MY_BINPLACES clear.sh run.sh config-test.ini suite1 suite2)

dsn_add_test()

add_subdirectory(backup_test)
add_subdirectory(balancer_simulator)
add_subdirectory(meta_state)
40 changes: 40 additions & 0 deletions src/meta/test/backup_test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# The MIT License (MIT)
#
# Copyright (c) 2015 Microsoft Corporation
#
# -=- Robust Distributed System Nucleus (rDSN) -=-
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

set(MY_PROJ_NAME backup_test)
set(MY_PROJ_LIBS
dsn_meta_server
dsn_replica_server
dsn_replication_common
dsn_runtime
hashtable
gtest
meta_test_utils
test_utils)
set(MY_BOOST_LIBS Boost::system Boost::filesystem Boost::regex)
set(MY_BINPLACES
"../run.sh"
"../clear.sh"
"../config-test.ini")
dsn_add_test()
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@
#include "meta/meta_service.h"
#include "meta/meta_state_service.h"
#include "meta/server_state.h"
#include "meta/test/misc/misc.h"
#include "meta_service_test_app.h"
#include "meta_test_base.h"
#include "meta/meta_test_utils/misc.h"
#include "../meta_service_test_app.h"
#include "meta/meta_test_utils/meta_test_base.h"
#include "runtime/api_layer1.h"
#include "runtime/rpc/rpc_address.h"
#include "runtime/rpc/rpc_holder.h"
Expand Down
Loading