2023-11-22 14:57:39 +08:00
|
|
|
#cmake_minimum_required(VERSION 3.2.0)
|
|
|
|
cmake_minimum_required(VERSION 2.8.0)
|
2023-03-27 20:48:27 +08:00
|
|
|
project(acl)
|
2017-02-12 21:39:38 +08:00
|
|
|
|
|
|
|
#set(CMAKE_BUILD_TYPE Release)
|
|
|
|
#set(CMAKE_BUILD_TYPE Release CACHE STRING "set build type to release")
|
|
|
|
|
|
|
|
#message(project_dir=${PROJECT_SOURCE_DIR})
|
|
|
|
|
|
|
|
if (${CMAKE_BINARY_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
|
|
|
|
message(FATAL_ERROR "Please into another dir to build!")
|
|
|
|
endif()
|
|
|
|
|
2017-03-25 23:05:44 +08:00
|
|
|
if (CMAKE_SYSTEM_NAME MATCHES "Android")
|
2019-10-17 16:39:52 +08:00
|
|
|
# xxx: -flto can't be used on NDK with gnustl_shared
|
|
|
|
if (ANDROID_STL MATCHES "gnustl_shared")
|
2020-03-23 22:30:47 +08:00
|
|
|
add_definitions("-Oz -g -DHAVE_NO_ATEXIT")
|
2019-10-17 16:39:52 +08:00
|
|
|
else()
|
|
|
|
add_definitions("-O3 -flto")
|
2020-06-28 15:52:24 +08:00
|
|
|
if (HAS_ATOMIC MATCHES "YES")
|
|
|
|
add_definitions("-DHAS_ATOMIC")
|
|
|
|
endif()
|
2019-10-17 16:39:52 +08:00
|
|
|
endif()
|
2017-02-12 21:39:38 +08:00
|
|
|
add_definitions("-DANDROID")
|
2019-09-19 09:00:59 +08:00
|
|
|
add_definitions("-DACL_CLIENT_ONLY")
|
2020-05-13 15:42:50 +08:00
|
|
|
# add_definitions("-Wno-invalid-source-encoding")
|
2019-09-30 14:19:27 +08:00
|
|
|
add_definitions("-fdata-sections -ffunction-sections")
|
2019-09-24 15:01:27 +08:00
|
|
|
add_definitions("-Wno-unused-command-line-argument")
|
2019-10-17 16:39:52 +08:00
|
|
|
string(APPEND CMAKE_C_FLAGS "-Qunused-arguments")
|
2017-03-31 23:04:16 +08:00
|
|
|
set(UNIX_OS true)
|
2017-03-25 23:05:44 +08:00
|
|
|
elseif (CMAKE_SYSTEM_NAME MATCHES "Linux")
|
2019-09-18 17:10:49 +08:00
|
|
|
add_definitions("-O2")
|
2019-09-19 09:00:59 +08:00
|
|
|
set(UNIX_OS true)
|
2017-03-25 23:05:44 +08:00
|
|
|
elseif (CMAKE_SYSTEM_NAME MATCHES "Darwin")
|
2019-09-19 09:00:59 +08:00
|
|
|
add_definitions("-O3")
|
|
|
|
add_definitions("-Wno-invalid-source-encoding")
|
2019-09-30 11:46:56 +08:00
|
|
|
add_definitions("-fdata-sections -ffunction-sections")
|
|
|
|
add_definitions("-flto")
|
|
|
|
add_definitions("-Os")
|
2017-03-31 23:04:16 +08:00
|
|
|
set(UNIX_OS true)
|
2017-07-11 15:18:41 +08:00
|
|
|
elseif (CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
|
2019-09-18 17:10:49 +08:00
|
|
|
add_definitions("-O2")
|
2019-09-19 09:00:59 +08:00
|
|
|
set(UNIX_OS true)
|
2017-03-31 23:04:16 +08:00
|
|
|
elseif (CMAKE_SYSTEM_NAME MATCHES "Windows")
|
2019-09-30 14:59:26 +08:00
|
|
|
set(CMAKE_SHARED_LINKER_FLAGS "/DYNAMICBASE ws2_32.lib IPHlpApi.lib")
|
2017-03-31 23:04:16 +08:00
|
|
|
set(WIN_OS true)
|
2017-02-12 21:39:38 +08:00
|
|
|
else()
|
|
|
|
message(FATAL_ERROR "unknown CMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME}")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
##############################################################################
|
|
|
|
|
|
|
|
include_directories(
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/include
|
|
|
|
)
|
|
|
|
|
2017-03-31 23:04:16 +08:00
|
|
|
set(src ${CMAKE_CURRENT_SOURCE_DIR}/src)
|
2017-02-12 21:39:38 +08:00
|
|
|
set(sources
|
2017-03-31 23:04:16 +08:00
|
|
|
${src}
|
2017-02-12 21:39:38 +08:00
|
|
|
${src}/stdlib
|
|
|
|
${src}/stdlib/debug
|
|
|
|
${src}/stdlib/memory
|
|
|
|
${src}/stdlib/filedir
|
|
|
|
${src}/stdlib/string
|
|
|
|
${src}/stdlib/common
|
|
|
|
${src}/stdlib/sys
|
|
|
|
${src}/stdlib/sys/unix
|
|
|
|
${src}/stdlib/configure
|
|
|
|
${src}/stdlib/iostuff
|
|
|
|
${src}/aio
|
|
|
|
${src}/code
|
|
|
|
${src}/db
|
|
|
|
${src}/db/memdb
|
|
|
|
${src}/db/mysql
|
|
|
|
${src}/db/null
|
|
|
|
${src}/db/zdb
|
|
|
|
${src}/event
|
|
|
|
${src}/init
|
|
|
|
${src}/ioctl
|
|
|
|
${src}/json
|
|
|
|
${src}/master
|
|
|
|
${src}/master/template
|
|
|
|
${src}/msg
|
|
|
|
${src}/net
|
|
|
|
${src}/net/dns
|
|
|
|
${src}/net/connect
|
|
|
|
${src}/net/listen
|
|
|
|
${src}/private
|
|
|
|
${src}/thread
|
|
|
|
${src}/unit_test
|
|
|
|
${src}/xml
|
|
|
|
)
|
|
|
|
|
|
|
|
foreach(iter ${sources})
|
|
|
|
aux_source_directory(${iter} lib_src)
|
|
|
|
endforeach()
|
|
|
|
|
2017-03-31 23:04:16 +08:00
|
|
|
##############################################################################
|
|
|
|
|
2019-09-06 11:27:36 +08:00
|
|
|
#if (CMAKE_BUILD_TYPE STREQUAL "")
|
|
|
|
# set(CMAKE_BUILD_TYPE "DEBUG")
|
|
|
|
#else()
|
|
|
|
# string(TOUPPER CMAKE_BUILD_TYPE CMAKE_BUILD_TYPE)
|
|
|
|
#endif()
|
2017-03-31 23:04:16 +08:00
|
|
|
|
|
|
|
if (${UNIX_OS})
|
|
|
|
add_definitions(
|
|
|
|
"-W"
|
|
|
|
"-fPIC"
|
|
|
|
"-Wall"
|
|
|
|
"-Werror"
|
|
|
|
"-Wshadow"
|
|
|
|
"-Wpointer-arith"
|
|
|
|
"-Waggregate-return"
|
|
|
|
"-Wmissing-prototypes"
|
|
|
|
"-D_REENTRANT"
|
|
|
|
"-D_USE_FAST_MACRO"
|
|
|
|
"-DACL_WRITEABLE_CHECK"
|
|
|
|
"-Wno-long-long"
|
|
|
|
"-Wuninitialized"
|
|
|
|
"-D_POSIX_PTHREAD_SEMANTICS"
|
|
|
|
"-DACL_PREPARE_COMPILE"
|
|
|
|
"-Wstrict-prototypes"
|
|
|
|
)
|
|
|
|
|
2018-08-08 14:05:29 +08:00
|
|
|
if (CMAKE_COMPILER_IS_GNUCC)
|
2021-01-28 18:34:03 +08:00
|
|
|
execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpfullversion -dumpversion
|
2018-08-08 14:05:29 +08:00
|
|
|
OUTPUT_VARIABLE GCC_VERSION)
|
|
|
|
string(REGEX MATCHALL "[0-9]+" GCC_VERSION_COMPONENTS ${GCC_VERSION})
|
|
|
|
list(GET GCC_VERSION_COMPONENTS 0 GCC_MAJOR)
|
|
|
|
list(GET GCC_VERSION_COMPONENTS 1 GCC_MINOR)
|
|
|
|
|
2020-05-13 00:01:46 +08:00
|
|
|
message(STATUS "cmake version=${CMAKE_VERSION}")
|
|
|
|
|
|
|
|
set(GCC_VERSION "${GCC_MAJOR}.${GCC_MINOR}")
|
|
|
|
message(STATUS "gcc version=${GCC_VERSION}")
|
|
|
|
|
|
|
|
if (GCC_VERSION GREATER "4.7")
|
|
|
|
message(STATUS "gcc version major=${GCC_MAJOR}")
|
|
|
|
message(STATUS "gcc version minor=${GCC_MINOR}")
|
|
|
|
add_definitions("-Wno-implicit-fallthrough")
|
2018-08-08 14:05:29 +08:00
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2019-09-18 17:10:49 +08:00
|
|
|
if (!CMAKE_BUILD_TYPE STREQUAL "RELEASE")
|
2017-03-31 23:04:16 +08:00
|
|
|
add_definitions("-g")
|
|
|
|
endif()
|
|
|
|
elseif (${WIN_OS})
|
|
|
|
add_definitions(
|
|
|
|
"-Yc"
|
2018-03-30 14:35:34 +08:00
|
|
|
"-D_WINSOCK_DEPRECATED_NO_WARNINGS"
|
2017-03-31 23:04:16 +08:00
|
|
|
"-DACL_WRITEABLE_CHECK"
|
|
|
|
"-DACL_PREPARE_COMPILE")
|
|
|
|
endif()
|
|
|
|
|
2019-06-28 10:54:27 +08:00
|
|
|
if (ACL_CLIENT_ONLY MATCHES "YES")
|
|
|
|
add_definitions("-DACL_CLIENT_ONLY")
|
|
|
|
message(STATUS "acl: ACL_CLIENT_ONLY been set")
|
|
|
|
endif()
|
|
|
|
|
2017-03-25 23:05:44 +08:00
|
|
|
if (CMAKE_SYSTEM_NAME MATCHES "Android")
|
2019-08-27 15:18:31 +08:00
|
|
|
set(lib_output_path ${CMAKE_CURRENT_SOURCE_DIR}/../android/lib/${ANDROID_ABI})
|
2017-03-25 23:05:44 +08:00
|
|
|
else()
|
2023-04-17 16:28:35 +08:00
|
|
|
set(lib_output_path ${PROJECT_BINARY_DIR}/../lib)
|
2019-09-30 14:59:26 +08:00
|
|
|
endif()
|
|
|
|
|
|
|
|
set(LIBRARY_OUTPUT_PATH ${lib_output_path})
|
|
|
|
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${lib_output_path})
|
|
|
|
|
|
|
|
add_library(acl_static STATIC ${lib_src})
|
2022-07-10 20:13:15 +08:00
|
|
|
|
|
|
|
if (${WIN_OS})
|
|
|
|
SET_TARGET_PROPERTIES(acl_static PROPERTIES OUTPUT_NAME "libacl")
|
|
|
|
else()
|
|
|
|
SET_TARGET_PROPERTIES(acl_static PROPERTIES OUTPUT_NAME "acl")
|
|
|
|
endif()
|
|
|
|
|
2019-09-30 14:59:26 +08:00
|
|
|
link_directories(${lib_output_path})
|
2019-09-30 14:19:27 +08:00
|
|
|
|
2020-09-27 23:35:04 +08:00
|
|
|
if (NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR AND ACL_BUILD_SHARED MATCHES "YES")
|
|
|
|
if (CMAKE_SYSTEM_NAME MATCHES "Android")
|
|
|
|
if (ANDROID_STL MATCHES "gnustl_shared")
|
|
|
|
set(sys_ldflags "-shared")
|
|
|
|
else()
|
|
|
|
set(sys_ldflags "-shared -flto")
|
|
|
|
endif()
|
|
|
|
target_compile_options(acl_static PRIVATE -fvisibility=hidden)
|
|
|
|
elseif (${UNIX_OS})
|
|
|
|
set(sys_ldflags "-shared -lpthread -ldl")
|
|
|
|
target_compile_options(acl_static PRIVATE -fvisibility=hidden)
|
2019-10-17 16:39:52 +08:00
|
|
|
endif()
|
2017-02-12 21:39:38 +08:00
|
|
|
|
2020-09-27 23:35:04 +08:00
|
|
|
set(CMAKE_SHARED_LINKER_FLAGS "${sys_ldflags}")
|
2019-10-17 16:58:44 +08:00
|
|
|
add_library(acl SHARED ${lib_src})
|
|
|
|
endif()
|
2017-02-12 21:39:38 +08:00
|
|
|
|
|
|
|
##############################################################################
|