diff --git a/CMakeLists.txt b/CMakeLists.txt index d887e30cd8..595dc64557 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,6 +18,5 @@ if(ENABLE_GCOV AND UNIX) set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage -lgcov") endif() dsn_common_setup() -dsn_add_pseudo_projects() add_subdirectory(src) diff --git a/bin/dsn.cg.bat b/bin/dsn.cg.bat deleted file mode 100644 index bca8aa4e80..0000000000 --- a/bin/dsn.cg.bat +++ /dev/null @@ -1,4 +0,0 @@ -@ECHO OFF -SET CODEGEN_ROOT=%~dp0 -CALL %CODEGEN_ROOT%\Windows\php.exe -f %CODEGEN_ROOT%\dsn.generate_code.php %1 %2 %3 %4 %5 %6 %7 %8 %9 -:EOF diff --git a/bin/dsn.cmake b/bin/dsn.cmake index 248f020841..8f9cc0891e 100644 --- a/bin/dsn.cmake +++ b/bin/dsn.cmake @@ -5,9 +5,8 @@ include(${CMAKE_CURRENT_LIST_DIR}/compiler_info.cmake) # See http://clang.llvm.org/docs/JSONCompilationDatabase.html set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE) -function(ms_add_project PROJ_LANG PROJ_TYPE PROJ_NAME PROJ_SRC PROJ_INC_PATH PROJ_LIBS PROJ_LIB_PATH PROJ_BINPLACES PROJ_BINDIRS DO_INSTALL) +function(ms_add_project PROJ_TYPE PROJ_NAME PROJ_SRC PROJ_INC_PATH PROJ_LIBS PROJ_LIB_PATH PROJ_BINPLACES PROJ_BINDIRS DO_INSTALL) if(DEFINED DSN_DEBUG_CMAKE) - message(STATUS "PROJ_LANG = ${PROJ_LANG}") message(STATUS "PROJ_TYPE = ${PROJ_TYPE}") message(STATUS "PROJ_NAME = ${PROJ_NAME}") message(STATUS "PROJ_SRC = ${PROJ_SRC}") @@ -18,10 +17,6 @@ function(ms_add_project PROJ_LANG PROJ_TYPE PROJ_NAME PROJ_SRC PROJ_INC_PATH PRO message(STATUS "DO_INSTALL = ${DO_INSTALL}") endif() - if(PROJ_LANG STREQUAL "") - message(FATAL_ERROR "Invalid project language.") - endif() - if(NOT((PROJ_TYPE STREQUAL "STATIC") OR (PROJ_TYPE STREQUAL "SHARED") OR (PROJ_TYPE STREQUAL "EXECUTABLE") OR (PROJ_TYPE STREQUAL "OBJECT"))) #"MODULE" is not used yet @@ -41,62 +36,45 @@ function(ms_add_project PROJ_LANG PROJ_TYPE PROJ_NAME PROJ_SRC PROJ_INC_PATH PRO set(INSTALL_DIR "bin/${PROJ_NAME}") set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${PROJ_NAME}") set(OUTPUT_DIRECTORY "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}") - if(NOT WIN32) - execute_process(COMMAND sh -c "echo ${PROJ_NAME} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_BINARY_DIR}/${INSTALL_DIR} ' ' >> ${CMAKE_SOURCE_DIR}/.matchfile") - endif() + execute_process(COMMAND sh -c "echo ${PROJ_NAME} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_BINARY_DIR}/${INSTALL_DIR} ' ' >> ${CMAKE_SOURCE_DIR}/.matchfile") elseif(PROJ_TYPE STREQUAL "STATIC") set(OUTPUT_DIRECTORY "${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}") - if(NOT WIN32) - execute_process(COMMAND sh -c "echo ${PROJ_NAME} ${CMAKE_CURRENT_SOURCE_DIR} ${OUTPUT_DIRECTORY} ' ' >> ${CMAKE_SOURCE_DIR}/.matchfile") - endif() + execute_process(COMMAND sh -c "echo ${PROJ_NAME} ${CMAKE_CURRENT_SOURCE_DIR} ${OUTPUT_DIRECTORY} ' ' >> ${CMAKE_SOURCE_DIR}/.matchfile") elseif(PROJ_TYPE STREQUAL "SHARED") set(OUTPUT_DIRECTORY "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}") - if(NOT WIN32) - execute_process(COMMAND sh -c "echo ${PROJ_NAME} ${CMAKE_CURRENT_SOURCE_DIR} ${OUTPUT_DIRECTORY} ' ' >> ${CMAKE_SOURCE_DIR}/.matchfile") - endif() + execute_process(COMMAND sh -c "echo ${PROJ_NAME} ${CMAKE_CURRENT_SOURCE_DIR} ${OUTPUT_DIRECTORY} ' ' >> ${CMAKE_SOURCE_DIR}/.matchfile") endif() if(DEFINED DSN_DEBUG_CMAKE) message(STATUS "OUTPUT_DIRECTORY = ${OUTPUT_DIRECTORY}") endif() - if(PROJ_LANG STREQUAL "CXX") - if(NOT (PROJ_INC_PATH STREQUAL "")) - include_directories(${PROJ_INC_PATH}) - endif() - if(NOT (PROJ_LIB_PATH STREQUAL "")) - link_directories(${PROJ_LIB_PATH}) - endif() + if(NOT (PROJ_INC_PATH STREQUAL "")) + include_directories(${PROJ_INC_PATH}) + endif() + if(NOT (PROJ_LIB_PATH STREQUAL "")) + link_directories(${PROJ_LIB_PATH}) + endif() - if((PROJ_TYPE STREQUAL "STATIC") OR (PROJ_TYPE STREQUAL "OBJECT")) - if(MSVC) - add_definitions(-D_LIB) - endif() - 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") - if(MSVC) - add_definitions(-D_CONSOLE) - endif() - add_executable(${PROJ_NAME} ${PROJ_SRC}) - 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}) + 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() - if(DO_INSTALL) - install(TARGETS ${PROJ_NAME} DESTINATION "${INSTALL_DIR}") - #if (WIN32) - # install(FILES "${PROJ_NAME}.pdb" DESTINATION "${INSTALL_DIR}") - #endif() - endif() + if(DO_INSTALL) + install(TARGETS ${PROJ_NAME} DESTINATION "${INSTALL_DIR}") endif() if((PROJ_TYPE STREQUAL "EXECUTABLE") AND (NOT (PROJ_BINPLACES STREQUAL ""))) @@ -128,101 +106,18 @@ function(ms_add_project PROJ_LANG PROJ_TYPE PROJ_NAME PROJ_SRC PROJ_INC_PATH PRO endif() endfunction(ms_add_project) -macro(ms_add_compiler_flags LANGUAGES SUFFIXES FLAGS) - foreach(LANG ${LANGUAGES}) - foreach(SUFFIX ${SUFFIXES}) - if(SUFFIX STREQUAL "") - set(SUFFIX "") - else() - string(TOUPPER ${SUFFIX} SUFFIX) - set(SUFFIX "_${SUFFIX}") - endif() - set(FLAG_VAR "CMAKE_${LANG}_FLAGS${SUFFIX}") - set(${FLAG_VAR} "${${FLAG_VAR}} ${FLAGS}" PARENT_SCOPE) - message(STATUS ${FLAG_VAR} ":" ${${FLAG_VAR}}) - endforeach() - endforeach() -endmacro(ms_add_compiler_flags) - -macro(ms_link_static_runtime FLAG_VAR) - if(MSVC) - if(${FLAG_VAR} MATCHES "/MD") - string(REPLACE "/MD" "/MT" "${FLAG_VAR}" "${${FLAG_VAR}}") - #Save persistently - set(${FLAG_VAR} ${${FLAG_VAR}} CACHE STRING "" FORCE) - endif() - endif() -endmacro(ms_link_static_runtime) - -macro(ms_replace_compiler_flags REPLACE_OPTION) - set(SUFFIXES "") - if((NOT DEFINED CMAKE_CONFIGURATION_TYPES) OR (CMAKE_CONFIGURATION_TYPES STREQUAL "")) - #set(SUFFIXES "_DEBUG" "_RELEASE" "_MINSIZEREL" "_RELWITHDEBINFO") - if((DEFINED CMAKE_BUILD_TYPE) AND (NOT (CMAKE_BUILD_TYPE STREQUAL ""))) - string(TOUPPER ${CMAKE_BUILD_TYPE} SUFFIXES) - set(SUFFIXES "_${SUFFIXES}") - endif() - else() - foreach(SUFFIX ${CMAKE_CONFIGURATION_TYPES}) - string(TOUPPER ${SUFFIX} SUFFIX) - set(SUFFIXES ${SUFFIXES} "_${SUFFIX}") - endforeach() - endif() - - foreach(SUFFIX "" ${SUFFIXES}) - foreach(LANG C CXX) - set(FLAG_VAR "CMAKE_${LANG}_FLAGS${SUFFIX}") - if(${REPLACE_OPTION} STREQUAL "STATIC_LINK") - ms_link_static_runtime(${FLAG_VAR}) - endif() - endforeach() - #message(STATUS ${FLAG_VAR} ":" ${${FLAG_VAR}}) - endforeach() -endmacro(ms_replace_compiler_flags) - -function(ms_check_cxx11_support) - if(UNIX) - include(CheckCXXCompilerFlag) - CHECK_CXX_COMPILER_FLAG("-std=c++1y" COMPILER_SUPPORTS_CXX11) - else() - if(MSVC_VERSION LESS 1700) - set(COMPILER_SUPPORTS_CXX11 0) - else() - set(COMPILER_SUPPORTS_CXX11 1) - endif() - endif() - - if(COMPILER_SUPPORTS_CXX11) - else() - message(FATAL_ERROR "You need a compiler with C++1y support.") - endif() -endfunction(ms_check_cxx11_support) - -macro(ms_find_source_files LANG SOURCE_DIR GLOB_OPTION PROJ_SRC) +macro(ms_find_source_files SOURCE_DIR GLOB_OPTION PROJ_SRC) set(TEMP_PROJ_SRC "") - if(${LANG} STREQUAL "CXX") - file(${GLOB_OPTION} - TEMP_PROJ_SRC - "${SOURCE_DIR}/*.cpp" - "${SOURCE_DIR}/*.cc" - "${SOURCE_DIR}/*.c" - "${SOURCE_DIR}/*.h" - "${SOURCE_DIR}/*.hpp" - ) - elseif(${LANG} STREQUAL "CS") - file(${GLOB_OPTION} - TEMP_PROJ_SRC - "${SOURCE_DIR}/*.cs" - ) - elseif(${LANG} STREQUAL "JAVA") - file(${GLOB_OPTION} - TEMP_PROJ_SRC - "${SOURCE_DIR}/*.java" - ) - endif() + file(${GLOB_OPTION} + TEMP_PROJ_SRC + "${SOURCE_DIR}/*.cpp" + "${SOURCE_DIR}/*.cc" + "${SOURCE_DIR}/*.c" + "${SOURCE_DIR}/*.h" + "${SOURCE_DIR}/*.hpp" + ) if(DEFINED DSN_DEBUG_CMAKE) - message(STATUS "LANG = ${LANG}") message(STATUS "SOURCE_DIR = ${SOURCE_DIR}") message(STATUS "GLOB_OPTION = ${GLOB_OPTION}") message(STATUS "PROJ_SRC = ${${PROJ_SRC}}") @@ -241,32 +136,18 @@ macro(dsn_setup_serialization) set(USE_PROTOBUF TRUE) endif () endforeach() - if (MY_PROJ_LANG STREQUAL "CXX") - if (USE_THRIFT) - if (WIN32) - list(APPEND MY_PROJ_LIBS thriftmt) - else () - list(APPEND MY_PROJ_LIBS thrift) - endif () - add_definitions(-DDSN_USE_THRIFT_SERIALIZATION) - add_definitions(-DDSN_ENABLE_THRIFT_RPC) - endif () - if (USE_PROTOBUF) - if (WIN32) - list(APPEND MY_PROJ_LIBS libprotobuf) - else () - list(APPEND MY_PROJ_LIBS protobuf.a) - endif () - add_definitions(-DDSN_USE_PROTOBUF_SERIALIZATION) - endif () + if (USE_THRIFT) + list(APPEND MY_PROJ_LIBS thrift) + add_definitions(-DDSN_USE_THRIFT_SERIALIZATION) + add_definitions(-DDSN_ENABLE_THRIFT_RPC) + endif () + if (USE_PROTOBUF) + list(APPEND MY_PROJ_LIBS protobuf.a) + add_definitions(-DDSN_USE_PROTOBUF_SERIALIZATION) endif () - #TODO : CSHARP endmacro(dsn_setup_serialization) function(dsn_add_project) - if((NOT DEFINED MY_PROJ_LANG) OR (MY_PROJ_LANG STREQUAL "")) - message(FATAL_ERROR "MY_PROJ_LANG is empty.") - endif() if((NOT DEFINED MY_PROJ_TYPE) OR (MY_PROJ_TYPE STREQUAL "")) message(FATAL_ERROR "MY_PROJ_TYPE is empty.") endif() @@ -280,7 +161,7 @@ function(dsn_add_project) set(MY_PROJ_SRC "") endif() set(TEMP_SRC "") - ms_find_source_files("${MY_PROJ_LANG}" "${CMAKE_CURRENT_SOURCE_DIR}" ${MY_SRC_SEARCH_MODE} TEMP_SRC) + ms_find_source_files("${CMAKE_CURRENT_SOURCE_DIR}" ${MY_SRC_SEARCH_MODE} TEMP_SRC) set(MY_PROJ_SRC ${TEMP_SRC} ${MY_PROJ_SRC}) if(NOT DEFINED MY_PROJ_INC_PATH) set(MY_PROJ_INC_PATH "") @@ -313,24 +194,22 @@ function(dsn_add_project) set(MY_SERIALIZATION_TYPE "") endif() - if(MY_PROJ_LANG STREQUAL "CXX") - set(MY_BOOST_LIBS "") - if(NOT (MY_BOOST_PACKAGES STREQUAL "")) - ms_setup_boost(TRUE "${MY_BOOST_PACKAGES}" MY_BOOST_LIBS) - endif() + set(MY_BOOST_LIBS "") + if(NOT (MY_BOOST_PACKAGES STREQUAL "")) + ms_setup_boost(TRUE "${MY_BOOST_PACKAGES}" MY_BOOST_LIBS) + endif() - if((MY_PROJ_TYPE STREQUAL "SHARED") OR (MY_PROJ_TYPE STREQUAL "EXECUTABLE")) - if(DSN_BUILD_RUNTIME AND(DEFINED DSN_IN_CORE) AND DSN_IN_CORE) - set(TEMP_LIBS "") - else() - set(TEMP_LIBS dsn_runtime) - endif() - set(MY_PROJ_LIBS ${MY_PROJ_LIBS} ${TEMP_LIBS} ${MY_BOOST_LIBS} -ltcmalloc) - if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux") - set(MY_PROJ_LIBS ${MY_PROJ_LIBS} ${DSN_SYSTEM_LIBS}) - else() - set(MY_PROJ_LIBS ${DSN_SYSTEM_LIBS} ${MY_PROJ_LIBS}) - endif() + if((MY_PROJ_TYPE STREQUAL "SHARED") OR (MY_PROJ_TYPE STREQUAL "EXECUTABLE")) + if(DSN_BUILD_RUNTIME AND(DEFINED DSN_IN_CORE) AND DSN_IN_CORE) + set(TEMP_LIBS "") + else() + set(TEMP_LIBS dsn_runtime) + endif() + set(MY_PROJ_LIBS ${MY_PROJ_LIBS} ${TEMP_LIBS} ${MY_BOOST_LIBS} -ltcmalloc) + if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux") + set(MY_PROJ_LIBS ${MY_PROJ_LIBS} ${DSN_SYSTEM_LIBS}) + else() + set(MY_PROJ_LIBS ${DSN_SYSTEM_LIBS} ${MY_PROJ_LIBS}) endif() endif() @@ -351,29 +230,25 @@ function(dsn_add_project) message(STATUS "MY_BOOST_PACKAGES = ${MY_BOOST_PACKAGES}") message(STATUS "MY_BOOST_LIBS = ${MY_BOOST_LIBS}") endif() - ms_add_project("${MY_PROJ_LANG}" "${MY_PROJ_TYPE}" "${MY_PROJ_NAME}" "${MY_PROJ_SRC}" "${MY_PROJ_INC_PATH}" "${MY_PROJ_LIBS}" "${MY_PROJ_LIB_PATH}" "${MY_BINPLACES}" "${MY_PROJ_BINDIRS}" "${MY_DO_INSTALL}") + ms_add_project("${MY_PROJ_TYPE}" "${MY_PROJ_NAME}" "${MY_PROJ_SRC}" "${MY_PROJ_INC_PATH}" "${MY_PROJ_LIBS}" "${MY_PROJ_LIB_PATH}" "${MY_BINPLACES}" "${MY_PROJ_BINDIRS}" "${MY_DO_INSTALL}") endfunction(dsn_add_project) function(dsn_add_static_library) - set(MY_PROJ_LANG "CXX") set(MY_PROJ_TYPE "STATIC") dsn_add_project() endfunction(dsn_add_static_library) function(dsn_add_shared_library) - set(MY_PROJ_LANG "CXX") set(MY_PROJ_TYPE "SHARED") dsn_add_project() endfunction(dsn_add_shared_library) function(dsn_add_executable) - set(MY_PROJ_LANG "CXX") set(MY_PROJ_TYPE "EXECUTABLE") dsn_add_project() endfunction(dsn_add_executable) function(dsn_add_object) - set(MY_PROJ_LANG "CXX") set(MY_PROJ_TYPE "OBJECT") dsn_add_project() endfunction(dsn_add_object) @@ -386,69 +261,49 @@ function(dsn_add_test) endfunction() function(dsn_setup_compiler_flags) - ms_replace_compiler_flags("STATIC_LINK") - - if(UNIX) - if(CMAKE_USE_PTHREADS_INIT) - add_compile_options(-pthread) - endif() - if(CMAKE_BUILD_TYPE STREQUAL "Debug") - add_definitions(-D_DEBUG) - add_definitions(-DDSN_BUILD_TYPE=Debug) - else() - add_definitions(-g) - add_definitions(-O2) - add_definitions(-DDSN_BUILD_TYPE=Release) - endif() - cmake_host_system_information(RESULT BUILD_HOSTNAME QUERY HOSTNAME) - add_definitions(-DDSN_BUILD_HOSTNAME=${BUILD_HOSTNAME}) - add_definitions(-D__STDC_FORMAT_MACROS) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1y" CACHE STRING "" FORCE) - add_compile_options(-Wall) - add_compile_options(-Werror) - add_compile_options(-Wno-sign-compare) - add_compile_options(-Wno-strict-aliasing) - add_compile_options(-Wuninitialized) - add_compile_options(-Wno-unused-result) - add_compile_options(-Wno-unused-variable) - add_compile_options(-Wno-deprecated-declarations) - add_compile_options(-Wno-inconsistent-missing-override) - - find_program(CCACHE_FOUND ccache) - if(CCACHE_FOUND) - set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache) - set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache) - if ("${COMPILER_FAMILY}" STREQUAL "clang") - add_compile_options(-Qunused-arguments) - endif() - message("use ccache to speed up compilation") - endif(CCACHE_FOUND) - - set(CMAKE_EXE_LINKER_FLAGS - "${CMAKE_EXE_LINKER_FLAGS} -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free" - CACHE - STRING - "" - FORCE) - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free" - CACHE - STRING - "" - FORCE) - - elseif(MSVC) - add_definitions(-D_CRT_SECURE_NO_WARNINGS) - add_definitions(-DWIN32_LEAN_AND_MEAN) - add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE) - add_definitions(-D_WINSOCK_DEPRECATED_NO_WARNINGS=1) - add_definitions(-D_WIN32_WINNT=0x0600) - add_definitions(-D_UNICODE) - add_definitions(-DUNICODE) - add_compile_options(-MP) - if(DEFINED DSN_PEDANTIC) - add_compile_options(-WX) + if(CMAKE_BUILD_TYPE STREQUAL "Debug") + add_definitions(-D_DEBUG) + add_definitions(-DDSN_BUILD_TYPE=Debug) + else() + add_definitions(-g) + add_definitions(-O2) + add_definitions(-DDSN_BUILD_TYPE=Release) + endif() + cmake_host_system_information(RESULT BUILD_HOSTNAME QUERY HOSTNAME) + add_definitions(-DDSN_BUILD_HOSTNAME=${BUILD_HOSTNAME}) + add_definitions(-D__STDC_FORMAT_MACROS) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1y" CACHE STRING "" FORCE) + add_compile_options(-Wall) + add_compile_options(-Werror) + add_compile_options(-Wno-sign-compare) + add_compile_options(-Wno-strict-aliasing) + add_compile_options(-Wuninitialized) + add_compile_options(-Wno-unused-result) + add_compile_options(-Wno-unused-variable) + add_compile_options(-Wno-deprecated-declarations) + add_compile_options(-Wno-inconsistent-missing-override) + + find_program(CCACHE_FOUND ccache) + if(CCACHE_FOUND) + set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache) + set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache) + if ("${COMPILER_FAMILY}" STREQUAL "clang") + add_compile_options(-Qunused-arguments) endif() - endif() + message("use ccache to speed up compilation") + endif(CCACHE_FOUND) + + set(CMAKE_EXE_LINKER_FLAGS + "${CMAKE_EXE_LINKER_FLAGS} -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free" + CACHE + STRING + "" + FORCE) + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free" + CACHE + STRING + "" + FORCE) endfunction(dsn_setup_compiler_flags) macro(ms_setup_boost STATIC_LINK PACKAGES BOOST_LIBS) @@ -456,14 +311,9 @@ macro(ms_setup_boost STATIC_LINK PACKAGES BOOST_LIBS) message(STATUS "BOOST_PACKAGES = ${PACKAGES}") endif() - set(Boost_USE_MULTITHREADED ON) - if(MSVC)#${STATIC_LINK}) - set(Boost_USE_STATIC_LIBS ON) - set(Boost_USE_STATIC_RUNTIME ON) - else() - set(Boost_USE_STATIC_LIBS OFF) - set(Boost_USE_STATIC_RUNTIME OFF) - endif() + set(Boost_USE_MULTITHREADED ON) + set(Boost_USE_STATIC_LIBS OFF) + set(Boost_USE_STATIC_RUNTIME OFF) find_package(Boost COMPONENTS ${PACKAGES} REQUIRED) @@ -479,57 +329,40 @@ macro(ms_setup_boost STATIC_LINK PACKAGES BOOST_LIBS) set(${BOOST_LIBS} ${TEMP_LIBS}) endmacro(ms_setup_boost) +# find necessary system libs function(dsn_setup_packages) - if(UNIX) - set(CMAKE_THREAD_PREFER_PTHREAD TRUE) - endif() find_package(Threads REQUIRED) set(DSN_SYSTEM_LIBS "") - if(UNIX AND (NOT APPLE)) - find_library(DSN_LIB_RT NAMES rt) - if(DSN_LIB_RT STREQUAL "DSN_LIB_RT-NOTFOUND") - message(FATAL_ERROR "Cannot find library rt") - endif() - set(DSN_SYSTEM_LIBS ${DSN_SYSTEM_LIBS} ${DSN_LIB_RT}) - endif() - - if(CMAKE_SYSTEM_NAME STREQUAL "Linux") - find_library(DSN_LIB_AIO NAMES aio) - if(DSN_LIB_AIO STREQUAL "DSN_LIB_AIO-NOTFOUND") - message(FATAL_ERROR "Cannot find library aio") - endif() - set(DSN_SYSTEM_LIBS ${DSN_SYSTEM_LIBS} ${DSN_LIB_AIO}) + find_library(DSN_LIB_RT NAMES rt) + if(DSN_LIB_RT STREQUAL "DSN_LIB_RT-NOTFOUND") + message(FATAL_ERROR "Cannot find library rt") endif() + set(DSN_SYSTEM_LIBS ${DSN_SYSTEM_LIBS} ${DSN_LIB_RT}) - if((CMAKE_SYSTEM_NAME STREQUAL "Linux")) - find_library(DSN_LIB_DL NAMES dl) - if(DSN_LIB_DL STREQUAL "DSN_LIB_DL-NOTFOUND") - message(FATAL_ERROR "Cannot find library dl") - endif() - set(DSN_SYSTEM_LIBS ${DSN_SYSTEM_LIBS} ${DSN_LIB_DL}) + find_library(DSN_LIB_AIO NAMES aio) + if(DSN_LIB_AIO STREQUAL "DSN_LIB_AIO-NOTFOUND") + message(FATAL_ERROR "Cannot find library aio") endif() + set(DSN_SYSTEM_LIBS ${DSN_SYSTEM_LIBS} ${DSN_LIB_AIO}) - if((CMAKE_SYSTEM_NAME STREQUAL "Linux")) - find_library(DSN_LIB_CRYPTO NAMES crypto) - if(DSN_LIB_CRYPTO STREQUAL "DSN_LIB_CRYPTO-NOTFOUND") - message(FATAL_ERROR "Cannot find library crypto") - endif() - set(DSN_SYSTEM_LIBS ${DSN_SYSTEM_LIBS} ${DSN_LIB_CRYPTO}) + find_library(DSN_LIB_DL NAMES dl) + if(DSN_LIB_DL STREQUAL "DSN_LIB_DL-NOTFOUND") + message(FATAL_ERROR "Cannot find library dl") endif() + set(DSN_SYSTEM_LIBS ${DSN_SYSTEM_LIBS} ${DSN_LIB_DL}) - if((CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")) - find_library(DSN_LIB_UTIL NAMES util) - if(DSN_LIB_UTIL STREQUAL "DSN_LIB_UTIL-NOTFOUND") - message(FATAL_ERROR "Cannot find library util") - endif() - set(DSN_SYSTEM_LIBS ${DSN_SYSTEM_LIBS} ${DSN_LIB_UTIL}) + # TODO(wutao1): maybe we do not need this? + find_library(DSN_LIB_CRYPTO NAMES crypto) + if(DSN_LIB_CRYPTO STREQUAL "DSN_LIB_CRYPTO-NOTFOUND") + message(FATAL_ERROR "Cannot find library crypto") endif() + set(DSN_SYSTEM_LIBS ${DSN_SYSTEM_LIBS} ${DSN_LIB_CRYPTO}) set(DSN_SYSTEM_LIBS ${DSN_SYSTEM_LIBS} - ${CMAKE_THREAD_LIBS_INIT} + ${CMAKE_THREAD_LIBS_INIT} # the thread library found by FindThreads CACHE STRING "rDSN system libs" FORCE ) endfunction(dsn_setup_packages) @@ -553,7 +386,6 @@ function(dsn_setup_include_path) else() include_directories(${DSN_ROOT}/include) include_directories(${DSN_ROOT}/include/dsn/cpp/serialization_helper) - include_directories(${DSN_ROOT}/include/ext) include_directories(${DSN_THIRDPARTY_ROOT}/include) endif() endfunction(dsn_setup_include_path) @@ -573,62 +405,15 @@ function(dsn_setup_install) install(DIRECTORY include/ DESTINATION include) install(DIRECTORY bin/ DESTINATION bin USE_SOURCE_PERMISSIONS) install(DIRECTORY ${PROJECT_BINARY_DIR}/lib/ DESTINATION lib) - #if(MSVC) - # install(FILES "bin/dsn.cg.bat" DESTINATION bin) - #else() - # install(PROGRAMS "bin/dsn.cg.sh" DESTINATION bin) - # install(PROGRAMS "bin/Linux/thrift" DESTINATION bin/Linux) - # install(PROGRAMS "bin/Linux/protoc" DESTINATION bin/Linux) - # install(PROGRAMS "bin/Darwin/thrift" DESTINATION bin/Darwin) - # install(PROGRAMS "bin/Darwin/protoc" DESTINATION bin/Darwin) - # install(PROGRAMS "bin/FreeBSD/thrift" DESTINATION bin/FreeBSD) - # install(PROGRAMS "bin/FreeBSD/protoc" DESTINATION bin/FreeBSD) - #endif() endif() endfunction(dsn_setup_install) -function(dsn_make_source_group_by_subdir GROUP_PREFIX SOURCE_LIST) - if(GROUP_PREFIX STREQUAL "") - # Assume that the source file path starts with ${CMAKE_CURRENT_SOURCE_DIR} - set(GROUP_PREFIX "${CMAKE_CURRENT_SOURCE_DIR}") - endif() - string(REPLACE "/" "\\" GROUP_PREFIX "${GROUP_PREFIX}/") - string(LENGTH "${GROUP_PREFIX}" GROUP_PREFIX_LENGTH) - foreach(SRC_FILE IN LISTS SOURCE_LIST) - get_filename_component(SRC_PATH "${SRC_FILE}" PATH) - string(REPLACE "/" "\\" SRC_PATH "${SRC_PATH}") - string(FIND "${SRC_PATH}" "${GROUP_PREFIX}" IDX) - # IDX != 0 means that either the source file is not in ${CMAKE_CURRENT_SOURCE_DIR} - # , or it is in the root of ${CMAKE_CURRENT_SOURCE_DIR}. - set(GROUP_NAME "") - if(IDX EQUAL 0) - #math(EXPR IDX "${IDX} + ${prefix_len}") - string(SUBSTRING "${SRC_PATH}" "${GROUP_PREFIX_LENGTH}" -1 GROUP_NAME) - endif() - source_group("${GROUP_NAME}" FILES "${SRC_FILE}") - endforeach() -endfunction(dsn_make_source_group_by_subdir) - -function(dsn_add_pseudo_projects) - if(DSN_BUILD_RUNTIME AND MSVC_IDE) - file(GLOB_RECURSE - PROJ_SRC - "${CMAKE_SOURCE_DIR}/include/dsn/*.h" - "${CMAKE_SOURCE_DIR}/include/dsn/*.hpp" - ) - dsn_make_source_group_by_subdir("${CMAKE_SOURCE_DIR}/include/dsn" "${PROJ_SRC}") - add_custom_target("dsn.include" SOURCES ${PROJ_SRC}) - endif() -endfunction(dsn_add_pseudo_projects) - function(dsn_common_setup) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__FILENAME__='\"$(notdir $(abspath $<))\"'") - if(NOT WIN32) - execute_process(COMMAND sh -c "rm -rf ${CMAKE_SOURCE_DIR}/.matchfile") - endif() + execute_process(COMMAND sh -c "rm -rf ${CMAKE_SOURCE_DIR}/.matchfile") - if(NOT (UNIX OR WIN32)) - message(FATAL_ERROR "Only Unix and Windows are supported.") + if(NOT (UNIX)) + message(FATAL_ERROR "Only Unix are supported.") endif() if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR) @@ -647,7 +432,13 @@ function(dsn_common_setup) endif() set(BUILD_SHARED_LIBS OFF) - ms_check_cxx11_support() + + include(CheckCXXCompilerFlag) + CHECK_CXX_COMPILER_FLAG("-std=c++1y" COMPILER_SUPPORTS_CXX1Y) + if(NOT ${COMPILER_SUPPORTS_CXX11}) + message(FATAL_ERROR "You need a compiler with C++1y support.") + endif() + dsn_setup_packages() dsn_setup_compiler_flags() dsn_setup_include_path() diff --git a/compile_thrift.py b/compile_thrift.py index bee2327031..7a1b09e377 100755 --- a/compile_thrift.py +++ b/compile_thrift.py @@ -134,13 +134,8 @@ def __str__(self): return self.msg def init_env(): - if platform.system() == "Windows": - env_tools["dsn_gentool"] = os.getcwd() + "/bin/dsn.cg.bat" - env_tools["thrift_exe"] = os.getcwd() + "/bin/Windows/thrift.exe" - else: - env_tools["dsn_gentool"] = os.getcwd() + "/bin/dsn.cg.sh" - env_tools["thrift_exe"] = os.getcwd() + "/bin/Linux/thrift" - env_tools["root_dir"] = os.getcwd() + env_tools["dsn_gentool"] = os.getcwd() + "/bin/dsn.cg.sh" + env_tools["thrift_exe"] = os.getcwd() + "/bin/Linux/thrift" def find_struct_define(line, enum_class_list): if len(line)<7 or line[0:7] != "struct ": diff --git a/src/dist/replication/test/meta_test/unit_test/CMakeLists.txt b/src/dist/replication/test/meta_test/unit_test/CMakeLists.txt index 6b353dd8a7..9ab2c6ef1e 100644 --- a/src/dist/replication/test/meta_test/unit_test/CMakeLists.txt +++ b/src/dist/replication/test/meta_test/unit_test/CMakeLists.txt @@ -9,7 +9,7 @@ set(MY_PROJ_SRC ../misc/misc.cpp) # "GLOB" for non-recursive search set(MY_SRC_SEARCH_MODE "GLOB") -ms_find_source_files("CXX" "${CMAKE_CURRENT_SOURCE_DIR}/../../../meta_server" "GLOB" MY_PROJ_SRC) +ms_find_source_files("${CMAKE_CURRENT_SOURCE_DIR}/../../../meta_server" "GLOB" MY_PROJ_SRC) set(MY_PROJ_INC_PATH "")